Skip to content

Commit 060d587

Browse files
committed
1 parent 9e7f5ac commit 060d587

37 files changed

+1076
-944
lines changed

DEPENDENCIES.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ graph LR;
288288
cacache-->ssri;
289289
cacache-->tar;
290290
cacache-->unique-filename;
291-
chalk-->ansi-styles;
292-
chalk-->supports-color;
293291
cidr-regex-->ip-regex;
294292
cli-columns-->string-width;
295293
cli-columns-->strip-ansi;
@@ -583,7 +581,6 @@ graph LR;
583581
npm-->validate-npm-package-name;
584582
npm-->which;
585583
npm-->write-file-atomic;
586-
npm-audit-report-->chalk;
587584
npm-bundled-->npm-normalize-package-bin;
588585
npm-install-checks-->semver;
589586
npm-package-arg-->hosted-git-info;
@@ -607,7 +604,6 @@ graph LR;
607604
npmcli-arborist-->benchmark;
608605
npmcli-arborist-->bin-links;
609606
npmcli-arborist-->cacache;
610-
npmcli-arborist-->chalk;
611607
npmcli-arborist-->common-ancestor-path;
612608
npmcli-arborist-->hosted-git-info;
613609
npmcli-arborist-->isaacs-string-locale-compare["@isaacs/string-locale-compare"];
@@ -787,7 +783,6 @@ graph LR;
787783
string-width-->strip-ansi;
788784
string_decoder-->safe-buffer;
789785
strip-ansi-->ansi-regex;
790-
supports-color-->has-flag;
791786
tar-->chownr;
792787
tar-->fs-minipass;
793788
tar-->minipass;

lib/commands/audit.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const auditReport = require('npm-audit-report')
1+
const npmAuditReport = require('npm-audit-report')
22
const fetch = require('npm-registry-fetch')
33
const localeCompare = require('@isaacs/string-locale-compare')('en')
44
const npa = require('npm-package-arg')
@@ -457,7 +457,10 @@ class Audit extends ArboristWorkspaceCmd {
457457
} else {
458458
// will throw if there's an error, because this is an audit command
459459
auditError(this.npm, arb.auditReport)
460-
const result = auditReport(arb.auditReport, opts)
460+
const result = npmAuditReport(arb.auditReport, {
461+
...opts,
462+
chalk: this.npm.chalk,
463+
})
461464
process.exitCode = process.exitCode || result.exitCode
462465
this.npm.output(result.report)
463466
}

