diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1ada9b291ecc..e2d424025744 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -67,10 +67,8 @@ module.exports = { "jest/no-standalone-expect": "off", "jest/no-test-callback": "off", "jest/valid-describe": "off", - "import/extensions": [ - "error", - { json: "always", js: "always", cjs: "always", mjs: "always" }, - ], + "import/extensions": ["error", "always"], + "no-restricted-imports": ["error", { patterns: ["**/src/**"] }], }, }, { diff --git a/Makefile b/Makefile index 341cd136a90f..d17500b8631a 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ NODE := $(YARN) node .PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap -build: build-bundle +build: build-no-bundle ifneq ("$(BABEL_COVERAGE)", "true") $(MAKE) build-standalone endif @@ -28,8 +28,15 @@ build-bundle: clean clean-lib $(MAKE) build-flow-typings $(MAKE) build-dist -build-bundle-ci: bootstrap-only - $(MAKE) build-bundle +build-no-bundle-ci: bootstrap-only + $(YARN) gulp build-dev + $(MAKE) build-flow-typings + $(MAKE) build-dist + +build-no-bundle: clean clean-lib + BABEL_ENV=development $(YARN) gulp build-dev + $(MAKE) build-flow-typings + $(MAKE) build-dist generate-tsconfig: $(NODE) scripts/generators/tsconfig.js @@ -46,7 +53,7 @@ build-typescript-legacy-typings: build-standalone: build-babel-standalone -build-standalone-ci: build-bundle-ci +build-standalone-ci: build-no-bundle-ci $(MAKE) build-standalone build-babel-standalone: @@ -61,12 +68,6 @@ build-plugin-transform-runtime-dist: cd packages/babel-plugin-transform-runtime; \ $(NODE) scripts/build-dist.js -build-no-bundle: clean clean-lib - BABEL_ENV=development $(YARN) gulp build-dev - # Ensure that build artifacts for types are created during local - # development too. - $(MAKE) build-flow-typings - watch: build-no-bundle BABEL_ENV=development $(YARN) gulp watch diff --git a/eslint/babel-eslint-tests/test/integration/parser-override.js b/eslint/babel-eslint-tests/test/integration/parser-override.js index 1091c40671a1..5c5632485b1c 100644 --- a/eslint/babel-eslint-tests/test/integration/parser-override.js +++ b/eslint/babel-eslint-tests/test/integration/parser-override.js @@ -34,6 +34,7 @@ describe("parserOverride", () => { const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it; babel7node12("works when parsing in a worker", async () => { const require = createRequire(import.meta.url); + // eslint-disable-next-line import/extensions const babelESLintWorker = require("@babel/eslint-parser/experimental-worker"); const { ast } = babelESLintWorker.parseForESLint(`27`, { diff --git a/jest.config.js b/jest.config.js index 276e156144d9..b60fa636a815 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ const supportsESM = parseInt(process.versions.node) >= 12; +const isPublishBundle = process.env.IS_PUBLISH; module.exports = { collectCoverageFrom: [ @@ -23,6 +24,9 @@ module.exports = { "/build/", "/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history "_browser\\.js", + // Some tests require internal files of bundled packages, which are not available + // in production builds. They are marked using the .skip-bundled.js extension. + ...(isPublishBundle ? ["\\.skip-bundled\\.js$"] : []), ], testEnvironment: "node", setupFilesAfterEnv: ["/test/testSetupFile.js"], diff --git a/packages/babel-parser/test/unit/tokenizer/types.js b/packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js similarity index 90% rename from packages/babel-parser/test/unit/tokenizer/types.js rename to packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js index f242441bd588..0cbcaa8d6fd6 100644 --- a/packages/babel-parser/test/unit/tokenizer/types.js +++ b/packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js @@ -1,4 +1,4 @@ -import { tt, tokenOperatorPrecedence } from "../../../src/tokenizer/types.js"; +import { tt, tokenOperatorPrecedence } from "../../../lib/tokenizer/types.js"; describe("token types", () => { it("should check if the binOp for relational === in", () => { diff --git a/packages/babel-parser/test/unit/util/identifier.js b/packages/babel-parser/test/unit/util/identifier.skip-bundled.js similarity index 96% rename from packages/babel-parser/test/unit/util/identifier.js rename to packages/babel-parser/test/unit/util/identifier.skip-bundled.js index c6c25ec942da..6a9b3f7b20fb 100644 --- a/packages/babel-parser/test/unit/util/identifier.js +++ b/packages/babel-parser/test/unit/util/identifier.skip-bundled.js @@ -1,7 +1,7 @@ import { isKeyword, keywordRelationalOperator, -} from "../../../src/util/identifier.js"; +} from "../../../lib/util/identifier.js"; describe("identifier", () => { describe("isKeyword", () => { diff --git a/packages/babel-parser/test/unit/util/location.js b/packages/babel-parser/test/unit/util/location.skip-bundled.js similarity index 93% rename from packages/babel-parser/test/unit/util/location.js rename to packages/babel-parser/test/unit/util/location.skip-bundled.js index 9c8fb79b37a4..463463c88921 100644 --- a/packages/babel-parser/test/unit/util/location.js +++ b/packages/babel-parser/test/unit/util/location.skip-bundled.js @@ -1,4 +1,4 @@ -import { getLineInfo } from "../../../src/util/location.js"; +import { getLineInfo } from "../../../lib/util/location.js"; describe("getLineInfo", () => { const input = "a\nb\nc\nd\ne\nf\ng\nh\ni"; diff --git a/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js b/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js similarity index 96% rename from packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js rename to packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js index f6e9282e42fa..ed7576030378 100644 --- a/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js +++ b/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js @@ -1,5 +1,5 @@ import { parseSync, traverse } from "@babel/core"; -import { shouldTransform } from "../src/util.ts"; +import { shouldTransform } from "../lib/util.js"; function getPath(input, parserOpts = {}) { let targetPath; diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js similarity index 98% rename from packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js rename to packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js index 89bc17afb5d7..e475940c0b31 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js @@ -1,5 +1,5 @@ import { parseSync, traverse } from "@babel/core"; -import { shouldTransform } from "../src/util.ts"; +import { shouldTransform } from "../lib/util.js"; function getPath(input, parserOpts = {}) { let targetPath; diff --git a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js b/packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js similarity index 97% rename from packages/babel-plugin-proposal-optional-chaining/test/util.test.js rename to packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js index d2b8a3d83331..ee3289dcc530 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js @@ -1,4 +1,4 @@ -import { willPathCastToBoolean } from "../src/util.js"; +import { willPathCastToBoolean } from "../lib/util.js"; import { parseSync, traverse } from "@babel/core"; function getPath(input, parserOpts) { diff --git a/packages/babel-preset-react/test/normalize-options.spec.js b/packages/babel-preset-react/test/normalize-options.skip-bundled.js similarity index 98% rename from packages/babel-preset-react/test/normalize-options.spec.js rename to packages/babel-preset-react/test/normalize-options.skip-bundled.js index b3e1b8dee390..5932ed4b6d73 100644 --- a/packages/babel-preset-react/test/normalize-options.spec.js +++ b/packages/babel-preset-react/test/normalize-options.skip-bundled.js @@ -1,4 +1,5 @@ -import normalizeOptions from "../src/normalize-options.js"; +import normalizeOptions from "../lib/normalize-options.js"; + describe("normalize options", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => { diff --git a/packages/babel-preset-typescript/test/normalize-options.spec.js b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js similarity index 98% rename from packages/babel-preset-typescript/test/normalize-options.spec.js rename to packages/babel-preset-typescript/test/normalize-options.skip-bundled.js index 710c9dc797c6..205409af007e 100644 --- a/packages/babel-preset-typescript/test/normalize-options.spec.js +++ b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js @@ -1,4 +1,5 @@ -import normalizeOptions from "../src/normalize-options.js"; +import normalizeOptions from "../lib/normalize-options.js"; + describe("normalize options", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => {