Enforce node protocol import (#17207)

* enable prefer-node-protocol rule

* prefer node protocol import

* fix broken scripts

* fix e2e-old-babel error

* strip node: protocol for old node versions

* update Makefile.mjs
This commit is contained in:
Huáng Jùnliàng
2025-03-31 10:49:22 -04:00
committed by GitHub
parent 5ed86fe5f4
commit 254525d565
152 changed files with 402 additions and 284 deletions
+7 -7
View File
@@ -1,10 +1,10 @@
import path from "path";
import fs from "fs";
import { cpus } from "os";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import { Transform as TransformStream } from "stream";
import { callbackify } from "util";
import path from "node:path";
import fs from "node:fs";
import { cpus } from "node:os";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { Transform as TransformStream } from "node:stream";
import { callbackify } from "node:util";
import colors from "picocolors";
import gulp from "gulp";
import { rollup } from "rollup";
+2 -2
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,12 +1,12 @@
import "shelljs/make.js";
import path from "path";
import path from "node:path";
import {
readFileSync,
writeFileSync,
readdirSync,
existsSync,
mkdirSync,
} from "fs";
} from "node:fs";
import semver from "semver";
import { execaSync } from "execa";
+2 -2
View File
@@ -1,6 +1,6 @@
const { transformAsync } = require("@babel/core");
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("fs");
const path = require("path");
const { mkdirSync, statSync, readFileSync, writeFileSync } = require("node:fs");
const path = require("node:path");
const { log } = require("./scripts/utils/logger.cjs");
const colors = require("picocolors");
+3
View File
@@ -1,3 +1,5 @@
// NOTE: This file must be runnable on all Node.js version
/* eslint-disable unicorn/prefer-node-protocol */
"use strict";
let jestSnapshot = false;
@@ -191,6 +193,7 @@ module.exports = function (api) {
: null,
require("./scripts/babel-plugin-bit-decorator/plugin.cjs"),
require("./scripts/babel-plugin-transform-node-protocol-import/plugin.cjs"),
].filter(Boolean),
overrides: [
{
@@ -3,7 +3,7 @@ import baseline from "@babel-baseline/core";
import current from "@babel/core";
import parser from "@babel-baseline/parser";
import { report } from "../../util.mjs";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
const suite = new Benchmark.Suite();
const fixtureName = "babel-parser-expression.txt";
@@ -1,5 +1,5 @@
import Benchmark from "benchmark";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
import {
report,
currentCore,
@@ -1,4 +1,4 @@
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
import {
currentCore,
baselineCore,
@@ -3,7 +3,7 @@ import baseline from "@babel-baseline/generator";
import current from "@babel/generator";
import parser from "@babel/parser";
import { report } from "../../util.mjs";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
const suite = new Benchmark.Suite();
@@ -1,4 +1,4 @@
import { copyFileSync, readFileSync, rmSync } from "fs";
import { copyFileSync, readFileSync, rmSync } from "node:fs";
// eslint-disable-next-line import/no-extraneous-dependencies
import { commonJS } from "$repo-utils";
import { Benchmark } from "../../util.mjs";
+1 -1
View File
@@ -2,7 +2,7 @@ import Benchmark from "benchmark";
import baseline from "@babel-baseline/parser";
import current from "@babel/parser";
import { report } from "../../util.mjs";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
const suite = new Benchmark.Suite();
+3 -3
View File
@@ -1,6 +1,6 @@
import path from "path";
import { readFileSync, writeFileSync } from "fs";
import { fileURLToPath } from "url";
import path from "node:path";
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
+2 -1
View File
@@ -121,6 +121,7 @@ export default [
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-node-protocol": "error",
"unicorn/prefer-string-starts-ends-with": "error",
},
},
@@ -306,7 +307,7 @@ export default [
rules: {
"n/no-unsupported-features/node-builtins": [
"error",
{ version: "12.17.0", ignores: ["module"] },
{ version: "20.19.0", ignores: ["module"] },
],
"@babel/development-internal/require-default-import-fallback": "error",
"import/no-unresolved": "error",
+1 -1
View File
@@ -54,7 +54,7 @@ export class Client {
export class WorkerClient extends Client {
static #worker_threads_cache: typeof import("worker_threads");
static get #worker_threads() {
return (WorkerClient.#worker_threads_cache ??= require("worker_threads"));
return (WorkerClient.#worker_threads_cache ??= require("node:worker_threads"));
}
#worker = new WorkerClient.#worker_threads.Worker(
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import escope from "eslint-scope";
import unpad from "dedent";
import { parseForESLint as parseForESLintOriginal } from "../lib/index.cjs";
@@ -1,7 +1,7 @@
import { Linter, ESLint } from "eslint";
import unpad from "dedent";
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
eslintConfigCompat,
babelESLintParserPath,
@@ -1,5 +1,5 @@
import { ESLint } from "eslint";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
describe("Babel config files", () => {
it("works with babel.config.mjs - ESLint " + ESLint.version, async () => {
@@ -1,5 +1,5 @@
import { ESLint } from "eslint";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
describe("https://github.com/babel/babel/issues/12985", () => {
it(
@@ -1,5 +1,5 @@
import { ESLint } from "eslint";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
describe("https://github.com/babel/babel-eslint/issues/558", () => {
it(
@@ -1,8 +1,8 @@
import { Linter, ESLint } from "eslint";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import * as parser from "../../../../../babel-eslint-parser/lib/index.cjs";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import {
babelESLintParserPath,
eslintConfigCompat,
@@ -1,6 +1,6 @@
import verifyAndAssertMessages from "../../helpers/verifyAndAssertMessages.js";
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
function verifyDecoratorsLegacyAndAssertMessages(
code,
@@ -1,6 +1,6 @@
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
import * as babelESLint from "@babel/eslint-parser";
import { itGte } from "$repo-utils";
+2 -2
View File
@@ -1,6 +1,6 @@
import slash from "slash";
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";
import * as util from "./util.ts";
import * as watcher from "./watcher.ts";
+2 -2
View File
@@ -1,8 +1,8 @@
import convertSourceMap from "convert-source-map";
import { AnyMap, encodedMap } from "@jridgewell/trace-mapping";
import slash from "slash";
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";
import * as util from "./util.ts";
import type { CmdOptions } from "./options.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "node:fs";
import * as commander from "commander";
import { version, DEFAULT_EXTENSIONS } from "@babel/core";
+2 -2
View File
@@ -1,7 +1,7 @@
import readdirRecursive from "fs-readdir-recursive";
import * as babel from "@babel/core";
import path from "path";
import fs from "fs";
import path from "node:path";
import fs from "node:fs";
import * as watcher from "./watcher.ts";
+2 -2
View File
@@ -1,5 +1,5 @@
import { createRequire } from "module";
import path from "path";
import { createRequire } from "node:module";
import path from "node:path";
import type { WatchOptions, FSWatcher } from "chokidar";
const fileToDeps = new Map<string, Set<string>>();
+1 -1
View File
@@ -2,7 +2,7 @@ import {
buildProcessTests,
buildParallelProcessTests,
} from "@babel/helper-transform-fixture-test-runner";
import path from "path";
import path from "node:path";
import { commonJS } from "$repo-utils";
const { __dirname } = commonJS(import.meta.url);
@@ -2,7 +2,7 @@
// NOTE: This script must be run _after_ build-data.js
const path = require("path");
const path = require("node:path");
const {
generateData,
@@ -1,6 +1,6 @@
const data = require("core-js-compat/data.json");
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const features = Object.keys(data);
@@ -1,6 +1,6 @@
"use strict";
const path = require("path");
const path = require("node:path");
const compatData = require("@mdn/browser-compat-data").javascript;
const { generateModuleSupport } = require("./build-modules-support");
const {
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");
const compatData = require("@mdn/browser-compat-data").javascript;
const { addElectronSupportFromChromium } = require("./chromium-to-electron");
@@ -1,6 +1,6 @@
"use strict";
const fs = require("fs");
const fs = require("node:fs");
const { addElectronSupportFromChromium } = require("./chromium-to-electron");
const envs = require("../build/compat-table/environments");
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import path from "path";
import path from "node:path";
import buildDebug from "debug";
import type { Handler } from "gensync";
import { validate } from "./validation/options.ts";
@@ -1,6 +1,6 @@
import buildDebug from "debug";
import nodeFs from "fs";
import path from "path";
import nodeFs from "node:fs";
import path from "node:path";
import json5 from "json5";
import gensync from "gensync";
import type { Handler } from "gensync";
@@ -17,7 +17,7 @@ import ConfigError from "../../errors/config-error.ts";
import * as fs from "../../gensync-utils/fs.ts";
import { createRequire } from "module";
import { createRequire } from "node:module";
import { endHiddenCallStack } from "../../errors/rewrite-stack-trace.ts";
import { isAsync } from "../../gensync-utils/async.ts";
const require = createRequire(import.meta.url);
@@ -1,8 +1,8 @@
import { isAsync, waitFor } from "../../gensync-utils/async.ts";
import type { Handler } from "gensync";
import path from "path";
import { pathToFileURL } from "url";
import { createRequire } from "module";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { createRequire } from "node:module";
import semver from "semver";
import buildDebug from "debug";
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import type { Handler } from "gensync";
import { makeStaticFileCache } from "./utils.ts";
@@ -3,16 +3,16 @@
*/
import buildDebug from "debug";
import path from "path";
import path from "node:path";
import type { Handler } from "gensync";
import { isAsync } from "../../gensync-utils/async.ts";
import loadCodeDefault, { supportsESM } from "./module-types.ts";
import { fileURLToPath, pathToFileURL } from "url";
import { fileURLToPath, pathToFileURL } from "node:url";
import { resolve as importMetaResolve } from "../../vendor/import-meta-resolve.js";
import { createRequire } from "module";
import { existsSync } from "fs";
import { createRequire } from "node:module";
import { existsSync } from "node:fs";
const require = createRequire(import.meta.url);
const debug = buildDebug("babel:config:loading:files:plugins");
@@ -3,7 +3,7 @@ import type { Handler } from "gensync";
import { makeStrongCache } from "../caching.ts";
import type { CacheConfigurator } from "../caching.ts";
import * as fs from "../../gensync-utils/fs.ts";
import nodeFs from "fs";
import nodeFs from "node:fs";
export function makeStaticFileCache<T>(
fn: (filepath: string, contents: string) => T,
+1 -1
View File
@@ -1,7 +1,7 @@
import type { Handler } from "gensync";
import type { PluginTarget, PluginOptions } from "./validation/options.ts";
import path from "path";
import path from "node:path";
import { createDescriptor } from "./config-descriptors.ts";
import type { UnloadedDescriptor } from "./config-descriptors.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import type { Handler } from "gensync";
import Plugin from "./plugin.ts";
import { mergeOptions } from "./util.ts";
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
const sep = `\\${path.sep}`;
const endSep = `(?:${sep}|$)`;
@@ -6,7 +6,7 @@ type nodeType = typeof import("./resolve-targets");
({}) as any as browserType as nodeType;
import type { ValidatedOptions } from "./validation/options.ts";
import path from "path";
import path from "node:path";
import getTargets, {
type InputTargets,
} from "@babel/helper-compilation-targets";
+1 -1
View File
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "node:fs";
import gensync from "gensync";
export const readFile = gensync<[filepath: string, encoding: "utf8"], string>({
+1 -1
View File
@@ -92,7 +92,7 @@ export const DEFAULT_EXTENSIONS = Object.freeze([
".cjs",
] as const);
import Module from "module" with { if: "USE_ESM && !IS_STANDALONE" };
import Module from "node:module" with { if: "USE_ESM && !IS_STANDALONE" };
import * as thisFile from "./index.ts" with { if: "USE_ESM && !IS_STANDALONE" };
if (USE_ESM && !IS_STANDALONE) {
// Pass this module to the CJS proxy, so that it can be synchronously accessed.
@@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import buildDebug from "debug";
import type { Handler } from "gensync";
import { file, traverseFast } from "@babel/types";
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import type { ResolvedConfig } from "../config/index.ts";
export default function normalizeOptions(config: ResolvedConfig) {
+1 -1
View File
@@ -1,6 +1,6 @@
import * as babel from "../lib/index.js";
import { TraceMap, originalPositionFor } from "@jridgewell/trace-mapping";
import path from "path";
import path from "node:path";
import generator from "@babel/generator";
import _Plugin from "../lib/config/plugin.js";
+2 -2
View File
@@ -1,5 +1,5 @@
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
loadOptionsSync as loadOptionsSyncOrig,
transformSync,
+2 -2
View File
@@ -1,5 +1,5 @@
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import * as babel from "../lib/index.js";
import {
+4 -4
View File
@@ -1,7 +1,7 @@
import fs from "fs";
import os from "os";
import path from "path";
import { fileURLToPath } from "url";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import * as babel from "../lib/index.js";
import rimraf from "rimraf";
import { itBabel7, itBabel8, itSatisfies, itNegate } from "$repo-utils";
+1 -1
View File
@@ -8,7 +8,7 @@ import {
createConfigItem,
createConfigItemSync,
} from "../lib/index.js";
import path from "path";
import path from "node:path";
import { itNoWin32, itBabel8, commonJS } from "$repo-utils";
import { supportsESM } from "./helpers/esm.js";
+1 -1
View File
@@ -1,5 +1,5 @@
import { loadPartialConfigSync, loadPartialConfigAsync } from "../lib/index.js";
import path from "path";
import path from "node:path";
import semver from "semver";
import { commonJS, itGte, itLt, USE_ESM } from "$repo-utils";
+2 -2
View File
@@ -1,8 +1,8 @@
import * as babel from "../lib/index.js";
import { commonJS, itGte } from "$repo-utils";
import path from "path";
import { spawnSync } from "child_process";
import path from "node:path";
import { spawnSync } from "node:child_process";
const { __dirname } = commonJS(import.meta.url);
@@ -1,5 +1,5 @@
import { execFile } from "child_process";
import { createRequire } from "module";
import { execFile } from "node:child_process";
import { createRequire } from "node:module";
import {
describeESM,
describeSatisfies,
@@ -1,5 +1,5 @@
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { transformSync } from "../lib/index.js";
const cwd = path.dirname(fileURLToPath(import.meta.url));
+3 -3
View File
@@ -1,6 +1,6 @@
import cp from "child_process";
import util from "util";
import path from "path";
import cp from "node:child_process";
import util from "node:util";
import path from "node:path";
import { USE_ESM, commonJS } from "$repo-utils";
import * as babel from "../../lib/index.js";
+2 -2
View File
@@ -1,6 +1,6 @@
import * as babel from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { itBabel7, itBabel7NoESM } from "$repo-utils";
const cwd = path.dirname(fileURLToPath(import.meta.url));
+4 -4
View File
@@ -1,8 +1,8 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import { parseSync } from "../lib/index.js";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
+2 -2
View File
@@ -1,6 +1,6 @@
import { transformSync } from "../lib/index.js";
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import _Plugin from "../lib/config/plugin.js";
const Plugin = _Plugin.default || _Plugin;
+2 -2
View File
@@ -1,6 +1,6 @@
import runner from "@babel/helper-transform-fixture-test-runner";
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
(runner.default || runner)(
path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures/plugins"),
+2 -2
View File
@@ -1,6 +1,6 @@
import * as babel from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { itGte } from "$repo-utils";
describe("addon resolution", function () {
+2 -2
View File
@@ -1,6 +1,6 @@
import { loadOptionsSync as loadOptionsSyncOrig } from "../lib/index.js";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const cwd = dirname(fileURLToPath(import.meta.url));
+2 -2
View File
@@ -1,6 +1,6 @@
import runner from "@babel/helper-transform-fixture-test-runner";
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import cloneDeep from "../lib/transformation/util/clone-deep.js";
import { itBabel8 } from "$repo-utils";
@@ -1,8 +1,8 @@
/*
Copies tests from the @babel/parser's TypeScript test suite to @babel/generator.
*/
const fs = require("fs");
const { join } = require("path");
const fs = require("node:fs");
const { join } = require("node:path");
const testsFrom = join(
__dirname,
+2 -2
View File
@@ -1,7 +1,7 @@
import { parse, parseExpression } from "@babel/parser";
import * as t from "@babel/types";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import fixtures from "@babel/helper-fixtures";
import { TraceMap, originalPositionFor } from "@jridgewell/trace-mapping";
import { commonJS, describeBabel7NoESM, itBabel7, itBabel8 } from "$repo-utils";
@@ -1,5 +1,5 @@
import { parse } from "@babel/parser";
import path from "path";
import path from "node:path";
import fixtures from "@babel/helper-fixtures";
import * as babel from "@babel/core";
import pluginTransformTypeScript from "@babel/plugin-transform-typescript";
@@ -1,5 +1,5 @@
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import _getTargets from "../../lib/index.js";
const getTargets = _getTargets.default || _getTargets;
@@ -1,5 +1,5 @@
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import _getTargets from "../../lib/index.js";
const getTargets = _getTargets.default || _getTargets;
@@ -1,5 +1,5 @@
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import _getTargets from "../../lib/index.js";
const getTargets = _getTargets.default || _getTargets;
@@ -1,5 +1,5 @@
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import _getTargets from "../../lib/index.js";
const getTargets = _getTargets.default || _getTargets;
+4 -4
View File
@@ -1,8 +1,8 @@
import semver from "semver";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import path from "node:path";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
import type { InputOptions } from "@babel/core";
import type { EncodedSourceMap } from "@jridgewell/gen-mapping";
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "node:assert";
import {
callExpression,
cloneNode,
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "node:assert";
import {
identifier,
importSpecifier,
@@ -1,6 +1,6 @@
import * as babel from "@babel/core";
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { ImportInjector } from "../lib/index.js";
@@ -1,4 +1,4 @@
import assert from "assert";
import assert from "node:assert";
import { template, types as t } from "@babel/core";
import { isModule } from "@babel/helper-module-imports";
@@ -1,4 +1,4 @@
import { basename, extname } from "path";
import { basename, extname } from "node:path";
import type { types as t, NodePath } from "@babel/core";
import { isIdentifierName } from "@babel/helper-validator-identifier";
@@ -1,6 +1,6 @@
import testRunner from "@babel/helper-transform-fixture-test-runner";
import path from "path";
import { URL } from "url";
import path from "node:path";
import { URL } from "node:url";
export default function (loc: string) {
if (!process.env.BABEL_8_BREAKING) {
@@ -16,24 +16,24 @@ import {
import { codeFrameColumns } from "@babel/code-frame";
import * as helpers from "./helpers.ts";
import visualizeSourceMap from "./source-map-visualizer.ts";
import assert from "assert";
import fs, { readFileSync, realpathSync } from "fs";
import path from "path";
import vm from "vm";
import assert from "node:assert";
import fs, { readFileSync, realpathSync } from "node:fs";
import path from "node:path";
import vm from "node:vm";
import LruCache from "lru-cache";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { diff } from "jest-diff";
import type { ChildProcess } from "child_process";
import { spawn } from "child_process";
import os from "os";
import type { ChildProcess } from "node:child_process";
import { spawn } from "node:child_process";
import os from "node:os";
import readdirRecursive from "fs-readdir-recursive";
import { createRequire } from "module";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const dirname = path.dirname(fileURLToPath(import.meta.url));
import checkDuplicateNodes from "@babel/helper-check-duplicate-nodes";
import { createHash } from "crypto";
import { createHash } from "node:crypto";
type Module = {
id: string;
@@ -1,5 +1,5 @@
import { runCodeInTestContext } from "../lib/index.js";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
const filename = fileURLToPath(import.meta.url);
@@ -1,11 +1,11 @@
/* eslint-disable import/no-extraneous-dependencies */
import fs from "fs";
import { join } from "path";
import { URL, fileURLToPath } from "url";
import fs from "node:fs";
import { join } from "node:path";
import { URL, fileURLToPath } from "node:url";
import { minify } from "terser";
import { babel, presetTypescript } from "$repo-utils/babel-top-level";
import { IS_BABEL_8 } from "$repo-utils";
import { gzipSync } from "zlib";
import { gzipSync } from "node:zlib";
import {
getHelperMetadata,
@@ -0,0 +1,61 @@
import fs from "node:fs";
import { createRequire } from "node:module";
const [parse, generate] = await Promise.all([
import("@babel/parser").then(ns => ns.parse),
import("@babel/generator").then(ns => ns.default.default || ns.default),
]).catch(error => {
console.error(error);
throw new Error(
"Before running generate-helpers.js you must compile @babel/parser and @babel/generator.",
{ cause: error }
);
});
const REGENERATOR_RUNTIME_IN_FILE = fs.readFileSync(
createRequire(import.meta.url).resolve("regenerator-runtime"),
"utf8"
);
const MIN_VERSION = "7.18.0";
const HEADER = `/* @minVersion ${MIN_VERSION} */
/*
* This file is auto-generated! Do not modify it directly.
* To re-generate, update the regenerator-runtime dependency of
* @babel/helpers and run 'yarn gulp generate-runtime-helpers'.
*/
/* eslint-disable */
`;
const COPYRIGHT = `/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */`;
export default function generateRegeneratorRuntimeHelper() {
const ast = parse(REGENERATOR_RUNTIME_IN_FILE, { sourceType: "script" });
const factoryFunction = ast.program.body[0].declarations[0].init.callee;
factoryFunction.type = "FunctionDeclaration";
factoryFunction.id = { type: "Identifier", name: "_regeneratorRuntime" };
factoryFunction.params = [];
factoryFunction.body.body.unshift(
...stmts(`
${COPYRIGHT}
_regeneratorRuntime = function () { return exports; };
var exports = {};
`)
);
const { code } = generate({
type: "ExportDefaultDeclaration",
declaration: factoryFunction,
});
return HEADER + code;
}
function stmts(code) {
return parse(`function _() { ${code} }`, {
sourceType: "script",
}).program.body[0].body.body;
}
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import _template from "@babel/template";
import _helpers from "../../lib/helpers-generated.js";
const template = _template.default || _template;
@@ -1,4 +1,5 @@
// NOTE: This file must be runnable on all Node.js version
/* eslint-disable unicorn/prefer-node-protocol */
const cp = require("child_process");
const fs = require("fs");
+7 -7
View File
@@ -1,15 +1,15 @@
import Module from "module";
import { inspect } from "util";
import path from "path";
import repl from "repl";
import Module from "node:module";
import { inspect } from "node:util";
import path from "node:path";
import repl from "node:repl";
import * as babel from "@babel/core";
import vm from "vm";
import vm from "node:vm";
import "core-js/stable/index.js";
import "regenerator-runtime/runtime.js";
// @ts-expect-error @babel/register is a CommonJS module
import register from "@babel/register";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { fileURLToPath } from "node:url";
import { createRequire } from "node:module";
import type { PluginAPI, PluginObject } from "@babel/core";
import { program } from "./program-setup.ts";
+3 -3
View File
@@ -3,9 +3,9 @@
* when found, before invoking the "real" _babel-node(1) executable.
*/
import path from "path";
import child_process from "child_process";
import { fileURLToPath } from "url";
import path from "node:path";
import child_process from "node:child_process";
import { fileURLToPath } from "node:url";
import getV8FlagsRaw from "v8flags";
import { splitArgs, nodeFlagsWithValue } from "./split-args.ts";
+2 -2
View File
@@ -1,5 +1,5 @@
import path from "path";
import { writeFileSync } from "fs";
import path from "node:path";
import { writeFileSync } from "node:fs";
import { commonJS } from "$repo-utils";
import {
buildProcessTests,
+1 -1
View File
@@ -2,7 +2,7 @@
/* eslint no-var: 0 */
var parser = require("..");
var fs = require("fs");
var fs = require("node:fs");
var filename = process.argv[2];
if (!filename) {
@@ -1,7 +1,7 @@
import path from "path";
import path from "node:path";
import runFixtureTests from "./helpers/run-fixture-tests.js";
import { parseExpression } from "../lib/index.js";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
runFixtureTests(
path.join(path.dirname(fileURLToPath(import.meta.url)), "expressions"),
+2 -2
View File
@@ -1,7 +1,7 @@
import path from "path";
import path from "node:path";
import runFixtureTests from "./helpers/run-fixture-tests.js";
import { parse } from "../lib/index.js";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { VISITOR_KEYS } from "@babel/types";
runFixtureTests(
+2 -2
View File
@@ -1,7 +1,7 @@
import path from "path";
import path from "node:path";
import runFixtureTests from "./helpers/run-fixture-tests.js";
import { parseExpression } from "../lib/index.js";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
const fixtures = path.join(
path.dirname(fileURLToPath(import.meta.url)),
@@ -1,4 +1,4 @@
import { inspect } from "util";
import { inspect } from "node:util";
import Difference from "./difference.js";
import "./polyfill.js";
@@ -1,7 +1,7 @@
import { multiple as getFixtures } from "@babel/helper-fixtures";
import _checkDuplicateNodes from "@babel/helper-check-duplicate-nodes";
import { readFileSync, unlinkSync, writeFileSync, existsSync } from "fs";
import { join } from "path";
import { readFileSync, unlinkSync, writeFileSync, existsSync } from "node:fs";
import { join } from "node:path";
import Difference from "./difference.js";
import FixtureError from "./fixture-error.js";
import toFuzzedOptions from "./to-fuzzed-options.js";
@@ -1,5 +1,5 @@
import { codeFrameColumns } from "@babel/code-frame";
import { runInThisContext } from "vm";
import { runInThisContext } from "node:vm";
export default function toContextualSyntaxError(
error,
+2 -2
View File
@@ -1,7 +1,7 @@
import path from "path";
import path from "node:path";
import runFixtureTests from "./helpers/run-fixture-tests.js";
import { parse } from "../lib/index.js";
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
const fixtures = path.join(
path.dirname(fileURLToPath(import.meta.url)),
@@ -1,7 +1,7 @@
import * as babel from "@babel/core";
import transformAmd from "../lib/index.js";
import externalHelpers from "@babel/plugin-external-helpers";
import path from "path";
import path from "node:path";
describe("'importInterop'", () => {
function transform(code, importInterop, filename) {
@@ -1,6 +1,6 @@
import * as babel from "@babel/core";
import { fileURLToPath } from "url";
import path from "path";
import { fileURLToPath } from "node:url";
import path from "node:path";
import transformCommonJS from "../lib/index.js";
@@ -1,7 +1,7 @@
import * as babel from "@babel/core";
import vm from "vm";
import { fileURLToPath } from "url";
import path from "path";
import vm from "node:vm";
import { fileURLToPath } from "node:url";
import path from "node:path";
import transformCommonJS from "../lib/index.js";
@@ -1,7 +1,7 @@
import * as babel from "@babel/core";
import transformCommonjs from "../lib/index.js";
import externalHelpers from "@babel/plugin-external-helpers";
import path from "path";
import path from "node:path";
describe("'importInterop'", () => {
function transform(code, importInterop, filename) {
@@ -1,7 +1,7 @@
import runner from "@babel/helper-plugin-test-runner";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
import { commonJS } from "$repo-utils";
import path from "path";
import path from "node:path";
import {
runCodeInTestContext,
createTestContext,

Some files were not shown because too many files have changed in this diff Show More