Skip to content

Conversation

@thomasjm
Copy link
Contributor

I needed to do this so that a call to node-gyp-build would work in one of my dependencies.

Sometimes a dependency comes with an executable script, which ultimately gets symlinked into node_modules/.bin. The existing patchShebangs call at the beginning of prepareAndInvokeNPM doesn't always catch these, because they don't always have the executable bit set. As a result, you get a failure in the Nix build because /usr/bin/env node doesn't exist.

So, this PR uses jq to traverse the bin field of package.json, turning these files executable and patching them as necessary.

This PR also exposes the preRebuild hook for buildNodeDependencies, and by extension for the shell attribute. I think this will resolve #226.

, dontNpmInstall ? false
, bypassCache ? false
, reconstructLock ? false
, preRebuild ? ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this parameter removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? It was missing before and it looked like an oversight so I added it. I think this will resolve #226.

# Change to the package directory to install dependencies
cd "$DIR/$packageName"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this can be rewritten in JavaScript code and executed by Node.js. This is what we do in other pieces of the script as well.

Otherwise, we need to introduce yet another build-time dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I like processing things with jq this way because it's so fast. If you consider the amount of NPM packages that need to get downloaded on a typical build, downloading a copy of jq seems like the least of one's problems :P

@svanderburg
Copy link
Owner

I've implemented my own implementation that does not rely on jq or examining the package.json config. I think this should work because references in bin/ always resolve to paths installed in the same output Nix store path.

I'm still validating whether this does not introduce new problems.

@pmiddend
Copy link

I was able to package my npm-based piece of software only with this patch. Would be great to have this merged!

@thomasjm
Copy link
Contributor Author

thomasjm commented Apr 7, 2023

Just wanted to check @svanderburg, is this fixed now? I'll close the PR if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preRebuild equivalent for buildNodeShell

3 participants