Skip to content

Commit

Permalink
fixup! chore(cli): remove log option from being passed anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Feb 22, 2022
1 parent 9c3ec00 commit cd72162
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 57 deletions.
8 changes: 4 additions & 4 deletions lib/commands/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Hook extends BaseCommand {
} else if (opts.parseable) {
this.npm.output(Object.keys(hook).join('\t'))
this.npm.output(Object.keys(hook).map(k => hook[k]).join('\t'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`+ ${this.hookName(hook)} ${
opts.unicode ? ' ➜ ' : ' -> '
} ${hook.endpoint}`)
Expand All @@ -64,7 +64,7 @@ class Hook extends BaseCommand {
})
} else if (!hooks.length) {
this.npm.output("You don't have any hooks configured yet.")
} else if (!opts.silent) {
} else if (!this.npm.silent) {
if (hooks.length === 1) {
this.npm.output('You have one hook configured.')
} else {
Expand Down Expand Up @@ -101,7 +101,7 @@ class Hook extends BaseCommand {
} else if (opts.parseable) {
this.npm.output(Object.keys(hook).join('\t'))
this.npm.output(Object.keys(hook).map(k => hook[k]).join('\t'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`- ${this.hookName(hook)} ${
opts.unicode ? ' ✘ ' : ' X '
} ${hook.endpoint}`)
Expand All @@ -115,7 +115,7 @@ class Hook extends BaseCommand {
} else if (opts.parseable) {
this.npm.output(Object.keys(hook).join('\t'))
this.npm.output(Object.keys(hook).map(k => hook[k]).join('\t'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`+ ${this.hookName(hook)} ${
opts.unicode ? ' ➜ ' : ' -> '
} ${hook.endpoint}`)
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Org extends BaseCommand {
this.npm.output(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
memDeets.org.size
Expand Down Expand Up @@ -116,7 +116,7 @@ class Org extends BaseCommand {
} else if (opts.parseable) {
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
this.npm.output([user, org, userCount, true].join('\t'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
Expand Down Expand Up @@ -147,7 +147,7 @@ class Org extends BaseCommand {
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))
})
} else if (!opts.silent) {
} else if (!this.npm.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
Expand Down
12 changes: 6 additions & 6 deletions lib/commands/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Team extends BaseCommand {
}))
} else if (opts.parseable) {
this.npm.output(`${entity}\tcreated`)
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`+@${entity}`)
}
}
Expand All @@ -86,7 +86,7 @@ class Team extends BaseCommand {
}))
} else if (opts.parseable) {
this.npm.output(`${entity}\tdeleted`)
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`-@${entity}`)
}
}
Expand All @@ -101,7 +101,7 @@ class Team extends BaseCommand {
}))
} else if (opts.parseable) {
this.npm.output(`${user}\t${entity}\tadded`)
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`${user} added to @${entity}`)
}
}
Expand All @@ -116,7 +116,7 @@ class Team extends BaseCommand {
}))
} else if (opts.parseable) {
this.npm.output(`${user}\t${entity}\tremoved`)
} else if (!opts.silent) {
} else if (!this.npm.silent) {
this.npm.output(`${user} removed from @${entity}`)
}
}
Expand All @@ -127,7 +127,7 @@ class Team extends BaseCommand {
this.npm.output(JSON.stringify(users, null, 2))
} else if (opts.parseable) {
this.npm.output(users.join('\n'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
const plural = users.length === 1 ? '' : 's'
const more = users.length === 0 ? '' : ':\n'
this.npm.output(`\n@${entity} has ${users.length} user${plural}${more}`)
Expand All @@ -141,7 +141,7 @@ class Team extends BaseCommand {
this.npm.output(JSON.stringify(teams, null, 2))
} else if (opts.parseable) {
this.npm.output(teams.join('\n'))
} else if (!opts.silent) {
} else if (!this.npm.silent) {
const plural = teams.length === 1 ? '' : 's'
const more = teams.length === 0 ? '' : ':\n'
this.npm.output(`\n@${entity} has ${teams.length} team${plural}${more}`)
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/mock-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class MockNpm {
get: (k) => ({ ...realConfig.defaults, ...config })[k],
set: (k, v) => {
config[k] = v
// mock how real npm derives silent
if (k === 'loglevel') {
this.flatOptions.silent = v === 'silent'
this.silent = v === 'silent'
Expand All @@ -168,9 +169,8 @@ class MockNpm {
setLoglevel(t, config.loglevel)
}

if (config.loglevel === 'silent') {
this.flatOptions.silent = true
this.silent = true
if (config.loglevel) {
this.config.set('loglevel', config.loglevel)
}
}

Expand Down
19 changes: 7 additions & 12 deletions test/lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { join } = require('path')
const fs = require('fs')
const ansiTrim = require('../../../lib/utils/ansi-trim.js')
const isWindows = require('../../../lib/utils/is-windows.js')
const { fake: mockNpm } = require('../../fixtures/mock-npm')

// getuid and getgid do not exist in windows, so we shim them
// to return 0, as that is the value that lstat will assign the
Expand Down Expand Up @@ -61,24 +62,18 @@ const clearLogs = () => {
}
}

const npm = {
const npm = mockNpm({
flatOptions: {
registry: 'https://registry.npmjs.org/',
},
set loglevel (v) {
this.flatOptions.silent = v === 'silent'
this.silent = v === 'silent'
this._loglevel = v
config: {
loglevel: 'info',
},
get loglevel () {
return this._loglevel
},
_loglevel: 'info',
version: '7.1.0',
output: data => {
output.push(data)
},
}
})

let latestNpm = npm.version
const pacote = {
Expand Down Expand Up @@ -220,7 +215,7 @@ t.test('node versions', t => {
npm.globalDir = dir
npm.localBin = dir
npm.globalBin = dir
npm.loglevel = 'silent'
npm.config.set('loglevel', 'silent')

st.teardown(() => {
delete npm.cache
Expand All @@ -229,7 +224,7 @@ t.test('node versions', t => {
delete npm.globalDir
delete npm.localBin
delete npm.globalBin
npm.loglevel = 'info'
npm.config.set('loglevel', 'info')
clearLogs()
})

Expand Down
26 changes: 14 additions & 12 deletions test/lib/commands/hook.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const t = require('tap')
const { fake: mockNpm } = require('../../fixtures/mock-npm')

const output = []
const npm = {
const npm = mockNpm({
flatOptions: {
json: false,
parseable: false,
silent: false,
loglevel: 'info',
unicode: false,
},
config: {
loglevel: 'info',
},
output: msg => {
output.push(msg)
},
}
})

const pkgTypes = {
semver: 'package',
Expand Down Expand Up @@ -179,9 +181,9 @@ t.test('npm hook add - parseable output', async t => {
})

t.test('npm hook add - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
hookArgs = null
output.length = 0
})
Expand Down Expand Up @@ -352,9 +354,9 @@ t.test('npm hook ls - parseable output', async t => {
})

t.test('npm hook ls - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
hookArgs = null
output.length = 0
})
Expand Down Expand Up @@ -413,9 +415,9 @@ t.test('npm hook rm - unicode output', async t => {
})

t.test('npm hook rm - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
hookArgs = null
output.length = 0
})
Expand Down Expand Up @@ -598,9 +600,9 @@ t.test('npm hook update - parseable output', async t => {
})

t.test('npm hook update - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
hookArgs = null
output.length = 0
})
Expand Down
20 changes: 11 additions & 9 deletions test/lib/commands/org.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const t = require('tap')
const ansiTrim = require('../../../lib/utils/ansi-trim.js')
const { fake: mockNpm } = require('../../fixtures/mock-npm')

const output = []
const npm = {
const npm = mockNpm({
flatOptions: {
json: false,
parseable: false,
silent: false,
},
config: {
loglevel: 'info',
},
output: msg => {
output.push(msg)
},
}
})

let orgSize = 1
let orgSetArgs = null
Expand Down Expand Up @@ -230,9 +232,9 @@ t.test('npm org add - parseable output', async t => {
})

t.test('npm org add - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
orgSetArgs = null
output.length = 0
})
Expand Down Expand Up @@ -426,9 +428,9 @@ t.test('npm org rm - parseable output', async t => {
})

t.test('npm org rm - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
orgRmArgs = null
orgLsArgs = null
output.length = 0
Expand Down Expand Up @@ -608,14 +610,14 @@ t.test('npm org ls - parseable output', async t => {
})

t.test('npm org ls - silent output', async t => {
npm.flatOptions.silent = true
npm.config.set('loglevel', 'silent')
orgList = {
one: 'developer',
two: 'admin',
three: 'owner',
}
t.teardown(() => {
npm.flatOptions.silent = false
npm.config.set('loglevel', 'info')
orgList = {}
orgLsArgs = null
output.length = 0
Expand Down
Loading

0 comments on commit cd72162

Please sign in to comment.