From 8b43c962498c8e2707527e4fca442d7a4fa51595 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 12 Aug 2019 15:07:36 -0700 Subject: [PATCH] ci: pass all configs to cipm installer Fixes the regression where random config values in a .npmrc file are not passed to lifecycle scripts, breaking build processes which rely on them. Fix: https://github.com/nodejs/node/issues/28987 Fix: https://npm.community/t/npm-ci-doesnt-respect-npmrc-variables/6032 Fix: https://npm.community/t/npm-ci-doesnt-fill-anymore-the-process-env-npm-config-cache-variable-on-post-install-scripts/6658 Fix: https://npm.community/t/npm-ci-does-not-compile-native-dependencies-according-to-npmrc-configuration/6069 Fix: https://npm.community/t/npm-6-9-x-not-passing-environment-to-node-gyp-regression-from-6-4-x/9323/2 --- lib/ci.js | 10 ++++++++-- test/tap/ci.js | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/ci.js b/lib/ci.js index 1fbb28b570f6f..375c1448a1ea1 100644 --- a/lib/ci.js +++ b/lib/ci.js @@ -1,7 +1,7 @@ 'use strict' +const npm = require('./npm.js') const Installer = require('libcipm') -const npmConfig = require('./config/figgy-config.js') const npmlog = require('npmlog') ci.usage = 'npm ci' @@ -10,7 +10,13 @@ ci.completion = (cb) => cb(null, []) module.exports = ci function ci (args, cb) { - return new Installer(npmConfig({ log: npmlog })).run().then(details => { + const opts = Object.create({ log: npmlog }) + for (const key in npm.config.list[0]) { + if (key !== 'log') { + opts[key] = npm.config.list[0][key] + } + } + return new Installer(opts).run().then(details => { npmlog.disableProgress() console.log(`added ${details.pkgCount} packages in ${ details.runTime / 1000 diff --git a/test/tap/ci.js b/test/tap/ci.js index 9150f26efeedc..3f3e251d03f1d 100644 --- a/test/tap/ci.js +++ b/test/tap/ci.js @@ -19,6 +19,9 @@ const EXEC_OPTS = { cwd: testDir } const PKG = { name: 'top', version: '1.2.3', + scripts: { + install: 'node -p process.env.npm_config_foo' + }, dependencies: { optimist: '0.6.0', clean: '2.1.6' @@ -77,6 +80,7 @@ test('basic installation', (t) => { .then(() => fixture.create(testDir)) .then(() => common.npm([ 'ci', + '--foo=asdf', '--registry', common.registry, '--loglevel', 'warn' ], EXEC_OPTS)) @@ -88,7 +92,7 @@ test('basic installation', (t) => { t.equal(stderr.trim(), '', 'no output on stderr') t.match( stdout.trim(), - /^added 6 packages in \d+(?:\.\d+)?s$/, + /\nasdf\nadded 6 packages in \d+(?:\.\d+)?s$/, 'no warnings on stderr, and final output has right number of packages' ) return fs.readdirAsync(path.join(testDir, 'node_modules')) @@ -144,6 +148,7 @@ test('supports npm-shrinkwrap.json as well', (t) => { .then(() => fixture.create(testDir)) .then(() => common.npm([ 'ci', + '--foo=asdf', '--registry', common.registry, '--loglevel', 'warn' ], EXEC_OPTS)) @@ -155,7 +160,7 @@ test('supports npm-shrinkwrap.json as well', (t) => { t.equal(stderr.trim(), '', 'no output on stderr') t.match( stdout.trim(), - /^added 6 packages in \d+(?:\.\d+)?s$/, + /\nasdf\nadded 6 packages in \d+(?:\.\d+)?s$/, 'no warnings on stderr, and final output has right number of packages' ) }) @@ -194,6 +199,7 @@ test('removes existing node_modules/ before installing', (t) => { .then(() => fixture.create(testDir)) .then(() => common.npm([ 'ci', + '--foo=asdf', '--registry', common.registry, '--loglevel', 'warn' ], EXEC_OPTS)) @@ -232,6 +238,7 @@ test('errors if package-lock.json missing', (t) => { .then(() => fixture.create(testDir)) .then(() => common.npm([ 'ci', + '--foo=asdf', '--registry', common.registry, '--loglevel', 'warn' ], EXEC_OPTS)) @@ -268,6 +275,7 @@ test('errors if package-lock.json invalid', (t) => { .then(() => fixture.create(testDir)) .then(() => common.npm([ 'ci', + '--foo=asdf', '--registry', common.registry, '--loglevel', 'warn' ], EXEC_OPTS))