Skip to content

Commit

Permalink
chore: enable mutating flat-options
Browse files Browse the repository at this point in the history
This will allow for changing configs that are read by commands through
flatOptions.

Based of npm#2795, land that first.

Relates to: npm#2765
Relates to: npm/rfcs#117
  • Loading branch information
ruyadorno committed Mar 1, 2021
1 parent 8863fef commit 52c4d3f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 9 deletions.
6 changes: 1 addition & 5 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]),

Expand Down
3 changes: 0 additions & 3 deletions test/lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down

0 comments on commit 52c4d3f

Please sign in to comment.