-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
fix: patchShebangs in nonexecutable bin files (#106) #107
base: master
Are you sure you want to change the base?
Changes from 2 commits
98c359b
a306d45
a75e8bc
48b2eaf
8c9b89b
40e09df
ff6d44a
60b003c
de6d2c6
99370e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||
{ nodejs, stdenv, mkShell, lib, fetchurl, writeText, writeTextFile, runCommand, fetchFromGitHub }: | ||||||||||
{ nodejs, stdenv, mkShell, lib, fetchurl, writeText, writeTextFile, runCommand, fetchFromGitHub, jq }: | ||||||||||
rec { | ||||||||||
default_nodejs = nodejs; | ||||||||||
|
||||||||||
|
@@ -331,6 +331,9 @@ rec { | |||||||||
|
||||||||||
${preInstallLinkCommands} | ||||||||||
|
||||||||||
jq -r '. | select(.bin != null) | .bin | values[]' package.json | while read binTarget; do | ||||||||||
chmod +x "$binTarget" # patchShebangs will only patch executable files | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should throw if binTarget is not found in my case: npmlock2nix.shell {
src = /tmp/package;
} the root package.json (/tmp/package/package.json) has a bin, or rather, npmlock2nix should ignore bin's for the root package (/tmp/package) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
even more, npmlock2nix.node_modules should ignore install scripts for the root package, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that so? I am not entirely sure that is true. Right now we do an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider this package.json {
"name": "root-package",
"version": "1",
"scripts": {
"postinstall": "node some/script.js"
},
"dependencies": {
"foo": "1.2.3"
}
} npmlock2nix has only two files for the root-package: package.json and package-lock.json these are symlinked to /build in npmlock2nix.node_modules Lines 365 to 368 in 33eb330
so the job of npmlock2nix.node_modules is only to populate node_modules |
||||||||||
done | ||||||||||
if grep -I -q -r '/bin/' .; then | ||||||||||
source $TMP/preinstall-env | ||||||||||
patchShebangs . | ||||||||||
|
@@ -348,6 +351,7 @@ rec { | |||||||||
|
||||||||||
nativeBuildInputs = nativeBuildInputs ++ [ | ||||||||||
nodejs | ||||||||||
jq | ||||||||||
]; | ||||||||||
|
||||||||||
propagatedBuildInputs = [ | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin
field could also have string as the value if there is a single executable1Currently, this
jq
expression doesn't seem to handle that case. I used something like'select(has("bin")) | .bin | if type == "string" then . else .[] end'
to handle that case. But this is the first time I wrotejq
expression, so it might be far from the optimal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really into maintaining jq expression.. I've done it once or twice but generally that isn't something that i want to maintain beyond a certain level of complexity.
How much effort would it be to rewrite this in a short nodejs script (without dependencies)? The conversaion so far makes me fear about any additional special cases that we will have to add in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jq is a standard tool for json manipulation, node feels like overkill for this
heh, not really ... there are three cases
the
bin
field ...all of these are handled
https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin