Skip to content

Commit

Permalink
ensure npm-command header is sent properly
Browse files Browse the repository at this point in the history
Reported by @lumaxis
  • Loading branch information
isaacs committed Aug 23, 2020
1 parent d159a31 commit b38f68a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({
projectScope: npm.projectScope,
npmVersion: npm.version,
nodeVersion: npm.config.get('node-version'),
npmCommand: npm.command,
// npm.command is not set until AFTER flatOptions are defined
// so we need to make this a getter.
get npmCommand () {
return npm.command
},

tmp: npm.tmp,
cache: join(npm.config.get('cache'), '_cacache'),
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Object {
"nodeBin": "/path/to/some/node",
"nodeVersion": "1.2.3",
"npmBin": "/path/to/npm/bin.js",
"npmCommand": "test",
"npmCommand": null,
"npmSession": "12345",
"npmVersion": "7.6.5",
"offline": "offline",
Expand Down
5 changes: 4 additions & 1 deletion test/lib/utils/flat-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Mocknpm {
this.color = true
this.projectScope = '@npmcli'
this.tmp = '/tmp'
this.command = 'test'
this.command = null
this.globalPrefix = '/usr/local'
this.localPrefix = '/path/to/npm/cli'
this.prefix = this.localPrefix
Expand Down Expand Up @@ -138,6 +138,9 @@ t.test('basic', t => {
cache: generatedFlat.cache.replace(/\\/g, '/')
}
t.matchSnapshot(clean, 'flat options')
t.equal(generatedFlat.npmCommand, null, 'command not set yet')
npm.command = 'view'
t.equal(generatedFlat.npmCommand, 'view', 'command updated via getter')
t.equal(generatedFlat.npmBin, require.main.filename)
// test the object is frozen
generatedFlat.newField = 'asdf'
Expand Down

0 comments on commit b38f68a

Please sign in to comment.