Only bundle the release build, and don't import src in tests (#13978)

* Only bundle the release build, and don't import `src` in tests

* Use file extension to signal skipping

* Remove unnecessary config change

* Fix imports
This commit is contained in:
Nicolò Ribaudo 2021-11-24 16:08:53 +01:00 committed by GitHub
parent 75996cb62b
commit ad1798ed48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 22 deletions

View File

@ -67,10 +67,8 @@ module.exports = {
"jest/no-standalone-expect": "off", "jest/no-standalone-expect": "off",
"jest/no-test-callback": "off", "jest/no-test-callback": "off",
"jest/valid-describe": "off", "jest/valid-describe": "off",
"import/extensions": [ "import/extensions": ["error", "always"],
"error", "no-restricted-imports": ["error", { patterns: ["**/src/**"] }],
{ json: "always", js: "always", cjs: "always", mjs: "always" },
],
}, },
}, },
{ {

View File

@ -18,7 +18,7 @@ NODE := $(YARN) node
.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap .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") ifneq ("$(BABEL_COVERAGE)", "true")
$(MAKE) build-standalone $(MAKE) build-standalone
endif endif
@ -28,8 +28,15 @@ build-bundle: clean clean-lib
$(MAKE) build-flow-typings $(MAKE) build-flow-typings
$(MAKE) build-dist $(MAKE) build-dist
build-bundle-ci: bootstrap-only build-no-bundle-ci: bootstrap-only
$(MAKE) build-bundle $(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: generate-tsconfig:
$(NODE) scripts/generators/tsconfig.js $(NODE) scripts/generators/tsconfig.js
@ -46,7 +53,7 @@ build-typescript-legacy-typings:
build-standalone: build-babel-standalone build-standalone: build-babel-standalone
build-standalone-ci: build-bundle-ci build-standalone-ci: build-no-bundle-ci
$(MAKE) build-standalone $(MAKE) build-standalone
build-babel-standalone: build-babel-standalone:
@ -61,12 +68,6 @@ build-plugin-transform-runtime-dist:
cd packages/babel-plugin-transform-runtime; \ cd packages/babel-plugin-transform-runtime; \
$(NODE) scripts/build-dist.js $(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 watch: build-no-bundle
BABEL_ENV=development $(YARN) gulp watch BABEL_ENV=development $(YARN) gulp watch

View File

@ -34,6 +34,7 @@ describe("parserOverride", () => {
const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it; const babel7node12 = parseInt(process.versions.node) < 12 ? it.skip : it;
babel7node12("works when parsing in a worker", async () => { babel7node12("works when parsing in a worker", async () => {
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
// eslint-disable-next-line import/extensions
const babelESLintWorker = require("@babel/eslint-parser/experimental-worker"); const babelESLintWorker = require("@babel/eslint-parser/experimental-worker");
const { ast } = babelESLintWorker.parseForESLint(`27`, { const { ast } = babelESLintWorker.parseForESLint(`27`, {

View File

@ -1,4 +1,5 @@
const supportsESM = parseInt(process.versions.node) >= 12; const supportsESM = parseInt(process.versions.node) >= 12;
const isPublishBundle = process.env.IS_PUBLISH;
module.exports = { module.exports = {
collectCoverageFrom: [ collectCoverageFrom: [
@ -23,6 +24,9 @@ module.exports = {
"<rootDir>/build/", "<rootDir>/build/",
"<rootDir>/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history "<rootDir>/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
"_browser\\.js", "_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", testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/test/testSetupFile.js"], setupFilesAfterEnv: ["<rootDir>/test/testSetupFile.js"],

View File

@ -1,4 +1,4 @@
import { tt, tokenOperatorPrecedence } from "../../../src/tokenizer/types.js"; import { tt, tokenOperatorPrecedence } from "../../../lib/tokenizer/types.js";
describe("token types", () => { describe("token types", () => {
it("should check if the binOp for relational === in", () => { it("should check if the binOp for relational === in", () => {

View File

@ -1,7 +1,7 @@
import { import {
isKeyword, isKeyword,
keywordRelationalOperator, keywordRelationalOperator,
} from "../../../src/util/identifier.js"; } from "../../../lib/util/identifier.js";
describe("identifier", () => { describe("identifier", () => {
describe("isKeyword", () => { describe("isKeyword", () => {

View File

@ -1,4 +1,4 @@
import { getLineInfo } from "../../../src/util/location.js"; import { getLineInfo } from "../../../lib/util/location.js";
describe("getLineInfo", () => { describe("getLineInfo", () => {
const input = "a\nb\nc\nd\ne\nf\ng\nh\ni"; const input = "a\nb\nc\nd\ne\nf\ng\nh\ni";

View File

@ -1,5 +1,5 @@
import { parseSync, traverse } from "@babel/core"; import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts"; import { shouldTransform } from "../lib/util.js";
function getPath(input, parserOpts = {}) { function getPath(input, parserOpts = {}) {
let targetPath; let targetPath;

View File

@ -1,5 +1,5 @@
import { parseSync, traverse } from "@babel/core"; import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts"; import { shouldTransform } from "../lib/util.js";
function getPath(input, parserOpts = {}) { function getPath(input, parserOpts = {}) {
let targetPath; let targetPath;

View File

@ -1,4 +1,4 @@
import { willPathCastToBoolean } from "../src/util.js"; import { willPathCastToBoolean } from "../lib/util.js";
import { parseSync, traverse } from "@babel/core"; import { parseSync, traverse } from "@babel/core";
function getPath(input, parserOpts) { function getPath(input, parserOpts) {

View File

@ -1,4 +1,5 @@
import normalizeOptions from "../src/normalize-options.js"; import normalizeOptions from "../lib/normalize-options.js";
describe("normalize options", () => { describe("normalize options", () => {
(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => { it("should throw on unknown options", () => {

View File

@ -1,4 +1,5 @@
import normalizeOptions from "../src/normalize-options.js"; import normalizeOptions from "../lib/normalize-options.js";
describe("normalize options", () => { describe("normalize options", () => {
(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => { it("should throw on unknown options", () => {