nix-community / npmlock2nix

nixify npm based packages [maintainer=@andir]
Apache License 2.0
130 stars 42 forks source link

bug: patchShebangs fails when files are not executable #106

Open milahu opened 3 years ago

milahu commented 3 years ago

package.json

{
  "name": "npmlock2nix-bug-patchshebangs",
  "version": "1.0.0",
  "scripts": {
    "install": "cross-env echo hello"
  },
  "dependencies": {
    "cross-env": "*"
  }
}

error

sh: /build/node_modules/.bin/cross-env: /usr/bin/env: bad interpreter: No such file or directory

/build/node_modules/.bin/cross-env is a symlink to /build/node_modules/cross-env/src/bin/cross-env.js

the source file cross-env/src/bin/cross-env.js is NOT patched by patchShebangs (find "$@" -type f -perm -0100) because it is not executable (file mode 0644)

solutions

in the preinstall hook, add

# patchShebangs will patch only executable files
cat package.json | jq -r '. | select(.bin != null) | .bin | values[]' \
  | while read binTarget; do chmod +x "$binTarget"; done

maybe avoid jq and use nix to extract a list of binTargets no, this concerns dependencies, where we dont have the json files parsed into nix