Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
In preparation for @npmcli/eslint-config@3.1.0
  • Loading branch information
wraithgar authored and lukekarrys committed Aug 22, 2022
1 parent d54f031 commit bd2ae5d
Show file tree
Hide file tree
Showing 29 changed files with 535 additions and 524 deletions.
5 changes: 3 additions & 2 deletions lib/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ class VerifySignatures {
let name = edge.name
try {
name = npa(edge.spec).subSpec.name
} catch (_) {
} catch {
// leave it as edge.name
}
try {
return npa(`${name}@${edge.spec}`)
} catch (_) {
} catch {
// Skip packages with invalid spec
}
}
Expand Down
9 changes: 7 additions & 2 deletions lib/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ class Edit extends BaseCommand {
}
const [bin, ...args] = this.npm.config.get('editor').split(/\s+/)
const editor = cp.spawn(bin, [...args, dir], { stdio: 'inherit' })
editor.on('exit', (code) => {
editor.on('exit', async (code) => {
if (code) {
return reject(new Error(`editor process exited with code: ${code}`))
}
this.npm.exec('rebuild', [dir]).catch(reject).then(resolve)
try {
await this.npm.exec('rebuild', [dir])
} catch (err) {
reject(err)
}
resolve()
})
})
})
Expand Down
135 changes: 64 additions & 71 deletions lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Org extends BaseCommand {
})
}

