From 52c4d3fa164613d0819781cbde1344109c46ff81 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Mon, 1 Mar 2021 13:58:15 -0500 Subject: [PATCH] chore: enable mutating flat-options This will allow for changing configs that are read by commands through flatOptions. Based of https://github.com/npm/cli/pull/2795, land that first. Relates to: https://github.com/npm/cli/pull/2765 Relates to: https://github.com/npm/rfcs/pull/117 --- lib/npm.js | 6 +----- lib/utils/flat-options.js | 2 +- test/lib/utils/flat-options.js | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/npm.js b/lib/npm.js index 0534e630606e4..c01dbc3e966ec 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -42,7 +42,6 @@ const { shellouts } = require('./utils/cmd-list.js') let warnedNonDashArg = false const _runCmd = Symbol('_runCmd') const _load = Symbol('_load') -const _flatOptions = Symbol('_flatOptions') const _tmpFolder = Symbol('_tmpFolder') const _title = Symbol('_title') const npm = module.exports = new class extends EventEmitter { @@ -140,9 +139,6 @@ const npm = module.exports = new class extends EventEmitter { if (!er && this.config.get('force')) this.log.warn('using --force', 'Recommended protections disabled.') - if (!er && !this[_flatOptions]) - this[_flatOptions] = require('./utils/flat-options.js')(this) - process.emit('timeEnd', 'npm:load') this.emit('load', er) }) @@ -203,7 +199,7 @@ const npm = module.exports = new class extends EventEmitter { } get flatOptions () { - return this[_flatOptions] + return require('./utils/flat-options.js')(this) } get lockfileVersion () { diff --git a/lib/utils/flat-options.js b/lib/utils/flat-options.js index c082e4137ab21..8099923e7444f 100644 --- a/lib/utils/flat-options.js +++ b/lib/utils/flat-options.js @@ -190,7 +190,7 @@ const flatten = obj => ({ noProxy: obj.noproxy, }) -const flatOptions = npm => npm.flatOptions || Object.freeze({ +const flatOptions = npm => Object.freeze({ // flatten the config object ...flatten(npm.config.list[0]), diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js index 6f580fabc4511..2c45d4cbc3516 100644 --- a/test/lib/utils/flat-options.js +++ b/test/lib/utils/flat-options.js @@ -150,9 +150,6 @@ t.test('basic', t => { // test the object is frozen generatedFlat.newField = 'asdf' t.equal(generatedFlat.newField, undefined, 'object is frozen') - const preExistingOpts = { flat: 'options' } - npm.flatOptions = preExistingOpts - t.equal(flatOptions(npm), preExistingOpts, 'use pre-existing npm.flatOptions') t.end() })