Skip to content

Commit

Permalink
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 2c1f206 commit b1cc530
Show file tree
Hide file tree
Showing 56 changed files with 153 additions and 323 deletions.
2 changes: 0 additions & 2 deletions lib/commands/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path')
const libaccess = require('libnpmaccess')
const readPackageJson = require('read-package-json-fast')

const log = require('../utils/log-shim.js')
const otplease = require('../utils/otplease.js')
const getIdentity = require('../utils/get-identity.js')
const BaseCommand = require('../base-command.js')
Expand Down Expand Up @@ -79,7 +78,6 @@ class Access extends BaseCommand {

return this[cmd](args, {
...this.npm.flatOptions,
log,
})
}

Expand Down
1 change: 0 additions & 1 deletion lib/commands/adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AddUser extends BaseCommand {
creds,
registry,
scope,
log,
})

await this.updateConfig({
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class CI extends ArboristWorkspaceCmd {
}

const where = this.npm.prefix
const { silent } = this.npm.flatOptions
const opts = {
...this.npm.flatOptions,
packageLock: true, // npm ci should never skip lock files
path: where,
log,
save: false, // npm ci should never modify the lockfile or package.json
workspaces: this.workspaceNames,
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class CI extends ArboristWorkspaceCmd {
scriptShell,
stdio: 'inherit',
stdioString: true,
banner: log.level !== 'silent',
banner: !silent,
event,
})
}
Expand Down
2 changes: 0 additions & 2 deletions lib/commands/dedupe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// dedupe duplicated packages, or find them in the tree
const Arborist = require('@npmcli/arborist')
const reifyFinish = require('../utils/reify-finish.js')
const log = require('../utils/log-shim.js')

const ArboristWorkspaceCmd = require('../arborist-cmd.js')

Expand Down Expand Up @@ -40,7 +39,6 @@ class Dedupe extends ArboristWorkspaceCmd {
const where = this.npm.prefix
const opts = {
...this.npm.flatOptions,
log,
path: where,
dryRun,
save,
Expand Down
3 changes: 0 additions & 3 deletions lib/commands/deprecate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const fetch = require('npm-registry-fetch')
const log = require('../utils/log-shim.js')
const otplease = require('../utils/otplease.js')
const npa = require('npm-package-arg')
const semver = require('semver')
Expand Down Expand Up @@ -51,7 +50,6 @@ class Deprecate extends BaseCommand {
...this.npm.flatOptions,
spec: p,
query: { write: true },
log,
})

Object.keys(packument.versions)
Expand All @@ -66,7 +64,6 @@ class Deprecate extends BaseCommand {
method: 'PUT',
body: packument,
ignoreBody: true,
log,
}))
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Diff extends BaseCommand {
...this.npm.flatOptions,
diffFiles: args,
where: this.top,
log,
})
return this.npm.output(res)
}
Expand Down Expand Up @@ -194,7 +193,6 @@ class Diff extends BaseCommand {
const packument = await pacote.packument(spec, {
...this.npm.flatOptions,
preferOnline: true,
log,
})
bSpec = pickManifest(
packument,
Expand Down
1 change: 0 additions & 1 deletion lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class DistTag extends BaseCommand {
async exec ([cmdName, pkg, tag]) {
const opts = {
...this.npm.flatOptions,
log,
}

if (['add', 'a', 'set', 's'].includes(cmdName)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Doctor extends BaseCommand {
stringLength: s => ansiTrim(s).length,
}

const silent = log.levels[log.level] > log.levels.error
const { silent } = this.npm.flatOptions
if (!silent) {
this.npm.output(table(outTable, tableOpts))
if (!allOk) {
Expand Down
2 changes: 0 additions & 2 deletions lib/commands/exec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const libexec = require('libnpmexec')
const BaseCommand = require('../base-command.js')
const getLocationMsg = require('../exec/get-workspace-location-msg.js')
const log = require('../utils/log-shim')

// it's like this:
//
Expand Down Expand Up @@ -77,7 +76,6 @@ class Exec extends BaseCommand {
call,
localBin,
locationMsg,
log,
globalBin,
output,
packages,
Expand Down
2 changes: 0 additions & 2 deletions lib/commands/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const pacote = require('pacote')
const semver = require('semver')
const npa = require('npm-package-arg')
const { depth } = require('treeverse')
const log = require('../utils/log-shim.js')
const { readTree: getFundingInfo, normalizeFunding, isValidFunding } = require('libnpmfund')

const completion = require('../utils/completion/installed-deep.js')
Expand Down Expand Up @@ -69,7 +68,6 @@ class Fund extends ArboristWorkspaceCmd {
// TODO: add !workspacesEnabled option handling to libnpmfund
const fundingInfo = getFundingInfo(tree, {
...this.flatOptions,
log,
workspaces: this.workspaceNames,
})

Expand Down
10 changes: 4 additions & 6 deletions lib/commands/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const hookApi = require('libnpmhook')
const otplease = require('../utils/otplease.js')
const relativeDate = require('tiny-relative-date')
const Table = require('cli-table3')
const log = require('../utils/log-shim.js')

const BaseCommand = require('../base-command.js')
class Hook extends BaseCommand {
Expand All @@ -23,7 +22,6 @@ class Hook extends BaseCommand {
async exec (args) {
return otplease({
...this.npm.flatOptions,
log,
}, (opts) => {
switch (args[0]) {
case 'add':
Expand All @@ -48,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
this.npm.output(`+ ${this.hookName(hook)} ${
opts.unicode ? ' ➜ ' : ' -> '
} ${hook.endpoint}`)
Expand All @@ -66,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
if (hooks.length === 1) {
this.npm.output('You have one hook configured.')
} else {
Expand Down Expand Up @@ -103,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
this.npm.output(`- ${this.hookName(hook)} ${
opts.unicode ? ' ✘ ' : ' X '
} ${hook.endpoint}`)
Expand All @@ -117,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
this.npm.output(`+ ${this.hookName(hook)} ${
opts.unicode ? ' ➜ ' : ' -> '
} ${hook.endpoint}`)
Expand Down
1 change: 0 additions & 1 deletion lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class Init extends BaseCommand {
color,
localBin,
locationMsg,
log,
globalBin,
output,
path,
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ class Install extends ArboristWorkspaceCmd {
)
}

const { silent } = this.npm.flatOptions
const opts = {
...this.npm.flatOptions,
log,
auditLevel: null,
path: where,
add: args,
Expand All @@ -173,7 +173,7 @@ class Install extends ArboristWorkspaceCmd {
scriptShell,
stdio: 'inherit',
stdioString: true,
banner: log.level !== 'silent',
banner: !silent,
event,
})
}
Expand Down
6 changes: 0 additions & 6 deletions lib/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Arborist = require('@npmcli/arborist')
const npa = require('npm-package-arg')
const rpj = require('read-package-json-fast')
const semver = require('semver')
const log = require('../utils/log-shim.js')

const reifyFinish = require('../utils/reify-finish.js')

Expand Down Expand Up @@ -69,7 +68,6 @@ class Link extends ArboristWorkspaceCmd {
const globalOpts = {
...this.npm.flatOptions,
path: globalTop,
log,
global: true,
prune: false,
}
Expand Down Expand Up @@ -118,15 +116,13 @@ class Link extends ArboristWorkspaceCmd {
const localArb = new Arborist({
...this.npm.flatOptions,
prune: false,
log,
path: this.npm.prefix,
save,
})
await localArb.reify({
...this.npm.flatOptions,
prune: false,
path: this.npm.prefix,
log,
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l)}`),
save,
workspaces: this.workspaceNames,
Expand All @@ -143,12 +139,10 @@ class Link extends ArboristWorkspaceCmd {
const arb = new Arborist({
...this.npm.flatOptions,
path: globalTop,
log,
global: true,
})
await arb.reify({
add,
log,
})
await reifyFinish(this.npm, arb)
}
Expand Down
1 change: 0 additions & 1 deletion lib/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Logout extends BaseCommand {
...this.npm.flatOptions,
method: 'DELETE',
ignoreBody: true,
log,
})
} else if (auth.isBasicAuth) {
log.verbose('logout', `clearing user credentials for ${reg}`)
Expand Down
8 changes: 3 additions & 5 deletions lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const liborg = require('libnpmorg')
const otplease = require('../utils/otplease.js')
const Table = require('cli-table3')
const BaseCommand = require('../base-command.js')
const log = require('../utils/log-shim.js')

class Org extends BaseCommand {
static description = 'Manage orgs'
Expand Down Expand Up @@ -35,7 +34,6 @@ class Org extends BaseCommand {
async exec ([cmd, orgname, username, role], cb) {
return otplease({
...this.npm.flatOptions,
log,
}, opts => {
switch (cmd) {
case 'add':
Expand Down Expand Up @@ -76,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
memDeets.org.size
Expand Down Expand Up @@ -118,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 && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
Expand Down Expand Up @@ -149,7 +147,7 @@ class Org extends BaseCommand {
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))
})
} else if (!opts.silent && opts.loglevel !== 'silent') {
} else if (!opts.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
Expand Down
2 changes: 0 additions & 2 deletions lib/commands/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class Owner extends BaseCommand {
async exec ([action, ...args]) {
const opts = {
...this.npm.flatOptions,
log,
}
switch (action) {
case 'ls':
Expand Down Expand Up @@ -198,7 +197,6 @@ class Owner extends BaseCommand {
method: 'PUT',
body,
spec,
log,
})
})

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Ping extends BaseCommand {
async exec (args) {
log.notice('PING', this.npm.config.get('registry'))
const start = Date.now()
const details = await pingUtil({ ...this.npm.flatOptions, log })
const details = await pingUtil({ ...this.npm.flatOptions })
const time = Date.now() - start
log.notice('PONG', `${time}ms`)
if (this.npm.config.get('json')) {
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Profile extends BaseCommand {
async get (args) {
const tfa = 'two-factor auth'
const info = await pulseTillDone.withPromise(
npmProfile.get({ ...this.npm.flatOptions, log })
npmProfile.get({ ...this.npm.flatOptions })
)

if (!info.cidr_whitelist) {
Expand Down Expand Up @@ -170,7 +170,7 @@ class Profile extends BaseCommand {
}

async set (args) {
const conf = { ...this.npm.flatOptions, log }
const conf = { ...this.npm.flatOptions }
const prop = (args[0] || '').toLowerCase().trim()

let value = args.length > 1 ? args.slice(1).join(' ') : null
Expand Down Expand Up @@ -285,7 +285,7 @@ class Profile extends BaseCommand {
if (auth.basic) {
log.info('profile', 'Updating authentication to bearer token')
const result = await npmProfile.createToken(
auth.basic.password, false, [], { ...this.npm.flatOptions, log }
auth.basic.password, false, [], { ...this.npm.flatOptions }
)

if (!result.token) {
Expand All @@ -309,7 +309,7 @@ class Profile extends BaseCommand {

log.info('profile', 'Determine if tfa is pending')
const userInfo = await pulseTillDone.withPromise(
npmProfile.get({ ...this.npm.flatOptions, log })
npmProfile.get({ ...this.npm.flatOptions })
)

const conf = { ...this.npm.flatOptions }
Expand Down
Loading

0 comments on commit b1cc530

Please sign in to comment.