Avoid using CJS globals in internal source files (#12963)
* Lint against CJS globals in modules * Use `import.meta.url` instead of `__filename` in `src` files * Prepare fixtures runner for `import.meta.url` * Use `import.meta.url` instead of `__filename` in `test/index` files * Remove `__dirname` from remaining test files dirname * Avoid using `module` in `src` files * Avoid using `require` in `src` files * Avoid using `require` in `test` files * Update `@types/node` * Compile dynamic import in `@babel/node` * Fix windows * Use `@babel/plugin-proposal-dynamic-import` from npm
This commit is contained in:
parent
ea620e822e
commit
d04842a700
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
|
const cjsGlobals = ["__dirname", "__filename", "require", "module", "exports"];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -68,6 +70,25 @@ module.exports = {
|
|||||||
"import/extensions": ["error", { json: "always", cjs: "always" }],
|
"import/extensions": ["error", { json: "always", cjs: "always" }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
"packages/*/src/**/*.{js,ts}",
|
||||||
|
"codemods/*/src/**/*.{js,ts}",
|
||||||
|
"eslint/*/src/**/*.{js,ts}",
|
||||||
|
"packages/*/test/**/*.js",
|
||||||
|
"codemods/*/test/**/*.js",
|
||||||
|
"eslint/*/test/**/*.js",
|
||||||
|
"packages/babel-helper-transform-fixture-test-runner/src/helpers.{ts,js}",
|
||||||
|
"test/**/*.js",
|
||||||
|
],
|
||||||
|
excludedFiles: [
|
||||||
|
// @babel/register is the require() hook, so it will always be CJS-based
|
||||||
|
"packages/babel-register/**/*.js",
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
"no-restricted-globals": ["error", ...cjsGlobals],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
files: ["packages/babel-plugin-*/src/index.{js,ts}"],
|
files: ["packages/babel-plugin-*/src/index.{js,ts}"],
|
||||||
excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
excludedFiles: ["packages/babel-plugin-transform-regenerator/**/*.js"],
|
||||||
|
|||||||
@ -159,6 +159,7 @@ module.exports = function (api) {
|
|||||||
convertESM ? "@babel/proposal-export-namespace-from" : null,
|
convertESM ? "@babel/proposal-export-namespace-from" : null,
|
||||||
convertESM ? "@babel/transform-modules-commonjs" : null,
|
convertESM ? "@babel/transform-modules-commonjs" : null,
|
||||||
convertESM ? pluginNodeImportInterop : null,
|
convertESM ? pluginNodeImportInterop : null,
|
||||||
|
convertESM ? pluginImportMetaUrl : null,
|
||||||
|
|
||||||
pluginPackageJsonMacro,
|
pluginPackageJsonMacro,
|
||||||
|
|
||||||
@ -177,14 +178,17 @@ module.exports = function (api) {
|
|||||||
plugins: ["babel-plugin-transform-charcodes"],
|
plugins: ["babel-plugin-transform-charcodes"],
|
||||||
assumptions: parserAssumptions,
|
assumptions: parserAssumptions,
|
||||||
},
|
},
|
||||||
{
|
convertESM && {
|
||||||
test: ["./packages/babel-cli", "./packages/babel-core"].map(normalize),
|
test: ["./packages/babel-cli", "./packages/babel-core"].map(normalize),
|
||||||
plugins: [
|
plugins: [
|
||||||
// Explicitly use the lazy version of CommonJS modules.
|
// Explicitly use the lazy version of CommonJS modules.
|
||||||
convertESM
|
["@babel/transform-modules-commonjs", { lazy: true }],
|
||||||
? ["@babel/transform-modules-commonjs", { lazy: true }]
|
],
|
||||||
: null,
|
},
|
||||||
].filter(Boolean),
|
convertESM && {
|
||||||
|
test: ["./packages/babel-node/src"].map(normalize),
|
||||||
|
// Used to conditionally import kexec
|
||||||
|
plugins: ["@babel/plugin-proposal-dynamic-import"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: sources.map(normalize),
|
test: sources.map(normalize),
|
||||||
@ -465,3 +469,83 @@ function pluginNodeImportInterop({ template }) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pluginImportMetaUrl({ types: t, template }) {
|
||||||
|
const isImportMeta = node =>
|
||||||
|
t.isMetaProperty(node) &&
|
||||||
|
t.isIdentifier(node.meta, { name: "import" }) &&
|
||||||
|
t.isIdentifier(node.property, { name: "meta" });
|
||||||
|
|
||||||
|
const isImportMetaUrl = node =>
|
||||||
|
t.isMemberExpression(node, { computed: false }) &&
|
||||||
|
t.isIdentifier(node.property, { name: "url" }) &&
|
||||||
|
isImportMeta(node.object);
|
||||||
|
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Program(programPath) {
|
||||||
|
// We must be sure to run this before the instanbul plugins, because its
|
||||||
|
// instrumentation breaks our detection.
|
||||||
|
programPath.traverse({
|
||||||
|
// fileURLToPath(import.meta.url)
|
||||||
|
CallExpression(path) {
|
||||||
|
const { node } = path;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!t.isIdentifier(node.callee, { name: "fileURLToPath" }) ||
|
||||||
|
node.arguments.length !== 1
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const arg = node.arguments[0];
|
||||||
|
|
||||||
|
if (
|
||||||
|
!t.isMemberExpression(arg, { computed: false }) ||
|
||||||
|
!t.isIdentifier(arg.property, { name: "url" }) ||
|
||||||
|
!isImportMeta(arg.object)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
path.replaceWith(t.identifier("__filename"));
|
||||||
|
},
|
||||||
|
|
||||||
|
// const require = createRequire(import.meta.url)
|
||||||
|
VariableDeclarator(path) {
|
||||||
|
const { node } = path;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!t.isIdentifier(node.id, { name: "require" }) ||
|
||||||
|
!t.isCallExpression(node.init) ||
|
||||||
|
!t.isIdentifier(node.init.callee, { name: "createRequire" }) ||
|
||||||
|
node.init.arguments.length !== 1 ||
|
||||||
|
!isImportMetaUrl(node.init.arguments[0])
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's just remove this declaration to unshadow the "global" cjs require.
|
||||||
|
path.remove();
|
||||||
|
},
|
||||||
|
|
||||||
|
// import.meta.url
|
||||||
|
MemberExpression(path) {
|
||||||
|
if (!isImportMetaUrl(path.node)) return;
|
||||||
|
|
||||||
|
path.replaceWith(
|
||||||
|
template.expression
|
||||||
|
.ast`\`file://\${__filename.replace(/\\\\/g, "/")}\``
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
MetaProperty(path) {
|
||||||
|
if (isImportMeta(path.node)) {
|
||||||
|
throw path.buildCodeFrameError("Unsupported import.meta");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import escope from "eslint-scope";
|
import escope from "eslint-scope";
|
||||||
import unpad from "dedent";
|
import unpad from "dedent";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
import { parseForESLint } from "../src";
|
import { parseForESLint } from "../src";
|
||||||
|
|
||||||
const BABEL_OPTIONS = {
|
const BABEL_OPTIONS = {
|
||||||
configFile: require.resolve(
|
configFile: path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"../../babel-eslint-shared-fixtures/config/babel.config.js",
|
"../../babel-eslint-shared-fixtures/config/babel.config.js",
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -73,6 +76,8 @@ describe("Babel and Espree", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
// Use the version of Espree that is a dependency of
|
// Use the version of Espree that is a dependency of
|
||||||
// the version of ESLint we are testing against.
|
// the version of ESLint we are testing against.
|
||||||
const espreePath = require.resolve("espree", {
|
const espreePath = require.resolve("espree", {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import dryErrorMessages from "./rules/dry-error-messages";
|
import dryErrorMessages from "./rules/dry-error-messages";
|
||||||
|
|
||||||
module.exports = {
|
export const rules = {
|
||||||
rules: {
|
"dry-error-messages": dryErrorMessages,
|
||||||
"dry-error-messages": dryErrorMessages,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default { rules };
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import rule from "../../src/rules/dry-error-messages";
|
import rule from "../../src/rules/dry-error-messages";
|
||||||
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";
|
import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const FILENAME = path.resolve(__dirname, "test/lib/index.js");
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
const FILENAME = path.resolve(dirname, "test/lib/index.js");
|
||||||
const ERRORS_MODULE = "errorsModule";
|
const ERRORS_MODULE = "errorsModule";
|
||||||
const MODULE_SAME_DIR = path.resolve(__dirname, "test/lib/errorsModule.js");
|
const MODULE_SAME_DIR = path.resolve(dirname, "test/lib/errorsModule.js");
|
||||||
const MODULE_PARENT_DIR = path.resolve(__dirname, "test/errorsModule.js");
|
const MODULE_PARENT_DIR = path.resolve(dirname, "test/errorsModule.js");
|
||||||
|
|
||||||
const ruleTester = new RuleTester();
|
const ruleTester = new RuleTester();
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import noDeprecatedClone from "./rules/no-deprecated-clone";
|
|||||||
import noUndefinedIdentifier from "./rules/no-undefined-identifier";
|
import noUndefinedIdentifier from "./rules/no-undefined-identifier";
|
||||||
import pluginName from "./rules/plugin-name";
|
import pluginName from "./rules/plugin-name";
|
||||||
|
|
||||||
module.exports = {
|
export const rules = {
|
||||||
rules: {
|
"no-deprecated-clone": noDeprecatedClone,
|
||||||
"no-deprecated-clone": noDeprecatedClone,
|
"no-undefined-identifier": noUndefinedIdentifier,
|
||||||
"no-undefined-identifier": noUndefinedIdentifier,
|
"plugin-name": pluginName,
|
||||||
"plugin-name": pluginName,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default { rules };
|
||||||
|
|||||||
@ -4,19 +4,20 @@ import noUnusedExpressions from "./rules/no-unused-expressions";
|
|||||||
import objectCurlySpacing from "./rules/object-curly-spacing";
|
import objectCurlySpacing from "./rules/object-curly-spacing";
|
||||||
import semi from "./rules/semi";
|
import semi from "./rules/semi";
|
||||||
|
|
||||||
module.exports = {
|
export const rules = {
|
||||||
rules: {
|
"new-cap": newCap,
|
||||||
"new-cap": newCap,
|
"no-invalid-this": noInvalidThis,
|
||||||
"no-invalid-this": noInvalidThis,
|
"no-unused-expressions": noUnusedExpressions,
|
||||||
"no-unused-expressions": noUnusedExpressions,
|
"object-curly-spacing": objectCurlySpacing,
|
||||||
"object-curly-spacing": objectCurlySpacing,
|
semi,
|
||||||
semi,
|
|
||||||
},
|
|
||||||
rulesConfig: {
|
|
||||||
"new-cap": "off",
|
|
||||||
"no-invalid-this": "off",
|
|
||||||
"no-unused-expressions": "off",
|
|
||||||
"object-curly-spacing": "off",
|
|
||||||
semi: "off",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const rulesConfig = {
|
||||||
|
"new-cap": "off",
|
||||||
|
"no-invalid-this": "off",
|
||||||
|
"no-unused-expressions": "off",
|
||||||
|
"object-curly-spacing": "off",
|
||||||
|
semi: "off",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default { rules, rulesConfig };
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import eslint from "eslint";
|
import eslint from "eslint";
|
||||||
import unpad from "dedent";
|
import unpad from "dedent";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import * as parser from "../../../babel-eslint-parser";
|
import * as parser from "../../../babel-eslint-parser";
|
||||||
|
|
||||||
export default function verifyAndAssertMessages(
|
export default function verifyAndAssertMessages(
|
||||||
@ -24,7 +26,8 @@ export default function verifyAndAssertMessages(
|
|||||||
sourceType,
|
sourceType,
|
||||||
requireConfigFile: false,
|
requireConfigFile: false,
|
||||||
babelOptions: {
|
babelOptions: {
|
||||||
configFile: require.resolve(
|
configFile: path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"../../../babel-eslint-shared-fixtures/config/babel.config.js",
|
"../../../babel-eslint-shared-fixtures/config/babel.config.js",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
import eslint from "eslint";
|
import eslint from "eslint";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
describe("https://github.com/babel/babel-eslint/issues/558", () => {
|
describe("https://github.com/babel/babel-eslint/issues/558", () => {
|
||||||
it("doesn't crash with eslint-plugin-import", () => {
|
it("doesn't crash with eslint-plugin-import", () => {
|
||||||
const engine = new eslint.CLIEngine({ ignore: false });
|
const engine = new eslint.CLIEngine({ ignore: false });
|
||||||
engine.executeOnFiles(
|
engine.executeOnFiles(
|
||||||
["a.js", "b.js", "c.js"].map(file =>
|
["a.js", "b.js", "c.js"].map(file =>
|
||||||
path.resolve(__dirname, `../fixtures/eslint-plugin-import/${file}`),
|
path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
`../fixtures/eslint-plugin-import/${file}`,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import eslint from "eslint";
|
import eslint from "eslint";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import * as parser from "@babel/eslint-parser";
|
import * as parser from "@babel/eslint-parser";
|
||||||
|
|
||||||
describe("ESLint config", () => {
|
describe("ESLint config", () => {
|
||||||
@ -10,7 +12,8 @@ describe("ESLint config", () => {
|
|||||||
parser: "@babel/eslint-parser",
|
parser: "@babel/eslint-parser",
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
babelOptions: {
|
babelOptions: {
|
||||||
configFile: require.resolve(
|
configFile: path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"../../../../babel-eslint-shared-fixtures/config/babel.config.js",
|
"../../../../babel-eslint-shared-fixtures/config/babel.config.js",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,11 +2,17 @@ import eslint from "eslint";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import * as parser from "../../../../../babel-eslint-parser";
|
import * as parser from "../../../../../babel-eslint-parser";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
eslint.linter.defineParser("@babel/eslint-parser", parser);
|
eslint.linter.defineParser("@babel/eslint-parser", parser);
|
||||||
|
|
||||||
const paths = {
|
const paths = {
|
||||||
fixtures: path.join(__dirname, "../../..", "fixtures", "rules"),
|
fixtures: path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"../../..",
|
||||||
|
"fixtures",
|
||||||
|
"rules",
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
const encoding = "utf8";
|
const encoding = "utf8";
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import verifyAndAssertMessages from "../../helpers/verifyAndAssertMessages";
|
import verifyAndAssertMessages from "../../helpers/verifyAndAssertMessages";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
describe("verify", () => {
|
describe("verify", () => {
|
||||||
it("arrow function support (issue #1)", () => {
|
it("arrow function support (issue #1)", () => {
|
||||||
@ -1080,7 +1082,8 @@ describe("verify", () => {
|
|||||||
parserOptions: {
|
parserOptions: {
|
||||||
sourceType,
|
sourceType,
|
||||||
babelOptions: {
|
babelOptions: {
|
||||||
configFile: require.resolve(
|
configFile: path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"../../../../babel-eslint-shared-fixtures/config/babel.config.decorators-legacy.js",
|
"../../../../babel-eslint-shared-fixtures/config/babel.config.decorators-legacy.js",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
* Basic declarations for the npm modules we use.
|
* Basic declarations for the npm modules we use.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
declare module "module" {
|
||||||
|
declare export function createRequire(url: any): any;
|
||||||
|
}
|
||||||
|
|
||||||
declare module "debug" {
|
declare module "debug" {
|
||||||
declare export default (namespace: string) => (formatter: string, ...args: any[]) => void;
|
declare export default (namespace: string) => (formatter: string, ...args: any[]) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
"@babel/eslint-parser": "workspace:*",
|
"@babel/eslint-parser": "workspace:*",
|
||||||
"@babel/eslint-plugin-development": "workspace:*",
|
"@babel/eslint-plugin-development": "workspace:*",
|
||||||
"@babel/eslint-plugin-development-internal": "workspace:*",
|
"@babel/eslint-plugin-development-internal": "workspace:*",
|
||||||
|
"@babel/plugin-proposal-dynamic-import": "^7.13.8",
|
||||||
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
|
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.13.0",
|
"@babel/plugin-proposal-object-rest-spread": "^7.13.0",
|
||||||
"@babel/plugin-transform-modules-commonjs": "^7.13.0",
|
"@babel/plugin-transform-modules-commonjs": "^7.13.0",
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import readdirRecursive from "fs-readdir-recursive";
|
|||||||
import * as babel from "@babel/core";
|
import * as babel from "@babel/core";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
export function chmod(src: string, dest: string): void {
|
export function chmod(src: string, dest: string): void {
|
||||||
try {
|
try {
|
||||||
@ -119,6 +120,9 @@ process.on("uncaughtException", function (err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export function requireChokidar(): Object {
|
export function requireChokidar(): Object {
|
||||||
|
// $FlowIgnore - https://github.com/facebook/flow/issues/6913#issuecomment-662787504
|
||||||
|
const require = createRequire(import /*::("")*/.meta.url);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// todo(babel 8): revert `@nicolo-ribaudo/chokidar-2` hack
|
// todo(babel 8): revert `@nicolo-ribaudo/chokidar-2` hack
|
||||||
return parseInt(process.versions.node) >= 8
|
return parseInt(process.versions.node) >= 8
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
const readdir = require("fs-readdir-recursive");
|
import readdir from "fs-readdir-recursive";
|
||||||
const helper = require("@babel/helper-fixtures");
|
import * as helper from "@babel/helper-fixtures";
|
||||||
const rimraf = require("rimraf");
|
import rimraf from "rimraf";
|
||||||
const { sync: makeDirSync } = require("make-dir");
|
import { sync as makeDirSync } from "make-dir";
|
||||||
const child = require("child_process");
|
import child from "child_process";
|
||||||
const escapeRegExp = require("lodash/escapeRegExp");
|
import escapeRegExp from "lodash/escapeRegExp";
|
||||||
const merge = require("lodash/merge");
|
import merge from "lodash/merge";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const { chmod } = require("../lib/babel/util");
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
import { chmod } from "../lib/babel/util";
|
||||||
const tmpLoc = path.join(__dirname, "tmp");
|
|
||||||
const rootDir = path.resolve(__dirname, "../../..");
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const fixtureLoc = path.join(dirname, "fixtures");
|
||||||
|
const tmpLoc = path.join(dirname, "tmp");
|
||||||
|
const rootDir = path.resolve(dirname, "../../..");
|
||||||
|
|
||||||
const fileFilter = function (x) {
|
const fileFilter = function (x) {
|
||||||
return x !== ".DS_Store";
|
return x !== ".DS_Store";
|
||||||
@ -131,7 +137,7 @@ const assertTest = function (stdout, stderr, opts, cwd) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildTest = function (binName, testName, opts) {
|
const buildTest = function (binName, testName, opts) {
|
||||||
const binLoc = path.join(__dirname, "../lib", binName);
|
const binLoc = path.join(dirname, "../lib", binName);
|
||||||
|
|
||||||
return function (callback) {
|
return function (callback) {
|
||||||
saveInFiles(opts.inFiles);
|
saveInFiles(opts.inFiles);
|
||||||
|
|||||||
@ -18,6 +18,10 @@ import type { CallerMetadata } from "../validation/options";
|
|||||||
|
|
||||||
import * as fs from "../../gensync-utils/fs";
|
import * as fs from "../../gensync-utils/fs";
|
||||||
|
|
||||||
|
import { createRequire } from "module";
|
||||||
|
// $FlowIgnore - https://github.com/facebook/flow/issues/6913#issuecomment-662787504
|
||||||
|
const require = createRequire(import /*::("")*/.meta.url);
|
||||||
|
|
||||||
const debug = buildDebug("babel:config:loading:files:configuration");
|
const debug = buildDebug("babel:config:loading:files:configuration");
|
||||||
|
|
||||||
export const ROOT_CONFIG_FILENAMES = [
|
export const ROOT_CONFIG_FILENAMES = [
|
||||||
|
|||||||
@ -2,6 +2,9 @@ import { isAsync, waitFor } from "../../gensync-utils/async";
|
|||||||
import type { Handler } from "gensync";
|
import type { Handler } from "gensync";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { pathToFileURL } from "url";
|
import { pathToFileURL } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
let import_;
|
let import_;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -9,6 +9,10 @@ import path from "path";
|
|||||||
import { type Handler } from "gensync";
|
import { type Handler } from "gensync";
|
||||||
import loadCjsOrMjsDefault from "./module-types";
|
import loadCjsOrMjsDefault from "./module-types";
|
||||||
|
|
||||||
|
import { createRequire } from "module";
|
||||||
|
// $FlowIgnore - https://github.com/facebook/flow/issues/6913#issuecomment-662787504
|
||||||
|
const require = createRequire(import /*::("")*/.meta.url);
|
||||||
|
|
||||||
const debug = buildDebug("babel:config:loading:files:plugins");
|
const debug = buildDebug("babel:config:loading:files:plugins");
|
||||||
|
|
||||||
const EXACT_RE = /^module:/;
|
const EXACT_RE = /^module:/;
|
||||||
|
|||||||
@ -3,6 +3,13 @@ import sourceMap from "source-map";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import Plugin from "../lib/config/plugin";
|
import Plugin from "../lib/config/plugin";
|
||||||
import generator from "@babel/generator";
|
import generator from "@babel/generator";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
import presetEnv from "../../babel-preset-env";
|
||||||
|
import pluginSyntaxFlow from "../../babel-plugin-syntax-flow";
|
||||||
|
import pluginFlowStripTypes from "../../babel-plugin-transform-flow-strip-types";
|
||||||
|
|
||||||
|
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function assertIgnored(result) {
|
function assertIgnored(result) {
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
@ -13,54 +20,26 @@ function assertNotIgnored(result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parse(code, opts) {
|
function parse(code, opts) {
|
||||||
return babel.parse(code, {
|
return babel.parse(code, { cwd, configFile: false, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function transform(code, opts) {
|
function transform(code, opts) {
|
||||||
return babel.transform(code, {
|
return babel.transform(code, { cwd, configFile: false, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformFile(filename, opts, cb) {
|
function transformFile(filename, opts, cb) {
|
||||||
return babel.transformFile(
|
return babel.transformFile(filename, { cwd, configFile: false, ...opts }, cb);
|
||||||
filename,
|
|
||||||
{
|
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
},
|
|
||||||
cb,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function transformFileSync(filename, opts) {
|
function transformFileSync(filename, opts) {
|
||||||
return babel.transformFileSync(filename, {
|
return babel.transformFileSync(filename, { cwd, configFile: false, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformAsync(code, opts) {
|
function transformAsync(code, opts) {
|
||||||
return babel.transformAsync(code, {
|
return babel.transformAsync(code, { cwd, configFile: false, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformFromAst(ast, code, opts) {
|
function transformFromAst(ast, code, opts) {
|
||||||
return babel.transformFromAst(ast, code, {
|
return babel.transformFromAst(ast, code, { cwd, configFile: false, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
configFile: false,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("parser and generator options", function () {
|
describe("parser and generator options", function () {
|
||||||
@ -111,7 +90,7 @@ describe("parser and generator options", function () {
|
|||||||
function newTransformWithPlugins(string) {
|
function newTransformWithPlugins(string) {
|
||||||
return transform(string, {
|
return transform(string, {
|
||||||
ast: true,
|
ast: true,
|
||||||
plugins: [__dirname + "/../../babel-plugin-syntax-flow"],
|
plugins: [cwd + "/../../babel-plugin-syntax-flow"],
|
||||||
parserOpts: {
|
parserOpts: {
|
||||||
parser: recast.parse,
|
parser: recast.parse,
|
||||||
},
|
},
|
||||||
@ -173,17 +152,13 @@ describe("api", function () {
|
|||||||
babelrc: false,
|
babelrc: false,
|
||||||
};
|
};
|
||||||
Object.freeze(options);
|
Object.freeze(options);
|
||||||
transformFile(
|
transformFile(cwd + "/fixtures/api/file.js", options, function (err, res) {
|
||||||
__dirname + "/fixtures/api/file.js",
|
if (err) return done(err);
|
||||||
options,
|
expect(res.code).toBe("foo();");
|
||||||
function (err, res) {
|
// keep user options untouched
|
||||||
if (err) return done(err);
|
expect(options).toEqual({ babelrc: false });
|
||||||
expect(res.code).toBe("foo();");
|
done();
|
||||||
// keep user options untouched
|
});
|
||||||
expect(options).toEqual({ babelrc: false });
|
|
||||||
done();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("transformFileSync", function () {
|
it("transformFileSync", function () {
|
||||||
@ -191,9 +166,9 @@ describe("api", function () {
|
|||||||
babelrc: false,
|
babelrc: false,
|
||||||
};
|
};
|
||||||
Object.freeze(options);
|
Object.freeze(options);
|
||||||
expect(
|
expect(transformFileSync(cwd + "/fixtures/api/file.js", options).code).toBe(
|
||||||
transformFileSync(__dirname + "/fixtures/api/file.js", options).code,
|
"foo();",
|
||||||
).toBe("foo();");
|
);
|
||||||
expect(options).toEqual({ babelrc: false });
|
expect(options).toEqual({ babelrc: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -249,15 +224,15 @@ describe("api", function () {
|
|||||||
it("options throw on falsy true", function () {
|
it("options throw on falsy true", function () {
|
||||||
return expect(function () {
|
return expect(function () {
|
||||||
transform("", {
|
transform("", {
|
||||||
plugins: [__dirname + "/../../babel-plugin-syntax-jsx", false],
|
plugins: [cwd + "/../../babel-plugin-syntax-jsx", false],
|
||||||
});
|
});
|
||||||
}).toThrow(/.plugins\[1\] must be a string, object, function/);
|
}).toThrow(/.plugins\[1\] must be a string, object, function/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("options merge backwards", function () {
|
it("options merge backwards", function () {
|
||||||
return transformAsync("", {
|
return transformAsync("", {
|
||||||
presets: [__dirname + "/../../babel-preset-env"],
|
presets: [cwd + "/../../babel-preset-env"],
|
||||||
plugins: [__dirname + "/../../babel-plugin-syntax-jsx"],
|
plugins: [cwd + "/../../babel-plugin-syntax-jsx"],
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
expect(result.options.plugins[0].manipulateOptions.toString()).toEqual(
|
expect(result.options.plugins[0].manipulateOptions.toString()).toEqual(
|
||||||
expect.stringContaining("jsx"),
|
expect.stringContaining("jsx"),
|
||||||
@ -336,18 +311,12 @@ describe("api", function () {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// env preset
|
// env preset
|
||||||
require(__dirname + "/../../babel-preset-env"),
|
presetEnv,
|
||||||
|
|
||||||
// Third preset for Flow.
|
// Third preset for Flow.
|
||||||
function () {
|
() => ({
|
||||||
return {
|
plugins: [pluginSyntaxFlow, pluginFlowStripTypes],
|
||||||
plugins: [
|
}),
|
||||||
require(__dirname + "/../../babel-plugin-syntax-flow"),
|
|
||||||
require(__dirname +
|
|
||||||
"/../../babel-plugin-transform-flow-strip-types"),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -393,9 +362,9 @@ describe("api", function () {
|
|||||||
process.env.BABEL_ENV = "development";
|
process.env.BABEL_ENV = "development";
|
||||||
|
|
||||||
const result = transform("", {
|
const result = transform("", {
|
||||||
cwd: path.join(__dirname, "fixtures", "config", "complex-plugin-config"),
|
cwd: path.join(cwd, "fixtures", "config", "complex-plugin-config"),
|
||||||
filename: path.join(
|
filename: path.join(
|
||||||
__dirname,
|
cwd,
|
||||||
"fixtures",
|
"fixtures",
|
||||||
"config",
|
"config",
|
||||||
"complex-plugin-config",
|
"complex-plugin-config",
|
||||||
@ -792,7 +761,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("only syntax plugin available", function (done) {
|
it("only syntax plugin available", function (done) {
|
||||||
transformFile(
|
transformFile(
|
||||||
__dirname + "/fixtures/api/parsing-errors/only-syntax/file.js",
|
cwd + "/fixtures/api/parsing-errors/only-syntax/file.js",
|
||||||
options,
|
options,
|
||||||
function (err) {
|
function (err) {
|
||||||
expect(err.message).toMatch(
|
expect(err.message).toMatch(
|
||||||
@ -809,7 +778,7 @@ describe("api", function () {
|
|||||||
|
|
||||||
it("both syntax and transform plugin available", function (done) {
|
it("both syntax and transform plugin available", function (done) {
|
||||||
transformFile(
|
transformFile(
|
||||||
__dirname + "/fixtures/api/parsing-errors/syntax-and-transform/file.js",
|
cwd + "/fixtures/api/parsing-errors/syntax-and-transform/file.js",
|
||||||
options,
|
options,
|
||||||
function (err) {
|
function (err) {
|
||||||
expect(err.message).toMatch(
|
expect(err.message).toMatch(
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import { loadOptions as loadOptionsOrig, transformSync } from "../lib";
|
import { loadOptions as loadOptionsOrig, transformSync } from "../lib";
|
||||||
|
|
||||||
|
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function loadOptions(opts) {
|
function loadOptions(opts) {
|
||||||
return loadOptionsOrig({ cwd: __dirname, ...opts });
|
return loadOptionsOrig({ cwd, ...opts });
|
||||||
}
|
}
|
||||||
|
|
||||||
function withAssumptions(assumptions) {
|
function withAssumptions(assumptions) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { join } from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import * as babel from "..";
|
import * as babel from "..";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -14,7 +15,11 @@ const nodeGte8 = (...args) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("asynchronicity", () => {
|
describe("asynchronicity", () => {
|
||||||
const base = join(__dirname, "fixtures", "async");
|
const base = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"fixtures",
|
||||||
|
"async",
|
||||||
|
);
|
||||||
let cwd;
|
let cwd;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import escapeRegExp from "lodash/escapeRegExp";
|
import escapeRegExp from "lodash/escapeRegExp";
|
||||||
import * as babel from "../lib";
|
import * as babel from "../lib";
|
||||||
|
|
||||||
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
import { isMJS, loadOptionsAsync, skipUnsupportedESM } from "./helpers/esm";
|
import { isMJS, loadOptionsAsync, skipUnsupportedESM } from "./helpers/esm";
|
||||||
|
|
||||||
// TODO: In Babel 8, we can directly uses fs.promises which is supported by
|
// TODO: In Babel 8, we can directly uses fs.promises which is supported by
|
||||||
@ -42,11 +45,11 @@ const pfs =
|
|||||||
});
|
});
|
||||||
|
|
||||||
function fixture(...args) {
|
function fixture(...args) {
|
||||||
return path.join(__dirname, "fixtures", "config", ...args);
|
return path.join(dirname, "fixtures", "config", ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadOptions(opts) {
|
function loadOptions(opts) {
|
||||||
return babel.loadOptions({ cwd: __dirname, ...opts });
|
return babel.loadOptions({ cwd: dirname, ...opts });
|
||||||
}
|
}
|
||||||
|
|
||||||
function pairs(items) {
|
function pairs(items) {
|
||||||
@ -1320,7 +1323,7 @@ describe("buildConfigChain", function () {
|
|||||||
it("should throw when `preset` requires `filename` but it was not passed", () => {
|
it("should throw when `preset` requires `filename` but it was not passed", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
loadOptions({
|
loadOptions({
|
||||||
presets: [require("./fixtures/config-loading/preset4")],
|
presets: ["./fixtures/config-loading/preset4"],
|
||||||
});
|
});
|
||||||
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
|
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
|
||||||
});
|
});
|
||||||
@ -1328,7 +1331,7 @@ describe("buildConfigChain", function () {
|
|||||||
it("should throw when `preset.overrides` requires `filename` but it was not passed", () => {
|
it("should throw when `preset.overrides` requires `filename` but it was not passed", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
loadOptions({
|
loadOptions({
|
||||||
presets: [require("./fixtures/config-loading/preset5")],
|
presets: ["./fixtures/config-loading/preset5"],
|
||||||
});
|
});
|
||||||
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
|
}).toThrow(/Preset \/\* your preset \*\/ requires a filename/);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,12 +3,16 @@ import loadConfigRunner, {
|
|||||||
createConfigItem,
|
createConfigItem,
|
||||||
} from "../lib/config";
|
} from "../lib/config";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const loadConfig = loadConfigRunner.sync;
|
const loadConfig = loadConfigRunner.sync;
|
||||||
|
|
||||||
describe("@babel/core config loading", () => {
|
describe("@babel/core config loading", () => {
|
||||||
const FILEPATH = path.join(
|
const FILEPATH = path.join(
|
||||||
__dirname,
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
"fixtures",
|
"fixtures",
|
||||||
"config-loading",
|
"config-loading",
|
||||||
"folder",
|
"folder",
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
import cp from "child_process";
|
import cp from "child_process";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
import * as babel from "../../lib";
|
import * as babel from "../../lib";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
// "minNodeVersion": "10.0.0" <-- For Ctrl+F when dropping node 10
|
// "minNodeVersion": "10.0.0" <-- For Ctrl+F when dropping node 10
|
||||||
const nodeSupportsESM = parseInt(process.versions.node) >= 12;
|
const nodeSupportsESM = parseInt(process.versions.node) >= 12;
|
||||||
const isWindows = process.platform === "win32";
|
const isWindows = process.platform === "win32";
|
||||||
@ -30,7 +36,7 @@ export function skipUnsupportedESM(esm, name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadOptionsAsync({ filename, cwd = __dirname }, mjs) {
|
export function loadOptionsAsync({ filename, cwd = dirname }, mjs) {
|
||||||
if (mjs) {
|
if (mjs) {
|
||||||
// import() crashes with jest
|
// import() crashes with jest
|
||||||
return spawn("load-options-async", filename, cwd);
|
return spawn("load-options-async", filename, cwd);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { loadOptions as loadOptionsOrig } from "../lib";
|
import { loadOptions as loadOptionsOrig } from "../lib";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function loadOptions(opts) {
|
function loadOptions(opts) {
|
||||||
return loadOptionsOrig({
|
return loadOptionsOrig({ cwd, ...opts });
|
||||||
cwd: __dirname,
|
|
||||||
...opts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("option-manager", () => {
|
describe("option-manager", () => {
|
||||||
@ -220,9 +220,7 @@ describe("option-manager", () => {
|
|||||||
it("throws for resolved but erroring preset", () => {
|
it("throws for resolved but erroring preset", () => {
|
||||||
return expect(() => {
|
return expect(() => {
|
||||||
loadOptions({
|
loadOptions({
|
||||||
presets: [
|
presets: [path.join(cwd, "fixtures/option-manager/not-a-preset")],
|
||||||
path.join(__dirname, "fixtures/option-manager/not-a-preset"),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}).toThrow(
|
}).toThrow(
|
||||||
/While processing: .*option-manager(?:\/|\\\\)not-a-preset\.js/,
|
/While processing: .*option-manager(?:\/|\\\\)not-a-preset\.js/,
|
||||||
@ -234,9 +232,7 @@ describe("option-manager", () => {
|
|||||||
function presetTest(name) {
|
function presetTest(name) {
|
||||||
it(name, function () {
|
it(name, function () {
|
||||||
const options = loadOptions({
|
const options = loadOptions({
|
||||||
presets: [
|
presets: [path.join(cwd, "fixtures/option-manager/presets", name)],
|
||||||
path.join(__dirname, "fixtures/option-manager/presets", name),
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(Array.isArray(options.plugins)).toBe(true);
|
expect(Array.isArray(options.plugins)).toBe(true);
|
||||||
@ -249,9 +245,7 @@ describe("option-manager", () => {
|
|||||||
it(name, function () {
|
it(name, function () {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
loadOptions({
|
loadOptions({
|
||||||
presets: [
|
presets: [path.join(cwd, "fixtures/option-manager/presets", name)],
|
||||||
path.join(__dirname, "fixtures/option-manager/presets", name),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
).toThrow(msg);
|
).toThrow(msg);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,9 +1,18 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { parse } from "../lib";
|
import { parse } from "../lib";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
function fixture(...args) {
|
function fixture(...args) {
|
||||||
return path.join(__dirname, "fixtures", "parse", ...args);
|
return path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"fixtures",
|
||||||
|
"parse",
|
||||||
|
...args,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("parse", function () {
|
describe("parse", function () {
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
import { transform } from "../lib/index";
|
import { transform } from "../lib/index";
|
||||||
import Plugin from "../lib/config/plugin";
|
import Plugin from "../lib/config/plugin";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
describe("traversal path", function () {
|
describe("traversal path", function () {
|
||||||
it("replaceWithSourceString", function () {
|
it("replaceWithSourceString", function () {
|
||||||
const expectCode = "function foo() {}";
|
const expectCode = "function foo() {}";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -25,7 +29,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "var fn = () => true;";
|
const expectCode = "var fn = () => true;";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -55,7 +59,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "var fn = () => { return true; }";
|
const expectCode = "var fn = () => { return true; }";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -77,7 +81,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "for (KEY in right);";
|
const expectCode = "for (KEY in right);";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -108,7 +112,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "for (var KEY in right);";
|
const expectCode = "for (var KEY in right);";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -130,7 +134,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "for (KEY;;);";
|
const expectCode = "for (KEY;;);";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
@ -161,7 +165,7 @@ describe("traversal path", function () {
|
|||||||
const expectCode = "for (var KEY;;);";
|
const expectCode = "for (var KEY;;);";
|
||||||
|
|
||||||
const actualCode = transform(expectCode, {
|
const actualCode = transform(expectCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
plugins: [
|
plugins: [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
visitor: {
|
visitor: {
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
import runner from "@babel/helper-transform-fixture-test-runner";
|
import runner from "@babel/helper-transform-fixture-test-runner";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
runner(`${__dirname}/fixtures/plugins`, "plugins");
|
runner(
|
||||||
|
path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures/plugins"),
|
||||||
|
"plugins",
|
||||||
|
);
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
import * as babel from "../lib/index";
|
import * as babel from "../lib/index";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
describe("addon resolution", function () {
|
describe("addon resolution", function () {
|
||||||
const base = path.join(__dirname, "fixtures", "resolution");
|
const base = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"fixtures",
|
||||||
|
"resolution",
|
||||||
|
);
|
||||||
let cwd;
|
let cwd;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import { loadOptions as loadOptionsOrig } from "../lib";
|
import { loadOptions as loadOptionsOrig } from "../lib";
|
||||||
import { join } from "path";
|
import { join, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const cwd = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function loadOptions(opts) {
|
function loadOptions(opts) {
|
||||||
return loadOptionsOrig({ cwd: __dirname, ...opts });
|
return loadOptionsOrig({ cwd, ...opts });
|
||||||
}
|
}
|
||||||
|
|
||||||
function withTargets(targets) {
|
function withTargets(targets) {
|
||||||
@ -83,7 +86,7 @@ describe("browserslist", () => {
|
|||||||
it("loads .browserslistrc by default", () => {
|
it("loads .browserslistrc by default", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
}).targets,
|
}).targets,
|
||||||
).toEqual({ chrome: "80.0.0" });
|
).toEqual({ chrome: "80.0.0" });
|
||||||
});
|
});
|
||||||
@ -91,7 +94,7 @@ describe("browserslist", () => {
|
|||||||
it("loads .browserslistrc relative to the input file", () => {
|
it("loads .browserslistrc relative to the input file", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
filename: "./nested/test.js",
|
filename: "./nested/test.js",
|
||||||
}).targets,
|
}).targets,
|
||||||
).toEqual({ edge: "14.0.0" });
|
).toEqual({ edge: "14.0.0" });
|
||||||
@ -101,7 +104,7 @@ describe("browserslist", () => {
|
|||||||
it("can disable config loading", () => {
|
it("can disable config loading", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
browserslistConfigFile: false,
|
browserslistConfigFile: false,
|
||||||
}).targets,
|
}).targets,
|
||||||
).toEqual({});
|
).toEqual({});
|
||||||
@ -110,7 +113,7 @@ describe("browserslist", () => {
|
|||||||
it("can specify a custom file", () => {
|
it("can specify a custom file", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
browserslistConfigFile: "./.browserslistrc-firefox",
|
browserslistConfigFile: "./.browserslistrc-firefox",
|
||||||
}).targets,
|
}).targets,
|
||||||
).toEqual({ firefox: "74.0.0" });
|
).toEqual({ firefox: "74.0.0" });
|
||||||
@ -119,7 +122,7 @@ describe("browserslist", () => {
|
|||||||
it("is relative to the project root", () => {
|
it("is relative to the project root", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
root: "..",
|
root: "..",
|
||||||
filename: "./nested/test.js",
|
filename: "./nested/test.js",
|
||||||
browserslistConfigFile: "./targets/.browserslistrc-firefox",
|
browserslistConfigFile: "./targets/.browserslistrc-firefox",
|
||||||
@ -132,7 +135,7 @@ describe("browserslist", () => {
|
|||||||
it("is forwarded to browserslist", () => {
|
it("is forwarded to browserslist", () => {
|
||||||
expect(
|
expect(
|
||||||
loadOptions({
|
loadOptions({
|
||||||
cwd: join(__dirname, "fixtures", "targets"),
|
cwd: join(cwd, "fixtures", "targets"),
|
||||||
browserslistEnv: "browserslist-loading-test",
|
browserslistEnv: "browserslist-loading-test",
|
||||||
}).targets,
|
}).targets,
|
||||||
).toEqual({ chrome: "70.0.0" });
|
).toEqual({ chrome: "70.0.0" });
|
||||||
|
|||||||
@ -1,3 +1,11 @@
|
|||||||
import runner from "@babel/helper-transform-fixture-test-runner";
|
import runner from "@babel/helper-transform-fixture-test-runner";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
runner(`${__dirname}/fixtures/transformation`, "transformation");
|
runner(
|
||||||
|
path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"/fixtures/transformation",
|
||||||
|
),
|
||||||
|
"transformation",
|
||||||
|
);
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fixtures from "@babel/helper-fixtures";
|
import fixtures from "@babel/helper-fixtures";
|
||||||
import sourcemap from "source-map";
|
import sourcemap from "source-map";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
describe("generation", function () {
|
describe("generation", function () {
|
||||||
it("completeness", function () {
|
it("completeness", function () {
|
||||||
@ -758,7 +759,9 @@ describe("CodeGenerator", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const suites = fixtures(`${__dirname}/fixtures`);
|
const suites = fixtures(
|
||||||
|
path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures"),
|
||||||
|
);
|
||||||
|
|
||||||
suites.forEach(function (testSuite) {
|
suites.forEach(function (testSuite) {
|
||||||
describe("generation/" + testSuite.title, function () {
|
describe("generation/" + testSuite.title, function () {
|
||||||
@ -783,7 +786,10 @@ suites.forEach(function (testSuite) {
|
|||||||
...task.options.parserOpts,
|
...task.options.parserOpts,
|
||||||
});
|
});
|
||||||
const options = {
|
const options = {
|
||||||
sourceFileName: path.relative(__dirname, actual.loc),
|
sourceFileName: path.relative(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
actual.loc,
|
||||||
|
),
|
||||||
...task.options,
|
...task.options,
|
||||||
sourceMaps: task.sourceMap ? true : task.options.sourceMaps,
|
sourceMaps: task.sourceMap ? true : task.options.sourceMaps,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
import getTargets from "../..";
|
import getTargets from "../..";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
it("allows custom browserslist env", () => {
|
it("allows custom browserslist env", () => {
|
||||||
const actual = getTargets(
|
const actual = getTargets(
|
||||||
{},
|
{},
|
||||||
{ configPath: __dirname, browserslistEnv: "custom" },
|
{
|
||||||
|
configPath: path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
browserslistEnv: "custom",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(actual).toEqual({ ie: "11.0.0" });
|
expect(actual).toEqual({ ie: "11.0.0" });
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import browserslist from "browserslist";
|
import browserslist from "browserslist";
|
||||||
import { join } from "path";
|
import { join, dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
import getTargets from "..";
|
import getTargets from "..";
|
||||||
|
|
||||||
describe("getTargets", () => {
|
describe("getTargets", () => {
|
||||||
@ -250,7 +251,13 @@ describe("getTargets", () => {
|
|||||||
{
|
{
|
||||||
esmodules: "intersect",
|
esmodules: "intersect",
|
||||||
},
|
},
|
||||||
{ configPath: join(__dirname, "fixtures", "foo.js") },
|
{
|
||||||
|
configPath: join(
|
||||||
|
dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"fixtures",
|
||||||
|
"foo.js",
|
||||||
|
),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
"use strict";
|
import { targetsSupported } from "../lib/filter-items";
|
||||||
|
|
||||||
const { targetsSupported } = require("../lib/filter-items");
|
|
||||||
|
|
||||||
describe("targetsSupported", () => {
|
describe("targetsSupported", () => {
|
||||||
const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`;
|
const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`;
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -2,6 +2,10 @@ import cloneDeep from "lodash/cloneDeep";
|
|||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const nodeVersion = semver.clean(process.version.slice(1));
|
const nodeVersion = semver.clean(process.version.slice(1));
|
||||||
|
|
||||||
@ -279,7 +283,11 @@ function wrapPackagesArray(type, names, optionsDir) {
|
|||||||
|
|
||||||
val[0] = path.resolve(optionsDir, val[0]);
|
val[0] = path.resolve(optionsDir, val[0]);
|
||||||
} else {
|
} else {
|
||||||
const monorepoPath = __dirname + "/../../babel-" + type + "-" + val[0];
|
const monorepoPath = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"../..",
|
||||||
|
`babel-${type}-${val[0]}`,
|
||||||
|
);
|
||||||
|
|
||||||
if (fs.existsSync(monorepoPath)) {
|
if (fs.existsSync(monorepoPath)) {
|
||||||
val[0] = monorepoPath;
|
val[0] = monorepoPath;
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
import * as babel from "@babel/core";
|
import * as babel from "@babel/core";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
import { ImportInjector } from "../";
|
import { ImportInjector } from "../";
|
||||||
|
|
||||||
|
const cwd = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
function test(sourceType, opts, initializer, inputCode, expectedCode) {
|
function test(sourceType, opts, initializer, inputCode, expectedCode) {
|
||||||
if (typeof opts === "function") {
|
if (typeof opts === "function") {
|
||||||
expectedCode = inputCode;
|
expectedCode = inputCode;
|
||||||
@ -15,7 +19,7 @@ function test(sourceType, opts, initializer, inputCode, expectedCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = babel.transform(inputCode, {
|
const result = babel.transform(inputCode, {
|
||||||
cwd: __dirname,
|
cwd,
|
||||||
sourceType,
|
sourceType,
|
||||||
filename: "example" + (sourceType === "module" ? ".mjs" : ".js"),
|
filename: "example" + (sourceType === "module" ? ".mjs" : ".js"),
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
|
|||||||
@ -1,7 +1,24 @@
|
|||||||
import testRunner from "@babel/helper-transform-fixture-test-runner";
|
import testRunner from "@babel/helper-transform-fixture-test-runner";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { URL } from "url";
|
||||||
|
|
||||||
export default function (loc) {
|
export default function (loc) {
|
||||||
const name = path.basename(path.dirname(loc));
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
testRunner(loc + "/fixtures", name);
|
if (!loc.startsWith("file://")) {
|
||||||
|
const name = path.basename(path.dirname(loc));
|
||||||
|
testRunner(loc + "/fixtures", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let fixtures = new URL("./fixtures", loc).pathname;
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
// Remove the leading / before the drive letter
|
||||||
|
// TODO: After dropping Node.js 10 support, use fileURLToPath
|
||||||
|
fixtures = fixtures.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = path.basename(new URL("..", loc).pathname);
|
||||||
|
|
||||||
|
testRunner(fixtures, name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,10 @@ import path from "path";
|
|||||||
import vm from "vm";
|
import vm from "vm";
|
||||||
import QuickLRU from "quick-lru";
|
import QuickLRU from "quick-lru";
|
||||||
import escapeRegExp from "./escape-regexp.cjs";
|
import escapeRegExp from "./escape-regexp.cjs";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
import { createRequire } from "module";
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
import _checkDuplicatedNodes from "babel-check-duplicated-nodes";
|
import _checkDuplicatedNodes from "babel-check-duplicated-nodes";
|
||||||
const checkDuplicatedNodes = _checkDuplicatedNodes.default;
|
const checkDuplicatedNodes = _checkDuplicatedNodes.default;
|
||||||
@ -43,14 +47,17 @@ function createContext() {
|
|||||||
// global creation in tests, which could cause things to bleed between tests.
|
// global creation in tests, which could cause things to bleed between tests.
|
||||||
runModuleInTestContext(
|
runModuleInTestContext(
|
||||||
"regenerator-runtime",
|
"regenerator-runtime",
|
||||||
__filename,
|
fileURLToPath(import.meta.url),
|
||||||
context,
|
context,
|
||||||
moduleCache,
|
moduleCache,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Populate the "babelHelpers" global with Babel's helper utilities.
|
// Populate the "babelHelpers" global with Babel's helper utilities.
|
||||||
runCacheableScriptInTestContext(
|
runCacheableScriptInTestContext(
|
||||||
path.join(__dirname, "babel-helpers-in-memory.js"),
|
path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"babel-helpers-in-memory.js",
|
||||||
|
),
|
||||||
buildExternalHelpers,
|
buildExternalHelpers,
|
||||||
context,
|
context,
|
||||||
moduleCache,
|
moduleCache,
|
||||||
@ -330,7 +337,10 @@ function validateFile(actualCode, expectedLoc, expectedCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeOutput(code, normalizePathSeparator) {
|
function normalizeOutput(code, normalizePathSeparator) {
|
||||||
const projectRoot = path.resolve(__dirname, "../../../");
|
const projectRoot = path.resolve(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"../../../",
|
||||||
|
);
|
||||||
const cwdSymbol = "<CWD>";
|
const cwdSymbol = "<CWD>";
|
||||||
let result = code
|
let result = code
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
import { runCodeInTestContext } from "..";
|
import { runCodeInTestContext } from "..";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const filename = fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
describe("helper-transform-fixture-test-runner", function () {
|
describe("helper-transform-fixture-test-runner", function () {
|
||||||
it("should not execute code in Node's global context", function () {
|
it("should not execute code in Node's global context", function () {
|
||||||
@ -10,7 +13,7 @@ describe("helper-transform-fixture-test-runner", function () {
|
|||||||
global.foo = "inner";
|
global.foo = "inner";
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
filename: `${__filename}.fake1`,
|
filename: `${filename}.fake1`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -20,7 +23,7 @@ describe("helper-transform-fixture-test-runner", function () {
|
|||||||
expect(global.foo).toBe("inner");
|
expect(global.foo).toBe("inner");
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
filename: `${__filename}.fake2`,
|
filename: `${filename}.fake2`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
@ -30,14 +33,14 @@ describe("helper-transform-fixture-test-runner", function () {
|
|||||||
delete global.foo;
|
delete global.foo;
|
||||||
`,
|
`,
|
||||||
{
|
{
|
||||||
filename: `${__filename}.fake3`,
|
filename: `${filename}.fake3`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it("should print correct trace position when error is thrown in the first line", () => {
|
it("should print correct trace position when error is thrown in the first line", () => {
|
||||||
const opts = {
|
const opts = {
|
||||||
filename: `${__filename}.fake4`,
|
filename: `${filename}.fake4`,
|
||||||
};
|
};
|
||||||
runCodeInTestContext(
|
runCodeInTestContext(
|
||||||
`try { throw new Error() } catch (e) {
|
`try { throw new Error() } catch (e) {
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import vm from "vm";
|
|||||||
import "core-js/stable";
|
import "core-js/stable";
|
||||||
import "regenerator-runtime/runtime";
|
import "regenerator-runtime/runtime";
|
||||||
import register from "@babel/register";
|
import register from "@babel/register";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
import { createRequire } from "module";
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const program = new commander.Command("babel-node");
|
const program = new commander.Command("babel-node");
|
||||||
|
|
||||||
@ -194,7 +198,7 @@ if (program.eval || program.print) {
|
|||||||
|
|
||||||
// add back on node and concat the sliced args
|
// add back on node and concat the sliced args
|
||||||
process.argv = ["node"].concat(args);
|
process.argv = ["node"].concat(args);
|
||||||
process.execArgv.push(__filename);
|
process.execArgv.push(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
Module.runMain();
|
Module.runMain();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -5,8 +5,12 @@
|
|||||||
|
|
||||||
import getV8Flags from "v8flags";
|
import getV8Flags from "v8flags";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import child_process from "child_process";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
let args = [path.join(__dirname, "_babel-node")];
|
let args = [
|
||||||
|
path.join(path.dirname(fileURLToPath(import.meta.url)), "_babel-node"),
|
||||||
|
];
|
||||||
|
|
||||||
let babelArgs = process.argv.slice(2);
|
let babelArgs = process.argv.slice(2);
|
||||||
let userArgs;
|
let userArgs;
|
||||||
@ -41,7 +45,7 @@ const aliases = new Map([
|
|||||||
["-gc", "--expose-gc"],
|
["-gc", "--expose-gc"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
getV8Flags(function (err, v8Flags) {
|
getV8Flags(async function (err, v8Flags) {
|
||||||
for (let i = 0; i < babelArgs.length; i++) {
|
for (let i = 0; i < babelArgs.length; i++) {
|
||||||
const arg = babelArgs[i];
|
const arg = babelArgs[i];
|
||||||
const flag = arg.split("=")[0];
|
const flag = arg.split("=")[0];
|
||||||
@ -69,17 +73,17 @@ getV8Flags(function (err, v8Flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const kexec = require("kexec");
|
const { default: kexec } = await import("kexec");
|
||||||
kexec(process.argv[0], args);
|
kexec(process.argv[0], args);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (
|
||||||
|
err.code !== "ERR_MODULE_NOT_FOUND" &&
|
||||||
err.code !== "MODULE_NOT_FOUND" &&
|
err.code !== "MODULE_NOT_FOUND" &&
|
||||||
err.code !== "UNDECLARED_DEPENDENCY"
|
err.code !== "UNDECLARED_DEPENDENCY"
|
||||||
) {
|
) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
const child_process = require("child_process");
|
|
||||||
const proc = child_process.spawn(process.argv[0], args, {
|
const proc = child_process.spawn(process.argv[0], args, {
|
||||||
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,15 +1,20 @@
|
|||||||
const includes = require("lodash/includes");
|
import includes from "lodash/includes";
|
||||||
const readdir = require("fs-readdir-recursive");
|
import readdir from "fs-readdir-recursive";
|
||||||
const helper = require("@babel/helper-fixtures");
|
import * as helper from "@babel/helper-fixtures";
|
||||||
const rimraf = require("rimraf");
|
import rimraf from "rimraf";
|
||||||
const { sync: makeDirSync } = require("make-dir");
|
import { sync as makeDirSync } from "make-dir";
|
||||||
const child = require("child_process");
|
import child from "child_process";
|
||||||
const merge = require("lodash/merge");
|
import merge from "lodash/merge";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
|
||||||
const fixtureLoc = path.join(__dirname, "fixtures");
|
const require = createRequire(import.meta.url);
|
||||||
const tmpLoc = path.join(__dirname, "tmp");
|
|
||||||
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
const fixtureLoc = path.join(dirname, "fixtures");
|
||||||
|
const tmpLoc = path.join(dirname, "tmp");
|
||||||
|
|
||||||
const fileFilter = function (x) {
|
const fileFilter = function (x) {
|
||||||
return x !== ".DS_Store";
|
return x !== ".DS_Store";
|
||||||
@ -91,7 +96,7 @@ const assertTest = function (stdout, stderr, opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buildTest = function (binName, testName, opts) {
|
const buildTest = function (binName, testName, opts) {
|
||||||
const binLoc = path.join(__dirname, "../lib", binName);
|
const binLoc = path.join(dirname, "../lib", binName);
|
||||||
|
|
||||||
return function (callback) {
|
return function (callback) {
|
||||||
saveInFiles(opts.inFiles);
|
saveInFiles(opts.inFiles);
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { runThrowTestsWithEstree } from "./helpers/runFixtureTests";
|
import { runThrowTestsWithEstree } from "./helpers/runFixtureTests";
|
||||||
import { parse } from "../lib";
|
import { parse } from "../lib";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
runThrowTestsWithEstree(path.join(__dirname, "fixtures"), parse);
|
runThrowTestsWithEstree(
|
||||||
|
path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures"),
|
||||||
|
parse,
|
||||||
|
);
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { runFixtureTests } from "./helpers/runFixtureTests";
|
import { runFixtureTests } from "./helpers/runFixtureTests";
|
||||||
import { parseExpression } from "../lib";
|
import { parseExpression } from "../lib";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
runFixtureTests(path.join(__dirname, "expressions"), parseExpression);
|
const fixtures = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"expressions",
|
||||||
|
);
|
||||||
|
|
||||||
|
runFixtureTests(fixtures, parseExpression);
|
||||||
|
|||||||
@ -2,8 +2,12 @@ import { multiple as getFixtures } from "@babel/helper-fixtures";
|
|||||||
import { codeFrameColumns } from "@babel/code-frame";
|
import { codeFrameColumns } from "@babel/code-frame";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const rootPath = path.join(__dirname, "../../../..");
|
const rootPath = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"../../../..",
|
||||||
|
);
|
||||||
|
|
||||||
const serialized = "$$ babel internal serialized type";
|
const serialized = "$$ babel internal serialized type";
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { runFixtureTests } from "./helpers/runFixtureTests";
|
import { runFixtureTests } from "./helpers/runFixtureTests";
|
||||||
import { parse } from "../lib";
|
import { parse } from "../lib";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
runFixtureTests(path.join(__dirname, "fixtures"), parse);
|
const fixtures = path.join(
|
||||||
|
path.dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"fixtures",
|
||||||
|
);
|
||||||
|
runFixtureTests(fixtures, parse);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
runner(__dirname);
|
|
||||||
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
runner(__dirname);
|
|
||||||
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
const babel = require("@babel/core");
|
import * as babel from "@babel/core";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
import transformCommonJS from "..";
|
||||||
|
|
||||||
test("Doesn't use the same object for two different nodes in the AST", function () {
|
test("Doesn't use the same object for two different nodes in the AST", function () {
|
||||||
const code = 'import Foo from "bar"; Foo; Foo;';
|
const code = 'import Foo from "bar"; Foo; Foo;';
|
||||||
|
|
||||||
const ast = babel.transform(code, {
|
const ast = babel.transform(code, {
|
||||||
cwd: __dirname,
|
cwd: path.dirname(fileURLToPath(import.meta.url)),
|
||||||
ast: true,
|
ast: true,
|
||||||
plugins: [[require("../"), { loose: true }]],
|
plugins: [[transformCommonJS, { loose: true }]],
|
||||||
}).ast;
|
}).ast;
|
||||||
|
|
||||||
expect(ast.program.body[0].declarations[0].id.type).toBe("Identifier");
|
expect(ast.program.body[0].declarations[0].id.type).toBe("Identifier");
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
const babel = require("@babel/core");
|
import * as babel from "@babel/core";
|
||||||
const vm = require("vm");
|
import vm from "vm";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
import transformCommonJS from "..";
|
||||||
|
|
||||||
test("Re-export doesn't overwrite __esModule flag", function () {
|
test("Re-export doesn't overwrite __esModule flag", function () {
|
||||||
let code = 'export * from "./dep";';
|
let code = 'export * from "./dep";';
|
||||||
@ -13,14 +17,14 @@ test("Re-export doesn't overwrite __esModule flag", function () {
|
|||||||
},
|
},
|
||||||
require: function (id) {
|
require: function (id) {
|
||||||
if (id === "./dep") return depStub;
|
if (id === "./dep") return depStub;
|
||||||
return require(id);
|
throw new Error("Unexpected dependency: " + id);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
context.exports = context.module.exports;
|
context.exports = context.module.exports;
|
||||||
|
|
||||||
code = babel.transform(code, {
|
code = babel.transform(code, {
|
||||||
cwd: __dirname,
|
cwd: path.dirname(fileURLToPath(import.meta.url)),
|
||||||
plugins: [[require("../"), { loose: true }]],
|
plugins: [[transformCommonJS, { loose: true }]],
|
||||||
ast: false,
|
ast: false,
|
||||||
}).code;
|
}).code;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
import runner from "@babel/helper-plugin-test-runner";
|
import runner from "@babel/helper-plugin-test-runner";
|
||||||
|
|
||||||
runner(__dirname);
|
runner(import.meta.url);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user