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] No way to shim a non-Node.js file #152

Open
1 task done
nex3 opened this issue Jul 29, 2024 · 0 comments
Open
1 task done

[BUG] No way to shim a non-Node.js file #152

nex3 opened this issue Jul 29, 2024 · 0 comments
Labels
Needs Triage needs an initial review

Comments

@nex3
Copy link

nex3 commented Jul 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The current shim behavior mostly works in a cross-platform way if the script you're providing is intended to run in Node.js specifically, because it's guaranteed that node.exe will be installed in the user's path on Windows. But it completely falls apart if you want to run anything else, such as a shell script (which can be very useful as a way to efficiently call out to another executable, for example).

I'm filing this as a bug because it's clearly the intention for the shim generation to support multiple different execution environments, since it has all this logic for sniffing the shebang. But that logic doesn't actually work. Let's say I have a shell script that starts with #!/bin/sh. Here's (the relevant part of) the shim that will be generate for Windows:

IF EXIST "%dp0%\/bin/bash.exe" (
  SET "_prog=%dp0%\/bin/bash.exe"
) ELSE (
  SET "_prog=/bin/bash"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

The first branch doesn't help because Bash isn't installed along with Node, and the second branch doesn't help either since Bash isn't going to be installed on the vast majority of Windows machines (and certainly won't be installed in /bin!).

Expected Behavior

Provide some way of supporting cross-platform executables that doesn't require spinning up a node.exe process. One easy option would be to detect the existence of $executable.cmd or $executable.ps1 scripts in the bin folder and call out to those; another would be to extend the package.json "bin" syntax to allow it to explicitly specify per-OS entrypoints.

Steps To Reproduce

  1. Create a package with "bin": "script", where script is:

    #!/bin/bash
    echo hello
  2. Run npm install -g . on Windows and observe that there's no way for shim to work correctly

Environment

N/A, based on reading code

@nex3 nex3 added the Needs Triage needs an initial review label Jul 29, 2024
nex3 added a commit to sass/embedded-host-node that referenced this issue Jul 30, 2024
This allows users to run `npx sass` when they've just installed
`sass-embedded` and directly run the Dart VM. Due to npm/cmd-shim#152,
there's no way to make this work on Windows CMD/Powershell without
substantially curtailing the performance on other operating systems.
nex3 added a commit to sass/embedded-host-node that referenced this issue Aug 1, 2024
This allows users to run `npx sass` when they've just installed
`sass-embedded` and directly run the Dart VM. Due to npm/cmd-shim#152,
there's no way to make this work on Windows CMD/Powershell without
substantially curtailing the performance on other operating systems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

1 participant