mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
9c7ff7277c
`importNpmLock.buildNodeModules` returns a derivation with a pre-built `node_modules` directory, as imported by `importNpmLock`. This is to be used together with `importNpmLock.hooks.linkNodeModulesHook` to facilitate `nix-shell`/`nix develop` based development workflows: ```nix pkgs.mkShell { packages = [ importNpmLock.hooks.linkNodeModulesHook nodejs ]; npmDeps = importNpmLock.buildNodeModules { npmRoot = ./.; inherit nodejs; }; } ``` will create a development shell where a `node_modules` directory is created & packages symlinked to the Nix store when activated. This code is adapted from https://github.com/adisbladis/buildNodeModules
32 lines
763 B
Bash
32 lines
763 B
Bash
linkNodeModulesHook() {
|
|
echo "Executing linkNodeModulesHook"
|
|
runHook preShellHook
|
|
|
|
if [ -n "${npmRoot-}" ]; then
|
|
pushd "$npmRoot"
|
|
fi
|
|
|
|
@nodejs@ @script@ @storePrefix@ "${npmDeps}/node_modules"
|
|
if test -f node_modules/.bin; then
|
|
export PATH=$(readlink -f node_modules/.bin):$PATH
|
|
fi
|
|
|
|
if [ -n "${npmRoot-}" ]; then
|
|
popd
|
|
fi
|
|
|
|
runHook postShellHook
|
|
echo "Finished executing linkNodeModulesShellHook"
|
|
}
|
|
|
|
if [ -z "${dontLinkNodeModules:-}" ] && [ -z "${shellHook-}" ]; then
|
|
echo "Using linkNodeModulesHook shell hook"
|
|
shellHook=linkNodeModulesHook
|
|
fi
|
|
|
|
|
|
if [ -z "${dontLinkNodeModules:-}" ]; then
|
|
echo "Using linkNodeModulesHook preConfigure hook"
|
|
preConfigureHooks+=(linkNodeModulesHook)
|
|
fi
|