mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-28 09:25:42 +08:00
update to modern code style (#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
This commit is contained in:
committed by
Dan Abramov
parent
43873dc9b8
commit
fe7b5c212b
37
packages/react-scripts/config/paths.js
vendored
37
packages/react-scripts/config/paths.js
vendored
@@ -10,13 +10,13 @@
|
||||
// @remove-on-eject-end
|
||||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var url = require('url');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const url = require('url');
|
||||
|
||||
// Make sure any symlinks in the project folder are resolved:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||
var appDirectory = fs.realpathSync(process.cwd());
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
function resolveApp(relativePath) {
|
||||
return path.resolve(appDirectory, relativePath);
|
||||
}
|
||||
@@ -36,20 +36,20 @@ function resolveApp(relativePath) {
|
||||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||
|
||||
var nodePaths = (process.env.NODE_PATH || '')
|
||||
const nodePaths = (process.env.NODE_PATH || '')
|
||||
.split(process.platform === 'win32' ? ';' : ':')
|
||||
.filter(Boolean)
|
||||
.filter(folder => !path.isAbsolute(folder))
|
||||
.map(resolveApp);
|
||||
|
||||
var envPublicUrl = process.env.PUBLIC_URL;
|
||||
const envPublicUrl = process.env.PUBLIC_URL;
|
||||
|
||||
function ensureSlash(path, needsSlash) {
|
||||
var hasSlash = path.endsWith('/');
|
||||
const hasSlash = path.endsWith('/');
|
||||
if (hasSlash && !needsSlash) {
|
||||
return path.substr(path, path.length - 1);
|
||||
} else if (!hasSlash && needsSlash) {
|
||||
return path + '/';
|
||||
return `${path}/`;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
@@ -66,10 +66,9 @@ function getPublicUrl(appPackageJson) {
|
||||
// We can't use a relative path in HTML because we don't want to load something
|
||||
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
||||
function getServedPath(appPackageJson) {
|
||||
var publicUrl = getPublicUrl(appPackageJson);
|
||||
var servedUrl = envPublicUrl || (
|
||||
publicUrl ? url.parse(publicUrl).pathname : '/'
|
||||
);
|
||||
const publicUrl = getPublicUrl(appPackageJson);
|
||||
const servedUrl = envPublicUrl ||
|
||||
(publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||
return ensureSlash(servedUrl, true);
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ module.exports = {
|
||||
appNodeModules: resolveApp('node_modules'),
|
||||
nodePaths: nodePaths,
|
||||
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||
servedPath: getServedPath(resolveApp('package.json'))
|
||||
servedPath: getServedPath(resolveApp('package.json')),
|
||||
};
|
||||
|
||||
// @remove-on-eject-begin
|
||||
@@ -114,12 +113,16 @@ module.exports = {
|
||||
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
|
||||
};
|
||||
|
||||
var ownPackageJson = require('../package.json');
|
||||
var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
||||
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
||||
const ownPackageJson = require('../package.json');
|
||||
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
|
||||
const reactScriptsLinked = fs.existsSync(reactScriptsPath) &&
|
||||
fs.lstatSync(reactScriptsPath).isSymbolicLink();
|
||||
|
||||
// config before publish: we're in ./packages/react-scripts/config/
|
||||
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
|
||||
if (
|
||||
!reactScriptsLinked &&
|
||||
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
|
||||
) {
|
||||
module.exports = {
|
||||
appPath: resolveApp('.'),
|
||||
appBuild: resolveOwn('../../build'),
|
||||
|
||||
Reference in New Issue
Block a user