npmlock2nix icon indicating copy to clipboard operation
npmlock2nix copied to clipboard

Introduce preInstallCustomCommands attribute for node modules

Open AleksanderGondek opened this issue 3 years ago • 5 comments

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

AleksanderGondek avatar May 14 '21 12:05 AleksanderGondek

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;

andir avatar May 14 '21 13:05 andir

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.

gilligan avatar May 14 '21 13:05 gilligan

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.

AleksanderGondek avatar May 15 '21 21:05 AleksanderGondek

I am very interested into this solution as esbuild seems to be ~broken (cf #128)

RaitoBezarius avatar Dec 15 '21 12:12 RaitoBezarius

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?

infinisil avatar Mar 18 '22 19:03 infinisil