Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 14, 2021
1 parent 1a94408 commit d2a8a1e
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 43 deletions.
12 changes: 8 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ module.exports = {
},
{
files: [
"packages/*/src/**/*.{js,ts,cjs}",
"codemods/*/src/**/*.{js,ts,cjs}",
"eslint/*/src/**/*.{js,ts,cjs}",
"packages/*/src/**/*.{js,ts,cjs,mjs}",
"codemods/*/src/**/*.{js,ts,cjs,mjs}",
"eslint/*/src/**/*.{js,ts,cjs,mjs}",
],
rules: {
"@babel/development/no-undefined-identifier": "error",
"@babel/development/no-deprecated-clone": "error",
"guard-for-in": "error",
"import/extensions": ["error", { json: "always", cjs: "always" }],
"import/extensions": [
"error",
{ json: "always", cjs: "always", mjs: "always" },
],
},
globals: { PACKAGE_JSON: "readonly" },
},
Expand All @@ -71,6 +74,7 @@ module.exports = {
"error",
{ json: "always", js: "always", cjs: "always", mjs: "always" },
],
"import/no-extraneous-dependencies": "off",
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"args": ["./src/index.js"],
"env": {
"BABEL_ENV": "test",
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
},
"os": ["darwin", "linux"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"args": ["./src/index.js"],
"env": {
"BABEL_ENV": "test",
"BABEL_SHOW_CONFIG_FOR": "./src/index.js"
},
"os": ["darwin", "linux"]
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-cli/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const buildTest = function (binName, testName, opts) {
};

fs.readdirSync(fixtureLoc).forEach(function (binName) {
if (binName.startsWith(".")) return;
if (binName.startsWith(".") || binName === "package.json") return;

const suiteLoc = path.join(fixtureLoc, binName);
describe("bin/" + binName, function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-core/test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ describe("parser and generator options", function () {
describe("api", function () {
it("exposes the resolvePlugin method", function () {
expect(() => babel.resolvePlugin("nonexistent-plugin")).toThrow(
/Cannot resolve module 'babel-plugin-nonexistent-plugin'/,
/Cannot (?:find|resolve) module 'babel-plugin-nonexistent-plugin'/,
);
});

it("exposes the resolvePreset method", function () {
expect(() => babel.resolvePreset("nonexistent-preset")).toThrow(
/Cannot resolve module 'babel-preset-nonexistent-preset'/,
/Cannot (?:find|resolve) module 'babel-preset-nonexistent-preset'/,
);
});

Expand Down
28 changes: 14 additions & 14 deletions packages/babel-core/test/resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ describe("addon resolution", function () {
// `require.resolve` is provided.
// see https://github.com/babel/babel/pull/12439/files#r535996000
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-preset-foo'/
: /Cannot resolve module 'babel-preset-foo'.*\n- If you want to resolve "foo", use "module:foo"/,
? /Cannot (?:find|resolve) module 'babel-preset-foo'/
: /Cannot (?:find|resolve) module 'babel-preset-foo'.*\n- If you want to resolve "foo", use "module:foo"/s,
);
});

Expand All @@ -371,8 +371,8 @@ describe("addon resolution", function () {
});
}).toThrow(
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-plugin-foo'/
: /Cannot resolve module 'babel-plugin-foo'.*\n- If you want to resolve "foo", use "module:foo"/,
? /Cannot (?:find|resolve) module 'babel-plugin-foo'/
: /Cannot (?:find|resolve) module 'babel-plugin-foo'.*\n- If you want to resolve "foo", use "module:foo"/s,
);
});

Expand All @@ -387,8 +387,8 @@ describe("addon resolution", function () {
});
}).toThrow(
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-preset-foo'/
: /Cannot resolve module 'babel-preset-foo'.*\n- Did you mean "@babel\/foo"\?/,
? /Cannot (?:find|resolve) module 'babel-preset-foo'/
: /Cannot (?:find|resolve) module 'babel-preset-foo'.*\n- Did you mean "@babel\/foo"\?/s,
);
});

Expand All @@ -403,8 +403,8 @@ describe("addon resolution", function () {
});
}).toThrow(
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-plugin-foo'/
: /Cannot resolve module 'babel-plugin-foo'.*\n- Did you mean "@babel\/foo"\?/,
? /Cannot (?:find|resolve) module 'babel-plugin-foo'/
: /Cannot (?:find|resolve) module 'babel-plugin-foo'.*\n- Did you mean "@babel\/foo"\?/s,
);
});

Expand All @@ -419,8 +419,8 @@ describe("addon resolution", function () {
});
}).toThrow(
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-preset-testplugin'/
: /Cannot resolve module 'babel-preset-testplugin'.*\n- Did you accidentally pass a plugin as a preset\?/,
? /Cannot (?:find|resolve) module 'babel-preset-testplugin'/
: /Cannot (?:find|resolve) module 'babel-preset-testplugin'.*\n- Did you accidentally pass a plugin as a preset\?/s,
);
});

Expand All @@ -435,8 +435,8 @@ describe("addon resolution", function () {
});
}).toThrow(
process.versions.node.startsWith("8.")
? /Cannot resolve module 'babel-plugin-testpreset'/
: /Cannot resolve module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a preset as a plugin\?/,
? /Cannot (?:find|resolve) module 'babel-plugin-testpreset'/
: /Cannot (?:find|resolve) module 'babel-plugin-testpreset'.*\n- Did you accidentally pass a preset as a plugin\?/s,
);
});

