Target latest Node for backend applications (#213)

Summary:
Consequently, Babel won’t transform classes to their roughly equivalent
ES5 counterparts, etc.

Test Plan:
Create `src/classy.js` with `class X {}; console.log(X);`. Then, add a
build target for `classy: resolveApp("src/classy.js"),` in `paths.js`.
Use `yarn backend` and inspect the contents of `bin/classy.js`; in
particular, look at the definition of `X` (whatever the argument to
`console.log` is). Before this commit, the result will be a big
complicated mess. After this commit, it will be `class X {}`.

Note also that `yarn travis --full` passes, indicating that the two
manual tests, which call out to the utilities in `bin/`, still work.

wchargin-branch: target-node
This commit is contained in:
William Chargin 2018-05-04 19:22:39 -07:00 committed by GitHub
parent b5e894bbb4
commit e9dbdeca96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View File

@ -49,6 +49,7 @@ const plugins = [
// https://github.com/facebookincubator/create-react-app/issues/720 // https://github.com/facebookincubator/create-react-app/issues/720
// Its also nice that we can enforce `NODE_ENV` being specified. // Its also nice that we can enforce `NODE_ENV` being specified.
var env = process.env.BABEL_ENV || process.env.NODE_ENV; var env = process.env.BABEL_ENV || process.env.NODE_ENV;
var backend = !!process.env.SOURCECRED_BACKEND;
if (env !== "development" && env !== "test" && env !== "production") { if (env !== "development" && env !== "test" && env !== "production") {
throw new Error( throw new Error(
"Using `babel-preset-react-app` requires that you specify `NODE_ENV` or " + "Using `babel-preset-react-app` requires that you specify `NODE_ENV` or " +
@ -101,11 +102,12 @@ if (env === "test") {
[ [
require.resolve("babel-preset-env"), require.resolve("babel-preset-env"),
{ {
targets: { targets: backend
// React parses on ie 9, so we should too ? {
node: "current",
}
: {
ie: 9, ie: 9,
// We currently minify with uglify
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
uglify: true, uglify: true,
}, },
// Disable polyfill transforms // Disable polyfill transforms
@ -117,7 +119,14 @@ if (env === "test") {
// JSX, Flow // JSX, Flow
require.resolve("babel-preset-react"), require.resolve("babel-preset-react"),
], ],
plugins: plugins.concat([ plugins: plugins.concat(
backend
? [
// Must come before `babel-plugin-transform-regenerator`.
require.resolve("babel-plugin-transform-es2015-for-of"),
]
: [],
[
// function* () { yield 42; yield 43; } // function* () { yield 42; yield 43; }
[ [
require.resolve("babel-plugin-transform-regenerator"), require.resolve("babel-plugin-transform-regenerator"),
@ -128,7 +137,8 @@ if (env === "test") {
], ],
// Adds syntax support for import() // Adds syntax support for import()
require.resolve("babel-plugin-syntax-dynamic-import"), require.resolve("babel-plugin-syntax-dynamic-import"),
]), ]
),
}; };
if (env === "production") { if (env === "production") {

View File

@ -9,6 +9,7 @@
"babel-eslint": "7.2.3", "babel-eslint": "7.2.3",
"babel-jest": "20.0.3", "babel-jest": "20.0.3",
"babel-loader": "7.1.2", "babel-loader": "7.1.2",
"babel-plugin-transform-es2015-for-of": "^6.23.0",
"babel-preset-react-app": "^3.1.1", "babel-preset-react-app": "^3.1.1",
"babel-runtime": "6.26.0", "babel-runtime": "6.26.0",
"case-sensitive-paths-webpack-plugin": "2.1.1", "case-sensitive-paths-webpack-plugin": "2.1.1",

View File

@ -3,6 +3,7 @@
// Do this as the first thing so that any code reading it knows the right env. // Do this as the first thing so that any code reading it knows the right env.
process.env.NODE_ENV = process.env.NODE_ENV || "development"; process.env.NODE_ENV = process.env.NODE_ENV || "development";
process.env.BABEL_ENV = process.env.NODE_ENV; process.env.BABEL_ENV = process.env.NODE_ENV;
process.env.SOURCECRED_BACKEND = true;
// Makes the script crash on unhandled rejections instead of silently // Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will // ignoring them. In the future, promise rejections that are not handled will