diff options
author | Mario Rodas <marsam@users.noreply.github.com> | 2023-07-08 06:45:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-08 06:45:46 -0500 |
commit | 43b091f45cc5b058d3a237668ee227bdd43894c0 (patch) | |
tree | 65ae5b8dccdf9be6d44f3b5f5313e2cd99d1e655 /pkgs/build-support | |
parent | 793abdf061a55f904b127e3475d5aeff239d6408 (diff) | |
parent | 3990bb5b5ee89fa64a6a6b5a3e486bdabe7290b9 (diff) |
Merge pull request #233804 from lilyinstarlight/feature/npm-workspaces
buildNpmPackage: add npmWorkspace and npmPruneFlags args
Diffstat (limited to 'pkgs/build-support')
3 files changed, 10 insertions, 6 deletions
diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index 1c3fb6a74efca..357a0bd073228 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -22,7 +22,7 @@ , npmBuildScript ? "build" # Flags to pass to all npm commands. , npmFlags ? [ ] - # Flags to pass to `npm ci` and `npm prune`. + # Flags to pass to `npm ci`. , npmInstallFlags ? [ ] # Flags to pass to `npm rebuild`. , npmRebuildFlags ? [ ] @@ -30,6 +30,10 @@ , npmBuildFlags ? [ ] # Flags to pass to `npm pack`. , npmPackFlags ? [ ] + # Flags to pass to `npm prune`. +, npmPruneFlags ? npmInstallFlags + # Value for npm `--workspace` flag and directory in which the files to be installed are found. +, npmWorkspace ? null , ... } @ args: diff --git a/pkgs/build-support/node/build-npm-package/hooks/npm-build-hook.sh b/pkgs/build-support/node/build-npm-package/hooks/npm-build-hook.sh index b712e3a0543a2..c341f672363a4 100644 --- a/pkgs/build-support/node/build-npm-package/hooks/npm-build-hook.sh +++ b/pkgs/build-support/node/build-npm-package/hooks/npm-build-hook.sh @@ -14,7 +14,7 @@ npmBuildHook() { exit 1 fi - if ! npm run "$npmBuildScript" $npmBuildFlags "${npmBuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then + if ! npm run ${npmWorkspace+--workspace=$npmWorkspace} "$npmBuildScript" $npmBuildFlags "${npmBuildFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}"; then echo echo 'ERROR: `npm build` failed' echo diff --git a/pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh b/pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh index 4282419d5d6b7..b17fb552cc6b5 100644 --- a/pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh +++ b/pkgs/build-support/node/build-npm-package/hooks/npm-install-hook.sh @@ -13,8 +13,8 @@ npmInstallHook() { while IFS= read -r file; do local dest="$packageOut/$(dirname "$file")" mkdir -p "$dest" - cp "$file" "$dest" - done < <(@jq@ --raw-output '.[0].files | map(.path) | join("\n")' <<< "$(npm pack --json --dry-run $npmPackFlags "${npmPackFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}")") + cp "${npmWorkspace-.}/$file" "$dest" + done < <(@jq@ --raw-output '.[0].files | map(.path) | join("\n")' <<< "$(npm pack --json --dry-run ${npmWorkspace+--workspace=$npmWorkspace} $npmPackFlags "${npmPackFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}")") while IFS=" " read -ra bin; do mkdir -p "$out/bin" @@ -22,13 +22,13 @@ npmInstallHook() { done < <(@jq@ --raw-output '(.bin | type) as $typ | if $typ == "string" then .name + " " + .bin elif $typ == "object" then .bin | to_entries | map(.key + " " + .value) | join("\n") - else "invalid type " + $typ | halt_error end' package.json) + else "invalid type " + $typ | halt_error end' "${npmWorkspace-.}/package.json") local -r nodeModulesPath="$packageOut/node_modules" if [ ! -d "$nodeModulesPath" ]; then if [ -z "${dontNpmPrune-}" ]; then - npm prune --omit dev --no-save $npmInstallFlags "${npmInstallFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}" + npm prune --omit=dev --no-save ${npmWorkspace+--workspace=$npmWorkspace} $npmPruneFlags "${npmPruneFlagsArray[@]}" $npmFlags "${npmFlagsArray[@]}" fi find node_modules -maxdepth 1 -type d -empty -delete |