nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 70 lines 2.1 kB view raw
1# shellcheck shell=bash 2 3npmConfigHook() { 4 echo "Executing npmConfigHook" 5 6 if [ -n "${npmRoot-}" ]; then 7 pushd "$npmRoot" 8 fi 9 10 if [ -z "${npmDeps-}" ]; then 11 echo "Error: 'npmDeps' should be set when using npmConfigHook." 12 exit 1 13 fi 14 15 echo "Configuring npm" 16 17 export HOME="$TMPDIR" 18 export npm_config_nodedir="@nodeSrc@" 19 export npm_config_node_gyp="@nodeGyp@" 20 npm config set offline true 21 npm config set progress false 22 npm config set fund false 23 24 echo "Installing patched package.json/package-lock.json" 25 26 # Save original package.json/package-lock.json for closure size reductions. 27 # The patched one contains store paths we don't want at runtime. 28 mv package.json .package.json.orig 29 if test -f package-lock.json; then # Not all packages have package-lock.json. 30 mv package-lock.json .package-lock.json.orig 31 fi 32 cp --no-preserve=mode "${npmDeps}/package.json" package.json 33 cp --no-preserve=mode "${npmDeps}/package-lock.json" package-lock.json 34 35 echo "Installing dependencies" 36 37 if ! npm install --ignore-scripts $npmInstallFlags "${npmInstallFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then 38 echo 39 echo "ERROR: npm failed to install dependencies" 40 echo 41 echo "Here are a few things you can try, depending on the error:" 42 echo '1. Set `npmFlags = [ "--legacy-peer-deps" ]`' 43 echo 44 45 exit 1 46 fi 47 48 patchShebangs node_modules 49 50 npm rebuild $npmRebuildFlags "${npmRebuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}" 51 52 patchShebangs node_modules 53 54 # Canonicalize symlinks from relative paths to the Nix store. 55 node @canonicalizeSymlinksScript@ @storePrefix@ 56 57 # Revert to pre-patched package.json/package-lock.json for closure size reductions 58 mv .package.json.orig package.json 59 if test -f ".package-lock.json.orig"; then 60 mv .package-lock.json.orig package-lock.json 61 fi 62 63 if [ -n "${npmRoot-}" ]; then 64 popd 65 fi 66 67 echo "Finished npmConfigHook" 68} 69 70postConfigureHooks+=(npmConfigHook)