npmlock2nix
npmlock2nix copied to clipboard
Introduce preInstallCustomCommands attribute for node modules
Fixes #70 - introduce new node_modules attribute: preInstallCustomCommands
.
It allows for execution of arbitrary shell scripts, running per node module pinned to given version - such approach, allows for fixing node modules which would otherwise be unfit for running on NixOS
Proposal: Make preInstallCustomCommands
a function instead. This would be more flexible in terms of what a user wants to execute.
Example:
preInstallCustomCommands = package_name: version: if package_name = "foo" && version == "bar" then "exit 123" else null;
In addition to @andir 's suggestion there would also have to be some tests for this new feature. Please have a look at the existing ones and see if you can figure out how to write one in the same way.
I have made the preInstallCustomCommands
a function.
However, I have not followed the suggested signature, as to the best of my understanding, the node module name & version are not available during the nix expression evaluation. Keeping the function as generic as possible, also helps in retaining the flexibility for the end user.
I am very interested into this solution as esbuild
seems to be ~broken (cf #128)
With NPM 7, hook scripts, which this PR relies on, are not supported anymore, see also https://github.com/nix-community/npmlock2nix/issues/110. However with #151 it will become possible to patch the sources of arbitrary packages, which should cover mostly the same use cases as hook scripts. @AleksanderGondek Could you try out #151 and see if that can be used for your use cases?