Skip to content

Commit 9622597

Browse files
authored
feat: refactor terminal display (#7339)
This removes `npmlog` and similar dependencies in favor of `lib/utils/display` doing that part.
1 parent 2a80dab commit 9622597

File tree

161 files changed

+2720
-6590
lines changed

Some content is hidden

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

161 files changed

+2720
-6590
lines changed

DEPENDENCIES.md

+6-23
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ graph LR;
3636
libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"];
3737
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
3838
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
39-
libnpmexec-->npmlog;
4039
libnpmexec-->pacote;
4140
libnpmexec-->proc-log;
4241
libnpmexec-->read-package-json-fast;
@@ -131,10 +130,10 @@ graph LR;
131130
npm-->npmcli-run-script["@npmcli/run-script"];
132131
npm-->npmcli-smoke-tests["@npmcli/smoke-tests"];
133132
npm-->npmcli-template-oss["@npmcli/template-oss"];
134-
npm-->npmlog;
135133
npm-->pacote;
136134
npm-->parse-conflict-json;
137135
npm-->proc-log;
136+
npm-->proggy;
138137
npm-->read;
139138
npm-->semver;
140139
npm-->ssri;
@@ -180,10 +179,10 @@ graph LR;
180179
npmcli-arborist-->npmcli-redact["@npmcli/redact"];
181180
npmcli-arborist-->npmcli-run-script["@npmcli/run-script"];
182181
npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"];
183-
npmcli-arborist-->npmlog;
184182
npmcli-arborist-->pacote;
185183
npmcli-arborist-->parse-conflict-json;
186184
npmcli-arborist-->proc-log;
185+
npmcli-arborist-->proggy;
187186
npmcli-arborist-->read-package-json-fast;
188187
npmcli-arborist-->semver;
189188
npmcli-arborist-->ssri;
@@ -234,8 +233,6 @@ graph LR;
234233
npmcli-smoke-tests-->npmcli-promise-spawn["@npmcli/promise-spawn"];
235234
npmcli-smoke-tests-->npmcli-template-oss["@npmcli/template-oss"];
236235
npmcli-smoke-tests-->semver;
237-
npmlog-->are-we-there-yet;
238-
npmlog-->gauge;
239236
pacote-->cacache;
240237
pacote-->fs-minipass;
241238
pacote-->npm-package-arg;
@@ -303,14 +300,6 @@ graph LR;
303300
foreground-child-->cross-spawn;
304301
foreground-child-->signal-exit;
305302
fs-minipass-->minipass;
306-
gauge-->aproba;
307-
gauge-->color-support;
308-
gauge-->console-control-strings;
309-
gauge-->has-unicode;
310-
gauge-->signal-exit;
311-
gauge-->string-width;
312-
gauge-->strip-ansi;
313-
gauge-->wide-align;
314303
glob-->foreground-child;
315304
glob-->jackspeak;
316305
glob-->minimatch;
@@ -373,7 +362,6 @@ graph LR;
373362
libnpmexec-->npmcli-mock-registry["@npmcli/mock-registry"];
374363
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
375364
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
376-
libnpmexec-->npmlog;
377365
libnpmexec-->pacote;
378366
libnpmexec-->proc-log;
379367
libnpmexec-->read-package-json-fast;
@@ -548,11 +536,11 @@ graph LR;
548536
npm-->npmcli-run-script["@npmcli/run-script"];
549537
npm-->npmcli-smoke-tests["@npmcli/smoke-tests"];
550538
npm-->npmcli-template-oss["@npmcli/template-oss"];
551-
npm-->npmlog;
552539
npm-->p-map;
553540
npm-->pacote;
554541
npm-->parse-conflict-json;
555542
npm-->proc-log;
543+
npm-->proggy;
556544
npm-->qrcode-terminal;
557545
npm-->read;
558546
npm-->remark-gfm;
@@ -627,10 +615,10 @@ graph LR;
627615
npmcli-arborist-->npmcli-redact["@npmcli/redact"];
628616
npmcli-arborist-->npmcli-run-script["@npmcli/run-script"];
629617
npmcli-arborist-->npmcli-template-oss["@npmcli/template-oss"];
630-
npmcli-arborist-->npmlog;
631618
npmcli-arborist-->pacote;
632619
npmcli-arborist-->parse-conflict-json;
633620
npmcli-arborist-->proc-log;
621+
npmcli-arborist-->proggy;
634622
npmcli-arborist-->promise-all-reject-late;
635623
npmcli-arborist-->promise-call-limit;
636624
npmcli-arborist-->read-package-json-fast;
@@ -721,10 +709,6 @@ graph LR;
721709
npmcli-smoke-tests-->semver;
722710
npmcli-smoke-tests-->tap;
723711
npmcli-smoke-tests-->which;
724-
npmlog-->are-we-there-yet;
725-
npmlog-->console-control-strings;
726-
npmlog-->gauge;
727-
npmlog-->set-blocking;
728712
p-map-->aggregate-error;
729713
pacote-->cacache;
730714
pacote-->fs-minipass;
@@ -812,7 +796,6 @@ graph LR;
812796
validate-npm-package-name-->builtins;
813797
wcwidth-->defaults;
814798
which-->isexe;
815-
wide-align-->string-width;
816799
wrap-ansi-->ansi-styles;
817800
wrap-ansi-->string-width;
818801
wrap-ansi-->strip-ansi;
@@ -836,5 +819,5 @@ packages higher up the chain.
836819
- @npmcli/package-json, npm-registry-fetch
837820
- @npmcli/git, make-fetch-happen, @npmcli/config
838821
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, read-package-json, promzard
839-
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, npmlog, parse-conflict-json, @npmcli/mock-globals, read
840-
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate
822+
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, parse-conflict-json, @npmcli/mock-globals, read
823+
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, @npmcli/redact, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, proggy, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate

lib/arborist-cmd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const log = require('./utils/log-shim.js')
1+
const log = require('proc-log')
22

33
// This is the base for all commands whose execWorkspaces just gets
44
// a list of workspace names and passes it on to new Arborist() to

lib/base-command.js

+1-1
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('./utils/log-shim.js')
7+
const log = require('proc-log')
88

99
class BaseCommand {
1010
static workspaces = false

lib/cli-entry.js

+1-1
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('./utils/log-shim.js')
21+
const log = 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)

lib/commands/adduser.js

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

@@ -27,7 +27,6 @@ class AddUser extends BaseCommand {
2727

2828
const creds = this.npm.config.getCredentialsByURI(registry)
2929

30-
log.disableProgress()
3130
log.notice('', `Log in on ${replaceInfo(registry)}`)
3231

3332
const { message, newCreds } = await auth.adduser(this.npm, {

lib/commands/audit.js

+3-7
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('../utils/log-shim.js')
11+
const log = require('proc-log')
1212
const reifyFinish = require('../utils/reify-finish.js')
1313

1414
const sortAlphabetically = (a, b) => localeCompare(a.name, b.name)
@@ -45,12 +45,8 @@ class VerifySignatures {
4545
})
4646
await Promise.all([...registries].map(registry => this.setKeys({ registry, tuf })))
4747

48-
const progress = log.newItem('verifying registry signatures', edges.size)
49-
const mapper = async (edge) => {
50-
progress.completeWork(1)
51-
await this.getVerifiedInfo(edge)
52-
}
53-
await pMap(edges, mapper, { concurrency: 20, stopOnError: true })
48+
log.verbose('verifying registry signatures')
49+
await pMap(edges, (e) => this.getVerifiedInfo(e), { concurrency: 20, stopOnError: true })
5450

5551
// Didn't find any dependencies that could be verified, e.g. only local
5652
// deps, missing version, not on a registry etc.

lib/commands/cache.js

+1-1
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('../utils/log-shim')
10+
const log = require('proc-log')
1111

1212
const searchCachePackage = async (path, parsed, cacheKeys) => {
1313
/* eslint-disable-next-line max-len */

lib/commands/ci.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const reifyFinish = require('../utils/reify-finish.js')
22
const runScript = require('@npmcli/run-script')
33
const fs = require('fs/promises')
4-
const log = require('../utils/log-shim.js')
4+
const log = require('proc-log')
55
const validateLockfile = require('../utils/validate-lockfile.js')
66

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

lib/commands/config.js

+25-30
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('../utils/log-shim.js')
9+
const log = 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
@@ -111,35 +111,30 @@ class Config extends BaseCommand {
111111
}
112112

113113
async exec ([action, ...args]) {
114-
log.disableProgress()
115-
try {
116-
switch (action) {
117-
case 'set':
118-
await this.set(args)
119-
break
120-
case 'get':
121-
await this.get(args)
122-
break
123-
case 'delete':
124-
case 'rm':
125-
case 'del':
126-
await this.del(args)
127-
break
128-
case 'list':
129-
case 'ls':
130-
await (this.npm.flatOptions.json ? this.listJson() : this.list())
131-
break
132-
case 'edit':
133-
await this.edit()
134-
break
135-
case 'fix':
136-
await this.fix()
137-
break
138-
default:
139-
throw this.usageError()
140-
}
141-
} finally {
142-
log.enableProgress()
114+
switch (action) {
115+
case 'set':
116+
await this.set(args)
117+
break
118+
case 'get':
119+
await this.get(args)
120+
break
121+
case 'delete':
122+
case 'rm':
123+
case 'del':
124+
await this.del(args)
125+
break
126+
case 'list':
127+
case 'ls':
128+
await (this.npm.flatOptions.json ? this.listJson() : this.list())
129+
break
130+
case 'edit':
131+
await this.edit()
132+
break
133+
case 'fix':
134+
await this.fix()
135+
break
136+
default:
137+
throw this.usageError()
143138
}
144139
}
145140

lib/commands/diff.js

+1-1
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('../utils/log-shim')
7+
const log = require('proc-log')
88
const pkgJson = require('@npmcli/package-json')
99
const BaseCommand = require('../base-command.js')
1010

lib/commands/dist-tag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const npa = require('npm-package-arg')
22
const regFetch = require('npm-registry-fetch')
33
const semver = require('semver')
4-
const log = require('../utils/log-shim')
4+
const log = require('proc-log')
55
const otplease = require('../utils/otplease.js')
66
const pkgJson = require('@npmcli/package-json')
77
const BaseCommand = require('../base-command.js')

0 commit comments

Comments
 (0)