diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index d287186cf4853..4e336ae5daf21 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -288,8 +288,6 @@ graph LR; cacache-->ssri; cacache-->tar; cacache-->unique-filename; - chalk-->ansi-styles; - chalk-->supports-color; cidr-regex-->ip-regex; cli-columns-->string-width; cli-columns-->strip-ansi; @@ -583,7 +581,6 @@ graph LR; npm-->validate-npm-package-name; npm-->which; npm-->write-file-atomic; - npm-audit-report-->chalk; npm-bundled-->npm-normalize-package-bin; npm-install-checks-->semver; npm-package-arg-->hosted-git-info; @@ -607,7 +604,6 @@ graph LR; npmcli-arborist-->benchmark; npmcli-arborist-->bin-links; npmcli-arborist-->cacache; - npmcli-arborist-->chalk; npmcli-arborist-->common-ancestor-path; npmcli-arborist-->hosted-git-info; npmcli-arborist-->isaacs-string-locale-compare["@isaacs/string-locale-compare"]; @@ -787,7 +783,6 @@ graph LR; string-width-->strip-ansi; string_decoder-->safe-buffer; strip-ansi-->ansi-regex; - supports-color-->has-flag; tar-->chownr; tar-->fs-minipass; tar-->minipass; diff --git a/lib/commands/audit.js b/lib/commands/audit.js index 8db29b0c67f33..500620f2cd01b 100644 --- a/lib/commands/audit.js +++ b/lib/commands/audit.js @@ -1,4 +1,4 @@ -const auditReport = require('npm-audit-report') +const npmAuditReport = require('npm-audit-report') const fetch = require('npm-registry-fetch') const localeCompare = require('@isaacs/string-locale-compare')('en') const npa = require('npm-package-arg') @@ -457,7 +457,10 @@ class Audit extends ArboristWorkspaceCmd { } else { // will throw if there's an error, because this is an audit command auditError(this.npm, arb.auditReport) - const result = auditReport(arb.auditReport, opts) + const result = npmAuditReport(arb.auditReport, { + ...opts, + chalk: this.npm.chalk, + }) process.exitCode = process.exitCode || result.exitCode this.npm.output(result.report) } diff --git a/lib/commands/exec.js b/lib/commands/exec.js index a5235c7845851..ed4b07dc39b4d 100644 --- a/lib/commands/exec.js +++ b/lib/commands/exec.js @@ -54,6 +54,7 @@ class Exec extends BaseCommand { localBin, globalBin, globalDir, + chalk, } = this.npm const output = this.npm.output.bind(this.npm) const scriptShell = this.npm.config.get('script-shell') || undefined @@ -83,6 +84,7 @@ class Exec extends BaseCommand { globalBin, globalPath, output, + chalk, packages, path: localPrefix, runPath, diff --git a/lib/commands/init.js b/lib/commands/init.js index 4f77b2903c100..539fba885deef 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -119,11 +119,11 @@ class Init extends BaseCommand { } const newArgs = [packageName, ...otherArgs] - const { color } = this.npm.flatOptions const { flatOptions, localBin, globalBin, + chalk, } = this.npm const output = this.npm.output.bind(this.npm) const runPath = path @@ -133,10 +133,10 @@ class Init extends BaseCommand { await libexec({ ...flatOptions, args: newArgs, - color, localBin, globalBin, output, + chalk, path, runPath, scriptShell, diff --git a/lib/npm.js b/lib/npm.js index afeaf0e79ebf2..f08ef32c180d9 100644 --- a/lib/npm.js +++ b/lib/npm.js @@ -1,6 +1,5 @@ const { resolve, dirname, join } = require('path') const Config = require('@npmcli/config') -const chalk = require('chalk') const which = require('which') const fs = require('fs/promises') @@ -42,12 +41,13 @@ class Npm { #loadPromise = null #title = 'npm' #argvClean = [] - #chalk = null - #logChalk = null - #noColorChalk = new chalk.Instance({ level: 0 }) #npmRoot = null #warnedNonDashArg = false + #chalk = null + #logChalk = null + #noColorChalk = null + #outputBuffer = [] #logFile = new LogFile() #display = new Display() @@ -194,6 +194,13 @@ class Npm { await this.time('npm:load:configload', () => this.config.load()) + const { Chalk, supportsColor, supportsColorStderr } = await import('chalk') + this.#noColorChalk = new Chalk({ level: 0 }) + this.#chalk = this.color ? new Chalk({ level: supportsColor.level }) + : this.#noColorChalk + this.#logChalk = this.logColor ? new Chalk({ level: supportsColorStderr.level }) + : this.#noColorChalk + // mkdir this separately since the logs dir can be set to // a different location. if this fails, then we don't have // a cache dir, but we don't want to fail immediately since @@ -301,20 +308,10 @@ class Npm { } get chalk () { - if (!this.#chalk) { - this.#chalk = new chalk.Instance({ - level: this.color ? chalk.level : 0, - }) - } return this.#chalk } get logChalk () { - if (!this.#logChalk) { - this.#logChalk = new chalk.Instance({ - level: this.logColor ? chalk.stderr.level : 0, - }) - } return this.#logChalk } diff --git a/lib/utils/explain-eresolve.js b/lib/utils/explain-eresolve.js index ba46f3480adb3..f3c6ae23a479d 100644 --- a/lib/utils/explain-eresolve.js +++ b/lib/utils/explain-eresolve.js @@ -44,7 +44,7 @@ const explain = (expl, chalk, depth) => { } // generate a full verbose report and tell the user how to fix it -const report = (expl, chalk, noColor) => { +const report = (expl, chalk, noColorChalk) => { const flags = [ expl.strictPeerDeps ? '--no-strict-peer-deps' : '', '--force', @@ -61,7 +61,7 @@ to accept an incorrect (and potentially broken) dependency resolution.` return { explanation: `${explain(expl, chalk, 4)}\n\n${fix}`, - file: `# npm resolution error report\n\n${explain(expl, noColor, Infinity)}\n\n${fix}`, + file: `# npm resolution error report\n\n${explain(expl, noColorChalk, Infinity)}\n\n${fix}`, } } diff --git a/lib/utils/reify-output.js b/lib/utils/reify-output.js index 5ac7fa4b01896..22036dc8110cf 100644 --- a/lib/utils/reify-output.js +++ b/lib/utils/reify-output.js @@ -116,6 +116,7 @@ const getAuditReport = (npm, report) => { reporter, ...npm.flatOptions, auditLevel, + chalk: npm.chalk, }) if (npm.command === 'audit') { process.exitCode = process.exitCode || res.exitCode diff --git a/node_modules/.gitignore b/node_modules/.gitignore index ef85a22014caa..0919145b131a3 100644 --- a/node_modules/.gitignore +++ b/node_modules/.gitignore @@ -111,7 +111,6 @@ !/gauge !/glob !/graceful-fs -!/has-flag !/has-unicode !/has !/hosted-git-info @@ -284,7 +283,6 @@ !/string-width !/strip-ansi-cjs !/strip-ansi -!/supports-color !/tar !/tar/node_modules/ /tar/node_modules/* diff --git a/node_modules/chalk/license b/node_modules/chalk/license index e7af2f77107d7..fa7ceba3eb4a9 100644 --- a/node_modules/chalk/license +++ b/node_modules/chalk/license @@ -1,6 +1,6 @@ MIT License -Copyright (c) Sindre Sorhus (sindresorhus.com) +Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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: diff --git a/node_modules/chalk/package.json b/node_modules/chalk/package.json index 47c23f29068ca..ddcf7589e9797 100644 --- a/node_modules/chalk/package.json +++ b/node_modules/chalk/package.json @@ -1,21 +1,31 @@ { "name": "chalk", - "version": "4.1.2", + "version": "5.2.0", "description": "Terminal string styling done right", "license": "MIT", "repository": "chalk/chalk", "funding": "https://github.com/chalk/chalk?sponsor=1", - "main": "source", + "type": "module", + "main": "./source/index.js", + "exports": "./source/index.js", + "imports": { + "#ansi-styles": "./source/vendor/ansi-styles/index.js", + "#supports-color": { + "node": "./source/vendor/supports-color/index.js", + "default": "./source/vendor/supports-color/browser.js" + } + }, + "types": "./source/index.d.ts", "engines": { - "node": ">=10" + "node": "^12.17.0 || ^14.13 || >=16.0.0" }, "scripts": { - "test": "xo && nyc ava && tsd", + "test": "xo && c8 ava && tsd", "bench": "matcha benchmark.js" }, "files": [ "source", - "index.d.ts" + "!source/index.test-d.ts" ], "keywords": [ "color", @@ -25,7 +35,6 @@ "console", "cli", "string", - "str", "ansi", "style", "styles", @@ -40,29 +49,33 @@ "command-line", "text" ], - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, "devDependencies": { - "ava": "^2.4.0", - "coveralls": "^3.0.7", - "execa": "^4.0.0", - "import-fresh": "^3.1.0", + "@types/node": "^16.11.10", + "ava": "^3.15.0", + "c8": "^7.10.0", + "color-convert": "^2.0.1", + "execa": "^6.0.0", + "log-update": "^5.0.0", "matcha": "^0.7.0", - "nyc": "^15.0.0", - "resolve-from": "^5.0.0", - "tsd": "^0.7.4", - "xo": "^0.28.2" + "tsd": "^0.19.0", + "xo": "^0.53.0", + "yoctodelay": "^2.0.0" }, "xo": { "rules": { "unicorn/prefer-string-slice": "off", - "unicorn/prefer-includes": "off", - "@typescript-eslint/member-ordering": "off", - "no-redeclare": "off", - "unicorn/string-content": "off", - "unicorn/better-regex": "off" + "@typescript-eslint/consistent-type-imports": "off", + "@typescript-eslint/consistent-type-exports": "off", + "@typescript-eslint/consistent-type-definitions": "off" } + }, + "c8": { + "reporter": [ + "text", + "lcov" + ], + "exclude": [ + "source/vendor" + ] } } diff --git a/node_modules/chalk/source/index.js b/node_modules/chalk/source/index.js index 75ec66350527a..8bc993da5d622 100644 --- a/node_modules/chalk/source/index.js +++ b/node_modules/chalk/source/index.js @@ -1,19 +1,22 @@ -'use strict'; -const ansiStyles = require('ansi-styles'); -const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color'); -const { +import ansiStyles from '#ansi-styles'; +import supportsColor from '#supports-color'; +import { // eslint-disable-line import/order stringReplaceAll, - stringEncaseCRLFWithFirstIndex -} = require('./util'); + stringEncaseCRLFWithFirstIndex, +} from './utilities.js'; -const {isArray} = Array; +const {stdout: stdoutColor, stderr: stderrColor} = supportsColor; + +const GENERATOR = Symbol('GENERATOR'); +const STYLER = Symbol('STYLER'); +const IS_EMPTY = Symbol('IS_EMPTY'); // `supportsColor.level` → `ansiStyles.color[name]` mapping const levelMapping = [ 'ansi', 'ansi', 'ansi256', - 'ansi16m' + 'ansi16m', ]; const styles = Object.create(null); @@ -28,7 +31,7 @@ const applyOptions = (object, options = {}) => { object.level = options.level === undefined ? colorLevel : options.level; }; -class ChalkClass { +export class Chalk { constructor(options) { // eslint-disable-next-line no-constructor-return return chalkFactory(options); @@ -36,69 +39,80 @@ class ChalkClass { } const chalkFactory = options => { - const chalk = {}; + const chalk = (...strings) => strings.join(' '); applyOptions(chalk, options); - chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_); - - Object.setPrototypeOf(chalk, Chalk.prototype); - Object.setPrototypeOf(chalk.template, chalk); - - chalk.template.constructor = () => { - throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.'); - }; - - chalk.template.Instance = ChalkClass; + Object.setPrototypeOf(chalk, createChalk.prototype); - return chalk.template; + return chalk; }; -function Chalk(options) { +function createChalk(options) { return chalkFactory(options); } +Object.setPrototypeOf(createChalk.prototype, Function.prototype); + for (const [styleName, style] of Object.entries(ansiStyles)) { styles[styleName] = { get() { - const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty); + const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]); Object.defineProperty(this, styleName, {value: builder}); return builder; - } + }, }; } styles.visible = { get() { - const builder = createBuilder(this, this._styler, true); + const builder = createBuilder(this, this[STYLER], true); Object.defineProperty(this, 'visible', {value: builder}); return builder; + }, +}; + +const getModelAnsi = (model, level, type, ...arguments_) => { + if (model === 'rgb') { + if (level === 'ansi16m') { + return ansiStyles[type].ansi16m(...arguments_); + } + + if (level === 'ansi256') { + return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_)); + } + + return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_)); } + + if (model === 'hex') { + return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_)); + } + + return ansiStyles[type][model](...arguments_); }; -const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256']; +const usedModels = ['rgb', 'hex', 'ansi256']; for (const model of usedModels) { styles[model] = { get() { const {level} = this; return function (...arguments_) { - const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler); - return createBuilder(this, styler, this._isEmpty); + const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]); + return createBuilder(this, styler, this[IS_EMPTY]); }; - } + }, }; -} -for (const model of usedModels) { const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); styles[bgModel] = { get() { const {level} = this; return function (...arguments_) { - const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler); - return createBuilder(this, styler, this._isEmpty); + const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]); + return createBuilder(this, styler, this[IS_EMPTY]); }; - } + }, }; } @@ -107,12 +121,12 @@ const proto = Object.defineProperties(() => {}, { level: { enumerable: true, get() { - return this._generator.level; + return this[GENERATOR].level; }, set(level) { - this._generator.level = level; - } - } + this[GENERATOR].level = level; + }, + }, }); const createStyler = (open, close, parent) => { @@ -131,46 +145,39 @@ const createStyler = (open, close, parent) => { close, openAll, closeAll, - parent + parent, }; }; const createBuilder = (self, _styler, _isEmpty) => { - const builder = (...arguments_) => { - if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) { - // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}` - return applyStyle(builder, chalkTag(builder, ...arguments_)); - } - - // Single argument is hot path, implicit coercion is faster than anything - // eslint-disable-next-line no-implicit-coercion - return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' ')); - }; + // Single argument is hot path, implicit coercion is faster than anything + // eslint-disable-next-line no-implicit-coercion + const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' ')); // We alter the prototype because we must return a function, but there is // no way to create a function with a different prototype Object.setPrototypeOf(builder, proto); - builder._generator = self; - builder._styler = _styler; - builder._isEmpty = _isEmpty; + builder[GENERATOR] = self; + builder[STYLER] = _styler; + builder[IS_EMPTY] = _isEmpty; return builder; }; const applyStyle = (self, string) => { if (self.level <= 0 || !string) { - return self._isEmpty ? '' : string; + return self[IS_EMPTY] ? '' : string; } - let styler = self._styler; + let styler = self[STYLER]; if (styler === undefined) { return string; } const {openAll, closeAll} = styler; - if (string.indexOf('\u001B') !== -1) { + if (string.includes('\u001B')) { while (styler !== undefined) { // Replace any instances already present with a re-opening code // otherwise only the part of the string until said closing code @@ -192,38 +199,27 @@ const applyStyle = (self, string) => { return openAll + string + closeAll; }; -let template; -const chalkTag = (chalk, ...strings) => { - const [firstString] = strings; - - if (!isArray(firstString) || !isArray(firstString.raw)) { - // If chalk() was called by itself or with a string, - // return the string itself as a string. - return strings.join(' '); - } +Object.defineProperties(createChalk.prototype, styles); - const arguments_ = strings.slice(1); - const parts = [firstString.raw[0]]; +const chalk = createChalk(); +export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0}); - for (let i = 1; i < firstString.length; i++) { - parts.push( - String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), - String(firstString.raw[i]) - ); - } +export { + modifierNames, + foregroundColorNames, + backgroundColorNames, + colorNames, - if (template === undefined) { - template = require('./templates'); - } + // TODO: Remove these aliases in the next major version + modifierNames as modifiers, + foregroundColorNames as foregroundColors, + backgroundColorNames as backgroundColors, + colorNames as colors, +} from './vendor/ansi-styles/index.js'; - return template(chalk, parts.join('')); +export { + stdoutColor as supportsColor, + stderrColor as supportsColorStderr, }; -Object.defineProperties(Chalk.prototype, styles); - -const chalk = Chalk(); // eslint-disable-line new-cap -chalk.supportsColor = stdoutColor; -chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap -chalk.stderr.supportsColor = stderrColor; - -module.exports = chalk; +export default chalk; diff --git a/node_modules/chalk/source/templates.js b/node_modules/chalk/source/templates.js deleted file mode 100644 index b130949d646fd..0000000000000 --- a/node_modules/chalk/source/templates.js +++ /dev/null @@ -1,134 +0,0 @@ -'use strict'; -const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi; -const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g; -const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/; -const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi; - -const ESCAPES = new Map([ - ['n', '\n'], - ['r', '\r'], - ['t', '\t'], - ['b', '\b'], - ['f', '\f'], - ['v', '\v'], - ['0', '\0'], - ['\\', '\\'], - ['e', '\u001B'], - ['a', '\u0007'] -]); - -function unescape(c) { - const u = c[0] === 'u'; - const bracket = c[1] === '{'; - - if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) { - return String.fromCharCode(parseInt(c.slice(1), 16)); - } - - if (u && bracket) { - return String.fromCodePoint(parseInt(c.slice(2, -1), 16)); - } - - return ESCAPES.get(c) || c; -} - -function parseArguments(name, arguments_) { - const results = []; - const chunks = arguments_.trim().split(/\s*,\s*/g); - let matches; - - for (const chunk of chunks) { - const number = Number(chunk); - if (!Number.isNaN(number)) { - results.push(number); - } else if ((matches = chunk.match(STRING_REGEX))) { - results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character)); - } else { - throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`); - } - } - - return results; -} - -function parseStyle(style) { - STYLE_REGEX.lastIndex = 0; - - const results = []; - let matches; - - while ((matches = STYLE_REGEX.exec(style)) !== null) { - const name = matches[1]; - - if (matches[2]) { - const args = parseArguments(name, matches[2]); - results.push([name].concat(args)); - } else { - results.push([name]); - } - } - - return results; -} - -function buildStyle(chalk, styles) { - const enabled = {}; - - for (const layer of styles) { - for (const style of layer.styles) { - enabled[style[0]] = layer.inverse ? null : style.slice(1); - } - } - - let current = chalk; - for (const [styleName, styles] of Object.entries(enabled)) { - if (!Array.isArray(styles)) { - continue; - } - - if (!(styleName in current)) { - throw new Error(`Unknown Chalk style: ${styleName}`); - } - - current = styles.length > 0 ? current[styleName](...styles) : current[styleName]; - } - - return current; -} - -module.exports = (chalk, temporary) => { - const styles = []; - const chunks = []; - let chunk = []; - - // eslint-disable-next-line max-params - temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => { - if (escapeCharacter) { - chunk.push(unescape(escapeCharacter)); - } else if (style) { - const string = chunk.join(''); - chunk = []; - chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string)); - styles.push({inverse, styles: parseStyle(style)}); - } else if (close) { - if (styles.length === 0) { - throw new Error('Found extraneous } in Chalk template literal'); - } - - chunks.push(buildStyle(chalk, styles)(chunk.join(''))); - chunk = []; - styles.pop(); - } else { - chunk.push(character); - } - }); - - chunks.push(chunk.join('')); - - if (styles.length > 0) { - const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`; - throw new Error(errMessage); - } - - return chunks.join(''); -}; diff --git a/node_modules/chalk/source/util.js b/node_modules/chalk/source/util.js deleted file mode 100644 index ca466fd466c07..0000000000000 --- a/node_modules/chalk/source/util.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const stringReplaceAll = (string, substring, replacer) => { - let index = string.indexOf(substring); - if (index === -1) { - return string; - } - - const substringLength = substring.length; - let endIndex = 0; - let returnValue = ''; - do { - returnValue += string.substr(endIndex, index - endIndex) + substring + replacer; - endIndex = index + substringLength; - index = string.indexOf(substring, endIndex); - } while (index !== -1); - - returnValue += string.substr(endIndex); - return returnValue; -}; - -const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => { - let endIndex = 0; - let returnValue = ''; - do { - const gotCR = string[index - 1] === '\r'; - returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix; - endIndex = index + 1; - index = string.indexOf('\n', endIndex); - } while (index !== -1); - - returnValue += string.substr(endIndex); - return returnValue; -}; - -module.exports = { - stringReplaceAll, - stringEncaseCRLFWithFirstIndex -}; diff --git a/node_modules/chalk/source/utilities.js b/node_modules/chalk/source/utilities.js new file mode 100644 index 0000000000000..4366dee0d84d7 --- /dev/null +++ b/node_modules/chalk/source/utilities.js @@ -0,0 +1,33 @@ +// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`. +export function stringReplaceAll(string, substring, replacer) { + let index = string.indexOf(substring); + if (index === -1) { + return string; + } + + const substringLength = substring.length; + let endIndex = 0; + let returnValue = ''; + do { + returnValue += string.slice(endIndex, index) + substring + replacer; + endIndex = index + substringLength; + index = string.indexOf(substring, endIndex); + } while (index !== -1); + + returnValue += string.slice(endIndex); + return returnValue; +} + +export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) { + let endIndex = 0; + let returnValue = ''; + do { + const gotCR = string[index - 1] === '\r'; + returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix; + endIndex = index + 1; + index = string.indexOf('\n', endIndex); + } while (index !== -1); + + returnValue += string.slice(endIndex); + return returnValue; +} diff --git a/node_modules/chalk/source/vendor/ansi-styles/index.js b/node_modules/chalk/source/vendor/ansi-styles/index.js new file mode 100644 index 0000000000000..eaa7bed6cb1ed --- /dev/null +++ b/node_modules/chalk/source/vendor/ansi-styles/index.js @@ -0,0 +1,223 @@ +const ANSI_BACKGROUND_OFFSET = 10; + +const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`; + +const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`; + +const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`; + +const styles = { + modifier: { + reset: [0, 0], + // 21 isn't widely supported and 22 does the same thing + bold: [1, 22], + dim: [2, 22], + italic: [3, 23], + underline: [4, 24], + overline: [53, 55], + inverse: [7, 27], + hidden: [8, 28], + strikethrough: [9, 29], + }, + color: { + black: [30, 39], + red: [31, 39], + green: [32, 39], + yellow: [33, 39], + blue: [34, 39], + magenta: [35, 39], + cyan: [36, 39], + white: [37, 39], + + // Bright color + blackBright: [90, 39], + gray: [90, 39], // Alias of `blackBright` + grey: [90, 39], // Alias of `blackBright` + redBright: [91, 39], + greenBright: [92, 39], + yellowBright: [93, 39], + blueBright: [94, 39], + magentaBright: [95, 39], + cyanBright: [96, 39], + whiteBright: [97, 39], + }, + bgColor: { + bgBlack: [40, 49], + bgRed: [41, 49], + bgGreen: [42, 49], + bgYellow: [43, 49], + bgBlue: [44, 49], + bgMagenta: [45, 49], + bgCyan: [46, 49], + bgWhite: [47, 49], + + // Bright color + bgBlackBright: [100, 49], + bgGray: [100, 49], // Alias of `bgBlackBright` + bgGrey: [100, 49], // Alias of `bgBlackBright` + bgRedBright: [101, 49], + bgGreenBright: [102, 49], + bgYellowBright: [103, 49], + bgBlueBright: [104, 49], + bgMagentaBright: [105, 49], + bgCyanBright: [106, 49], + bgWhiteBright: [107, 49], + }, +}; + +export const modifierNames = Object.keys(styles.modifier); +export const foregroundColorNames = Object.keys(styles.color); +export const backgroundColorNames = Object.keys(styles.bgColor); +export const colorNames = [...foregroundColorNames, ...backgroundColorNames]; + +function assembleStyles() { + const codes = new Map(); + + for (const [groupName, group] of Object.entries(styles)) { + for (const [styleName, style] of Object.entries(group)) { + styles[styleName] = { + open: `\u001B[${style[0]}m`, + close: `\u001B[${style[1]}m`, + }; + + group[styleName] = styles[styleName]; + + codes.set(style[0], style[1]); + } + + Object.defineProperty(styles, groupName, { + value: group, + enumerable: false, + }); + } + + Object.defineProperty(styles, 'codes', { + value: codes, + enumerable: false, + }); + + styles.color.close = '\u001B[39m'; + styles.bgColor.close = '\u001B[49m'; + + styles.color.ansi = wrapAnsi16(); + styles.color.ansi256 = wrapAnsi256(); + styles.color.ansi16m = wrapAnsi16m(); + styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET); + styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); + styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); + + // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js + Object.defineProperties(styles, { + rgbToAnsi256: { + value(red, green, blue) { + // We use the extended greyscale palette here, with the exception of + // black and white. normal palette only has 4 greyscale shades. + if (red === green && green === blue) { + if (red < 8) { + return 16; + } + + if (red > 248) { + return 231; + } + + return Math.round(((red - 8) / 247) * 24) + 232; + } + + return 16 + + (36 * Math.round(red / 255 * 5)) + + (6 * Math.round(green / 255 * 5)) + + Math.round(blue / 255 * 5); + }, + enumerable: false, + }, + hexToRgb: { + value(hex) { + const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16)); + if (!matches) { + return [0, 0, 0]; + } + + let [colorString] = matches; + + if (colorString.length === 3) { + colorString = [...colorString].map(character => character + character).join(''); + } + + const integer = Number.parseInt(colorString, 16); + + return [ + /* eslint-disable no-bitwise */ + (integer >> 16) & 0xFF, + (integer >> 8) & 0xFF, + integer & 0xFF, + /* eslint-enable no-bitwise */ + ]; + }, + enumerable: false, + }, + hexToAnsi256: { + value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)), + enumerable: false, + }, + ansi256ToAnsi: { + value(code) { + if (code < 8) { + return 30 + code; + } + + if (code < 16) { + return 90 + (code - 8); + } + + let red; + let green; + let blue; + + if (code >= 232) { + red = (((code - 232) * 10) + 8) / 255; + green = red; + blue = red; + } else { + code -= 16; + + const remainder = code % 36; + + red = Math.floor(code / 36) / 5; + green = Math.floor(remainder / 6) / 5; + blue = (remainder % 6) / 5; + } + + const value = Math.max(red, green, blue) * 2; + + if (value === 0) { + return 30; + } + + // eslint-disable-next-line no-bitwise + let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red)); + + if (value === 2) { + result += 60; + } + + return result; + }, + enumerable: false, + }, + rgbToAnsi: { + value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)), + enumerable: false, + }, + hexToAnsi: { + value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)), + enumerable: false, + }, + }); + + return styles; +} + +const ansiStyles = assembleStyles(); + +export default ansiStyles; diff --git a/node_modules/chalk/source/vendor/supports-color/browser.js b/node_modules/chalk/source/vendor/supports-color/browser.js new file mode 100644 index 0000000000000..9fa6888f10288 --- /dev/null +++ b/node_modules/chalk/source/vendor/supports-color/browser.js @@ -0,0 +1,30 @@ +/* eslint-env browser */ + +const level = (() => { + if (navigator.userAgentData) { + const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium'); + if (brand && brand.version > 93) { + return 3; + } + } + + if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) { + return 1; + } + + return 0; +})(); + +const colorSupport = level !== 0 && { + level, + hasBasic: true, + has256: level >= 2, + has16m: level >= 3, +}; + +const supportsColor = { + stdout: colorSupport, + stderr: colorSupport, +}; + +export default supportsColor; diff --git a/node_modules/chalk/source/vendor/supports-color/index.js b/node_modules/chalk/source/vendor/supports-color/index.js new file mode 100644 index 0000000000000..a7cea61e9eb5f --- /dev/null +++ b/node_modules/chalk/source/vendor/supports-color/index.js @@ -0,0 +1,181 @@ +import process from 'node:process'; +import os from 'node:os'; +import tty from 'node:tty'; + +// From: https://github.com/sindresorhus/has-flag/blob/main/index.js +function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) { + const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); + const position = argv.indexOf(prefix + flag); + const terminatorPosition = argv.indexOf('--'); + return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); +} + +const {env} = process; + +let flagForceColor; +if ( + hasFlag('no-color') + || hasFlag('no-colors') + || hasFlag('color=false') + || hasFlag('color=never') +) { + flagForceColor = 0; +} else if ( + hasFlag('color') + || hasFlag('colors') + || hasFlag('color=true') + || hasFlag('color=always') +) { + flagForceColor = 1; +} + +function envForceColor() { + if ('FORCE_COLOR' in env) { + if (env.FORCE_COLOR === 'true') { + return 1; + } + + if (env.FORCE_COLOR === 'false') { + return 0; + } + + return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); + } +} + +function translateLevel(level) { + if (level === 0) { + return false; + } + + return { + level, + hasBasic: true, + has256: level >= 2, + has16m: level >= 3, + }; +} + +function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) { + const noFlagForceColor = envForceColor(); + if (noFlagForceColor !== undefined) { + flagForceColor = noFlagForceColor; + } + + const forceColor = sniffFlags ? flagForceColor : noFlagForceColor; + + if (forceColor === 0) { + return 0; + } + + if (sniffFlags) { + if (hasFlag('color=16m') + || hasFlag('color=full') + || hasFlag('color=truecolor')) { + return 3; + } + + if (hasFlag('color=256')) { + return 2; + } + } + + // Check for Azure DevOps pipelines. + // Has to be above the `!streamIsTTY` check. + if ('TF_BUILD' in env && 'AGENT_NAME' in env) { + return 1; + } + + if (haveStream && !streamIsTTY && forceColor === undefined) { + return 0; + } + + const min = forceColor || 0; + + if (env.TERM === 'dumb') { + return min; + } + + if (process.platform === 'win32') { + // Windows 10 build 10586 is the first Windows release that supports 256 colors. + // Windows 10 build 14931 is the first release that supports 16m/TrueColor. + const osRelease = os.release().split('.'); + if ( + Number(osRelease[0]) >= 10 + && Number(osRelease[2]) >= 10_586 + ) { + return Number(osRelease[2]) >= 14_931 ? 3 : 2; + } + + return 1; + } + + if ('CI' in env) { + if ('GITHUB_ACTIONS' in env) { + return 3; + } + + if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') { + return 1; + } + + return min; + } + + if ('TEAMCITY_VERSION' in env) { + return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; + } + + if (env.COLORTERM === 'truecolor') { + return 3; + } + + if (env.TERM === 'xterm-kitty') { + return 3; + } + + if ('TERM_PROGRAM' in env) { + const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); + + switch (env.TERM_PROGRAM) { + case 'iTerm.app': { + return version >= 3 ? 3 : 2; + } + + case 'Apple_Terminal': { + return 2; + } + // No default + } + } + + if (/-256(color)?$/i.test(env.TERM)) { + return 2; + } + + if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { + return 1; + } + + if ('COLORTERM' in env) { + return 1; + } + + return min; +} + +export function createSupportsColor(stream, options = {}) { + const level = _supportsColor(stream, { + streamIsTTY: stream && stream.isTTY, + ...options, + }); + + return translateLevel(level); +} + +const supportsColor = { + stdout: createSupportsColor({isTTY: tty.isatty(1)}), + stderr: createSupportsColor({isTTY: tty.isatty(2)}), +}; + +export default supportsColor; diff --git a/node_modules/has-flag/index.js b/node_modules/has-flag/index.js deleted file mode 100644 index b6f80b1f8ffd7..0000000000000 --- a/node_modules/has-flag/index.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -module.exports = (flag, argv = process.argv) => { - const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); - const position = argv.indexOf(prefix + flag); - const terminatorPosition = argv.indexOf('--'); - return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); -}; diff --git a/node_modules/has-flag/license b/node_modules/has-flag/license deleted file mode 100644 index e7af2f77107d7..0000000000000 --- a/node_modules/has-flag/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/has-flag/package.json b/node_modules/has-flag/package.json deleted file mode 100644 index a9cba4b856d04..0000000000000 --- a/node_modules/has-flag/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "has-flag", - "version": "4.0.0", - "description": "Check if argv has a specific flag", - "license": "MIT", - "repository": "sindresorhus/has-flag", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=8" - }, - "scripts": { - "test": "xo && ava && tsd" - }, - "files": [ - "index.js", - "index.d.ts" - ], - "keywords": [ - "has", - "check", - "detect", - "contains", - "find", - "flag", - "cli", - "command-line", - "argv", - "process", - "arg", - "args", - "argument", - "arguments", - "getopt", - "minimist", - "optimist" - ], - "devDependencies": { - "ava": "^1.4.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" - } -} diff --git a/node_modules/npm-audit-report/lib/colors.js b/node_modules/npm-audit-report/lib/colors.js index 2fbf5c36093de..e6688f2f1c8c6 100644 --- a/node_modules/npm-audit-report/lib/colors.js +++ b/node_modules/npm-audit-report/lib/colors.js @@ -1,16 +1,14 @@ -const chalk = require('chalk') -module.exports = color => { - const identity = x => x - const green = color ? s => chalk.green.bold(s) : identity - const red = color ? s => chalk.red.bold(s) : identity - const magenta = color ? s => chalk.magenta.bold(s) : identity - const yellow = color ? s => chalk.yellow.bold(s) : identity - const white = color ? s => chalk.bold(s) : identity +module.exports = (chalk) => { + const green = s => chalk.green.bold(s) + const red = s => chalk.red.bold(s) + const magenta = s => chalk.magenta.bold(s) + const yellow = s => chalk.yellow.bold(s) + const white = s => chalk.bold(s) const severity = (sev, s) => sev.toLowerCase() === 'moderate' ? yellow(s || sev) : sev.toLowerCase() === 'high' ? red(s || sev) : sev.toLowerCase() === 'critical' ? magenta(s || sev) : white(s || sev) - const dim = color ? s => chalk.dim(s) : identity + const dim = s => chalk.dim(s) return { dim, diff --git a/node_modules/npm-audit-report/lib/index.js b/node_modules/npm-audit-report/lib/index.js index 63063f92526a1..d0ced01efefec 100644 --- a/node_modules/npm-audit-report/lib/index.js +++ b/node_modules/npm-audit-report/lib/index.js @@ -12,7 +12,7 @@ const exitCode = require('./exit-code.js') module.exports = Object.assign((data, options = {}) => { const { reporter = 'install', - color = true, + chalk, unicode = true, indent = 2, } = options @@ -35,7 +35,7 @@ module.exports = Object.assign((data, options = {}) => { } return { - report: reporters[reporter](data, { color, unicode, indent }), + report: reporters[reporter](data, { chalk, unicode, indent }), exitCode: exitCode(data, auditLevel), } }, { reporters }) diff --git a/node_modules/npm-audit-report/lib/reporters/detail.js b/node_modules/npm-audit-report/lib/reporters/detail.js index ba2f013836d9d..6dde8ec88de44 100644 --- a/node_modules/npm-audit-report/lib/reporters/detail.js +++ b/node_modules/npm-audit-report/lib/reporters/detail.js @@ -3,14 +3,14 @@ const colors = require('../colors.js') const install = require('./install.js') -module.exports = (data, { color }) => { - const summary = install.summary(data, { color }) +module.exports = (data, { chalk }) => { + const summary = install.summary(data, { chalk }) const none = data.metadata.vulnerabilities.total === 0 - return none ? summary : fullReport(data, { color, summary }) + return none ? summary : fullReport(data, { chalk, summary }) } -const fullReport = (data, { color, summary }) => { - const c = colors(color) +const fullReport = (data, { chalk, summary }) => { + const c = colors(chalk) const output = [c.white('# npm audit report'), ''] const printed = new Set() diff --git a/node_modules/npm-audit-report/lib/reporters/install.js b/node_modules/npm-audit-report/lib/reporters/install.js index cb8a249691e29..0a1e82533e657 100644 --- a/node_modules/npm-audit-report/lib/reporters/install.js +++ b/node_modules/npm-audit-report/lib/reporters/install.js @@ -1,7 +1,7 @@ const colors = require('../colors.js') -const calculate = (data, { color }) => { - const c = colors(color) +const calculate = (data, { chalk }) => { + const c = colors(chalk) const output = [] const { metadata: { vulnerabilities } } = data const vulnCount = vulnerabilities.total diff --git a/node_modules/npm-audit-report/package.json b/node_modules/npm-audit-report/package.json index 8779f4c1d2c7e..492071c1faf90 100644 --- a/node_modules/npm-audit-report/package.json +++ b/node_modules/npm-audit-report/package.json @@ -1,6 +1,6 @@ { "name": "npm-audit-report", - "version": "4.0.0", + "version": "5.0.0", "description": "Given a response from the npm security api, render it into a variety of security reports", "main": "lib/index.js", "scripts": { @@ -28,13 +28,10 @@ ], "author": "GitHub Inc.", "license": "ISC", - "dependencies": { - "chalk": "^4.0.0" - }, "devDependencies": { - "@npmcli/eslint-config": "^3.0.1", - "@npmcli/template-oss": "4.5.1", - "require-inject": "^1.4.4", + "@npmcli/eslint-config": "^4.0.0", + "@npmcli/template-oss": "4.14.1", + "chalk": "^5.2.0", "tap": "^16.0.0" }, "directories": { @@ -58,6 +55,6 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "4.5.1" + "version": "4.14.1" } } diff --git a/node_modules/supports-color/browser.js b/node_modules/supports-color/browser.js deleted file mode 100644 index 62afa3a7425dc..0000000000000 --- a/node_modules/supports-color/browser.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; -module.exports = { - stdout: false, - stderr: false -}; diff --git a/node_modules/supports-color/index.js b/node_modules/supports-color/index.js deleted file mode 100644 index 6fada390fb88d..0000000000000 --- a/node_modules/supports-color/index.js +++ /dev/null @@ -1,135 +0,0 @@ -'use strict'; -const os = require('os'); -const tty = require('tty'); -const hasFlag = require('has-flag'); - -const {env} = process; - -let forceColor; -if (hasFlag('no-color') || - hasFlag('no-colors') || - hasFlag('color=false') || - hasFlag('color=never')) { - forceColor = 0; -} else if (hasFlag('color') || - hasFlag('colors') || - hasFlag('color=true') || - hasFlag('color=always')) { - forceColor = 1; -} - -if ('FORCE_COLOR' in env) { - if (env.FORCE_COLOR === 'true') { - forceColor = 1; - } else if (env.FORCE_COLOR === 'false') { - forceColor = 0; - } else { - forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3); - } -} - -function translateLevel(level) { - if (level === 0) { - return false; - } - - return { - level, - hasBasic: true, - has256: level >= 2, - has16m: level >= 3 - }; -} - -function supportsColor(haveStream, streamIsTTY) { - if (forceColor === 0) { - return 0; - } - - if (hasFlag('color=16m') || - hasFlag('color=full') || - hasFlag('color=truecolor')) { - return 3; - } - - if (hasFlag('color=256')) { - return 2; - } - - if (haveStream && !streamIsTTY && forceColor === undefined) { - return 0; - } - - const min = forceColor || 0; - - if (env.TERM === 'dumb') { - return min; - } - - if (process.platform === 'win32') { - // Windows 10 build 10586 is the first Windows release that supports 256 colors. - // Windows 10 build 14931 is the first release that supports 16m/TrueColor. - const osRelease = os.release().split('.'); - if ( - Number(osRelease[0]) >= 10 && - Number(osRelease[2]) >= 10586 - ) { - return Number(osRelease[2]) >= 14931 ? 3 : 2; - } - - return 1; - } - - if ('CI' in env) { - if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') { - return 1; - } - - return min; - } - - if ('TEAMCITY_VERSION' in env) { - return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; - } - - if (env.COLORTERM === 'truecolor') { - return 3; - } - - if ('TERM_PROGRAM' in env) { - const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); - - switch (env.TERM_PROGRAM) { - case 'iTerm.app': - return version >= 3 ? 3 : 2; - case 'Apple_Terminal': - return 2; - // No default - } - } - - if (/-256(color)?$/i.test(env.TERM)) { - return 2; - } - - if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { - return 1; - } - - if ('COLORTERM' in env) { - return 1; - } - - return min; -} - -function getSupportLevel(stream) { - const level = supportsColor(stream, stream && stream.isTTY); - return translateLevel(level); -} - -module.exports = { - supportsColor: getSupportLevel, - stdout: translateLevel(supportsColor(true, tty.isatty(1))), - stderr: translateLevel(supportsColor(true, tty.isatty(2))) -}; diff --git a/node_modules/supports-color/license b/node_modules/supports-color/license deleted file mode 100644 index e7af2f77107d7..0000000000000 --- a/node_modules/supports-color/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -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: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/supports-color/package.json b/node_modules/supports-color/package.json deleted file mode 100644 index f7182edcea2ba..0000000000000 --- a/node_modules/supports-color/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "supports-color", - "version": "7.2.0", - "description": "Detect whether a terminal supports color", - "license": "MIT", - "repository": "chalk/supports-color", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=8" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js", - "browser.js" - ], - "keywords": [ - "color", - "colour", - "colors", - "terminal", - "console", - "cli", - "ansi", - "styles", - "tty", - "rgb", - "256", - "shell", - "xterm", - "command-line", - "support", - "supports", - "capability", - "detect", - "truecolor", - "16m" - ], - "dependencies": { - "has-flag": "^4.0.0" - }, - "devDependencies": { - "ava": "^1.4.1", - "import-fresh": "^3.0.0", - "xo": "^0.24.0" - }, - "browser": "browser.js" -} diff --git a/package-lock.json b/package-lock.json index 730a831eee429..fec66587dbaaf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -92,7 +92,7 @@ "abbrev": "^2.0.0", "archy": "~1.0.0", "cacache": "^17.1.2", - "chalk": "^4.1.2", + "chalk": "^5.2.0", "ci-info": "^3.8.0", "cli-columns": "^4.0.0", "cli-table3": "^0.6.3", @@ -124,7 +124,7 @@ "ms": "^2.1.2", "node-gyp": "^9.3.1", "nopt": "^7.1.0", - "npm-audit-report": "^4.0.0", + "npm-audit-report": "^5.0.0", "npm-install-checks": "^6.1.1", "npm-package-arg": "^10.1.0", "npm-pick-manifest": "^8.0.1", @@ -770,6 +770,22 @@ "node": ">=v14" } }, + "node_modules/@commitlint/format/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@commitlint/is-ignored": { "version": "17.4.4", "resolved": "https://registry.npmjs.org/@commitlint/is-ignored/-/is-ignored-17.4.4.tgz", @@ -850,6 +866,22 @@ "node": ">=v14" } }, + "node_modules/@commitlint/load/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@commitlint/message": { "version": "17.4.2", "resolved": "https://registry.npmjs.org/@commitlint/message/-/message-17.4.2.tgz", @@ -955,6 +987,22 @@ "node": ">=v14" } }, + "node_modules/@commitlint/types/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@conventional-commits/parser": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@conventional-commits/parser/-/parser-0.4.1.tgz", @@ -1446,6 +1494,22 @@ "node": ">= 10.18.0" } }, + "node_modules/@lerna/child-process/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/@lerna/collect-updates": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@lerna/collect-updates/-/collect-updates-4.0.0.tgz", @@ -3460,16 +3524,12 @@ } }, "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz", + "integrity": "sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==", "inBundle": true, - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, "engines": { - "node": ">=10" + "node": "^12.17.0 || ^14.13 || >=16.0.0" }, "funding": { "url": "https://github.com/chalk/chalk?sponsor=1" @@ -5118,6 +5178,23 @@ "concat-map": "0.0.1" } }, + "node_modules/eslint/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "peer": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/eslint/node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -5940,7 +6017,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "inBundle": true, + "dev": true, "engines": { "node": ">=8" } @@ -9492,13 +9569,10 @@ } }, "node_modules/npm-audit-report": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-4.0.0.tgz", - "integrity": "sha512-k2o5476sLrp94b6Gl819YzlS7LAdb8lgE6yQCysBEji5E3WoUdRve6tiVMLKAPPdLfItU4kOSUycWS5HFTrbug==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/npm-audit-report/-/npm-audit-report-5.0.0.tgz", + "integrity": "sha512-EkXrzat7zERmUhHaoren1YhTxFwsOu5jypE84k6632SXTHcQE1z8V51GC6GVZt8LxkC+tbBcKMUBZAgk8SUSbw==", "inBundle": true, - "dependencies": { - "chalk": "^4.0.0" - }, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } @@ -10940,6 +11014,22 @@ "node": ">=14.0.0" } }, + "node_modules/release-please/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/release-please/node_modules/type-fest": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", @@ -11990,7 +12080,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "inBundle": true, + "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -15559,7 +15649,6 @@ "@npmcli/eslint-config": "^4.0.0", "@npmcli/template-oss": "4.14.1", "benchmark": "^2.1.4", - "chalk": "^4.1.0", "minify-registry-metadata": "^3.0.0", "nock": "^13.3.0", "tap": "^16.3.4", @@ -15639,7 +15728,6 @@ "dependencies": { "@npmcli/arborist": "^6.2.9", "@npmcli/run-script": "^6.0.0", - "chalk": "^4.1.0", "ci-info": "^3.7.1", "npm-package-arg": "^10.1.0", "npmlog": "^7.0.1", @@ -15655,6 +15743,7 @@ "@npmcli/mock-registry": "^1.0.0", "@npmcli/template-oss": "4.14.1", "bin-links": "^4.0.1", + "chalk": "^5.2.0", "just-extend": "^6.2.0", "just-safe-set": "^4.2.1", "minify-registry-metadata": "^3.0.0", diff --git a/package.json b/package.json index 0023c1c0f5538..ab229f9b8ca5b 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "abbrev": "^2.0.0", "archy": "~1.0.0", "cacache": "^17.1.2", - "chalk": "^4.1.2", + "chalk": "^5.2.0", "ci-info": "^3.8.0", "cli-columns": "^4.0.0", "cli-table3": "^0.6.3", @@ -94,7 +94,7 @@ "ms": "^2.1.2", "node-gyp": "^9.3.1", "nopt": "^7.1.0", - "npm-audit-report": "^4.0.0", + "npm-audit-report": "^5.0.0", "npm-install-checks": "^6.1.1", "npm-package-arg": "^10.1.0", "npm-pick-manifest": "^8.0.1", diff --git a/tap-snapshots/test/lib/utils/explain-dep.js.test.cjs b/tap-snapshots/test/lib/utils/explain-dep.js.test.cjs index 8550617eb0a00..876cc6552b760 100644 --- a/tap-snapshots/test/lib/utils/explain-dep.js.test.cjs +++ b/tap-snapshots/test/lib/utils/explain-dep.js.test.cjs @@ -5,7 +5,7 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' -exports[`test/lib/utils/explain-dep.js TAP > ellipses test one 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic > ellipses test one 1`] = ` manydep@1.0.0 manydep@"1.0.0" from prod-dep@1.2.3 node_modules/prod-dep @@ -13,7 +13,7 @@ manydep@1.0.0 7 more (optdep, extra-neos, deep-dev, peer, the root project, ...) ` -exports[`test/lib/utils/explain-dep.js TAP > ellipses test two 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic > ellipses test two 1`] = ` manydep@1.0.0 manydep@"1.0.0" from prod-dep@1.2.3 node_modules/prod-dep @@ -21,29 +21,29 @@ manydep@1.0.0 6 more (optdep, extra-neos, deep-dev, peer, the root project, a package with a pretty long name) ` -exports[`test/lib/utils/explain-dep.js TAP bundled > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic bundled > explain color deep 1`] = ` bundle-of-joy@1.0.0 bundled node_modules/bundle-of-joy bundled prod-dep@"1.x" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP bundled > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic bundled > explain nocolor shallow 1`] = ` bundle-of-joy@1.0.0 bundled node_modules/bundle-of-joy bundled prod-dep@"1.x" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP bundled > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic bundled > print color 1`] = ` bundle-of-joy@1.0.0 bundled node_modules/bundle-of-joy ` -exports[`test/lib/utils/explain-dep.js TAP bundled > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic bundled > print nocolor 1`] = ` bundle-of-joy@1.0.0 bundled node_modules/bundle-of-joy ` -exports[`test/lib/utils/explain-dep.js TAP deepDev > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic deepDev > explain color deep 1`] = ` deep-dev@2.3.4 dev node_modules/deep-dev deep-dev@"2.x" from metadev@3.4.5 @@ -53,7 +53,7 @@ exports[`test/lib/utils/explain-dep.js TAP deepDev > explain color deep 1`] = ` dev topdev@"4.x" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP deepDev > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic deepDev > explain nocolor shallow 1`] = ` deep-dev@2.3.4 dev node_modules/deep-dev deep-dev@"2.x" from metadev@3.4.5 @@ -62,37 +62,37 @@ node_modules/deep-dev node_modules/topdev ` -exports[`test/lib/utils/explain-dep.js TAP deepDev > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic deepDev > print color 1`] = ` deep-dev@2.3.4 dev node_modules/deep-dev ` -exports[`test/lib/utils/explain-dep.js TAP deepDev > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic deepDev > print nocolor 1`] = ` deep-dev@2.3.4 dev node_modules/deep-dev ` -exports[`test/lib/utils/explain-dep.js TAP extraneous > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic extraneous > explain color deep 1`] = ` extra-neos@1337.420.69-lol extraneous node_modules/extra-neos ` -exports[`test/lib/utils/explain-dep.js TAP extraneous > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic extraneous > explain nocolor shallow 1`] = ` extra-neos@1337.420.69-lol extraneous node_modules/extra-neos ` -exports[`test/lib/utils/explain-dep.js TAP extraneous > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic extraneous > print color 1`] = ` extra-neos@1337.420.69-lol extraneous node_modules/extra-neos ` -exports[`test/lib/utils/explain-dep.js TAP extraneous > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic extraneous > print nocolor 1`] = ` extra-neos@1337.420.69-lol extraneous node_modules/extra-neos ` -exports[`test/lib/utils/explain-dep.js TAP manyDeps > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic manyDeps > explain color deep 1`] = ` manydep@1.0.0 manydep@"1.0.0" from prod-dep@1.2.3 node_modules/prod-dep @@ -118,7 +118,7 @@ exports[`test/lib/utils/explain-dep.js TAP manyDeps > explain color deep 1`] = ` manydep@"1" from yet another a package with a pretty long name@1.2.3 ` -exports[`test/lib/utils/explain-dep.js TAP manyDeps > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic manyDeps > explain nocolor shallow 1`] = ` manydep@1.0.0 manydep@"1.0.0" from prod-dep@1.2.3 node_modules/prod-dep @@ -126,103 +126,103 @@ manydep@1.0.0 8 more (optdep, extra-neos, deep-dev, peer, the root project, ...) ` -exports[`test/lib/utils/explain-dep.js TAP manyDeps > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic manyDeps > print color 1`] = ` manydep@1.0.0 ` -exports[`test/lib/utils/explain-dep.js TAP manyDeps > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic manyDeps > print nocolor 1`] = ` manydep@1.0.0 ` -exports[`test/lib/utils/explain-dep.js TAP optional > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic optional > explain color deep 1`] = ` optdep@1.0.0 optional node_modules/optdep optional optdep@"1.0.0" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP optional > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic optional > explain nocolor shallow 1`] = ` optdep@1.0.0 optional node_modules/optdep optional optdep@"1.0.0" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP optional > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic optional > print color 1`] = ` optdep@1.0.0 optional node_modules/optdep ` -exports[`test/lib/utils/explain-dep.js TAP optional > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic optional > print nocolor 1`] = ` optdep@1.0.0 optional node_modules/optdep ` -exports[`test/lib/utils/explain-dep.js TAP overridden > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic overridden > explain color deep 1`] = ` overridden-root@1.0.0 overridden node_modules/overridden-root overridden overridden-dep@"1.0.0" (was "^2.0.0") from the root project ` -exports[`test/lib/utils/explain-dep.js TAP overridden > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic overridden > explain nocolor shallow 1`] = ` overridden-root@1.0.0 overridden node_modules/overridden-root overridden overridden-dep@"1.0.0" (was "^2.0.0") from the root project ` -exports[`test/lib/utils/explain-dep.js TAP overridden > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic overridden > print color 1`] = ` overridden-root@1.0.0 overridden node_modules/overridden-root ` -exports[`test/lib/utils/explain-dep.js TAP overridden > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic overridden > print nocolor 1`] = ` overridden-root@1.0.0 overridden node_modules/overridden-root ` -exports[`test/lib/utils/explain-dep.js TAP peer > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic peer > explain color deep 1`] = ` peer@1.0.0 peer node_modules/peer peer peer@"1.0.0" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP peer > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic peer > explain nocolor shallow 1`] = ` peer@1.0.0 peer node_modules/peer peer peer@"1.0.0" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP peer > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic peer > print color 1`] = ` peer@1.0.0 peer node_modules/peer ` -exports[`test/lib/utils/explain-dep.js TAP peer > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic peer > print nocolor 1`] = ` peer@1.0.0 peer node_modules/peer ` -exports[`test/lib/utils/explain-dep.js TAP prodDep > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic prodDep > explain color deep 1`] = ` prod-dep@1.2.3 node_modules/prod-dep prod-dep@"1.x" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP prodDep > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic prodDep > explain nocolor shallow 1`] = ` prod-dep@1.2.3 node_modules/prod-dep prod-dep@"1.x" from the root project ` -exports[`test/lib/utils/explain-dep.js TAP prodDep > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic prodDep > print color 1`] = ` prod-dep@1.2.3 node_modules/prod-dep ` -exports[`test/lib/utils/explain-dep.js TAP prodDep > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic prodDep > print nocolor 1`] = ` prod-dep@1.2.3 node_modules/prod-dep ` -exports[`test/lib/utils/explain-dep.js TAP workspaces > explain color deep 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic workspaces > explain color deep 1`] = ` a@1.0.0 a a@1.0.0 @@ -230,7 +230,7 @@ exports[`test/lib/utils/explain-dep.js TAP workspaces > explain color deep 1`] = workspace a from the root project ` -exports[`test/lib/utils/explain-dep.js TAP workspaces > explain nocolor shallow 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic workspaces > explain nocolor shallow 1`] = ` a@1.0.0 a a@1.0.0 @@ -238,12 +238,12 @@ a workspace a from the root project ` -exports[`test/lib/utils/explain-dep.js TAP workspaces > print color 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic workspaces > print color 1`] = ` a@1.0.0 a ` -exports[`test/lib/utils/explain-dep.js TAP workspaces > print nocolor 1`] = ` +exports[`test/lib/utils/explain-dep.js TAP basic workspaces > print nocolor 1`] = ` a@1.0.0 a ` diff --git a/tap-snapshots/test/lib/utils/explain-eresolve.js.test.cjs b/tap-snapshots/test/lib/utils/explain-eresolve.js.test.cjs index 99ad5c0f31e90..3d73019d3e45b 100644 --- a/tap-snapshots/test/lib/utils/explain-eresolve.js.test.cjs +++ b/tap-snapshots/test/lib/utils/explain-eresolve.js.test.cjs @@ -5,7 +5,7 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' -exports[`test/lib/utils/explain-eresolve.js TAP chain-conflict > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic chain-conflict > explain with color, depth of 2 1`] = ` While resolving: project@1.2.3 Found: @isaacs/testing-peer-dep-conflict-chain-d@2.0.0 node_modules/@isaacs/testing-peer-dep-conflict-chain-d @@ -17,7 +17,7 @@ Could not resolve dependency: @isaacs/testing-peer-dep-conflict-chain-c@"1" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP chain-conflict > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic chain-conflict > explain with no color, depth of 6 1`] = ` While resolving: project@1.2.3 Found: @isaacs/testing-peer-dep-conflict-chain-d@2.0.0 node_modules/@isaacs/testing-peer-dep-conflict-chain-d @@ -29,7 +29,7 @@ node_modules/@isaacs/testing-peer-dep-conflict-chain-c @isaacs/testing-peer-dep-conflict-chain-c@"1" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP chain-conflict > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic chain-conflict > report from color 1`] = ` # npm resolution error report While resolving: project@1.2.3 @@ -47,7 +47,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP chain-conflict > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic chain-conflict > report with color 1`] = ` While resolving: project@1.2.3 Found: @isaacs/testing-peer-dep-conflict-chain-d@2.0.0 node_modules/@isaacs/testing-peer-dep-conflict-chain-d @@ -63,7 +63,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP chain-conflict > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic chain-conflict > report with no color 1`] = ` While resolving: project@1.2.3 Found: @isaacs/testing-peer-dep-conflict-chain-d@2.0.0 node_modules/@isaacs/testing-peer-dep-conflict-chain-d @@ -79,7 +79,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP cycleNested > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic cycleNested > explain with color, depth of 2 1`] = ` Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @isaacs/peer-dep-cycle-c@"2.x" from the root project @@ -97,7 +97,7 @@ Conflicting peer dependency: @isaacs/peer-dep-cycle-c@1.0.0[2 node_modules/@isaacs/peer-dep-cycle-a ` -exports[`test/lib/utils/explain-eresolve.js TAP cycleNested > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic cycleNested > explain with no color, depth of 6 1`] = ` Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @isaacs/peer-dep-cycle-c@"2.x" from the root project @@ -116,7 +116,7 @@ node_modules/@isaacs/peer-dep-cycle-c @isaacs/peer-dep-cycle-a@"1.x" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP cycleNested > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic cycleNested > report from color 1`] = ` # npm resolution error report Found: @isaacs/peer-dep-cycle-c@2.0.0 @@ -141,7 +141,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP cycleNested > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic cycleNested > report with color 1`] = ` Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @isaacs/peer-dep-cycle-c@"2.x" from the root project @@ -164,7 +164,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP cycleNested > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic cycleNested > report with no color 1`] = ` Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @isaacs/peer-dep-cycle-c@"2.x" from the root project @@ -187,7 +187,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP eslint-plugin case > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic eslint-plugin case > explain with color, depth of 2 1`] = ` While resolving: eslint-plugin-react@7.24.0 Found: eslint@6.8.0 node_modules/eslint @@ -204,7 +204,7 @@ Conflicting peer dependency: eslint@7.31.0 dev eslint-plugin-eslint-plugin@"^3.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP eslint-plugin case > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic eslint-plugin case > explain with no color, depth of 6 1`] = ` While resolving: eslint-plugin-react@7.24.0 Found: eslint@6.8.0 node_modules/eslint @@ -227,7 +227,7 @@ node_modules/eslint dev eslint-plugin-eslint-plugin@"^3.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP eslint-plugin case > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic eslint-plugin case > report from color 1`] = ` # npm resolution error report While resolving: eslint-plugin-react@7.24.0 @@ -261,7 +261,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP eslint-plugin case > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic eslint-plugin case > report with color 1`] = ` While resolving: eslint-plugin-react@7.24.0 Found: eslint@6.8.0 node_modules/eslint @@ -285,7 +285,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP eslint-plugin case > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic eslint-plugin case > report with no color 1`] = ` While resolving: eslint-plugin-react@7.24.0 Found: eslint@6.8.0 node_modules/eslint @@ -309,7 +309,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP gatsby > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic gatsby > explain with color, depth of 2 1`] = ` While resolving: gatsby-recipes@0.2.31 Found: ink@3.0.0-7 node_modules/ink @@ -325,7 +325,7 @@ Could not resolve dependency: node_modules/gatsby-recipes ` -exports[`test/lib/utils/explain-eresolve.js TAP gatsby > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic gatsby > explain with no color, depth of 6 1`] = ` While resolving: gatsby-recipes@0.2.31 Found: ink@3.0.0-7 node_modules/ink @@ -349,7 +349,7 @@ node_modules/ink-box gatsby@"" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP gatsby > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic gatsby > report from color 1`] = ` # npm resolution error report While resolving: gatsby-recipes@0.2.31 @@ -379,7 +379,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP gatsby > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic gatsby > report with color 1`] = ` While resolving: gatsby-recipes@0.2.31 Found: ink@3.0.0-7 node_modules/ink @@ -406,7 +406,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP gatsby > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic gatsby > report with no color 1`] = ` While resolving: gatsby-recipes@0.2.31 Found: ink@3.0.0-7 node_modules/ink @@ -433,7 +433,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, but has current edge > explain with color, depth of 2 1`] = ` While resolving: eslint@7.22.0 Found: dev eslint@"file:." from the root project @@ -443,7 +443,7 @@ Could not resolve dependency: dev eslint-plugin-jsdoc@"^22.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, but has current edge > explain with no color, depth of 6 1`] = ` While resolving: eslint@7.22.0 Found: dev eslint@"file:." from the root project @@ -453,7 +453,7 @@ node_modules/eslint-plugin-jsdoc dev eslint-plugin-jsdoc@"^22.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, but has current edge > report from color 1`] = ` # npm resolution error report While resolving: eslint@7.22.0 @@ -469,7 +469,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, but has current edge > report with color 1`] = ` While resolving: eslint@7.22.0 Found: dev eslint@"file:." from the root project @@ -483,7 +483,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, but has current edge > report with no color 1`] = ` While resolving: eslint@7.22.0 Found: dev eslint@"file:." from the root project @@ -497,7 +497,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, no current edge, idk > explain with color, depth of 2 1`] = ` While resolving: eslint@7.22.0 Found: peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0 node_modules/eslint-plugin-jsdoc @@ -509,7 +509,7 @@ Could not resolve dependency: dev eslint-plugin-jsdoc@"^22.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, no current edge, idk > explain with no color, depth of 6 1`] = ` While resolving: eslint@7.22.0 Found: peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0 node_modules/eslint-plugin-jsdoc @@ -521,7 +521,7 @@ node_modules/eslint-plugin-jsdoc dev eslint-plugin-jsdoc@"^22.1.0" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, no current edge, idk > report from color 1`] = ` # npm resolution error report While resolving: eslint@7.22.0 @@ -539,7 +539,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, no current edge, idk > report with color 1`] = ` While resolving: eslint@7.22.0 Found: peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0 node_modules/eslint-plugin-jsdoc @@ -555,7 +555,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic no current node, no current edge, idk > report with no color 1`] = ` While resolving: eslint@7.22.0 Found: peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0 node_modules/eslint-plugin-jsdoc @@ -571,7 +571,7 @@ this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > explain with color, depth of 2 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic withShrinkwrap > explain with color, depth of 2 1`] = ` While resolving: @isaacs/peer-dep-cycle-b@1.0.0 Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @@ -584,7 +584,7 @@ Could not resolve dependency: node_modules/@isaacs/peer-dep-cycle-a ` -exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > explain with no color, depth of 6 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic withShrinkwrap > explain with no color, depth of 6 1`] = ` While resolving: @isaacs/peer-dep-cycle-b@1.0.0 Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @@ -598,7 +598,7 @@ node_modules/@isaacs/peer-dep-cycle-b @isaacs/peer-dep-cycle-a@"1.x" from the root project ` -exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > report from color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic withShrinkwrap > report from color 1`] = ` # npm resolution error report While resolving: @isaacs/peer-dep-cycle-b@1.0.0 @@ -618,7 +618,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > report with color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic withShrinkwrap > report with color 1`] = ` While resolving: @isaacs/peer-dep-cycle-b@1.0.0 Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c @@ -636,7 +636,7 @@ this command with --no-strict-peer-deps, --force, or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution. ` -exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > report with no color 1`] = ` +exports[`test/lib/utils/explain-eresolve.js TAP basic withShrinkwrap > report with no color 1`] = ` While resolving: @isaacs/peer-dep-cycle-b@1.0.0 Found: @isaacs/peer-dep-cycle-c@2.0.0 node_modules/@isaacs/peer-dep-cycle-c diff --git a/test/lib/commands/help-search.js b/test/lib/commands/help-search.js index ce6e5f7cf00b0..8da725fad7692 100644 --- a/test/lib/commands/help-search.js +++ b/test/lib/commands/help-search.js @@ -1,6 +1,5 @@ const t = require('tap') const { load: loadMockNpm } = require('../../fixtures/mock-npm.js') -const chalk = require('chalk') /* eslint-disable max-len */ const docsFixtures = { @@ -70,6 +69,8 @@ t.test('npm help-search long output with color', async t => { }, }) + const chalk = await import('chalk').then(v => v.default) + const highlightedText = chalk.bgBlack.red('help-search') t.equal( output.split('\n').some(line => line.includes(highlightedText)), diff --git a/test/lib/utils/ansi-trim.js b/test/lib/utils/ansi-trim.js index de8d392937000..5a9e3b0c87cba 100644 --- a/test/lib/utils/ansi-trim.js +++ b/test/lib/utils/ansi-trim.js @@ -1,5 +1,8 @@ const t = require('tap') const ansiTrim = require('../../../lib/utils/ansi-trim.js') -const chalk = require('chalk') -t.equal(ansiTrim('foo'), 'foo', 'does nothing if no ansis') -t.equal(ansiTrim(chalk.red('foo')), 'foo', 'strips out ansis') + +t.test('basic', async t => { + const chalk = await import('chalk').then(v => v.default) + t.equal(ansiTrim('foo'), 'foo', 'does nothing if no ansis') + t.equal(ansiTrim(chalk.red('foo')), 'foo', 'strips out ansis') +}) diff --git a/test/lib/utils/explain-dep.js b/test/lib/utils/explain-dep.js index e5389fd26d796..06174f36a7ffc 100644 --- a/test/lib/utils/explain-dep.js +++ b/test/lib/utils/explain-dep.js @@ -1,269 +1,277 @@ const { resolve } = require('path') const t = require('tap') -const Chalk = require('chalk') const { explainNode, printNode } = require('../../../lib/utils/explain-dep.js') const { cleanCwd } = require('../../fixtures/clean-snapshot') -const testdir = t.testdirName -const color = new Chalk.Instance({ level: Chalk.level }) -const noColor = new Chalk.Instance({ level: 0 }) - t.cleanSnapshot = (str) => cleanCwd(str) -const cases = { - prodDep: { - name: 'prod-dep', - version: '1.2.3', - location: 'node_modules/prod-dep', - dependents: [ - { - type: 'prod', - name: 'prod-dep', - spec: '1.x', - from: { - location: '/path/to/project', +const getCases = (testdir) => { + const cases = { + prodDep: { + name: 'prod-dep', + version: '1.2.3', + location: 'node_modules/prod-dep', + dependents: [ + { + type: 'prod', + name: 'prod-dep', + spec: '1.x', + from: { + location: '/path/to/project', + }, }, - }, - ], - }, + ], + }, - deepDev: { - name: 'deep-dev', - version: '2.3.4', - location: 'node_modules/deep-dev', - dev: true, - dependents: [ - { - type: 'prod', - name: 'deep-dev', - spec: '2.x', - from: { - name: 'metadev', - version: '3.4.5', - location: 'node_modules/dev/node_modules/metadev', - dependents: [ - { - type: 'prod', - name: 'metadev', - spec: '3.x', - from: { - name: 'topdev', - version: '4.5.6', - location: 'node_modules/topdev', - dependents: [ - { - type: 'dev', - name: 'topdev', - spec: '4.x', - from: { - location: '/path/to/project', + deepDev: { + name: 'deep-dev', + version: '2.3.4', + location: 'node_modules/deep-dev', + dev: true, + dependents: [ + { + type: 'prod', + name: 'deep-dev', + spec: '2.x', + from: { + name: 'metadev', + version: '3.4.5', + location: 'node_modules/dev/node_modules/metadev', + dependents: [ + { + type: 'prod', + name: 'metadev', + spec: '3.x', + from: { + name: 'topdev', + version: '4.5.6', + location: 'node_modules/topdev', + dependents: [ + { + type: 'dev', + name: 'topdev', + spec: '4.x', + from: { + location: '/path/to/project', + }, }, - }, - ], + ], + }, }, - }, - ], + ], + }, }, - }, - ], - }, + ], + }, - optional: { - name: 'optdep', - version: '1.0.0', - location: 'node_modules/optdep', - optional: true, - dependents: [ - { - type: 'optional', - name: 'optdep', + optional: { + name: 'optdep', + version: '1.0.0', + location: 'node_modules/optdep', + optional: true, + dependents: [ + { + type: 'optional', + name: 'optdep', + spec: '1.0.0', + from: { + location: '/path/to/project', + }, + }, + ], + }, + + peer: { + name: 'peer', + version: '1.0.0', + location: 'node_modules/peer', + peer: true, + dependents: [ + { + type: 'peer', + name: 'peer', + spec: '1.0.0', + from: { + location: '/path/to/project', + }, + }, + ], + }, + + bundled: { + name: 'bundle-of-joy', + version: '1.0.0', + location: 'node_modules/bundle-of-joy', + bundled: true, + dependents: [ + { + type: 'prod', + name: 'prod-dep', + spec: '1.x', + bundled: true, + from: { + location: '/path/to/project', + }, + }, + ], + }, + + extraneous: { + name: 'extra-neos', + version: '1337.420.69-lol', + location: 'node_modules/extra-neos', + dependents: [], + extraneous: true, + }, + + overridden: { + name: 'overridden-root', + version: '1.0.0', + location: 'node_modules/overridden-root', + overridden: true, + dependents: [{ + type: 'prod', + name: 'overridden-dep', spec: '1.0.0', + rawSpec: '^2.0.0', + overridden: true, from: { location: '/path/to/project', }, - }, - ], - }, + }], + }, + } - peer: { - name: 'peer', + cases.manyDeps = { + name: 'manydep', version: '1.0.0', - location: 'node_modules/peer', - peer: true, dependents: [ { - type: 'peer', - name: 'peer', + type: 'prod', + name: 'manydep', spec: '1.0.0', + from: cases.prodDep, + }, + { + type: 'optional', + name: 'manydep', + spec: '1.x', + from: cases.optional, + }, + { + type: 'prod', + name: 'manydep', + spec: '1.0.x', + from: cases.extraneous, + }, + { + type: 'dev', + name: 'manydep', + spec: '*', + from: cases.deepDev, + }, + { + type: 'peer', + name: 'manydep', + spec: '>1.0.0-beta <1.0.1', + from: cases.peer, + }, + { + type: 'prod', + name: 'manydep', + spec: '>1.0.0-beta <1.0.1', from: { location: '/path/to/project', }, }, - ], - }, - - bundled: { - name: 'bundle-of-joy', - version: '1.0.0', - location: 'node_modules/bundle-of-joy', - bundled: true, - dependents: [ { type: 'prod', - name: 'prod-dep', - spec: '1.x', - bundled: true, + name: 'manydep', + spec: '1', from: { - location: '/path/to/project', + name: 'a package with a pretty long name', + version: '1.2.3', + dependents: { + location: '/path/to/project', + }, }, }, - ], - }, - - extraneous: { - name: 'extra-neos', - version: '1337.420.69-lol', - location: 'node_modules/extra-neos', - dependents: [], - extraneous: true, - }, - - overridden: { - name: 'overridden-root', - version: '1.0.0', - location: 'node_modules/overridden-root', - overridden: true, - dependents: [{ - type: 'prod', - name: 'overridden-dep', - spec: '1.0.0', - rawSpec: '^2.0.0', - overridden: true, - from: { - location: '/path/to/project', - }, - }], - }, -} - -cases.manyDeps = { - name: 'manydep', - version: '1.0.0', - dependents: [ - { - type: 'prod', - name: 'manydep', - spec: '1.0.0', - from: cases.prodDep, - }, - { - type: 'optional', - name: 'manydep', - spec: '1.x', - from: cases.optional, - }, - { - type: 'prod', - name: 'manydep', - spec: '1.0.x', - from: cases.extraneous, - }, - { - type: 'dev', - name: 'manydep', - spec: '*', - from: cases.deepDev, - }, - { - type: 'peer', - name: 'manydep', - spec: '>1.0.0-beta <1.0.1', - from: cases.peer, - }, - { - type: 'prod', - name: 'manydep', - spec: '>1.0.0-beta <1.0.1', - from: { - location: '/path/to/project', - }, - }, - { - type: 'prod', - name: 'manydep', - spec: '1', - from: { - name: 'a package with a pretty long name', - version: '1.2.3', - dependents: { - location: '/path/to/project', + { + type: 'prod', + name: 'manydep', + spec: '1', + from: { + name: 'another package with a pretty long name', + version: '1.2.3', + dependents: { + location: '/path/to/project', + }, }, }, - }, - { - type: 'prod', - name: 'manydep', - spec: '1', - from: { - name: 'another package with a pretty long name', - version: '1.2.3', - dependents: { - location: '/path/to/project', + { + type: 'prod', + name: 'manydep', + spec: '1', + from: { + name: 'yet another a package with a pretty long name', + version: '1.2.3', + dependents: { + location: '/path/to/project', + }, }, }, - }, - { - type: 'prod', - name: 'manydep', - spec: '1', - from: { - name: 'yet another a package with a pretty long name', - version: '1.2.3', - dependents: { - location: '/path/to/project', - }, + ], + } + + cases.workspaces = { + name: 'a', + version: '1.0.0', + location: 'a', + isWorkspace: true, + dependents: [], + linksIn: [ + { + name: 'a', + version: '1.0.0', + location: 'node_modules/a', + isWorkspace: true, + dependents: [ + { + type: 'workspace', + name: 'a', + spec: `file:${resolve(testdir, 'ws-project', 'a')}`, + from: { location: resolve(testdir, 'ws-project') }, + }, + ], }, - }, - ], -} + ], + } -cases.workspaces = { - name: 'a', - version: '1.0.0', - location: 'a', - isWorkspace: true, - dependents: [], - linksIn: [ - { - name: 'a', - version: '1.0.0', - location: 'node_modules/a', - isWorkspace: true, - dependents: [ - { - type: 'workspace', - name: 'a', - spec: `file:${resolve(testdir, 'ws-project', 'a')}`, - from: { location: resolve(testdir, 'ws-project') }, - }, - ], - }, - ], + return cases } -for (const [name, expl] of Object.entries(cases)) { - t.test(name, t => { - t.matchSnapshot(printNode(expl, color), 'print color') - t.matchSnapshot(printNode(expl, noColor), 'print nocolor') - t.matchSnapshot(explainNode(expl, Infinity, color), 'explain color deep') - t.matchSnapshot(explainNode(expl, 2, noColor), 'explain nocolor shallow') - t.end() - }) -} +t.test('basic', async t => { + const { Chalk } = await import('chalk') + const color = new Chalk({ level: 3 }) + const noColor = new Chalk({ level: 0 }) + + const testdir = t.testdir() + const cases = getCases(testdir) + + for (const [name, expl] of Object.entries(getCases(testdir))) { + t.test(name, t => { + t.matchSnapshot(printNode(expl, color), 'print color') + t.matchSnapshot(printNode(expl, noColor), 'print nocolor') + t.matchSnapshot(explainNode(expl, Infinity, color), 'explain color deep') + t.matchSnapshot(explainNode(expl, 2, noColor), 'explain nocolor shallow') + t.end() + }) + } -// make sure that we show the last one if it's the only one that would -// hit the ... -cases.manyDeps.dependents.pop() -t.matchSnapshot(explainNode(cases.manyDeps, 2, noColor), 'ellipses test one') -cases.manyDeps.dependents.pop() -t.matchSnapshot(explainNode(cases.manyDeps, 2, noColor), 'ellipses test two') + // make sure that we show the last one if it's the only one that would + // hit the ... + cases.manyDeps.dependents.pop() + t.matchSnapshot(explainNode(cases.manyDeps, 2, noColor), 'ellipses test one') + cases.manyDeps.dependents.pop() + t.matchSnapshot(explainNode(cases.manyDeps, 2, noColor), 'ellipses test two') +}) diff --git a/test/lib/utils/explain-eresolve.js b/test/lib/utils/explain-eresolve.js index 0f60556ef2ac9..157cc97a5a3cb 100644 --- a/test/lib/utils/explain-eresolve.js +++ b/test/lib/utils/explain-eresolve.js @@ -1,29 +1,31 @@ const t = require('tap') -const Chalk = require('chalk') const { explain, report } = require('../../../lib/utils/explain-eresolve.js') const cases = require('../../fixtures/eresolve-explanations.js') -const color = new Chalk.Instance({ level: Chalk.level }) -const noColor = new Chalk.Instance({ level: 0 }) +t.test('basic', async t => { + const { Chalk } = await import('chalk') + const color = new Chalk({ level: 3 }) + const noColor = new Chalk({ level: 0 }) -for (const [name, expl] of Object.entries(cases)) { + for (const [name, expl] of Object.entries(cases)) { // no sense storing the whole contents of each object in the snapshot // we can trust that JSON.stringify still works just fine. - expl.toJSON = () => ({ name, json: true }) + expl.toJSON = () => ({ name, json: true }) - t.test(name, t => { - const colorReport = report(expl, color, noColor) - t.matchSnapshot(colorReport.explanation, 'report with color') - t.matchSnapshot(colorReport.file, 'report from color') + t.test(name, t => { + const colorReport = report(expl, color, noColor) + t.matchSnapshot(colorReport.explanation, 'report with color') + t.matchSnapshot(colorReport.file, 'report from color') - const noColorReport = report(expl, noColor, noColor) - t.matchSnapshot(noColorReport.explanation, 'report with no color') - t.equal(noColorReport.file, colorReport.file, 'same report written for object') + const noColorReport = report(expl, noColor, noColor) + t.matchSnapshot(noColorReport.explanation, 'report with no color') + t.equal(noColorReport.file, colorReport.file, 'same report written for object') - t.matchSnapshot(explain(expl, color, 2), 'explain with color, depth of 2') - t.matchSnapshot(explain(expl, noColor, 6), 'explain with no color, depth of 6') + t.matchSnapshot(explain(expl, color, 2), 'explain with color, depth of 2') + t.matchSnapshot(explain(expl, noColor, 6), 'explain with no color, depth of 6') - t.end() - }) -} + t.end() + }) + } +})