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.
This commit is contained in:
parent
d94833deff
commit
4a6511fb98
1 changed files with 2 additions and 2 deletions
|
@ -49,7 +49,7 @@ index 1fa8b1f96..a026bb50d 100644
|
||||||
+ if (process.env['NIX_NODEJS_BUILDNPMPACKAGE']) {
|
+ if (process.env['NIX_NODEJS_BUILDNPMPACKAGE']) {
|
||||||
+ const spawn = require('@npmcli/promise-spawn')
|
+ 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 })
|
+ 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
|
+ // 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
|
+ // We ignore this.npmConfig to maintain an environment that's as close
|
||||||
+ // to the rest of the build as possible.
|
+ // 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(() => npmWithNixFlags('ci --ignore-scripts', 'Install'))
|
||||||
+ .then(patchShebangs)
|
+ .then(patchShebangs)
|
||||||
+ .then(() => npmWithNixFlags('rebuild', 'Rebuild'))
|
+ .then(() => npmWithNixFlags('rebuild', 'Rebuild'))
|
||||||
|
|
Loading…
Reference in a new issue