lib/commands/exec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Exec extends BaseCommand {
5454
localBin,
5555
globalBin,
5656
globalDir,
57+
chalk,
5758
} = this.npm
5859
const output = this.npm.output.bind(this.npm)
5960
const scriptShell = this.npm.config.get('script-shell') || undefined
@@ -83,6 +84,7 @@ class Exec extends BaseCommand {
8384
globalBin,
8485
globalPath,
8586
output,
87+
chalk,
8688
packages,
8789
path: localPrefix,
8890
runPath,

lib/commands/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ class Init extends BaseCommand {
119119
}
120120

121121
const newArgs = [packageName, ...otherArgs]
122-
const { color } = this.npm.flatOptions
123122
const {
124123
flatOptions,
125124
localBin,
126125
globalBin,
126+
chalk,
127127
} = this.npm
128128
const output = this.npm.output.bind(this.npm)
129129
const runPath = path
@@ -133,10 +133,10 @@ class Init extends BaseCommand {
133133
await libexec({
134134
...flatOptions,
135135
args: newArgs,
136-
color,
137136
localBin,
138137
globalBin,
139138
output,
139+
chalk,
140140
path,
141141
runPath,
142142
scriptShell,

lib/npm.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { resolve, dirname, join } = require('path')
22
const Config = require('@npmcli/config')
3-
const chalk = require('chalk')
43
const which = require('which')
54
const fs = require('fs/promises')
65

@@ -42,12 +41,13 @@ class Npm {
4241
#loadPromise = null
4342
#title = 'npm'
4443
#argvClean = []
45-
#chalk = null
46-
#logChalk = null
47-
#noColorChalk = new chalk.Instance({ level: 0 })
4844
#npmRoot = null
4945
#warnedNonDashArg = false
5046

47+
#chalk = null
48+
#logChalk = null
49+
#noColorChalk = null
50+
5151
#outputBuffer = []
5252
#logFile = new LogFile()
5353
#display = new Display()
@@ -194,6 +194,13 @@ class Npm {
194194

195195
await this.time('npm:load:configload', () => this.config.load())
196196

197+
const { Chalk, supportsColor, supportsColorStderr } = await import('chalk')
198+
this.#noColorChalk = new Chalk({ level: 0 })
199+
this.#chalk = this.color ? new Chalk({ level: supportsColor.level })
200+
: this.#noColorChalk
201+
this.#logChalk = this.logColor ? new Chalk({ level: supportsColorStderr.level })
202+
: this.#noColorChalk
203+
197204
// mkdir this separately since the logs dir can be set to
198205
// a different location. if this fails, then we don't have
199206
// a cache dir, but we don't want to fail immediately since
@@ -301,20 +308,10 @@ class Npm {
301308
}
302309

303310
get chalk () {
304-
if (!this.#chalk) {
305-
this.#chalk = new chalk.Instance({
306-
level: this.color ? chalk.level : 0,
307-
})
308-
}
309311
return this.#chalk
310312
}
311313

312314
get logChalk () {
313-
if (!this.#logChalk) {
314-
this.#logChalk = new chalk.Instance({
315-
level: this.logColor ? chalk.stderr.level : 0,
316-
})
317-
}
318315
return this.#logChalk
319316
}
320317

lib/utils/explain-eresolve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const explain = (expl, chalk, depth) => {
4444
}
4545

4646
// generate a full verbose report and tell the user how to fix it
47-
const report = (expl, chalk, noColor) => {
47+
const report = (expl, chalk, noColorChalk) => {
4848
const flags = [
4949
expl.strictPeerDeps ? '--no-strict-peer-deps' : '',
5050
'--force',
@@ -61,7 +61,7 @@ to accept an incorrect (and potentially broken) dependency resolution.`
6161

6262
return {
6363
explanation: `${explain(expl, chalk, 4)}\n\n${fix}`,
64-
file: `# npm resolution error report\n\n${explain(expl, noColor, Infinity)}\n\n${fix}`,
64+
file: `# npm resolution error report\n\n${explain(expl, noColorChalk, Infinity)}\n\n${fix}`,
6565
}
6666
}
6767

lib/utils/reify-output.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const getAuditReport = (npm, report) => {
116116
reporter,
117117
...npm.flatOptions,
118118
auditLevel,
119+
chalk: npm.chalk,
119120
})
120121
if (npm.command === 'audit') {
121122
process.exitCode = process.exitCode || res.exitCode

node_modules/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
!/gauge
112112
!/glob
113113
!/graceful-fs
114-
!/has-flag
115114
!/has-unicode
116115
!/has
117116
!/hosted-git-info
@@ -284,7 +283,6 @@
284283
!/string-width
285284
!/strip-ansi-cjs
286285
!/strip-ansi
287-
!/supports-color
288286
!/tar
289287
!/tar/node_modules/
290288
/tar/node_modules/*

node_modules/chalk/license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

node_modules/chalk/package.json

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
{
22
"name": "chalk",
3-
"version": "4.1.2",
3+
"version": "5.2.0",
44
"description": "Terminal string styling done right",
55
"license": "MIT",
66
"repository": "chalk/chalk",
77
"funding": "https://github.com/chalk/chalk?sponsor=1",
8-
"main": "source",
8+
"type": "module",
9+
"main": "./source/index.js",
10+
"exports": "./source/index.js",
11+
"imports": {
12+
"#ansi-styles": "./source/vendor/ansi-styles/index.js",
13+
"#supports-color": {
14+
"node": "./source/vendor/supports-color/index.js",
15+
"default": "./source/vendor/supports-color/browser.js"
16+
}
17+
},
18+
"types": "./source/index.d.ts",
919
"engines": {
10-
"node": ">=10"
20+
"node": "^12.17.0 || ^14.13 || >=16.0.0"
1121
},
1222
"scripts": {
13-
"test": "xo && nyc ava && tsd",
23+
"test": "xo && c8 ava && tsd",
1424
"bench": "matcha benchmark.js"
1525
},
1626
"files": [
1727
"source",
18-
"index.d.ts"
28+
"!source/index.test-d.ts"
1929
],
2030
"keywords": [
2131
"color",
@@ -25,7 +35,6 @@
2535
"console",
2636
"cli",
2737
"string",
28-
"str",
2938
"ansi",
3039
"style",
3140
"styles",
@@ -40,29 +49,33 @@
4049
"command-line",
4150
"text"
4251
],
43-
"dependencies": {
44-
"ansi-styles": "^4.1.0",
45-
"supports-color": "^7.1.0"
46-
},
4752
"devDependencies": {
48-
"ava": "^2.4.0",
49-
"coveralls": "^3.0.7",
50-
"execa": "^4.0.0",
51-
"import-fresh": "^3.1.0",
53+
"@types/node": "^16.11.10",
54+
"ava": "^3.15.0",
55+
"c8": "^7.10.0",
56+
"color-convert": "^2.0.1",
57+
"execa": "^6.0.0",
58+
"log-update": "^5.0.0",
5259
"matcha": "^0.7.0",
53-
"nyc": "^15.0.0",
54-
"resolve-from": "^5.0.0",
55-
"tsd": "^0.7.4",
56-
"xo": "^0.28.2"
60+
"tsd": "^0.19.0",
61+
"xo": "^0.53.0",
62+
"yoctodelay": "^2.0.0"
5763
},
5864
"xo": {
5965
"rules": {
6066
"unicorn/prefer-string-slice": "off",
61-
"unicorn/prefer-includes": "off",
62-
"@typescript-eslint/member-ordering": "off",
63-
"no-redeclare": "off",
64-
"unicorn/string-content": "off",
65-
"unicorn/better-regex": "off"
67+
"@typescript-eslint/consistent-type-imports": "off",
68+
"@typescript-eslint/consistent-type-exports": "off",
69+
"@typescript-eslint/consistent-type-definitions": "off"
6670
}
71+
},
72+
"c8": {
73+
"reporter": [
74+
"text",
75+
"lcov"
76+
],
77+
"exclude": [
78+
"source/vendor"
79+
]
6780
}
6881
}

0 commit comments

Comments
 (0)