Skip to content

Commit 9123de4

Browse files
committed
feat: do all ouput over proc-log events
1 parent 87f6c09 commit 9123de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+646
-523
lines changed

lib/base-command.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { relative } = require('path')
44

55
const { definitions } = require('@npmcli/config/lib/definitions')
66
const { aliases: cmdAliases } = require('./utils/cmd-list')
7-
const { log } = require('proc-log')
7+
const { log, output } = require('proc-log')
88

99
class BaseCommand {
1010
static workspaces = false
@@ -119,7 +119,7 @@ class BaseCommand {
119119
const { config } = this.npm
120120

121121
if (config.get('usage')) {
122-
return this.npm.output(this.usage)
122+
return output.standard(this.usage)
123123
}
124124

125125
const hasWsConfig = config.get('workspaces') || config.get('workspace').length

lib/cli-entry.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = async (process, validateEngines) => {
1818
exitHandler.setNpm(npm)
1919

2020
// only log node and npm paths in argv initially since argv can contain sensitive info. a cleaned version will be logged later
21-
const { log } = require('proc-log')
21+
const { log, output } = require('proc-log')
2222
log.verbose('cli', process.argv.slice(0, 2).join(' '))
2323
log.info('using', 'npm@%s', npm.version)
2424
log.info('using', 'node@%s', process.version)
@@ -41,7 +41,7 @@ module.exports = async (process, validateEngines) => {
4141

4242
// npm -v
4343
if (npm.config.get('version', 'cli')) {
44-
npm.output(npm.version)
44+
output.standard(npm.version)
4545
return exitHandler()
4646
}
4747

@@ -53,7 +53,7 @@ module.exports = async (process, validateEngines) => {
5353

5454
cmd = npm.argv.shift()
5555
if (!cmd) {
56-
npm.output(npm.usage)
56+
output.standard(npm.usage)
5757
process.exitCode = 1
5858
return exitHandler()
5959
}
@@ -64,8 +64,8 @@ module.exports = async (process, validateEngines) => {
6464
if (err.code === 'EUNKNOWNCOMMAND') {
6565
const didYouMean = require('./utils/did-you-mean.js')
6666
const suggestions = await didYouMean(npm.localPrefix, cmd)
67-
npm.output(`Unknown command: "${cmd}"${suggestions}\n`)
68-
npm.output('To see a list of supported npm commands, run:\n npm help')
67+
output.standard(`Unknown command: "${cmd}"${suggestions}\n`)
68+
output.standard('To see a list of supported npm commands, run:\n npm help')
6969
process.exitCode = 1
7070
return exitHandler()
7171
}

lib/commands/access.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const libnpmaccess = require('libnpmaccess')
22
const npa = require('npm-package-arg')
3+
const { output } = require('proc-log')
34
const pkgJson = require('@npmcli/package-json')
45
const localeCompare = require('@isaacs/string-locale-compare')('en')
56

@@ -197,22 +198,22 @@ class Access extends BaseCommand {
197198
}
198199

199200
#output (items, limiter) {
200-
const output = {}
201+
const outputs = {}
201202
const lookup = {
202203
__proto__: null,
203204
read: 'read-only',
204205
write: 'read-write',
205206
}
206207
for (const item in items) {
207208
const val = items[item]
208-
output[item] = lookup[val] || val
209+
outputs[item] = lookup[val] || val
209210
}
210211
if (this.npm.config.get('json')) {
211-
this.npm.output(JSON.stringify(output, null, 2))
212+
output.standard(JSON.stringify(outputs, null, 2))
212213
} else {
213-
for (const item of Object.keys(output).sort(localeCompare)) {
214+
for (const item of Object.keys(outputs).sort(localeCompare)) {
214215
if (!limiter || limiter === item) {
215-
this.npm.output(`${item}: ${output[item]}`)
216+
output.standard(`${item}: ${outputs[item]}`)
216217
}
217218
}
218219
}

lib/commands/adduser.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { log } = require('proc-log')
1+
const { log, output } = require('proc-log')
22
const { redactLog: replaceInfo } = require('@npmcli/redact')
33
const auth = require('../utils/auth.js')
44

@@ -44,7 +44,7 @@ class AddUser extends BaseCommand {
4444

4545
await this.npm.config.save('user')
4646

47-
this.npm.output(message)
47+
output.standard(message)
4848
}
4949
}
5050
module.exports = AddUser

lib/commands/audit.js

+29-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const tufClient = require('@sigstore/tuf')
88

99
const ArboristWorkspaceCmd = require('../arborist-cmd.js')
1010
const auditError = require('../utils/audit-error.js')
11-
const { log } = require('proc-log')
11+
const { log, output } = require('proc-log')
1212
const reifyFinish = require('../utils/reify-finish.js')
1313

1414
const sortAlphabetically = (a, b) => localeCompare(a.name, b.name)
@@ -65,7 +65,7 @@ class VerifySignatures {
6565
}
6666

6767
if (this.npm.config.get('json')) {
68-
this.npm.output(JSON.stringify({
68+
output.standard(JSON.stringify({
6969
invalid,
7070
missing,
7171
}, null, 2))
@@ -77,91 +77,91 @@ class VerifySignatures {
7777
const auditedPlural = this.auditedWithKeysCount > 1 ? 's' : ''
7878
const timing = `audited ${this.auditedWithKeysCount} package${auditedPlural} in ` +
7979
`${Math.floor(Number(elapsed) / 1e9)}s`
80-
this.npm.output(timing)
81-
this.npm.output('')
80+
output.standard(timing)
81+
output.standard('')
8282

8383
const verifiedBold = this.npm.chalk.bold('verified')
8484
if (this.verifiedSignatureCount) {
8585
if (this.verifiedSignatureCount === 1) {
8686
/* eslint-disable-next-line max-len */
87-
this.npm.output(`${this.verifiedSignatureCount} package has a ${verifiedBold} registry signature`)
87+
output.standard(`${this.verifiedSignatureCount} package has a ${verifiedBold} registry signature`)
8888
} else {
8989
/* eslint-disable-next-line max-len */
90-
this.npm.output(`${this.verifiedSignatureCount} packages have ${verifiedBold} registry signatures`)
90+
output.standard(`${this.verifiedSignatureCount} packages have ${verifiedBold} registry signatures`)
9191
}
92-
this.npm.output('')
92+
output.standard('')
9393
}
9494

9595
if (this.verifiedAttestationCount) {
9696
if (this.verifiedAttestationCount === 1) {
9797
/* eslint-disable-next-line max-len */
98-
this.npm.output(`${this.verifiedAttestationCount} package has a ${verifiedBold} attestation`)
98+
output.standard(`${this.verifiedAttestationCount} package has a ${verifiedBold} attestation`)
9999
} else {
100100
/* eslint-disable-next-line max-len */
101-
this.npm.output(`${this.verifiedAttestationCount} packages have ${verifiedBold} attestations`)
101+
output.standard(`${this.verifiedAttestationCount} packages have ${verifiedBold} attestations`)
102102
}
103-
this.npm.output('')
103+
output.standard('')
104104
}
105105

106106
if (missing.length) {
107107
const missingClr = this.npm.chalk.bold(this.npm.chalk.red('missing'))
108108
if (missing.length === 1) {
109109
/* eslint-disable-next-line max-len */
110-
this.npm.output(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
110+
output.standard(`1 package has a ${missingClr} registry signature but the registry is providing signing keys:`)
111111
} else {
112112
/* eslint-disable-next-line max-len */
113-
this.npm.output(`${missing.length} packages have ${missingClr} registry signatures but the registry is providing signing keys:`)
113+
output.standard(`${missing.length} packages have ${missingClr} registry signatures but the registry is providing signing keys:`)
114114
}
115-
this.npm.output('')
115+
output.standard('')
116116
missing.map(m =>
117-
this.npm.output(`${this.npm.chalk.red(`${m.name}@${m.version}`)} (${m.registry})`)
117+
output.standard(`${this.npm.chalk.red(`${m.name}@${m.version}`)} (${m.registry})`)
118118
)
119119
}
120120

121121
if (invalid.length) {
122122
if (missing.length) {
123-
this.npm.output('')
123+
output.standard('')
124124
}
125125
const invalidClr = this.npm.chalk.bold(this.npm.chalk.red('invalid'))
126126
// We can have either invalid signatures or invalid provenance
127127
const invalidSignatures = this.invalid.filter(i => i.code === 'EINTEGRITYSIGNATURE')
128128
if (invalidSignatures.length) {
129129
if (invalidSignatures.length === 1) {
130-
this.npm.output(`1 package has an ${invalidClr} registry signature:`)
130+
output.standard(`1 package has an ${invalidClr} registry signature:`)
131131
} else {
132132
/* eslint-disable-next-line max-len */
133-
this.npm.output(`${invalidSignatures.length} packages have ${invalidClr} registry signatures:`)
133+
output.standard(`${invalidSignatures.length} packages have ${invalidClr} registry signatures:`)
134134
}
135-
this.npm.output('')
135+
output.standard('')
136136
invalidSignatures.map(i =>
137-
this.npm.output(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
137+
output.standard(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
138138
)
139-
this.npm.output('')
139+
output.standard('')
140140
}
141141

142142
const invalidAttestations = this.invalid.filter(i => i.code === 'EATTESTATIONVERIFY')
143143
if (invalidAttestations.length) {
144144
if (invalidAttestations.length === 1) {
145-
this.npm.output(`1 package has an ${invalidClr} attestation:`)
145+
output.standard(`1 package has an ${invalidClr} attestation:`)
146146
} else {
147147
/* eslint-disable-next-line max-len */
148-
this.npm.output(`${invalidAttestations.length} packages have ${invalidClr} attestations:`)
148+
output.standard(`${invalidAttestations.length} packages have ${invalidClr} attestations:`)
149149
}
150-
this.npm.output('')
150+
output.standard('')
151151
invalidAttestations.map(i =>
152-
this.npm.output(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
152+
output.standard(`${this.npm.chalk.red(`${i.name}@${i.version}`)} (${i.registry})`)
153153
)
154-
this.npm.output('')
154+
output.standard('')
155155
}
156156

157157
if (invalid.length === 1) {
158158
/* eslint-disable-next-line max-len */
159-
this.npm.output(`Someone might have tampered with this package since it was published on the registry!`)
159+
output.standard(`Someone might have tampered with this package since it was published on the registry!`)
160160
} else {
161161
/* eslint-disable-next-line max-len */
162-
this.npm.output(`Someone might have tampered with these packages since they were published on the registry!`)
162+
output.standard(`Someone might have tampered with these packages since they were published on the registry!`)
163163
}
164-
this.npm.output('')
164+
output.standard('')
165165
}
166166
}
167167

@@ -463,7 +463,7 @@ class Audit extends ArboristWorkspaceCmd {
463463
chalk: this.npm.chalk,
464464
})
465465
process.exitCode = process.exitCode || result.exitCode
466-
this.npm.output(result.report)
466+
output.standard(result.report)
467467
}
468468
}
469469

lib/commands/cache.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const BaseCommand = require('../base-command.js')
77
const npa = require('npm-package-arg')
88
const jsonParse = require('json-parse-even-better-errors')
99
const localeCompare = require('@isaacs/string-locale-compare')('en')
10-
const { log } = require('proc-log')
10+
const { log, output } = require('proc-log')
1111

1212
const searchCachePackage = async (path, parsed, cacheKeys) => {
1313
/* eslint-disable-next-line max-len */
@@ -135,7 +135,7 @@ class Cache extends BaseCommand {
135135
log.warn(`Not Found: ${key}`)
136136
break
137137
}
138-
this.npm.output(`Deleted: ${key}`)
138+
output.standard(`Deleted: ${key}`)
139139
await cacache.rm.entry(cachePath, key)
140140
// XXX this could leave other entries without content!
141141
await cacache.rm.content(cachePath, entry.integrity)
@@ -170,20 +170,20 @@ class Cache extends BaseCommand {
170170
? `~${cache.slice(process.env.HOME.length)}`
171171
: cache
172172
const stats = await cacache.verify(cache)
173-
this.npm.output(`Cache verified and compressed (${prefix})`)
174-
this.npm.output(`Content verified: ${stats.verifiedContent} (${stats.keptSize} bytes)`)
173+
output.standard(`Cache verified and compressed (${prefix})`)
174+
output.standard(`Content verified: ${stats.verifiedContent} (${stats.keptSize} bytes)`)
175175
if (stats.badContentCount) {
176-
this.npm.output(`Corrupted content removed: ${stats.badContentCount}`)
176+
output.standard(`Corrupted content removed: ${stats.badContentCount}`)
177177
}
178178
if (stats.reclaimedCount) {
179179
/* eslint-disable-next-line max-len */
180-
this.npm.output(`Content garbage-collected: ${stats.reclaimedCount} (${stats.reclaimedSize} bytes)`)
180+
output.standard(`Content garbage-collected: ${stats.reclaimedCount} (${stats.reclaimedSize} bytes)`)
181181
}
182182
if (stats.missingContent) {
183-
this.npm.output(`Missing content: ${stats.missingContent}`)
183+
output.standard(`Missing content: ${stats.missingContent}`)
184184
}
185-
this.npm.output(`Index entries: ${stats.totalEntries}`)
186-
this.npm.output(`Finished in ${stats.runTime.total / 1000}s`)
185+
output.standard(`Index entries: ${stats.totalEntries}`)
186+
output.standard(`Finished in ${stats.runTime.total / 1000}s`)
187187
}
188188

189189
// npm cache ls [--package <spec> ...]
@@ -203,10 +203,10 @@ class Cache extends BaseCommand {
203203
results.add(key)
204204
}
205205
}
206-
[...results].sort(localeCompare).forEach(key => this.npm.output(key))
206+
[...results].sort(localeCompare).forEach(key => output.standard(key))
207207
return
208208
}
209-
cacheKeys.sort(localeCompare).forEach(key => this.npm.output(key))
209+
cacheKeys.sort(localeCompare).forEach(key => output.standard(key))
210210
}
211211
}
212212

lib/commands/completion.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
const fs = require('fs/promises')
3333
const nopt = require('nopt')
3434
const { resolve } = require('path')
35+
const { output } = require('proc-log')
3536

3637
const Npm = require('../npm.js')
3738
const { definitions, shorthands } = require('@npmcli/config/lib/definitions')
@@ -185,7 +186,7 @@ class Completion extends BaseCommand {
185186
}
186187

187188
if (compls.length > 0) {
188-
this.npm.output(compls.join('\n'))
189+
output.standard(compls.join('\n'))
189190
}
190191
}
191192
}

lib/commands/config.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ini = require('ini')
66
const localeCompare = require('@isaacs/string-locale-compare')('en')
77
const pkgJson = require('@npmcli/package-json')
88
const { defaults, definitions } = require('@npmcli/config/lib/definitions')
9-
const { log } = require('proc-log')
9+
const { log, output } = require('proc-log')
1010

1111
// These are the configs that we can nerf-dart. Not all of them currently even
1212
// *have* config definitions so we have to explicitly validate them here
@@ -185,7 +185,7 @@ class Config extends BaseCommand {
185185
const pref = keys.length > 1 ? `${key}=` : ''
186186
out.push(pref + this.npm.config.get(key))
187187
}
188-
this.npm.output(out.join('\n'))
188+
output.standard(out.join('\n'))
189189
}
190190

191191
async del (keys) {
@@ -282,7 +282,7 @@ ${defData}
282282
this.npm.config.repair(problems)
283283
const locations = []
284284

285-
this.npm.output('The following configuration problems have been repaired:\n')
285+
output.standard('The following configuration problems have been repaired:\n')
286286
const summary = problems.map(({ action, from, to, key, where }) => {
287287
// coverage disabled for else branch because it is intentionally omitted
288288
// istanbul ignore else
@@ -295,7 +295,7 @@ ${defData}
295295
return `- \`${key}\` deleted from ${where} config`
296296
}
297297
}).join('\n')
298-
this.npm.output(summary)
298+
output.standard(summary)
299299

300300
return await Promise.all(locations.map((location) => this.npm.config.save(location)))
301301
}
@@ -354,7 +354,7 @@ ${defData}
354354
}
355355
}
356356

357-
this.npm.output(msg.join('\n').trim())
357+
output.standard(msg.join('\n').trim())
358358
}
359359

360360
async listJson () {
@@ -366,7 +366,7 @@ ${defData}
366366

367367
publicConf[key] = this.npm.config.get(key)
368368
}
369-
this.npm.output(JSON.stringify(publicConf, null, 2))
369+
output.standard(JSON.stringify(publicConf, null, 2))
370370
}
371371
}
372372

lib/commands/diff.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const libnpmdiff = require('libnpmdiff')
44
const npa = require('npm-package-arg')
55
const pacote = require('pacote')
66
const pickManifest = require('npm-pick-manifest')
7-
const { log } = require('proc-log')
7+
const { log, output } = require('proc-log')
88
const pkgJson = require('@npmcli/package-json')
99
const BaseCommand = require('../base-command.js')
1010

@@ -64,7 +64,7 @@ class Diff extends BaseCommand {
6464
diffFiles: args,
6565
where: this.top,
6666
})
67-
return this.npm.output(res)
67+
return output.standard(res)
6868
}
6969

7070
async execWorkspaces (args) {

0 commit comments

Comments
 (0)