Skip to content

Commit cc1e657

Browse files
tuchk4gaearon
authored andcommitted
update to modern code style (facebook#1738)
* mv create-react-app/index.js -> create-react-app/creteReactApp.js * update to modern code style * var -> cosnt * set trailing-coma to es5 for prettier
1 parent bda001c commit cc1e657

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1017
-843
lines changed

bin/react-scripts.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,38 @@ var script = process.argv[2];
1515
var args = process.argv.slice(3);
1616

1717
switch (script) {
18-
case 'build':
19-
case 'eject':
20-
case 'start':
21-
case 'test':
22-
var result = spawn.sync(
23-
'node',
24-
[require.resolve('../scripts/' + script)].concat(args),
25-
{stdio: 'inherit'}
26-
);
27-
if (result.signal) {
28-
if (result.signal === 'SIGKILL') {
29-
console.log(
30-
'The build failed because the process exited too early. ' +
31-
'This probably means the system ran out of memory or someone called ' +
32-
'`kill -9` on the process.'
33-
);
34-
} else if (result.signal === 'SIGTERM') {
35-
console.log(
36-
'The build failed because the process exited too early. ' +
37-
'Someone might have called `kill` or `killall`, or the system could ' +
38-
'be shutting down.'
39-
);
18+
case 'build':
19+
case 'eject':
20+
case 'start':
21+
case 'test':
22+
var result = spawn.sync(
23+
'node',
24+
[require.resolve('../scripts/' + script)].concat(args),
25+
{ stdio: 'inherit' }
26+
);
27+
if (result.signal) {
28+
if (result.signal === 'SIGKILL') {
29+
console.log(
30+
'The build failed because the process exited too early. ' +
31+
'This probably means the system ran out of memory or someone called ' +
32+
'`kill -9` on the process.'
33+
);
34+
} else if (result.signal === 'SIGTERM') {
35+
console.log(
36+
'The build failed because the process exited too early. ' +
37+
'Someone might have called `kill` or `killall`, or the system could ' +
38+
'be shutting down.'
39+
);
40+
}
41+
process.exit(1);
4042
}
41-
process.exit(1);
42-
}
43-
process.exit(result.status);
44-
break;
45-
default:
46-
console.log('Unknown script "' + script + '".');
47-
console.log('Perhaps you need to update react-scripts?');
48-
console.log('See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases');
49-
break;
43+
process.exit(result.status);
44+
break;
45+
default:
46+
console.log('Unknown script "' + script + '".');
47+
console.log('Perhaps you need to update react-scripts?');
48+
console.log(
49+
'See: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases'
50+
);
51+
break;
5052
}

config/env.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,36 @@
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
20-
.keys(process.env)
18+
const raw = Object.keys(process.env)
2119
.filter(key => REACT_APP.test(key))
22-
.reduce((env, key) => {
23-
env[key] = process.env[key];
24-
return env;
25-
}, {
26-
// Useful for determining whether we’re running in production mode.
27-
// Most importantly, it switches React into the correct mode.
28-
'NODE_ENV': process.env.NODE_ENV || 'development',
29-
// Useful for resolving the correct path to static assets in `public`.
30-
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
31-
// This should only be used as an escape hatch. Normally you would put
32-
// images into the `src` and `import` them in code to get their paths.
33-
'PUBLIC_URL': publicUrl
34-
});
20+
.reduce(
21+
(env, key) => {
22+
env[key] = process.env[key];
23+
return env;
24+
},
25+
{
26+
// Useful for determining whether we’re running in production mode.
27+
// Most importantly, it switches React into the correct mode.
28+
NODE_ENV: process.env.NODE_ENV || 'development',
29+
// Useful for resolving the correct path to static assets in `public`.
30+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
31+
// This should only be used as an escape hatch. Normally you would put
32+
// images into the `src` and `import` them in code to get their paths.
33+
PUBLIC_URL: publicUrl,
34+
}
35+
);
3536
// Stringify all values so we can feed into Webpack DefinePlugin
36-
var stringified = {
37-
'process.env': Object
38-
.keys(raw)
39-
.reduce((env, key) => {
37+
const stringified = {
38+
'process.env': Object.keys(raw).reduce(
39+
(env, key) => {
4040
env[key] = JSON.stringify(raw[key]);
4141
return env;
42-
}, {})
42+
},
43+
{}
44+
),
4345
};
4446

4547
return { raw, stringified };

config/jest/babelTransform.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
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');
1312

1413
module.exports = babelJest.createTransformer({
1514
presets: [require.resolve('babel-preset-react-app')],
16-
babelrc: false
15+
babelrc: false,
1716
});

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
};

config/paths.js

+20-17
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,10 +66,9 @@ 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 || (
71-
publicUrl ? url.parse(publicUrl).pathname : '/'
72-
);
69+
const publicUrl = getPublicUrl(appPackageJson);
70+
const servedUrl = envPublicUrl ||
71+
(publicUrl ? url.parse(publicUrl).pathname : '/');
7372
return ensureSlash(servedUrl, true);
7473
}
7574

@@ -86,7 +85,7 @@ module.exports = {
8685
appNodeModules: resolveApp('node_modules'),
8786
nodePaths: nodePaths,
8887
publicUrl: getPublicUrl(resolveApp('package.json')),
89-
servedPath: getServedPath(resolveApp('package.json'))
88+
servedPath: getServedPath(resolveApp('package.json')),
9089
};
9190

9291
// @remove-on-eject-begin
@@ -114,12 +113,16 @@ module.exports = {
114113
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
115114
};
116115

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

121121
// config before publish: we're in ./packages/react-scripts/config/
122-
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
122+
if (
123+
!reactScriptsLinked &&
124+
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
125+
) {
123126
module.exports = {
124127
appPath: resolveApp('.'),
125128
appBuild: resolveOwn('../../build'),

0 commit comments

Comments
 (0)