Centralize Babel's own compilation config to make it easier to follow. (#7599)

This commit is contained in:
Logan Smyth 2018-03-19 21:49:17 -07:00 committed by GitHub
parent edb0a70e14
commit 6d6fe844fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 80 additions and 80 deletions

View File

@ -1,48 +1,69 @@
"use strict";
const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const envOpts = {
loose: true,
module.exports = function(api) {
const env = api.env();
const includeCoverage = process.env.BABEL_COVERAGE === "true";
const envOpts = {
loose: true,
modules: false,
exclude: ["transform-typeof-symbol"],
};
let convertESM = true;
switch (env) {
// Configs used during bundling builds.
case "babylon":
case "standalone":
convertESM = false;
break;
case "production":
// Config during builds before publish.
break;
case "development":
envOpts.debug = true;
envOpts.targets = {
node: "current",
};
break;
case "test":
envOpts.targets = {
node: "current",
};
break;
}
const config = {
comments: false,
presets: [["@babel/env", envOpts]],
plugins: [
// TODO: Use @babel/preset-flow when
// https://github.com/babel/babel/issues/7233 is fixed
"@babel/plugin-transform-flow-strip-types",
["@babel/proposal-class-properties", { loose: true }],
"@babel/proposal-export-namespace-from",
"@babel/proposal-numeric-separator",
["@babel/proposal-object-rest-spread", { useBuiltIns: true }],
convertESM ? "@babel/transform-modules-commonjs" : null,
].filter(Boolean),
overrides: [
{
test: "packages/babylon",
plugins: [
"babel-plugin-transform-charcodes",
["@babel/transform-for-of", { assumeArray: true }],
],
},
],
};
// we need to do this as long as we do not test everything from source
if (includeCoverage) {
config.auxiliaryCommentBefore = "istanbul ignore next";
config.plugins.push("babel-plugin-istanbul");
}
return config;
};
switch (env) {
case "development":
envOpts.debug = true;
// fall-through
case "test":
case "cov":
envOpts.targets = {
node: "current",
};
}
const config = {
comments: false,
presets: [["@babel/env", envOpts]],
plugins: [
// TODO: Use @babel/preset-flow when
// https://github.com/babel/babel/issues/7233 is fixed
"@babel/plugin-transform-flow-strip-types",
["@babel/proposal-class-properties", { loose: true }],
"@babel/proposal-export-namespace-from",
"@babel/proposal-numeric-separator",
["@babel/proposal-object-rest-spread", { useBuiltIns: true }],
],
overrides: [
{
test: "packages/babylon",
plugins: [
"babel-plugin-transform-charcodes",
["@babel/transform-for-of", { assumeArray: true }],
],
},
],
};
// we need to do this as long as we do not test everything from source
if (env === "cov") {
config.auxiliaryCommentBefore = "istanbul ignore next";
config.plugins.push("babel-plugin-istanbul");
}
module.exports = config;

View File

@ -1,16 +0,0 @@
"use strict";
const cloneDeep = require("lodash/cloneDeep");
const babelrc = require("./.babelrc.js");
const config = cloneDeep(babelrc);
const presetEnv = config.presets.find(preset => preset[0] === "@babel/env");
if (!presetEnv) {
throw new Error("Error while extracting @preset/env from .babelrc.js");
}
presetEnv[1].modules = false;
module.exports = config;

View File

@ -98,8 +98,9 @@ function buildRollup(packages) {
format: "cjs",
plugins: [
rollupBabel({
envName: "babylon",
babelrc: false,
extends: "./.babelrc.rollup.js",
extends: "./.babelrc.js",
}),
rollupNodeResolve(),
],

View File

@ -2,7 +2,7 @@ MAKEFLAGS = -j1
FLOW_COMMIT = 622bbc4f07acb77eb1109830c70815f827401d90
TEST262_COMMIT = 52f70e2f637731aae92a9c9a2d831310c3ab2e1e
export NODE_ENV = test
export BABEL_ENV = test
# Fix color output until TravisCI fixes https://github.com/travis-ci/travis-ci/issues/7967
export FORCE_COLOR = true
@ -22,7 +22,7 @@ build: clean
node scripts/generators/typescript.js > ./packages/babel-types/lib/index.d.ts
# generate docs
node scripts/generators/docs.js > ./packages/babel-types/README.md
ifneq ("$(BABEL_ENV)", "cov")
ifneq ("$(BABEL_COVERAGE)", "true")
make build-standalone
make build-preset-env-standalone
endif
@ -82,7 +82,7 @@ test-ci:
test-ci-coverage: SHELL:=/bin/bash
test-ci-coverage:
BABEL_ENV=cov make bootstrap
BABEL_COVERAGE=true BABEL_ENV=test make bootstrap
TEST_TYPE=cov ./scripts/test-cov.sh
bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json

View File

@ -12,6 +12,7 @@
"devDependencies": {
"@babel/cli": "7.0.0-beta.41",
"@babel/core": "7.0.0-beta.41",
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.41",
"@babel/preset-env": "7.0.0-beta.41",
"@babel/preset-flow": "7.0.0-beta.41",
"@babel/preset-stage-0": "7.0.0-beta.41",

View File

@ -39,25 +39,18 @@ function webpackBuild(opts) {
test: /\.js$/,
loader: "babel-loader",
options: {
// Use the bundled config so that module syntax is passed through
// for Webpack.
envName: "standalone",
// Some of the node_modules may have their own "babel" section in
// their project.json (or a ".babelrc" file). We need to ignore
// those as we're using our own Babel options.
babelrc: false,
presets: [
[
"@babel/env",
{
loose: true,
exclude: ["transform-typeof-symbol"],
},
],
],
overrides: [
{
exclude: /node_modules/,
presets: [["@babel/stage-0", { loose: true }]],
},
],
// We explicitly load the `.babelrc.js` file since searching is
// turned off, but we still want to use the main config.
extends: "./.babelrc.js",
},
},
],