Skip to content

Commit

Permalink
Only bundle in production
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 18, 2021
1 parent 1684596 commit 7730462
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 39 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Expand Up @@ -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/**"] }],
},
},
{
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Expand Up @@ -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",
{
Expand Down
13 changes: 0 additions & 13 deletions 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",

Expand All @@ -37,7 +25,6 @@ module.exports = {
"<rootDir>/build/",
"<rootDir>/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history
"_browser\\.js",
...(supportsESM ? importsSrc : []),
],
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/test/testSetupFile.js"],
Expand Down
11 changes: 9 additions & 2 deletions 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),
Expand Down
14 changes: 9 additions & 5 deletions 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);
Expand Down
9 changes: 7 additions & 2 deletions 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", () => {
Expand Down
@@ -1,5 +1,4 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts";

function getPath(input, parserOpts = {}) {
let targetPath;
Expand All @@ -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]) {} })",
Expand Down
@@ -1,5 +1,4 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts";

function getPath(input, parserOpts = {}) {
let targetPath;
Expand All @@ -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?.(...[], ...[])",
Expand Down
@@ -1,4 +1,3 @@
import { willPathCastToBoolean } from "../src/util.js";
import { parseSync, traverse } from "@babel/core";

function getPath(input, parserOpts) {
Expand All @@ -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) {}",
Expand Down
12 changes: 10 additions & 2 deletions 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(
Expand Down
12 changes: 10 additions & 2 deletions 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(
Expand Down

0 comments on commit 7730462

Please sign in to comment.