Skip to content

Commit 52c4d3f

Browse files
committed
chore: enable mutating flat-options
This will allow for changing configs that are read by commands through flatOptions. Based of #2795, land that first. Relates to: #2765 Relates to: npm/rfcs#117
1 parent 8863fef commit 52c4d3f

File tree

3 files changed

+2
-9
lines changed

3 files changed

+2
-9
lines changed

lib/npm.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const { shellouts } = require('./utils/cmd-list.js')
4242
let warnedNonDashArg = false
4343
const _runCmd = Symbol('_runCmd')
4444
const _load = Symbol('_load')
45-
const _flatOptions = Symbol('_flatOptions')
4645
const _tmpFolder = Symbol('_tmpFolder')
4746
const _title = Symbol('_title')
4847
const npm = module.exports = new class extends EventEmitter {
@@ -140,9 +139,6 @@ const npm = module.exports = new class extends EventEmitter {
140139
if (!er && this.config.get('force'))
141140
this.log.warn('using --force', 'Recommended protections disabled.')
142141

143-
if (!er && !this[_flatOptions])
144-
this[_flatOptions] = require('./utils/flat-options.js')(this)
145-
146142
process.emit('timeEnd', 'npm:load')
147143
this.emit('load', er)
148144
})
@@ -203,7 +199,7 @@ const npm = module.exports = new class extends EventEmitter {
203199
}
204200

205201
get flatOptions () {
206-
return this[_flatOptions]
202+
return require('./utils/flat-options.js')(this)
207203
}
208204

209205
get lockfileVersion () {

lib/utils/flat-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const flatten = obj => ({
190190
noProxy: obj.noproxy,
191191
})
192192

193-
const flatOptions = npm => npm.flatOptions || Object.freeze({
193+
const flatOptions = npm => Object.freeze({
194194
// flatten the config object
195195
...flatten(npm.config.list[0]),
196196

test/lib/utils/flat-options.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ t.test('basic', t => {
150150
// test the object is frozen
151151
generatedFlat.newField = 'asdf'
152152
t.equal(generatedFlat.newField, undefined, 'object is frozen')
153-
const preExistingOpts = { flat: 'options' }
154-
npm.flatOptions = preExistingOpts
155-
t.equal(flatOptions(npm), preExistingOpts, 'use pre-existing npm.flatOptions')
156153
t.end()
157154
})
158155

0 commit comments

Comments
 (0)