Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore npm.flatOptions.npmCommand #2903

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ const npm = module.exports = new class extends EventEmitter {
}

get flatOptions () {
return this.config.flat
const { flat } = this.config
if (this.command)
flat.npmCommand = this.command
return flat
}

get lockfileVersion () {
Expand Down
9 changes: 8 additions & 1 deletion test/lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const npmlog = require('npmlog')

const npmPath = resolve(__dirname, '..', '..')
const Config = require('@npmcli/config')
const { definitions, shorthands } = require('../../lib/utils/config')
const { definitions, shorthands, flatten } = require('../../lib/utils/config')
const freshConfig = (opts = {}) => {
for (const env of Object.keys(process.env).filter(e => /^npm_/.test(e)))
delete process.env[env]
Expand All @@ -55,6 +55,7 @@ const freshConfig = (opts = {}) => {
npmPath,
log: npmlog,
...opts,
flatten,
})
}

Expand Down Expand Up @@ -312,6 +313,9 @@ t.test('npm.load', t => {
if (er)
throw er

t.equal(npm.command, 'll', 'command set to first npm command')
t.equal(npm.flatOptions.npmCommand, 'll', 'npmCommand flatOption set')

t.same(consoleLogs, [[npm.commands.ll.usage]], 'print usage')
consoleLogs.length = 0
npm.config.set('usage', false)
Expand All @@ -323,6 +327,9 @@ t.test('npm.load', t => {
if (er)
throw er

t.strictSame([npm.command, npm.flatOptions.npmCommand], ['ll', 'll'],
'does not change npm.command when another command is called')

t.match(logs, [
[
'error',
Expand Down