Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to modern code style #1738

Merged
merged 4 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
"postinstall": "lerna bootstrap",
"publish": "tasks/release.sh",
"start": "node packages/react-scripts/scripts/start.js",
"test": "node packages/react-scripts/scripts/test.js --env=jsdom"
"test": "node packages/react-scripts/scripts/test.js --env=jsdom",
"format": "prettier --trailing-comma es5 --single-quote --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'"
},
"devDependencies": {
"eslint": "3.16.1",
"lerna": "2.0.0-beta.38",
"lerna-changelog": "^0.2.3"
"lerna-changelog": "^0.2.3",
"prettier": "^0.21.0"
}
}
100 changes: 60 additions & 40 deletions packages/babel-preset-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@ const plugins = [
// The following two plugins use Object.assign directly, instead of Babel's
// extends helper. Note that this assumes `Object.assign` is available.
// { ...todo, completed: true }
[require.resolve('babel-plugin-transform-object-rest-spread'), {
useBuiltIns: true
}],
[
require.resolve('babel-plugin-transform-object-rest-spread'),
{
useBuiltIns: true,
},
],
// Transforms JSX
[require.resolve('babel-plugin-transform-react-jsx'), {
useBuiltIns: true
}],
[
require.resolve('babel-plugin-transform-react-jsx'),
{
useBuiltIns: true,
},
],
// Polyfills the runtime needed for async/await and generators
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
moduleName: path.dirname(require.resolve('babel-runtime/package'))
}]
[
require.resolve('babel-plugin-transform-runtime'),
{
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
moduleName: path.dirname(require.resolve('babel-runtime/package')),
},
],
];

// This is similar to how `env` works in Babel:
Expand All @@ -42,9 +51,11 @@ const plugins = [
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (env !== 'development' && env !== 'test' && env !== 'production') {
throw new Error(
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or '+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' + JSON.stringify(env) + '.'
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(env) +
'.'
);
}

Expand All @@ -59,54 +70,63 @@ if (env === 'development' || env === 'test') {
// Adds component stack to warning messages
require.resolve('babel-plugin-transform-react-jsx-source'),
// Adds __self attribute to JSX which React will use for some warnings
require.resolve('babel-plugin-transform-react-jsx-self')
require.resolve('babel-plugin-transform-react-jsx-self'),
]);
}

if (env === 'test') {
module.exports = {
presets: [
// ES features necessary for user's Node version
[require('babel-preset-env').default, {
targets: {
node: 'current',
[
require('babel-preset-env').default,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but is there any reason this isn't require.resolve sub the default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably fix. I don't remember.

{
targets: {
node: 'current',
},
},
}],
],
// JSX, Flow
require.resolve('babel-preset-react')
require.resolve('babel-preset-react'),
],
plugins: plugins.concat([
// Compiles import() to a deferred require()
require.resolve('babel-plugin-dynamic-import-node')
])
require.resolve('babel-plugin-dynamic-import-node'),
]),
};
} else {
module.exports = {
presets: [
// Latest stable ECMAScript features
[require.resolve('babel-preset-env'), {
targets: {
// React parses on ie 9, so we should too
ie: 9,
// We currently minify with uglify
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
uglify: true
[
require.resolve('babel-preset-env'),
{
targets: {
// React parses on ie 9, so we should too
ie: 9,
// We currently minify with uglify
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
uglify: true,
},
// Disable polyfill transforms
useBuiltIns: false,
},
// Disable polyfill transforms
useBuiltIns: false
}],
],
// JSX, Flow
require.resolve('babel-preset-react')
require.resolve('babel-preset-react'),
],
plugins: plugins.concat([
// function* () { yield 42; yield 43; }
[require.resolve('babel-plugin-transform-regenerator'), {
// Async functions are converted to generators by babel-preset-latest
async: false
}],
[
require.resolve('babel-plugin-transform-regenerator'),
{
// Async functions are converted to generators by babel-preset-latest
async: false,
},
],
// Adds syntax support for import()
require.resolve('babel-plugin-syntax-dynamic-import'),
])
]),
};

if (env === 'production') {
Expand Down
Loading