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

symlink for bin files when node-linker=hoisted #4782

Closed
alimo opened this issue May 23, 2022 · 2 comments · Fixed by #5048
Closed

symlink for bin files when node-linker=hoisted #4782

alimo opened this issue May 23, 2022 · 2 comments · Fixed by #5048
Assignees
Milestone

Comments

@alimo
Copy link

alimo commented May 23, 2022

Describe the user story

When using CodePush for React Native, the App Center CLI issues the following command to publish a new release:

node node_modules/.bin/react-native bundle ...

This command assumes the bin file is a JS file and can be executed with node. This is true when using npm or classic yarn. But with pnpm (as you have described in the limitations section of the docs), binstubs are shell files. So the following error happens:

/path/to/node_modules/.bin/react-native:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list

Providing an option to use symlinks instead of shell files for binstubs would solve this problem.

Describe the solution you'd like

Two solutions are possible:

  1. When using node-linker=hoisted in the .npmrc file, pnpm can automatically use symlinks instead of shell scripts to match more closely with npm and classic yarn behavior.
  2. Add a setting to .npmrc to opt-in for this feature.

Describe the drawbacks of your solution

Solution 1:

  • Some existing projects or scripts using node-linker=hoisted might rely on the binstubs being shell files.

Solution 2:

  • If node-linker is not set to hoisted, this setting could break bin files and scripts since NODE_PATH is not being set. (This could be solved by showing a warning/error to users)

Describe alternatives you've considered

I've worked around the issue described in the user story section by manually modifying the .bin/react-native file. But this change is temporary and will be overridden by pnpm.

@zkochan
Copy link
Member

zkochan commented May 23, 2022

I am not against such setting, but it would not work on Windows. Even npm uses command shims on Windows because executable symlinks are not allowed on Windows.

@alimo
Copy link
Author

alimo commented May 24, 2022

The "App Center CLI" I mentioned, treats Windows differently because of that. So if npm uses shims on Windows, pnpm could do the same.

I know what I'm asking for is very specific. But the goal here is to increase compatibility with npm. Which would benefit people (including me) porting their projects (like React Native ones) from npm/yarn to pnpm.

Although this whole issue isn't a blocker for me and the performance gain is much greater than the burden of manually changing a file every once in a while.

@zkochan zkochan self-assigned this Jul 17, 2022
zkochan added a commit that referenced this issue Jul 17, 2022
A new setting supported: `prefer-symlinked-executables`
When `true`, on Posix systems pnpm will create symlinks to executables in
`node_modules/.bin` instead of command shims.

This setting is `true` by default when `node-linker` is set to
`hoisted`.

close #4782
zkochan added a commit that referenced this issue Jul 18, 2022
A new setting supported: `prefer-symlinked-executables`
When `true`, on Posix systems pnpm will create symlinks to executables in
`node_modules/.bin` instead of command shims.

This setting is `true` by default when `node-linker` is set to
`hoisted`.

close #4782
@zkochan zkochan added this to the v7.6 milestone Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants