diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 744bb1342010..1c38103fe6cb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -75,6 +75,7 @@ module.exports = { { json: "always", js: "always", cjs: "always", mjs: "always" }, ], "import/no-extraneous-dependencies": "off", + "no-restricted-imports": ["error", { patterns: ["**/src/**"] }], }, }, { diff --git a/Makefile b/Makefile index 6936a21e86ae..277cc108b40a 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,8 @@ build-bundle: clean clean-lib $(MAKE) build-flow-typings $(MAKE) build-dist -build-bundle-ci: bootstrap-only - $(MAKE) build-bundle +build-ci: bootstrap-only + $(MAKE) build-no-bundle-ci generate-tsconfig: $(NODE) scripts/generators/tsconfig.js @@ -46,7 +46,7 @@ build-typescript-legacy-typings: build-standalone: build-babel-standalone -build-standalone-ci: build-bundle-ci +build-standalone-ci: build-ci $(MAKE) build-standalone build-babel-standalone: @@ -61,10 +61,13 @@ build-plugin-transform-runtime-dist: cd packages/babel-plugin-transform-runtime; \ $(NODE) scripts/build-dist.js -build-no-bundle: clean clean-lib +build-no-bundle-ci: clean clean-lib + $(YARN) gulp build-dev + $(MAKE) build-flow-typings + $(MAKE) build-dist + +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 diff --git a/babel.config.js b/babel.config.js index 0df5312deef7..383a11d6cd38 100644 --- a/babel.config.js +++ b/babel.config.js @@ -219,6 +219,7 @@ module.exports = function (api) { { test: sources.map(source => normalize(source.replace("/src", "/test"))), plugins: [ + "@babel/plugin-proposal-dynamic-import", [ "@babel/transform-modules-commonjs", { diff --git a/jest.config.js b/jest.config.js index 22fd65c51e14..fd11a502d12d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,17 +1,5 @@ const supportsESM = parseInt(process.versions.node) >= 12; -// These tests files are directly importing `src` files rather than the compiled versions -const importsSrc = [ - "packages/babel-parser/test/unit/tokenizer/types.js", - "packages/babel-parser/test/unit/util/identifier.js", - "packages/babel-parser/test/unit/util/location.js", - "packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js", - "packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js", - "packages/babel-plugin-proposal-optional-chaining/test/util.test.js", - "packages/babel-preset-react/test/normalize-options.spec.js", - "packages/babel-preset-typescript/test/normalize-options.spec.js", -]; - module.exports = { runner: supportsESM ? "./test/jest-light-runner" : "jest-runner", @@ -37,7 +25,6 @@ module.exports = { "/build/", "/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history "_browser\\.js", - ...(supportsESM ? importsSrc : []), ], 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.js index f242441bd588..0785c3055e16 100644 --- a/packages/babel-parser/test/unit/tokenizer/types.js +++ b/packages/babel-parser/test/unit/tokenizer/types.js @@ -1,6 +1,13 @@ -import { tt, tokenOperatorPrecedence } from "../../../src/tokenizer/types.js"; +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("token types", () => { + let tt, tokenOperatorPrecedence; + beforeAll(async () => { + ({ tt, tokenOperatorPrecedence } = await import( + "../../../lib/tokenizer/types.js" + )); + }); -describe("token types", () => { it("should check if the binOp for relational === in", () => { expect(tokenOperatorPrecedence(tt.relational)).toEqual( tokenOperatorPrecedence(tt._in), diff --git a/packages/babel-parser/test/unit/util/identifier.js b/packages/babel-parser/test/unit/util/identifier.js index c6c25ec942da..7ac5639eeb83 100644 --- a/packages/babel-parser/test/unit/util/identifier.js +++ b/packages/babel-parser/test/unit/util/identifier.js @@ -1,9 +1,13 @@ -import { - isKeyword, - keywordRelationalOperator, -} from "../../../src/util/identifier.js"; +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("identifier", () => { + let isKeyword, keywordRelationalOperator; + beforeAll(async () => { + ({ isKeyword, keywordRelationalOperator } = await import( + "../../../lib/util/identifier.js" + )); + }); -describe("identifier", () => { describe("isKeyword", () => { it("break is a keyword", () => { expect(isKeyword("break")).toBe(true); diff --git a/packages/babel-parser/test/unit/util/location.js b/packages/babel-parser/test/unit/util/location.js index 9c8fb79b37a4..7439ebfeb383 100644 --- a/packages/babel-parser/test/unit/util/location.js +++ b/packages/babel-parser/test/unit/util/location.js @@ -1,6 +1,11 @@ -import { getLineInfo } from "../../../src/util/location.js"; +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("getLineInfo", () => { + let getLineInfo; + beforeAll(async () => { + ({ getLineInfo } = await import("../../../lib/util/location.js")); + }); -describe("getLineInfo", () => { const input = "a\nb\nc\nd\ne\nf\ng\nh\ni"; it("reports correct position", () => { 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.test.js index f6e9282e42fa..23a34a258639 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.test.js @@ -1,5 +1,4 @@ import { parseSync, traverse } from "@babel/core"; -import { shouldTransform } from "../src/util.ts"; function getPath(input, parserOpts = {}) { let targetPath; @@ -19,7 +18,14 @@ function getPath(input, parserOpts = {}) { return targetPath; } -describe("shouldTransform", () => { +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("shouldTransform", () => { + let shouldTransform; + beforeAll(async () => { + ({ shouldTransform } = await import("../lib/util.js")); + }); + const positiveCases = [ "(function a([a]) {})", "({ b: function a([a]) {} })", 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.test.js index 89bc17afb5d7..9147705cced4 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.test.js @@ -1,5 +1,4 @@ import { parseSync, traverse } from "@babel/core"; -import { shouldTransform } from "../src/util.ts"; function getPath(input, parserOpts = {}) { let targetPath; @@ -20,7 +19,14 @@ function getPath(input, parserOpts = {}) { return targetPath; } -describe("shouldTransform", () => { +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("shouldTransform", () => { + let shouldTransform; + beforeAll(async () => { + ({ shouldTransform } = await import("../lib/util.js")); + }); + const positiveCases = [ "fn?.(...[], 0)", "fn?.(...[], ...[])", diff --git a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js b/packages/babel-plugin-proposal-optional-chaining/test/util.test.js index d2b8a3d83331..afbd65c9ff19 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/util.test.js @@ -1,4 +1,3 @@ -import { willPathCastToBoolean } from "../src/util.js"; import { parseSync, traverse } from "@babel/core"; function getPath(input, parserOpts) { @@ -13,7 +12,14 @@ function getPath(input, parserOpts) { return targetPath; } -describe("willPathCastToBoolean", () => { +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("willPathCastToBoolean", () => { + let willPathCastToBoolean; + beforeAll(async () => { + ({ willPathCastToBoolean } = await import("../lib/util.js")); + }); + const positiveCases = [ "if(a?.b) {}", "while(a?.b) {}", diff --git a/packages/babel-preset-react/test/normalize-options.spec.js b/packages/babel-preset-react/test/normalize-options.spec.js index b3e1b8dee390..bbb2ab7299c5 100644 --- a/packages/babel-preset-react/test/normalize-options.spec.js +++ b/packages/babel-preset-react/test/normalize-options.spec.js @@ -1,5 +1,13 @@ -import normalizeOptions from "../src/normalize-options.js"; -describe("normalize options", () => { +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("normalize options", () => { + let normalizeOptions; + beforeAll(async () => { + ({ + default: { default: normalizeOptions }, + } = await import("../lib/normalize-options.js")); + }); + (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ throwIfNamespaces: true })).toThrowError( diff --git a/packages/babel-preset-typescript/test/normalize-options.spec.js b/packages/babel-preset-typescript/test/normalize-options.spec.js index 710c9dc797c6..6553964e2c5e 100644 --- a/packages/babel-preset-typescript/test/normalize-options.spec.js +++ b/packages/babel-preset-typescript/test/normalize-options.spec.js @@ -1,5 +1,13 @@ -import normalizeOptions from "../src/normalize-options.js"; -describe("normalize options", () => { +const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; + +describeSkipPublish("normalize options", () => { + let normalizeOptions; + beforeAll(async () => { + ({ + default: { default: normalizeOptions }, + } = await import("../lib/normalize-options.js")); + }); + (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ allowNamespace: true })).toThrowError(