Expand All @@ -449,7 +449,7 @@ describe("addon resolution", function () {
babelrc: false,
presets: ["foo"],
});
}).toThrow(/Cannot resolve module 'babel-preset-foo'/);
}).toThrow(/Cannot (?:find|resolve) module 'babel-preset-foo'/);
});

it("should throw about missing plugins", function () {
Expand All @@ -461,6 +461,6 @@ describe("addon resolution", function () {
babelrc: false,
plugins: ["foo"],
});
}).toThrow(/Cannot resolve module 'babel-plugin-foo'/);
}).toThrow(/Cannot (?:find|resolve) module 'babel-plugin-foo'/);
});
});
6 changes: 5 additions & 1 deletion packages/babel-helper-fixtures/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ function shouldIgnore(name, ignore?: Array<string>) {
const base = path.basename(name, ext);

return (
name[0] === "." || ext === ".md" || base === "LICENSE" || base === "options"
name[0] === "." ||
ext === ".md" ||
base === "LICENSE" ||
base === "options" ||
name === "package.json"
);
}

Expand Down
12 changes: 7 additions & 5 deletions packages/babel-node/test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ const assertTest = function (stdout, stderr, ipcMessage, opts) {
const buildTest = function (testName, opts) {
return function (callback) {
saveInFiles(opts.inFiles);
let args = [binLoc];
args.push("--config-file", "../config.json");
args = args.concat(opts.args);
const args = [binLoc].concat(opts.args);

const spawnOpts = {};
if (opts.ipc) {
Expand Down Expand Up @@ -141,9 +139,10 @@ const buildTest = function (testName, opts) {
if (err) {
err.message =
args.map(arg => `"${arg}"`).join(" ") + ": " + err.message;
callback(err);
} else {
callback();
}

callback(err);
});

if (opts.stdin) {
Expand Down Expand Up @@ -203,6 +202,9 @@ describe("bin/babel-node", function () {
// copy .babelrc file to tmp directory
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}
if (!opts.inFiles["package.json"]) {
opts.inFiles["package.json"] = `{ "type": "commonjs" }`;
}

// eslint-disable-next-line jest/valid-title
it(testName, buildTest(testName, opts), 20000);
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-node/test/fixtures/cli/require/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
["@babel/preset-react", { "runtime": "classic" }]
]
}
1 change: 0 additions & 1 deletion packages/babel-node/test/fixtures/package.json

This file was deleted.

5 changes: 2 additions & 3 deletions packages/babel-parser/test/estree-throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { fileURLToPath } from "url";
runFixtureTestsWithoutExactASTMatch(
path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures"),
(input, options = {}) => {
options.plugins = options.plugins || [];
options.plugins.push("estree");
return parse(input, options);
const plugins = options.plugins || [];
return parse(input, { ...options, plugins: plugins.concat("estree") });
},
);
12 changes: 6 additions & 6 deletions packages/babel-preset-env/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const pluginLegacyBabelPolyfill = _pluginLegacyBabelPolyfill.default;
const transformations = _transformations.default;
const availablePlugins = _availablePlugins.default;

import _pluginCoreJS2 from "babel-plugin-polyfill-corejs2";
import _pluginCoreJS3 from "babel-plugin-polyfill-corejs3";
import _pluginRegenerator from "babel-plugin-polyfill-regenerator";
const pluginCoreJS2 = _pluginCoreJS2.default;
const pluginCoreJS3 = _pluginCoreJS3.default;
const pluginRegenerator = _pluginRegenerator.default;
import { createRequire } from "module";
const require = createRequire(import.meta.url);

const pluginCoreJS2 = require("babel-plugin-polyfill-corejs2").default;
const pluginCoreJS3 = require("babel-plugin-polyfill-corejs3").default;
const pluginRegenerator = require("babel-plugin-polyfill-regenerator").default;

describe("babel-preset-env", () => {
describe("transformIncludesAndExcludes", () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-register/test/cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";

const require = createRequire(import.meta.url);

const testCacheFilename = path.join(
path.dirname(fileURLToPath(import.meta.url)),
Expand Down Expand Up @@ -39,7 +42,7 @@ describe("@babel/register - caching", () => {

beforeEach(() => {
// Since lib/cache is a singleton we need to fully reload it
jest.resetModules();
jest.resetModules(require);
const cache = require("../lib/cache.js");

load = cache.load;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use strict";
import { createRequire } from "module";
import path from "path";
import fs from "fs";
import child from "child_process";

const fs = require("fs");
const path = require("path");
const child = require("child_process");
const require = createRequire(import.meta.url);

let currentHook;
let currentOptions;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/test/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as t from "@babel/types";
import _traverse, { NodePath } from "../lib/index.js";
const traverse = _traverse.default;

function getPath(code, options): NodePath<t.Program> {
function getPath(code, options) {
const ast =
typeof code === "string" ? parse(code, options) : createNode(code);
let path;
Expand Down

0 comments on commit d2a8a1e

Please sign in to comment.