From 4a6511fb9820ee8cfe172a790b8ac22fb96e698e Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Wed, 13 Sep 2023 21:37:29 -0400 Subject: [PATCH] nodejs: make buildNpmPackage git dep lockfile fixup fail gracefully when no lockfile exists and git deps forced Some git dependencies with install scripts might genuinely have no declared dependencies of their own and thus theoretically should be able to build without a lockfile. Making the lockfile fixup fail gracefully instead of fatally when `forceGitDeps = true` is on allows those packages to work. --- .../web/nodejs/node-npm-build-npm-package-logic.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/web/nodejs/node-npm-build-npm-package-logic.patch b/pkgs/development/web/nodejs/node-npm-build-npm-package-logic.patch index a9ac6b0589ef..a24ab07a3d80 100644 --- a/pkgs/development/web/nodejs/node-npm-build-npm-package-logic.patch +++ b/pkgs/development/web/nodejs/node-npm-build-npm-package-logic.patch @@ -49,7 +49,7 @@ index 1fa8b1f96..a026bb50d 100644 + if (process.env['NIX_NODEJS_BUILDNPMPACKAGE']) { + const spawn = require('@npmcli/promise-spawn') + -+ const npmWithNixFlags = (args, cmd) => spawn('bash', ['-c', 'npm ' + args + ` $npm${cmd}Flags "$\{npm${cmd}FlagsArray[@]}" $npmFlags "$\{npmFlagsArray[@]}"`], { cwd: dir, env: { ...process.env, _PACOTE_NO_PREPARE_: noPrepare.join('\n') } }, { message: `\`npm ${args}\` failed` }) ++ const npmWithNixFlags = (args, cmd) => spawn('bash', ['-c', 'npm ' + args + ` $npm${cmd}Flags "$\{npm${cmd}FlagsArray[@]}" $npmFlags "$\{npmFlagsArray[@]}" || [ -n "$forceGitDeps" ]`], { cwd: dir, env: { ...process.env, _PACOTE_NO_PREPARE_: noPrepare.join('\n') } }, { message: `\`npm ${args}\` failed` }) + const patchShebangs = () => spawn('bash', ['-c', 'source $stdenv/setup; patchShebangs node_modules'], { cwd: dir }) + + // the DirFetcher will do its own preparation to run the prepare scripts @@ -57,7 +57,7 @@ index 1fa8b1f96..a026bb50d 100644 + // + // We ignore this.npmConfig to maintain an environment that's as close + // to the rest of the build as possible. -+ return spawn('bash', ['-c', '$prefetchNpmDeps --fixup-lockfile package-lock.json'], { cwd: dir }) ++ return spawn('bash', ['-c', '$prefetchNpmDeps --fixup-lockfile package-lock.json || [ -n "$forceGitDeps" ]'], { cwd: dir }) + .then(() => npmWithNixFlags('ci --ignore-scripts', 'Install')) + .then(patchShebangs) + .then(() => npmWithNixFlags('rebuild', 'Rebuild'))