set (org, user, role, opts) {
async set (org, user, role, opts) {
role = role || 'developer'
if (!org) {
throw new Error('First argument `orgname` is required.')
Expand All @@ -67,27 +67,26 @@ class Org extends BaseCommand {
)
}

return liborg.set(org, user, role, opts).then(memDeets => {
if (opts.json) {
this.npm.output(JSON.stringify(memDeets, null, 2))
} else if (opts.parseable) {
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
this.npm.output(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!this.npm.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
const memDeets = await liborg.set(org, user, role, opts)
if (opts.json) {
this.npm.output(JSON.stringify(memDeets, null, 2))
} else if (opts.parseable) {
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
this.npm.output(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!this.npm.silent) {
this.npm.output(
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
memDeets.org.size
} member${memDeets.org.size === 1 ? '' : 's'} in this org.`
)
}
)
}

return memDeets
})
return memDeets
}

rm (org, user, opts) {
async rm (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}
Expand All @@ -96,68 +95,62 @@ class Org extends BaseCommand {
throw new Error('Second argument `username` is required.')
}

return liborg
.rm(org, user, opts)
.then(() => {
return liborg.ls(org, opts)
})
.then(roster => {
user = user.replace(/^[~@]?/, '')
org = org.replace(/^[~@]?/, '')
const userCount = Object.keys(roster).length
if (opts.json) {
this.npm.output(
JSON.stringify({
user,
org,
userCount,
deleted: true,
})
)
} else if (opts.parseable) {
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
this.npm.output([user, org, userCount, true].join('\t'))
} else if (!this.npm.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
} in this org.`
)
}
})
await liborg.rm(org, user, opts)
const roster = await liborg.ls(org, opts)
user = user.replace(/^[~@]?/, '')
org = org.replace(/^[~@]?/, '')
const userCount = Object.keys(roster).length
if (opts.json) {
this.npm.output(
JSON.stringify({
user,
org,
userCount,
deleted: true,
})
)
} else if (opts.parseable) {
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
this.npm.output([user, org, userCount, true].join('\t'))
} else if (!this.npm.silent) {
this.npm.output(
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
userCount === 1 ? '' : 's'
} in this org.`
)
}
}

ls (org, user, opts) {
async ls (org, user, opts) {
if (!org) {
throw new Error('First argument `orgname` is required.')
}

return liborg.ls(org, opts).then(roster => {
if (user) {
const newRoster = {}
if (roster[user]) {
newRoster[user] = roster[user]
}

roster = newRoster
let roster = await liborg.ls(org, opts)
if (user) {
const newRoster = {}
if (roster[user]) {
newRoster[user] = roster[user]
}
if (opts.json) {
this.npm.output(JSON.stringify(roster, null, 2))
} else if (opts.parseable) {
this.npm.output(['user', 'role'].join('\t'))
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))

roster = newRoster
}
if (opts.json) {
this.npm.output(JSON.stringify(roster, null, 2))
} else if (opts.parseable) {
this.npm.output(['user', 'role'].join('\t'))
Object.keys(roster).forEach(user => {
this.npm.output([user, roster[user]].join('\t'))
})
} else if (!this.npm.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
.forEach(user => {
table.push([user, roster[user]])
})
} else if (!this.npm.silent) {
const table = new Table({ head: ['user', 'role'] })
Object.keys(roster)
.sort()
.forEach(user => {
table.push([user, roster[user]])
})
this.npm.output(table.toString())
}
})
this.npm.output(table.toString())
}
}
}
module.exports = Org
1 change: 1 addition & 0 deletions lib/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class Outdated extends ArboristWorkspaceCmd {
try {
alias = npa(edge.spec).subSpec
} catch (err) {
// ignore errors, no alias
}
const spec = npa(alias ? alias.name : edge.name)
const node = edge.to || edge
Expand Down
45 changes: 20 additions & 25 deletions lib/commands/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,27 @@ class Token extends BaseCommand {
const cidr = conf.cidr
const readonly = conf.readOnly

return readUserInfo
.password()
.then(password => {
const validCIDR = this.validateCIDRList(cidr)
log.info('token', 'creating')
return pulseTillDone.withPromise(
otplease(this.npm, conf, conf => {
return profile.createToken(password, readonly, validCIDR, conf)
})
)
})
.then(result => {
delete result.key
delete result.updated
if (conf.json) {
this.npm.output(JSON.stringify(result))
} else if (conf.parseable) {
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
} else {
const table = new Table()
for (const k of Object.keys(result)) {
table.push({ [chalk.bold(k)]: String(result[k]) })
}
this.npm.output(table.toString())
}
const password = await readUserInfo.password()
const validCIDR = this.validateCIDRList(cidr)
log.info('token', 'creating')
const result = await pulseTillDone.withPromise(
otplease(this.npm, conf, conf => {
return profile.createToken(password, readonly, validCIDR, conf)
})
)
delete result.key
delete result.updated
if (conf.json) {
this.npm.output(JSON.stringify(result))
} else if (conf.parseable) {
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
} else {
const table = new Table()
for (const k of Object.keys(result)) {
table.push({ [chalk.bold(k)]: String(result[k]) })
}
this.npm.output(table.toString())
}
}

config () {
Expand Down
20 changes: 11 additions & 9 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Npm extends EventEmitter {
// this is async but we dont await it, since its ok if it doesnt
// finish before the command finishes running. it uses command and argv
// so it must be initiated here, after the command name is set
// eslint-disable-next-line promise/catch-or-return
updateNotifier(this).then((msg) => (this.updateNotification = msg))

// Options are prefixed by a hyphen-minus (-, \u2d).
Expand Down Expand Up @@ -173,16 +174,15 @@ class Npm extends EventEmitter {

async load () {
if (!this.#loadPromise) {
this.#loadPromise = this.time('npm:load', () => this[_load]().catch(er => er).then((er) => {
this.loadErr = er
if (!er) {
if (this.config.get('force')) {
log.warn('using --force', 'Recommended protections disabled.')
}
} else {
this.#loadPromise = this.time('npm:load', async () => {
await this[_load]().catch((er) => {
this.loadErr = er
throw er
})
if (this.config.get('force')) {
log.warn('using --force', 'Recommended protections disabled.')
}
}))
})
}
return this.#loadPromise
}
Expand Down Expand Up @@ -229,7 +229,9 @@ class Npm extends EventEmitter {
const node = this.time('npm:load:whichnode', () => {
try {
return which.sync(process.argv[0])
} catch {} // TODO should we throw here?
} catch {
// TODO should we throw here?
}
})

if (node && node.toUpperCase() !== process.execPath.toUpperCase()) {
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/queryable.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ const setter = ({ data, key, value, force }) => {
let maybeIndex = Number.NaN
try {
maybeIndex = Number(_key)
} catch (err) {}
} catch {
// leave it NaN
}
if (!Number.isNaN(maybeIndex)) {
_key = maybeIndex
}
Expand Down
2 changes: 2 additions & 0 deletions scripts/dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ const iterate = function (node, dependedBy, annotations, onlyOurs) {

main().then(() => {
process.exit(0)
return 0
}).catch(err => {
console.error(err)
process.exit(1)
return 1
})
4 changes: 3 additions & 1 deletion test/lib/commands/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ t.formatSnapshot = obj =>
(k, v) => {
try {
return JSON.parse(v)
} catch {}
} catch {
// leave invalid JSON as a string
}
return v
},
2
Expand Down
1 change: 1 addition & 0 deletions workspaces/arborist/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ for (const file of commandFiles) {
if (bin.loglevel !== 'silent') {
console[process.exitCode ? 'error' : 'log'](r)
}
return r
})
}
}
Expand Down
Loading

0 comments on commit bd2ae5d

Please sign in to comment.