From ede3374a6c05cfe9e0f0bdcc8d3cd446a09e46ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 16 Mar 2024 21:12:08 +0100 Subject: [PATCH 1/2] Replace `chalk` with `picocolors` --- Gulpfile.mjs | 16 ++--- babel-worker.cjs | 10 +-- package.json | 2 +- packages/babel-code-frame/package.json | 2 +- packages/babel-code-frame/src/index.ts | 40 ++++++----- packages/babel-code-frame/test/index.js | 69 ++++++++----------- packages/babel-highlight/package.json | 5 +- packages/babel-highlight/src/index.ts | 69 +++++++++++-------- packages/babel-highlight/test/index.js | 44 ++++++++---- .../parser-tests/utils/parser-test-runner.js | 8 +-- test/esm/package.json | 2 +- test/esm/test-runner.js | 6 +- yarn.lock | 30 ++++---- 13 files changed, 160 insertions(+), 143 deletions(-) diff --git a/Gulpfile.mjs b/Gulpfile.mjs index c778c7785fe7..32adb9d5a74f 100644 --- a/Gulpfile.mjs +++ b/Gulpfile.mjs @@ -5,7 +5,7 @@ import { createRequire } from "module"; import { fileURLToPath } from "url"; import plumber from "gulp-plumber"; import through from "through2"; -import chalk from "chalk"; +import colors from "picocolors"; import filter from "gulp-filter"; import gulp from "gulp"; import { rollup } from "rollup"; @@ -125,7 +125,7 @@ function generateHelpers(generator, dest, filename, message) { file.contents = Buffer.from( await formatCode(await generateCode(filename), dest + file.path) ); - log(`${chalk.green("✔")} Generated ${message}`); + log(`${colors.green("✔")} Generated ${message}`); callback(null, file); }) ) @@ -352,7 +352,7 @@ function buildRollup(packages, buildStandalone) { /@babel\/preset-modules\/.*/, ]; - log(`Compiling '${chalk.cyan(input)}' with rollup ...`); + log(`Compiling '${colors.cyan(input)}' with rollup ...`); const bundle = await rollup({ input, external: buildStandalone ? [] : external, @@ -562,15 +562,15 @@ function buildRollup(packages, buildStandalone) { if (!process.env.IS_PUBLISH) { log( - chalk.yellow( - `Skipped minification of '${chalk.cyan( + colors.yellow( + `Skipped minification of '${colors.cyan( outputFile )}' because not publishing` ) ); return undefined; } - log(`Minifying '${chalk.cyan(outputFile)}'...`); + log(`Minifying '${colors.cyan(outputFile)}'...`); await bundle.write({ file: outputFile.replace(/\.js$/, ".min.js"), @@ -597,7 +597,7 @@ function buildRollup(packages, buildStandalone) { function buildRollupDts(packages) { async function build(input, output, banner) { - log(`Bundling '${chalk.cyan(output)}' with rollup ...`); + log(`Bundling '${colors.cyan(output)}' with rollup ...`); const bundle = await rollup({ input, @@ -837,7 +837,7 @@ ${fs.readFileSync(path.join(path.dirname(input), "license"), "utf8")}*/ gulp.task("build-cjs-bundles", () => { if (!USE_ESM) { log( - chalk.yellow( + colors.yellow( "Skipping CJS-compat bundles for ESM-based builds, because not compiling to ESM" ) ); diff --git a/babel-worker.cjs b/babel-worker.cjs index 1687e316cf2e..08fc34272a31 100644 --- a/babel-worker.cjs +++ b/babel-worker.cjs @@ -2,11 +2,7 @@ const { transformAsync } = require("@babel/core"); const { mkdirSync, statSync, readFileSync, writeFileSync } = require("fs"); const path = require("path"); const { log } = require("./scripts/utils/logger.cjs"); - -let chalk; -const chalkP = import("chalk").then(ns => { - chalk = ns.default; -}); +const colors = require("picocolors"); function needCompile(src, dest) { let destStat; @@ -24,13 +20,11 @@ function needCompile(src, dest) { } exports.transform = async function transform(src, dest, opts = {}) { - if (!chalk) await chalkP; - mkdirSync(path.dirname(dest), { recursive: true }); if (!needCompile(src, dest)) { return; } - log(`Compiling '${chalk.cyan(src)}'...`); + log(`Compiling '${colors.cyan(src)}'...`); const content = readFileSync(src, { encoding: "utf8" }); const { code, map } = await transformAsync(content, { filename: src, diff --git a/package.json b/package.json index 76e05dc5b1c4..f5e464f34841 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "@yarnpkg/types": "^4.0.0", "babel-plugin-transform-charcodes": "^0.2.0", "c8": "^8.0.1", - "chalk": "^5.3.0", "charcodes": "^0.2.0", "core-js": "^3.31.1", "eslint": "^8.57.0", @@ -71,6 +70,7 @@ "jest-worker": "^30.0.0-alpha.2", "lint-staged": "^15.2.0", "mergeiterator": "^1.4.4", + "picocolors": "^1.0.0", "prettier": "^3.2.5", "rollup": "^4.9.1", "rollup-plugin-dts": "^6.1.0", diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json index 635d394b81d8..ed163f1e4f20 100644 --- a/packages/babel-code-frame/package.json +++ b/packages/babel-code-frame/package.json @@ -17,7 +17,7 @@ "main": "./lib/index.js", "dependencies": { "@babel/highlight": "workspace:^", - "chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)" + "picocolors": "^1.0.0" }, "devDependencies": { "import-meta-resolve": "^4.0.0", diff --git a/packages/babel-code-frame/src/index.ts b/packages/babel-code-frame/src/index.ts index 4f3f82f2b141..6d44f56f40fd 100644 --- a/packages/babel-code-frame/src/index.ts +++ b/packages/babel-code-frame/src/index.ts @@ -1,17 +1,19 @@ import highlight, { shouldHighlight } from "@babel/highlight"; -import chalk, { Chalk as ChalkClass, type ChalkInstance as Chalk } from "chalk"; +import colors, { createColors } from "picocolors"; +import type { Colors, Formatter } from "picocolors/types"; -let chalkWithForcedColor: Chalk = undefined; -function getChalk(forceColor: boolean) { +const compose: (f: (gv: U) => V, g: (v: T) => U) => (v: T) => V = + (f, g) => v => + f(g(v)); + +let pcWithForcedColor: Colors = undefined; +function getColors(forceColor: boolean) { if (forceColor) { - chalkWithForcedColor ??= process.env.BABEL_8_BREAKING - ? new ChalkClass({ level: 1 }) - : // @ts-expect-error .Instance was .constructor in chalk 2 - new chalk.constructor({ enabled: true, level: 1 }); - return chalkWithForcedColor; + pcWithForcedColor ??= createColors(true); + return pcWithForcedColor; } - return chalk; + return colors; } let deprecationWarningShown = false; @@ -49,13 +51,13 @@ export interface Options { } /** - * Chalk styles for code frame token types. + * Styles for code frame token types. */ -function getDefs(chalk: Chalk) { +function getDefs(colors: Colors) { return { - gutter: chalk.grey, - marker: chalk.red.bold, - message: chalk.red.bold, + gutter: colors.gray, + marker: compose(colors.red, colors.bold), + message: compose(colors.red, colors.bold), }; } @@ -149,10 +151,10 @@ export function codeFrameColumns( ): string { const highlighted = (opts.highlightCode || opts.forceColor) && shouldHighlight(opts); - const chalk = getChalk(opts.forceColor); - const defs = getDefs(chalk); - const maybeHighlight = (chalkFn: Chalk, string: string) => { - return highlighted ? chalkFn(string) : string; + const colors = getColors(opts.forceColor); + const defs = getDefs(colors); + const maybeHighlight = (fmt: Formatter, string: string) => { + return highlighted ? fmt(string) : string; }; const lines = rawLines.split(NEWLINE); const { start, end, markerLines } = getMarkerLines(loc, lines, opts); @@ -210,7 +212,7 @@ export function codeFrameColumns( } if (highlighted) { - return chalk.reset(frame); + return colors.reset(frame); } else { return frame; } diff --git a/packages/babel-code-frame/test/index.js b/packages/babel-code-frame/test/index.js index aa7412c729b5..7ee4c31bea48 100644 --- a/packages/babel-code-frame/test/index.js +++ b/packages/babel-code-frame/test/index.js @@ -1,51 +1,35 @@ -import { USE_ESM } from "$repo-utils"; - import stripAnsi from "strip-ansi"; -import chalk from "chalk"; +import colors, { createColors } from "picocolors"; import _codeFrame, { codeFrameColumns } from "../lib/index.js"; const codeFrame = _codeFrame.default || _codeFrame; import { createRequire } from "module"; const require = createRequire(import.meta.url); +const babelHighlightPicocolors = require( + require.resolve("picocolors", { + paths: [require.resolve("@babel/highlight")], + }), +); -describe("@babel/code-frame", function () { - let babelHighlightChalk; - beforeAll(async function () { - if (USE_ESM && process.env.BABEL_8_BREAKING) { - const { resolve } = await import("import-meta-resolve"); - ({ default: babelHighlightChalk } = await import( - resolve("chalk", resolve("@babel/highlight", import.meta.url)) - )); - } else { - babelHighlightChalk = require( - require.resolve("chalk", { - paths: [require.resolve("@babel/highlight")], - }), - ); - } - }); +const compose = (f, g) => v => f(g(v)); - function stubColorSupport(supported) { - let originalChalkEnabled; - let originalChalkLevel; - let originalHighlightChalkEnabled; - let originalHighlightChalkLevel; +describe("@babel/code-frame", function () { + function stubColorSupport(colors, supported) { + let originalColorsCopy; beforeEach(function () { - originalChalkLevel = chalk.level; - originalChalkEnabled = chalk.enabled; - originalHighlightChalkLevel = babelHighlightChalk.level; - originalHighlightChalkEnabled = babelHighlightChalk.enabled; - - babelHighlightChalk.level = chalk.level = supported ? 1 : 0; - babelHighlightChalk.enabled = chalk.enabled = supported; + if (supported === colors.isColorSupported) { + originalColorsCopy = null; + } else { + originalColorsCopy = { ...colors }; + Object.assign(colors, createColors(supported)); + } }); afterEach(function () { - chalk.level = originalChalkLevel; - chalk.enabled = originalChalkEnabled; - babelHighlightChalk.level = originalHighlightChalkLevel; - babelHighlightChalk.enabled = originalHighlightChalkEnabled; + if (originalColorsCopy) { + Object.assign(colors, originalColorsCopy); + } }); } @@ -139,7 +123,8 @@ describe("@babel/code-frame", function () { }); describe("when colors are supported", () => { - stubColorSupport(true); + stubColorSupport(colors, true); + stubColorSupport(babelHighlightPicocolors, true); test("opts.highlightCode", function () { const rawLines = "console.log('babel')"; @@ -191,8 +176,8 @@ describe("@babel/code-frame", function () { ); }); test("opts.forceColor", function () { - const marker = chalk.red.bold; - const gutter = chalk.grey; + const marker = compose(colors.red, colors.bold); + const gutter = colors.gray; const rawLines = ["", "", "", ""].join("\n"); expect( @@ -202,7 +187,7 @@ describe("@babel/code-frame", function () { forceColor: true, }), ).toEqual( - chalk.reset( + colors.reset( [ " " + gutter(" 2 |"), marker(">") + gutter(" 3 |"), @@ -213,8 +198,8 @@ describe("@babel/code-frame", function () { }); test("jsx", function () { - const gutter = chalk.grey; - const yellow = chalk.yellow; + const gutter = colors.gray; + const yellow = colors.yellow; const rawLines = ["
"].join("\n"); @@ -228,7 +213,7 @@ describe("@babel/code-frame", function () { ), ).toEqual( JSON.stringify( - chalk.reset( + colors.reset( " " + gutter(" 1 |") + " " + diff --git a/packages/babel-highlight/package.json b/packages/babel-highlight/package.json index e3679b7547b4..884816cc25e1 100644 --- a/packages/babel-highlight/package.json +++ b/packages/babel-highlight/package.json @@ -16,8 +16,9 @@ "main": "./lib/index.js", "dependencies": { "@babel/helper-validator-identifier": "workspace:^", - "chalk": "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)", - "js-tokens": "condition:BABEL_8_BREAKING ? ^8.0.0 : ^4.0.0" + "chalk": "condition:BABEL_8_BREAKING ? : ^2.4.2", + "js-tokens": "condition:BABEL_8_BREAKING ? ^8.0.0 : ^4.0.0", + "picocolors": "^1.0.0" }, "devDependencies": { "strip-ansi": "^4.0.0" diff --git a/packages/babel-highlight/src/index.ts b/packages/babel-highlight/src/index.ts index 5774460ebdff..adf502af3934 100644 --- a/packages/babel-highlight/src/index.ts +++ b/packages/babel-highlight/src/index.ts @@ -8,7 +8,12 @@ import { isKeyword, } from "@babel/helper-validator-identifier"; -import chalk, { Chalk as ChalkClass, type ChalkInstance as Chalk } from "chalk"; +import colors, { createColors } from "picocolors"; +import type { Colors, Formatter } from "picocolors/types"; + +const compose: (f: (gv: U) => V, g: (v: T) => U) => (v: T) => V = + (f, g) => v => + f(g(v)); /** * Names that are always allowed as identifiers, but also appear as keywords @@ -37,19 +42,19 @@ type Token = { value: string; }; /** - * Chalk styles for token types. + * Styles for token types. */ -function getDefs(chalk: Chalk): Record { +function getDefs(colors: Colors): Record { return { - keyword: chalk.cyan, - capitalized: chalk.yellow, - jsxIdentifier: chalk.yellow, - punctuator: chalk.yellow, - number: chalk.magenta, - string: chalk.green, - regex: chalk.magenta, - comment: chalk.grey, - invalid: chalk.white.bgRed.bold, + keyword: colors.cyan, + capitalized: colors.yellow, + jsxIdentifier: colors.yellow, + punctuator: colors.yellow, + number: colors.magenta, + string: colors.green, + regex: colors.magenta, + comment: colors.gray, + invalid: compose(compose(colors.white, colors.bgRed), colors.bold), }; } @@ -218,7 +223,7 @@ if (process.env.BABEL_8_BREAKING) { /** * Highlight `text` using the token definitions in `defs`. */ -function highlightTokens(defs: Record, text: string) { +function highlightTokens(defs: Record, text: string) { let highlighted = ""; for (const { type, value } of tokenize(text)) { @@ -248,23 +253,16 @@ type Options = { * Whether the code should be highlighted given the passed options. */ export function shouldHighlight(options: Options): boolean { - return chalk.level > 0 || options.forceColor; + return colors.isColorSupported || options.forceColor; } -let chalkWithForcedColor: Chalk = undefined; -function getChalk(forceColor: boolean) { +let pcWithForcedColor: Colors = undefined; +function getColors(forceColor: boolean) { if (forceColor) { - chalkWithForcedColor ??= process.env.BABEL_8_BREAKING - ? new ChalkClass({ level: 1 }) - : // @ts-expect-error .Instance was .constructor in chalk 2 - new chalk.constructor({ enabled: true, level: 1 }); - return chalkWithForcedColor; + pcWithForcedColor ??= createColors(true); + return pcWithForcedColor; } - return chalk; -} -if (!process.env.BABEL_8_BREAKING && !USE_ESM) { - // eslint-disable-next-line no-restricted-globals - exports.getChalk = (options: Options) => getChalk(options.forceColor); + return colors; } /** @@ -272,9 +270,26 @@ if (!process.env.BABEL_8_BREAKING && !USE_ESM) { */ export default function highlight(code: string, options: Options = {}): string { if (code !== "" && shouldHighlight(options)) { - const defs = getDefs(getChalk(options.forceColor)); + const defs = getDefs(getColors(options.forceColor)); return highlightTokens(defs, code); } else { return code; } } + +if (!process.env.BABEL_8_BREAKING && !USE_ESM && !IS_STANDALONE) { + let chalk: any, chalkWithForcedColor: any; + // eslint-disable-next-line no-restricted-globals + exports.getChalk = ({ forceColor }: Options) => { + // eslint-disable-next-line no-restricted-globals + chalk ??= require("chalk"); + if (forceColor) { + chalkWithForcedColor ??= new chalk.constructor({ + enabled: true, + level: 1, + }); + return chalkWithForcedColor; + } + return chalk; + }; +} diff --git a/packages/babel-highlight/test/index.js b/packages/babel-highlight/test/index.js index 95fa88e354f9..a902c4211f29 100644 --- a/packages/babel-highlight/test/index.js +++ b/packages/babel-highlight/test/index.js @@ -1,7 +1,7 @@ import { USE_ESM } from "$repo-utils"; import stripAnsi from "strip-ansi"; -import chalk from "chalk"; +import colors, { createColors } from "picocolors"; import { createRequire } from "module"; const require = createRequire(import.meta.url); @@ -14,19 +14,21 @@ const describeBabel7NoESM = describe("@babel/highlight", function () { function stubColorSupport(supported) { - let originalChalkLevel; - let originalChalkEnabled; + let originalColorsCopy; beforeEach(function () { - originalChalkLevel = chalk.level; - originalChalkEnabled = chalk.enabled; - chalk.level = supported ? 1 : 0; - chalk.enabled = supported; + if (supported === colors.isColorSupported) { + originalColorsCopy = null; + } else { + originalColorsCopy = { ...colors }; + Object.assign(colors, createColors(supported)); + } }); afterEach(function () { - chalk.level = originalChalkLevel; - chalk.enabled = originalChalkEnabled; + if (originalColorsCopy) { + Object.assign(colors, originalColorsCopy); + } }); } @@ -91,13 +93,31 @@ describe("@babel/highlight", function () { }); describeBabel7NoESM("getChalk", function () { - let getChalk; + let getChalk, chalk; beforeAll(() => { + chalk = require("chalk"); ({ getChalk } = require("../lib/index.js")); }); + function stubChalkColorSupport(supported) { + let originalChalkLevel; + let originalChalkEnabled; + + beforeEach(function () { + originalChalkLevel = chalk.level; + originalChalkEnabled = chalk.enabled; + chalk.level = supported ? 1 : 0; + chalk.enabled = supported; + }); + + afterEach(function () { + chalk.level = originalChalkLevel; + chalk.enabled = originalChalkEnabled; + }); + } + describe("when colors are supported", function () { - stubColorSupport(true); + stubChalkColorSupport(true); describe("when forceColor is not passed", function () { it("returns a Chalk instance", function () { @@ -115,7 +135,7 @@ describe("@babel/highlight", function () { }); describe("when colors are not supported", function () { - stubColorSupport(false); + stubChalkColorSupport(false); describe("when forceColor is not passed", function () { it("returns a Chalk instance", function () { diff --git a/scripts/parser-tests/utils/parser-test-runner.js b/scripts/parser-tests/utils/parser-test-runner.js index 98743fc3161d..e26f1a1bf8d1 100644 --- a/scripts/parser-tests/utils/parser-test-runner.js +++ b/scripts/parser-tests/utils/parser-test-runner.js @@ -1,8 +1,8 @@ import fs from "fs/promises"; -import chalk from "chalk"; +import colors from "picocolors"; import { parse as parser } from "../../../packages/babel-parser/lib/index.js"; -const dot = chalk.gray("."); +const dot = colors.gray("."); class TestRunner { constructor({ @@ -260,11 +260,11 @@ class TestRunner { console.log(`Testing complete (${summary.count} tests).`); console.log("Summary:"); - console.log(chalk.green(goodnews.join("\n").replace(/^/gm, " ✔ "))); + console.log(colors.green(goodnews.join("\n").replace(/^/gm, " ✔ "))); if (!summary.passed) { console.log(""); - console.log(chalk.red(badnews.join("\n").replace(/^/gm, " ✘ "))); + console.log(colors.red(badnews.join("\n").replace(/^/gm, " ✘ "))); console.log(""); console.log("Details:"); console.log(badnewsDetails.join("\n").replace(/^/gm, " ")); diff --git a/test/esm/package.json b/test/esm/package.json index acc2376ae5e9..520c73e192c5 100644 --- a/test/esm/package.json +++ b/test/esm/package.json @@ -6,6 +6,6 @@ "devDependencies": { "@babel/runtime": "workspace:^", "@babel/runtime-corejs3": "workspace:^", - "chalk": "^5.3.0" + "picocolors": "^1.0.0" } } diff --git a/test/esm/test-runner.js b/test/esm/test-runner.js index 441633875f92..fd0a3dfe87ac 100644 --- a/test/esm/test-runner.js +++ b/test/esm/test-runner.js @@ -1,4 +1,4 @@ -import chalk from "chalk"; +import colors from "picocolors"; export default async function testRunner({ title, testcases }) { console.log(title); @@ -6,9 +6,9 @@ export default async function testRunner({ title, testcases }) { for (const [subtitle, testcase] of testcases) { try { await testcase(); - console.log(chalk.green(indent + "✓ " + subtitle)); + console.log(colors.green(indent + "✓ " + subtitle)); } catch (e) { - console.log(chalk.red(indent + "✗ " + subtitle)); + console.log(colors.red(indent + "✗ " + subtitle)); console.error(e); process.exitCode = 1; } diff --git a/yarn.lock b/yarn.lock index 4441d712b065..081dde68eaa9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -284,8 +284,8 @@ __metadata: resolution: "@babel/code-frame@workspace:packages/babel-code-frame" dependencies: "@babel/highlight": "workspace:^" - chalk: "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)" import-meta-resolve: "npm:^4.0.0" + picocolors: "npm:^1.0.0" strip-ansi: "npm:^4.0.0" languageName: unknown linkType: soft @@ -1247,8 +1247,9 @@ __metadata: resolution: "@babel/highlight@workspace:packages/babel-highlight" dependencies: "@babel/helper-validator-identifier": "workspace:^" - chalk: "condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)" + chalk: "condition:BABEL_8_BREAKING ? : ^2.4.2" js-tokens: "condition:BABEL_8_BREAKING ? ^8.0.0 : ^4.0.0" + picocolors: "npm:^1.0.0" strip-ansi: "npm:^4.0.0" languageName: unknown linkType: soft @@ -4362,7 +4363,7 @@ __metadata: dependencies: "@babel/runtime": "workspace:^" "@babel/runtime-corejs3": "workspace:^" - chalk: "npm:^5.3.0" + picocolors: "npm:^1.0.0" languageName: unknown linkType: soft @@ -7128,7 +7129,6 @@ __metadata: "@yarnpkg/types": "npm:^4.0.0" babel-plugin-transform-charcodes: "npm:^0.2.0" c8: "npm:^8.0.1" - chalk: "npm:^5.3.0" charcodes: "npm:^0.2.0" core-js: "npm:^3.31.1" eslint: "npm:^8.57.0" @@ -7150,6 +7150,7 @@ __metadata: jest-worker: "npm:^30.0.0-alpha.2" lint-staged: "npm:^15.2.0" mergeiterator: "npm:^1.4.4" + picocolors: "npm:^1.0.0" prettier: "npm:^3.2.5" rollup: "npm:^4.9.1" rollup-plugin-dts: "npm:^6.1.0" @@ -7727,20 +7728,19 @@ __metadata: languageName: node linkType: hard -"chalk-BABEL_8_BREAKING-true@npm:chalk@^5.3.0, chalk@npm:5.3.0, chalk@npm:^5.3.0": - version: 5.3.0 - resolution: "chalk@npm:5.3.0" - checksum: 10/6373caaab21bd64c405bfc4bd9672b145647fc9482657b5ea1d549b3b2765054e9d3d928870cdf764fb4aad67555f5061538ff247b8310f110c5c888d92397ea +"chalk@condition:BABEL_8_BREAKING ? : ^2.4.2": + version: 0.0.0-condition-0a3819 + resolution: "chalk@condition:BABEL_8_BREAKING?:^2.4.2#0a3819" + dependencies: + chalk-BABEL_8_BREAKING-false: "npm:chalk@^2.4.2" + checksum: 10/69cc7db142bd6802351b6471c5c6eb1b8465a5e070e7f14f8d92e59ba2492b86db2bc42c12bd2ad4f055add5392f1d0611a21c4c1019c30b2f1799237ae21834 languageName: node linkType: hard -"chalk@condition:BABEL_8_BREAKING ? ^5.3.0 : ^2.4.2 (esm:default|Chalk)": - version: 0.0.0-condition-90587c - resolution: "chalk@condition:BABEL_8_BREAKING?^5.3.0:^2.4.2(esm:default|Chalk)#90587c" - dependencies: - chalk-BABEL_8_BREAKING-false: "npm:chalk@^2.4.2" - chalk-BABEL_8_BREAKING-true: "npm:chalk@^5.3.0" - checksum: 10/dbb98f9a2d72cb6dcb43e8d6eab7de58c67db9ed08f83314a26013daef55918ff2d748554dc07bb5cb58b0f0900af4ee8c57b0f5f84a93fc1da4459eb9644e56 +"chalk@npm:5.3.0, chalk@npm:^5.3.0": + version: 5.3.0 + resolution: "chalk@npm:5.3.0" + checksum: 10/6373caaab21bd64c405bfc4bd9672b145647fc9482657b5ea1d549b3b2765054e9d3d928870cdf764fb4aad67555f5061538ff247b8310f110c5c888d92397ea languageName: node linkType: hard From 8f7ea7db1dd86857d25ee961bb240a2736e80e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sat, 16 Mar 2024 21:30:57 +0100 Subject: [PATCH 2/2] Remove chalk workarounds fro babel.config.js --- babel.config.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/babel.config.js b/babel.config.js index 3e1f539788ed..e26dd9579f58 100644 --- a/babel.config.js +++ b/babel.config.js @@ -325,10 +325,6 @@ module.exports = function (api) { test: unambiguousSources.map(normalize), sourceType: "unambiguous", }, - env === "standalone" && { - test: /chalk/, - plugins: [pluginReplaceNavigator], - }, ].filter(Boolean), }; @@ -1051,20 +1047,3 @@ function pluginGeneratorOptimization({ types: t }) { }, }; } - -function pluginReplaceNavigator({ template }) { - return { - visitor: { - MemberExpression(path) { - const object = path.get("object"); - if (object.isIdentifier({ name: "navigator" })) { - object.replaceWith( - template.expression.ast` - typeof navigator == "object" ? navigator : {} - ` - ); - } - }, - }, - }; -}