Prepare codebase for inline Babel 8 breaking changes (#12440)
This commit is contained in:
parent
3bd6a3d781
commit
c139d1602b
38
.github/workflows/ci.yml
vendored
38
.github/workflows/ci.yml
vendored
@ -82,6 +82,9 @@ jobs:
|
||||
- name: Build babel artifacts
|
||||
run: |
|
||||
BABEL_ENV=test-legacy make -j build-standalone-ci
|
||||
env:
|
||||
BABEL_8_BREAKING: false
|
||||
STRIP_BABEL_8_FLAG: true
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: babel-artifact
|
||||
@ -164,6 +167,41 @@ jobs:
|
||||
run: |
|
||||
BABEL_ENV=test node ./node_modules/.bin/jest --ci --color
|
||||
|
||||
test-babel-8-breaking:
|
||||
name: Test Babel 8 breaking changes
|
||||
needs: prepare-yarn-cache
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js 12
|
||||
uses: actions/setup-node@v2-beta
|
||||
with:
|
||||
node-version: 12 # Node.js 12 is the first LTS supported by Babel 8
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: yarn-${{ hashFiles('yarn.lock') }}
|
||||
- name: Install and build
|
||||
run: make -j bootstrap
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
BABEL_8_BREAKING: true
|
||||
STRIP_BABEL_8_FLAG: true
|
||||
- name: Test
|
||||
# Hack: --color has supports-color@5 returned true for GitHub CI
|
||||
# Remove once `chalk` is bumped to 4.0.
|
||||
run: |
|
||||
yarn jest --ci --color
|
||||
yarn test:esm
|
||||
env:
|
||||
BABEL_ENV: test
|
||||
BABEL_8_BREAKING: true
|
||||
BABEL_TYPES_8_BREAKING: true
|
||||
|
||||
test-windows:
|
||||
name: Test on Windows
|
||||
needs: build
|
||||
|
||||
15
Gulpfile.js
15
Gulpfile.js
@ -110,7 +110,7 @@ if (process.env.CIRCLE_PR_NUMBER) {
|
||||
|
||||
const babelVersion =
|
||||
require("./packages/babel-core/package.json").version + versionSuffix;
|
||||
function buildRollup(packages) {
|
||||
function buildRollup(packages, targetBrowsers) {
|
||||
const sourcemap = process.env.NODE_ENV === "production";
|
||||
return Promise.all(
|
||||
packages.map(async ({ src, format, dest, name, filename }) => {
|
||||
@ -166,11 +166,12 @@ function buildRollup(packages) {
|
||||
],
|
||||
}),
|
||||
rollupJson(),
|
||||
rollupNodePolyfills({
|
||||
sourceMap: sourcemap,
|
||||
include: "**/*.{js,ts}",
|
||||
}),
|
||||
],
|
||||
targetBrowsers &&
|
||||
rollupNodePolyfills({
|
||||
sourceMap: sourcemap,
|
||||
include: "**/*.{js,ts}",
|
||||
}),
|
||||
].filter(Boolean),
|
||||
});
|
||||
|
||||
const outputFile = path.join(src, dest, filename || "index.js");
|
||||
@ -235,7 +236,7 @@ const standaloneBundle = [
|
||||
];
|
||||
|
||||
gulp.task("build-rollup", () => buildRollup(libBundles));
|
||||
gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle));
|
||||
gulp.task("build-babel-standalone", () => buildRollup(standaloneBundle, true));
|
||||
|
||||
gulp.task("build-babel", () => buildBabel(/* exclude */ libBundles));
|
||||
gulp.task("build", gulp.parallel("build-rollup", "build-babel"));
|
||||
|
||||
2
Makefile
2
Makefile
@ -206,7 +206,7 @@ clone-license:
|
||||
./scripts/clone-license.sh
|
||||
|
||||
prepublish-build: clean-lib clean-runtime-helpers
|
||||
NODE_ENV=production BABEL_ENV=production $(MAKE) build-bundle
|
||||
NODE_ENV=production BABEL_ENV=production STRIP_BABEL_8_FLAG=true $(MAKE) build-bundle
|
||||
$(MAKE) prepublish-build-standalone clone-license
|
||||
|
||||
prepublish:
|
||||
|
||||
@ -77,6 +77,11 @@ module.exports = function (api) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (process.env.STRIP_BABEL_8_FLAG && bool(process.env.BABEL_8_BREAKING)) {
|
||||
// Never apply polyfills when compiling for Babel 8
|
||||
polyfillRequireResolve = false;
|
||||
}
|
||||
|
||||
if (includeRegeneratorRuntime) {
|
||||
const babelRuntimePkgPath = require.resolve("@babel/runtime/package.json");
|
||||
|
||||
@ -119,6 +124,11 @@ module.exports = function (api) {
|
||||
|
||||
convertESM ? "@babel/proposal-export-namespace-from" : null,
|
||||
convertESM ? "@babel/transform-modules-commonjs" : null,
|
||||
|
||||
process.env.STRIP_BABEL_8_FLAG && [
|
||||
pluginToggleBabel8Breaking,
|
||||
{ breaking: bool(process.env.BABEL_8_BREAKING) },
|
||||
],
|
||||
polyfillRequireResolve && pluginPolyfillRequireResolve,
|
||||
].filter(Boolean),
|
||||
overrides: [
|
||||
@ -165,6 +175,11 @@ module.exports = function (api) {
|
||||
return config;
|
||||
};
|
||||
|
||||
// env vars from the cli are always strings, so !!ENV_VAR returns true for "false"
|
||||
function bool(value) {
|
||||
return value && value === "false" && value === "0";
|
||||
}
|
||||
|
||||
// TODO(Babel 8) This polyfill is only needed for Node.js 6 and 8
|
||||
function pluginPolyfillRequireResolve({ template, types: t }) {
|
||||
return {
|
||||
@ -204,3 +219,32 @@ function pluginPolyfillRequireResolve({ template, types: t }) {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function pluginToggleBabel8Breaking({ types: t }, { breaking }) {
|
||||
return {
|
||||
visitor: {
|
||||
"IfStatement|ConditionalExpression"(path) {
|
||||
let test = path.get("test");
|
||||
let keepConsequent = breaking;
|
||||
|
||||
if (test.isUnaryExpression({ operator: "!" })) {
|
||||
test = test.get("argument");
|
||||
keepConsequent = !keepConsequent;
|
||||
}
|
||||
|
||||
if (!test.matchesPattern("process.env.BABEL_8_BREAKING")) return;
|
||||
|
||||
path.replaceWith(
|
||||
keepConsequent
|
||||
? path.node.consequent
|
||||
: path.node.alternate || t.emptyStatement()
|
||||
);
|
||||
},
|
||||
MemberExpression(path) {
|
||||
if (path.matchesPattern("process.env.BABEL_8_BREAKING")) {
|
||||
throw path.buildCodeFrameError("This check could not be stripped.");
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -122,7 +122,11 @@ function pushTask(taskName, taskDir, suite, suiteName) {
|
||||
const test = {
|
||||
optionsDir: taskOptsLoc ? path.dirname(taskOptsLoc) : null,
|
||||
title: humanize(taskName, true),
|
||||
disabled: taskName[0] === ".",
|
||||
disabled:
|
||||
taskName[0] === "." ||
|
||||
(process.env.BABEL_8_BREAKING
|
||||
? taskOpts.BABEL_8_BREAKING === false
|
||||
: taskOpts.BABEL_8_BREAKING === true),
|
||||
options: taskOpts,
|
||||
validateLogs: taskOpts.validateLogs,
|
||||
ignoreOutput: taskOpts.ignoreOutput,
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import * as t from "../lib";
|
||||
|
||||
describe("regressions", () => {
|
||||
it("jest .toMatchInlineSnapshot used 'Line' for comments", () => {
|
||||
const babel7 = process.env.BABEL_TYPES_8_BREAKING ? it.skip : it;
|
||||
|
||||
babel7("jest .toMatchInlineSnapshot used 'Line' for comments", () => {
|
||||
expect(() => {
|
||||
t.file(t.program([]), [{ type: "Line" }]);
|
||||
}).not.toThrow();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user