npmHooks.npmInstallHook: extract npmInstall{Manuals,Executables}

+79 -25
+4 -1
pkgs/build-support/node/build-npm-package/hooks/default.nix
··· 7 7 , prefetch-npm-deps 8 8 , diffutils 9 9 , installShellFiles 10 + , nodejsInstallManuals 11 + , nodejsInstallExecutables 10 12 }: 11 13 12 14 { ··· 39 41 propagatedBuildInputs = [ 40 42 installShellFiles 41 43 makeWrapper 44 + nodejsInstallManuals 45 + nodejsInstallExecutables 42 46 ]; 43 47 substitutions = { 44 - hostNode = "${nodejs}/bin/node"; 45 48 jq = "${jq}/bin/jq"; 46 49 }; 47 50 } ./npm-install-hook.sh;
+2 -24
pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh
··· 14 14 cp "${npmWorkspace-.}/$file" "$dest" 15 15 done < <(@jq@ --raw-output '.[0].files | map(.path | select(. | startswith("node_modules/") | not)) | join("\n")' <<< "$(npm_config_cache="$HOME/.npm" npm pack --json --dry-run --loglevel=warn --no-foreground-scripts ${npmWorkspace+--workspace=$npmWorkspace} $npmPackFlags "${npmPackFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}")") 16 16 17 - # Based on code from Python's buildPythonPackage wrap.sh script, for 18 - # supporting both the case when makeWrapperArgs is an array and a 19 - # IFS-separated string. 20 - # 21 - # TODO: remove the string branch when __structuredAttrs are used. 22 - if [[ "${makeWrapperArgs+defined}" == "defined" && "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then 23 - local -a user_args=("${makeWrapperArgs[@]}") 24 - else 25 - local -a user_args="(${makeWrapperArgs:-})" 26 - fi 27 - while IFS=" " read -ra bin; do 28 - mkdir -p "$out/bin" 29 - makeWrapper @hostNode@ "$out/bin/${bin[0]}" --add-flags "$packageOut/${bin[1]}" "${user_args[@]}" 30 - done < <(@jq@ --raw-output '(.bin | type) as $typ | if $typ == "string" then 31 - .name + " " + .bin 32 - elif $typ == "object" then .bin | to_entries | map(.key + " " + .value) | join("\n") 33 - elif $typ == "null" then empty 34 - else "invalid type " + $typ | halt_error end' "${npmWorkspace-.}/package.json") 17 + nodejsInstallExecutables "${npmWorkspace-.}/package.json" 35 18 36 - while IFS= read -r man; do 37 - installManPage "$packageOut/$man" 38 - done < <(@jq@ --raw-output '(.man | type) as $typ | if $typ == "string" then .man 39 - elif $typ == "list" then .man | join("\n") 40 - elif $typ == "null" then empty 41 - else "invalid type " + $typ | halt_error end' "${npmWorkspace-.}/package.json") 19 + nodejsInstallManuals "${npmWorkspace-.}/package.json" 42 20 43 21 local -r nodeModulesPath="$packageOut/node_modules" 44 22
+27
pkgs/by-name/no/nodejsInstallExecutables/hook.sh
··· 1 + # shellcheck shell=bash 2 + 3 + nodejsInstallExecutables() { 4 + local -r packageJson="${1-./package.json}" 5 + 6 + local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' package.json)" 7 + 8 + # Based on code from Python's buildPythonPackage wrap.sh script, for 9 + # supporting both the case when makeWrapperArgs is an array and a 10 + # IFS-separated string. 11 + # 12 + # TODO: remove the string branch when __structuredAttrs are used. 13 + if [[ "${makeWrapperArgs+defined}" == "defined" && "$(declare -p makeWrapperArgs)" =~ ^'declare -a makeWrapperArgs=' ]]; then 14 + local -a user_args=("${makeWrapperArgs[@]}") 15 + else 16 + local -a user_args="(${makeWrapperArgs:-})" 17 + fi 18 + 19 + while IFS=" " read -ra bin; do 20 + mkdir -p "$out/bin" 21 + makeWrapper @hostNode@ "$out/bin/${bin[0]}" --add-flags "$packageOut/${bin[1]}" "${user_args[@]}" 22 + done < <(@jq@ --raw-output '(.bin | type) as $typ | if $typ == "string" then 23 + .name + " " + .bin 24 + elif $typ == "object" then .bin | to_entries | map(.key + " " + .value) | join("\n") 25 + elif $typ == "null" then empty 26 + else "invalid type " + $typ | halt_error end' "$packageJson") 27 + }
+19
pkgs/by-name/no/nodejsInstallExecutables/package.nix
··· 1 + { 2 + makeSetupHook, 3 + installShellFiles, 4 + makeWrapper, 5 + nodejs, 6 + jq, 7 + }: 8 + 9 + makeSetupHook { 10 + name = "nodejs-install-executables"; 11 + propagatedBuildInputs = [ 12 + installShellFiles 13 + makeWrapper 14 + ]; 15 + substitutions = { 16 + hostNode = "${nodejs}/bin/node"; 17 + jq = "${jq}/bin/jq"; 18 + }; 19 + } ./hook.sh
+14
pkgs/by-name/no/nodejsInstallManuals/hook.sh
··· 1 + # shellcheck shell=bash 2 + 3 + nodejsInstallManuals() { 4 + local -r packageJson="${1-./package.json}" 5 + 6 + local -r packageOut="$out/lib/node_modules/$(@jq@ --raw-output '.name' package.json)" 7 + 8 + while IFS= read -r man; do 9 + installManPage "$packageOut/$man" 10 + done < <(@jq@ --raw-output '(.man | type) as $typ | if $typ == "string" then .man 11 + elif $typ == "list" then .man | join("\n") 12 + elif $typ == "null" then empty 13 + else "invalid type " + $typ | halt_error end' "$packageJson") 14 + }
+13
pkgs/by-name/no/nodejsInstallManuals/package.nix
··· 1 + { 2 + makeSetupHook, 3 + installShellFiles, 4 + jq, 5 + }: 6 + 7 + makeSetupHook { 8 + name = "nodejs-install-manuals"; 9 + propagatedBuildInputs = [ installShellFiles ]; 10 + substitutions = { 11 + jq = "${jq}/bin/jq"; 12 + }; 13 + } ./hook.sh