Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Yarn Berry does not support bash/shell scripts as binaries - unlike Yarn Classic, NPM, and PNPM #6668

Open
1 task
osuritz opened this issue Jan 28, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@osuritz
Copy link

osuritz commented Jan 28, 2025

Self-service

  • I'd be willing to implement a fix

Describe the bug

Hey folks,

I'm in the middle of upgrading some repos at work from Yarn Classic (1.x) to Yarn Berry (I've tested this with both the latest 3.x and 4.x)

We have some internal packages that expose "binaries" (via package.json > bin section) that are actually shell scripts. Some sanity checklist notes:

  1. These files have a "shebang" directives (either #!/bin/bash or #!/usr/bin/env bash)
  2. They are marked as executable (chmod +x)
  3. Invoking yarn bin {bin-name} correctly outputs the path to the actual script. To that effect, calling yarn bin {bin-name} | bash correctly executes the script correctly.

In Yarn Classic (1.x), NPM (v9 and v10), PNPM (v9 and v10), I'm able to invoke these shell-script binaries like so, respectively:

  • yarn {bin-name}
  • npc {bin-name}
  • ppm {bin-name}

I get the expected output. Cool.

In Yarn Berry (tested v3.x and v4.x), however, invoking the binary via yarn {bin-name} will yield a syntax error because it attempts to parse the binary as if were a JavaScript file.

I couldn't find documentation calling out this breaking change and justification is to why Yarn Berry would stop supporting shell-script based binaries when all other package managers support them.
There's an argument to be made that shell scripts aren't going to be as portable as JS-based files and all binaries should be either actual binaries or JS files but I think that's a separate discussion to the problem at hand.

To reproduce

// package.json
{
  ...
  "bin": {
    "foo": "./bin/my-foo"
  }
}
# bin/my-foo
#!/usr/bin/env bash

# Sample shell script file

echo "Hello World"
yarn install
yarn foo

Expected: ==> Hello World
Actual:

# Sample shell script file
^

SyntaxError: Invalid or unexpected token

Environment

System:
  OS: macOS 15.2 (although this occurs on Linux / GitHub Action linux as well)
  CPU: (12) x64 Apple M3 Pro
Binaries:
  Node: 20.12.1
  Yarn: 3.8.7
  npm: 10.5.0

Additional context

No response

@osuritz osuritz added the bug Something isn't working label Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant