Skip to content

Commit a892da5

Browse files
committed
update to modern code style
1 parent 5a369e4 commit a892da5

19 files changed

+407
-419
lines changed

packages/create-react-app/createReactApp.js

+111-166
Large diffs are not rendered by default.

packages/create-react-app/index.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright (c) 2015-present, Facebook, Inc.
5+
* All rights reserved.
6+
*
7+
* This source code is licensed under the BSD-style license found in the
8+
* LICENSE file in the root directory of this source tree. An additional grant
9+
* of patent rights can be found in the PATENTS file in the same directory.
10+
*/
11+
12+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13+
// /!\ DO NOT MODIFY THIS FILE /!\
14+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
//
16+
// create-react-app is installed globally on people's computers. This means
17+
// that it is extremely difficult to have them upgrade the version and
18+
// because there's only one global version installed, it is very prone to
19+
// breaking changes.
20+
//
21+
// The only job of create-react-app is to init the repository and then
22+
// forward all the commands to the local version of create-react-app.
23+
//
24+
// If you need to add a new command, please add it to the scripts/ folder.
25+
//
26+
// The only reason to modify this file is to add more warnings and
27+
// troubleshooting information for the `create-react-app` command.
28+
//
29+
// Do not make breaking changes! We absolutely don't want to have to
30+
// tell people to update their global version of create-react-app.
31+
//
32+
// Also be careful with new language features.
33+
// This file must work on Node 0.10+.
34+
//
35+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36+
// /!\ DO NOT MODIFY THIS FILE /!\
37+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38+
39+
'use strict';
40+
41+
var chalk = require('chalk');
42+
43+
var currentNodeVersion = process.versions.node;
44+
if (currentNodeVersion.split('.')[0] < 4) {
45+
console.error(
46+
chalk.red(
47+
'You are running Node ' + currentNodeVersion + '.\n' +
48+
'Create React App requires Node 4 or higher. \n' +
49+
'Please update your version of Node.'
50+
)
51+
);
52+
process.exit(1);
53+
}
54+
55+
require('./createReactApp');

packages/create-react-app/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"url": "https://github.com/facebookincubator/create-react-app/issues"
1515
},
1616
"files": [
17-
"index.js"
17+
"index.js",
18+
"createReactApp.js"
1819
],
1920
"bin": {
2021
"create-react-app": "./index.js"

packages/react-scripts/config/env.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
1414
// injected into the application via DefinePlugin in Webpack configuration.
15-
16-
var REACT_APP = /^REACT_APP_/i;
15+
const REACT_APP = /^REACT_APP_/i;
1716

1817
function getClientEnvironment(publicUrl) {
19-
var raw = Object
18+
const raw = Object
2019
.keys(process.env)
2120
.filter(key => REACT_APP.test(key))
2221
.reduce((env, key) => {
@@ -33,7 +32,7 @@ function getClientEnvironment(publicUrl) {
3332
'PUBLIC_URL': publicUrl
3433
});
3534
// Stringify all values so we can feed into Webpack DefinePlugin
36-
var stringified = {
35+
const stringified = {
3736
'process.env': Object
3837
.keys(raw)
3938
.reduce((env, key) => {

packages/react-scripts/config/jest/babelTransform.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
109
'use strict';
1110

1211
const babelJest = require('babel-jest');

packages/react-scripts/config/jest/fileTransform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ const path = require('path');
1616

1717
module.exports = {
1818
process(src, filename) {
19-
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
19+
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
2020
},
2121
};

packages/react-scripts/config/paths.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
var path = require('path');
14-
var fs = require('fs');
15-
var url = require('url');
13+
const path = require('path');
14+
const fs = require('fs');
15+
const url = require('url');
1616

1717
// Make sure any symlinks in the project folder are resolved:
1818
// https://github.com/facebookincubator/create-react-app/issues/637
19-
var appDirectory = fs.realpathSync(process.cwd());
19+
const appDirectory = fs.realpathSync(process.cwd());
2020
function resolveApp(relativePath) {
2121
return path.resolve(appDirectory, relativePath);
2222
}
@@ -36,20 +36,20 @@ function resolveApp(relativePath) {
3636
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
3737
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
3838

39-
var nodePaths = (process.env.NODE_PATH || '')
39+
const nodePaths = (process.env.NODE_PATH || '')
4040
.split(process.platform === 'win32' ? ';' : ':')
4141
.filter(Boolean)
4242
.filter(folder => !path.isAbsolute(folder))
4343
.map(resolveApp);
4444

45-
var envPublicUrl = process.env.PUBLIC_URL;
45+
const envPublicUrl = process.env.PUBLIC_URL;
4646

4747
function ensureSlash(path, needsSlash) {
48-
var hasSlash = path.endsWith('/');
48+
const hasSlash = path.endsWith('/');
4949
if (hasSlash && !needsSlash) {
5050
return path.substr(path, path.length - 1);
5151
} else if (!hasSlash && needsSlash) {
52-
return path + '/';
52+
return `${path}/`;
5353
} else {
5454
return path;
5555
}
@@ -66,8 +66,8 @@ function getPublicUrl(appPackageJson) {
6666
// We can't use a relative path in HTML because we don't want to load something
6767
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
6868
function getServedPath(appPackageJson) {
69-
var publicUrl = getPublicUrl(appPackageJson);
70-
var servedUrl = envPublicUrl || (
69+
const publicUrl = getPublicUrl(appPackageJson);
70+
const servedUrl = envPublicUrl || (
7171
publicUrl ? url.parse(publicUrl).pathname : '/'
7272
);
7373
return ensureSlash(servedUrl, true);
@@ -114,9 +114,9 @@ module.exports = {
114114
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
115115
};
116116

117-
var ownPackageJson = require('../package.json');
118-
var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
119-
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
117+
const ownPackageJson = require('../package.json');
118+
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
119+
const reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
120120

121121
// config before publish: we're in ./packages/react-scripts/config/
122122
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {

packages/react-scripts/config/webpack.config.dev.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
var autoprefixer = require('autoprefixer');
14-
var webpack = require('webpack');
15-
var HtmlWebpackPlugin = require('html-webpack-plugin');
16-
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
17-
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18-
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
19-
var getClientEnvironment = require('./env');
20-
var paths = require('./paths');
13+
const autoprefixer = require('autoprefixer');
14+
const webpack = require('webpack');
15+
const HtmlWebpackPlugin = require('html-webpack-plugin');
16+
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
17+
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18+
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
19+
const getClientEnvironment = require('./env');
20+
const paths = require('./paths');
2121

2222
// @remove-on-eject-begin
2323
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
24-
var path = require('path');
24+
const path = require('path');
2525
// @remove-on-eject-end
2626

2727
// Webpack uses `publicPath` to determine where the app is being served from.
2828
// In development, we always serve from the root. This makes config easier.
29-
var publicPath = '/';
29+
const publicPath = '/';
3030
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3131
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3232
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
33-
var publicUrl = '';
33+
const publicUrl = '';
3434
// Get environment variables to inject into our app.
35-
var env = getClientEnvironment(publicUrl);
35+
const env = getClientEnvironment(publicUrl);
3636

3737
// This is the development configuration.
3838
// It is focused on developer experience and fast rebuilds.
@@ -202,18 +202,16 @@ module.exports = {
202202
loader: 'postcss-loader',
203203
options: {
204204
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
205-
plugins: function () {
206-
return [
207-
autoprefixer({
208-
browsers: [
209-
'>1%',
210-
'last 4 versions',
211-
'Firefox ESR',
212-
'not ie < 9', // React doesn't support IE8 anyway
213-
]
214-
})
215-
]
216-
}
205+
plugins: () => ([
206+
autoprefixer({
207+
browsers: [
208+
'>1%',
209+
'last 4 versions',
210+
'Firefox ESR',
211+
'not ie < 9', // React doesn't support IE8 anyway
212+
]
213+
})
214+
])
217215
}
218216
}
219217
]

packages/react-scripts/config/webpack.config.prod.js

+23-25
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
var autoprefixer = require('autoprefixer');
14-
var webpack = require('webpack');
15-
var HtmlWebpackPlugin = require('html-webpack-plugin');
16-
var ExtractTextPlugin = require('extract-text-webpack-plugin');
17-
var ManifestPlugin = require('webpack-manifest-plugin');
18-
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
19-
var paths = require('./paths');
20-
var getClientEnvironment = require('./env');
13+
const autoprefixer = require('autoprefixer');
14+
const webpack = require('webpack');
15+
const HtmlWebpackPlugin = require('html-webpack-plugin');
16+
const ExtractTextPlugin = require('extract-text-webpack-plugin');
17+
const ManifestPlugin = require('webpack-manifest-plugin');
18+
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
19+
const paths = require('./paths');
20+
const getClientEnvironment = require('./env');
2121

2222
// @remove-on-eject-begin
2323
// `path` is not used after eject - see https://github.com/facebookincubator/create-react-app/issues/1174
24-
var path = require('path');
24+
const path = require('path');
2525
// @remove-on-eject-end
2626

2727
// Webpack uses `publicPath` to determine where the app is being served from.
2828
// It requires a trailing slash, or the file assets will get an incorrect path.
29-
var publicPath = paths.servedPath;
29+
const publicPath = paths.servedPath;
3030
// Some apps do not use client-side routing with pushState.
3131
// For these, "homepage" can be set to "." to enable relative asset paths.
32-
var shouldUseRelativeAssetPaths = publicPath === './';
32+
const shouldUseRelativeAssetPaths = publicPath === './';
3333
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3434
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3535
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
36-
var publicUrl = publicPath.slice(0, -1);
36+
const publicUrl = publicPath.slice(0, -1);
3737
// Get environment variables to inject into our app.
38-
var env = getClientEnvironment(publicUrl);
38+
const env = getClientEnvironment(publicUrl);
3939

4040
// Assert this just to be safe.
4141
// Development builds of React are slow and not intended for production.
@@ -209,18 +209,16 @@ module.exports = {
209209
loader: 'postcss-loader',
210210
options: {
211211
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
212-
plugins: function () {
213-
return [
214-
autoprefixer({
215-
browsers: [
216-
'>1%',
217-
'last 4 versions',
218-
'Firefox ESR',
219-
'not ie < 9', // React doesn't support IE8 anyway
220-
]
221-
})
222-
]
223-
}
212+
plugins: () => ([
213+
autoprefixer({
214+
browsers: [
215+
'>1%',
216+
'last 4 versions',
217+
'Firefox ESR',
218+
'not ie < 9', // React doesn't support IE8 anyway
219+
]
220+
})
221+
])
224222
}
225223
}
226224
]

packages/react-scripts/config/webpackDevServer.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
// @remove-on-eject-end
1111
'use strict';
1212

13-
var config = require('./webpack.config.dev');
14-
var paths = require('./paths');
13+
const config = require('./webpack.config.dev');
14+
const paths = require('./paths');
1515

16-
var protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
17-
var host = process.env.HOST || 'localhost';
16+
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
17+
const host = process.env.HOST || 'localhost';
1818

1919
module.exports = {
2020
// Enable gzip compression of generated files.

packages/react-scripts/fixtures/kitchensink/src/features/syntax/ComputedProperties.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import React, { Component, PropTypes } from 'react'
1111

1212
function load(prefix) {
1313
return [
14-
{ id: 1, [prefix + 'name']: '1' },
15-
{ id: 2, [prefix + 'name']: '2' },
16-
{ id: 3, [prefix + 'name']: '3' },
17-
{ id: 4, [prefix + 'name']: '4' }
14+
{ id: 1, [`${prefix} name`]: '1' },
15+
{ id: 2, [`${prefix} name`]: '2' },
16+
{ id: 3, [`${prefix} name`]: '3' },
17+
{ id: 4, [`${prefix} name`]: '4' }
1818
];
1919
}
2020

0 commit comments

Comments
 (0)