Skip to content

Commit c6d5c92

Browse files
authored
Merge pull request #2 from xiaohu-developer/master
update create-react-app
2 parents 5029aed + 6302f9d commit c6d5c92

28 files changed

+523
-262
lines changed

Diff for: .travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ cache:
99
- packages/create-react-app/node_modules
1010
- packages/react-scripts/node_modules
1111
script: tasks/e2e.sh
12+
env:
13+
- USE_YARN=no
14+
- USE_YARN=yes

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ and then run `npm start` or `npm run build`.
6868
6. Make sure to include “Migrating from ...” instructions for the previous release. Often you can copy and paste them.
6969
7. After merging the changelog update, create a GitHub Release with the same text. See previous Releases for inspiration.
7070
8. **Do not run `npm publish`. Instead, run `npm run publish`.**
71-
9. Wait for a long time, and it will get published. Don’t worry that it’s stuck. It will bundle dependencies into a single tarball before publishing for faster installs. In the end the publish script will prompt for versions before publishing the packages.
71+
9. Wait for a long time, and it will get published. Don’t worry that it’s stuck. In the end the publish script will prompt for versions before publishing the packages.
7272

7373
Make sure to test the released version! If you want to be extra careful, you can publish a prerelease by running `npm run publish -- --tag next` instead of `npm run publish`.
7474

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ The [User Guide](https://github.com/facebookincubator/create-react-app/blob/mast
109109
- [Post-Processing CSS](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#post-processing-css)
110110
- [Adding Images and Fonts](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-images-and-fonts)
111111
- [Using the `public` Folder](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#using-the-public-folder)
112+
- [Using Global Variables](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#using-global-variables)
112113
- [Adding Bootstrap](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-bootstrap)
113114
- [Adding Flow](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-flow)
114115
- [Adding Custom Environment Variables](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables)
@@ -118,7 +119,9 @@ The [User Guide](https://github.com/facebookincubator/create-react-app/blob/mast
118119
- [Using HTTPS in Development](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#using-https-in-development)
119120
- [Generating Dynamic `<meta>` Tags on the Server](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#generating-dynamic-meta-tags-on-the-server)
120121
- [Running Tests](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests)
122+
- [Developing Components in Isolation](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#developing-components-in-isolation)
121123
- [Deployment](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment)
124+
- [Troubleshooting](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#troubleshooting)
122125

123126
A copy of the user guide will be created as `README.md` in your project folder.
124127

@@ -130,7 +133,7 @@ Please refer to the [User Guide](https://github.com/facebookincubator/create-rea
130133

131134
* **One Dependency:** There is just one build dependency. It uses Webpack, Babel, ESLint, and other amazing projects, but provides a cohesive curated experience on top of them.
132135

133-
* **Zero Configuration:** There are no configuration files or command line options. Configuring both development and production builds is handled for you so you can focus on writing code.
136+
* **Convention over Configuration:** You don't need to configure anything by default. Reasonably good configuration of both development and production builds is handled for you so you can focus on writing code.
134137

135138
* **No Lock-In:** You can “eject” to a custom setup at any time. Run a single command, and all the configuration and build dependencies will be moved directly into your project, so you can pick up right where you left off.
136139

@@ -206,6 +209,7 @@ Some of the more popular and actively maintained ones are:
206209
* [mozilla/neo](https://github.com/mozilla/neo)
207210
* [NYTimes/kyt](https://github.com/NYTimes/kyt)
208211
* [zeit/next.js](https://github.com/zeit/next.js)
212+
* [gatsbyjs/gatsby](https://github.com/gatsbyjs/gatsby)
209213

210214
Notable alternatives also include:
211215

Diff for: packages/babel-preset-react-app/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ Then create a file named `.babelrc` with following contents in the root folder o
2323
"presets": ["react-app"]
2424
}
2525
```
26+
27+
This preset uses the `useBuiltIns` option with [transform-object-rest-spread](http://babeljs.io/docs/plugins/transform-object-rest-spread/) and [transform-react-jsx](http://babeljs.io/docs/plugins/transform-react-jsx/), which assumes that `Object.assign` is available or polyfilled.

Diff for: packages/babel-preset-react-app/index.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ var path = require('path');
1313
const plugins = [
1414
// class { handleClick = () => { } }
1515
require.resolve('babel-plugin-transform-class-properties'),
16+
// The following two plugins use Object.assign directly, instead of Babel's
17+
// extends helper. Note that this assumes `Object.assign` is available.
1618
// { ...todo, completed: true }
17-
require.resolve('babel-plugin-transform-object-rest-spread'),
19+
[require.resolve('babel-plugin-transform-object-rest-spread'), {
20+
useBuiltIns: true
21+
}],
22+
// Transforms JSX
23+
[require.resolve('babel-plugin-transform-react-jsx'), {
24+
useBuiltIns: true
25+
}],
1826
// function* () { yield 42; yield 43; }
1927
[require.resolve('babel-plugin-transform-regenerator'), {
2028
// Async functions are converted to generators by babel-preset-latest
@@ -27,15 +35,7 @@ const plugins = [
2735
regenerator: true,
2836
// Resolve the Babel runtime relative to the config.
2937
moduleName: path.dirname(require.resolve('babel-runtime/package'))
30-
}],
31-
// The following two plugins are currently necessary to get
32-
// babel-preset-env to work with rest/spread. More info here:
33-
// https://github.com/babel/babel-preset-env#caveats
34-
// https://github.com/babel/babel/issues/4074
35-
// const { a, ...z } = obj;
36-
require.resolve('babel-plugin-transform-es2015-destructuring'),
37-
// const fn = ({ a, ...otherProps }) => otherProps;
38-
require.resolve('babel-plugin-transform-es2015-parameters')
38+
}]
3939
];
4040

4141
// This is similar to how `env` works in Babel:
@@ -54,6 +54,12 @@ if (env !== 'development' && env !== 'test' && env !== 'production') {
5454
}
5555

5656
if (env === 'development' || env === 'test') {
57+
// The following two plugins are currently necessary to make React warnings
58+
// include more valuable information. They are included here because they are
59+
// currently not enabled in babel-preset-react. See the below threads for more info:
60+
// https://github.com/babel/babel/issues/4702
61+
// https://github.com/babel/babel/pull/3540#issuecomment-228673661
62+
// https://github.com/facebookincubator/create-react-app/issues/989
5763
plugins.push.apply(plugins, [
5864
// Adds component stack to warning messages
5965
require.resolve('babel-plugin-transform-react-jsx-source'),
@@ -68,7 +74,7 @@ if (env === 'test') {
6874
// ES features necessary for user's Node version
6975
[require('babel-preset-env').default, {
7076
targets: {
71-
node: parseFloat(process.versions.node),
77+
node: 'current',
7278
},
7379
}],
7480
// JSX, Flow
@@ -99,4 +105,3 @@ if (env === 'test') {
99105
// ]);
100106
}
101107
}
102-

Diff for: packages/babel-preset-react-app/package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
],
1313
"dependencies": {
1414
"babel-plugin-transform-class-properties": "6.16.0",
15-
"babel-plugin-transform-es2015-destructuring": "6.16.0",
16-
"babel-plugin-transform-es2015-parameters": "6.17.0",
17-
"babel-plugin-transform-object-rest-spread": "6.16.0",
15+
"babel-plugin-transform-object-rest-spread": "6.19.0",
1816
"babel-plugin-transform-react-constant-elements": "6.9.1",
17+
"babel-plugin-transform-react-jsx": "6.8.0",
1918
"babel-plugin-transform-react-jsx-self": "6.11.0",
2019
"babel-plugin-transform-react-jsx-source": "6.9.0",
2120
"babel-plugin-transform-regenerator": "6.16.1",
2221
"babel-plugin-transform-runtime": "6.15.0",
23-
"babel-preset-env": "0.0.6",
22+
"babel-preset-env": "0.0.8",
2423
"babel-preset-latest": "6.16.0",
2524
"babel-preset-react": "6.16.0",
2625
"babel-runtime": "6.11.6"

Diff for: packages/create-react-app/index.js

+40-12
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,54 @@ function createApp(name, verbose, version) {
101101
process.chdir(root);
102102

103103
console.log('Installing packages. This might take a couple minutes.');
104-
console.log('Installing react-scripts from npm...');
104+
console.log('Installing react-scripts...');
105105
console.log();
106106

107107
run(root, appName, version, verbose, originalDirectory);
108108
}
109109

110-
function run(root, appName, version, verbose, originalDirectory) {
111-
var installPackage = getInstallPackage(version);
112-
var packageName = getPackageName(installPackage);
110+
function install(packageToInstall, verbose, callback) {
113111
var args = [
114-
'install',
115-
verbose && '--verbose',
116-
'--save-dev',
117-
'--save-exact',
118-
installPackage,
119-
].filter(function(e) { return e; });
120-
var proc = spawn('npm', args, {stdio: 'inherit'});
112+
'add',
113+
'--dev',
114+
'--exact',
115+
packageToInstall,
116+
];
117+
var proc = spawn('yarn', args, {stdio: 'inherit'});
118+
119+
var yarnExists = true;
120+
proc.on('error', function (err) {
121+
if (err.code === 'ENOENT') {
122+
yarnExists = false;
123+
}
124+
});
121125
proc.on('close', function (code) {
126+
if (yarnExists) {
127+
callback(code, 'yarn', args);
128+
return;
129+
}
130+
// No Yarn installed, continuing with npm.
131+
args = [
132+
'install',
133+
verbose && '--verbose',
134+
'--save-dev',
135+
'--save-exact',
136+
packageToInstall,
137+
].filter(function(e) { return e; });
138+
var npmProc = spawn('npm', args, {stdio: 'inherit'});
139+
npmProc.on('close', function (code) {
140+
callback(code, 'npm', args);
141+
});
142+
});
143+
}
144+
145+
function run(root, appName, version, verbose, originalDirectory) {
146+
var packageToInstall = getInstallPackage(version);
147+
var packageName = getPackageName(packageToInstall);
148+
149+
install(packageToInstall, verbose, function (code, command, args) {
122150
if (code !== 0) {
123-
console.error('`npm ' + args.join(' ') + '` failed');
151+
console.error('`' + command + ' ' + args.join(' ') + '` failed');
124152
return;
125153
}
126154

Diff for: packages/eslint-config-react-app/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ module.exports = {
4343

4444
settings: {
4545
'import/ignore': [
46-
'node_modules',
47-
'\\.(json|css|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$',
46+
'node_modules'
4847
],
4948
'import/extensions': ['.js'],
5049
'import/resolver': {

Diff for: packages/react-dev-utils/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ compiler.plugin('done', function(stats) {
142142
});
143143
```
144144

145+
#### `getProcessForPort(port: number): string`
146+
147+
Finds the currently running process on `port`.
148+
Returns a string containing the name and directory, e.g.,
149+
150+
```
151+
create-react-app
152+
in /Users/developer/create-react-app
153+
```
154+
155+
```js
156+
var getProcessForPort = require('react-dev-utils/getProcessForPort');
157+
158+
getProcessForPort(3000);
159+
```
160+
145161
#### `openBrowser(url: string): boolean`
146162

147163
Attempts to open the browser with a given URL.

Diff for: packages/react-dev-utils/getProcessForPort.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var chalk = require('chalk');
2+
var execSync = require('child_process').execSync;
3+
var path = require('path');
4+
5+
var execOptions = {
6+
encoding: 'utf8',
7+
stdio: [
8+
'pipe', // stdin (default)
9+
'pipe', // stdout (default)
10+
'ignore' //stderr
11+
]
12+
};
13+
14+
function isProcessAReactApp(processCommand) {
15+
return /^node .*react-scripts\/scripts\/start\.js\s?$/.test(processCommand);
16+
}
17+
18+
function getProcessIdOnPort(port) {
19+
return execSync('lsof -i:' + port + ' -P -t -sTCP:LISTEN', execOptions).trim();
20+
}
21+
22+
function getPackageNameInDirectory(directory) {
23+
var packagePath = path.join(directory.trim(), 'package.json');
24+
25+
try {
26+
return require(packagePath).name;
27+
} catch(e) {
28+
return null;
29+
}
30+
31+
}
32+
33+
function getProcessCommand(processId, processDirectory) {
34+
var command = execSync('ps -o command -p ' + processId + ' | sed -n 2p', execOptions);
35+
36+
if (isProcessAReactApp(command)) {
37+
const packageName = getPackageNameInDirectory(processDirectory);
38+
return (packageName) ? packageName + '\n' : command;
39+
} else {
40+
return command;
41+
}
42+
43+
}
44+
45+
function getDirectoryOfProcessById(processId) {
46+
return execSync('lsof -p '+ processId + ' | grep cwd | awk \'{print $9}\'', execOptions).trim();
47+
}
48+
49+
function getProcessForPort(port) {
50+
try {
51+
var processId = getProcessIdOnPort(port);
52+
var directory = getDirectoryOfProcessById(processId);
53+
var command = getProcessCommand(processId, directory);
54+
return chalk.cyan(command) + chalk.blue(' in ') + chalk.cyan(directory);
55+
} catch(e) {
56+
return null;
57+
}
58+
}
59+
60+
module.exports = getProcessForPort;
61+

Diff for: packages/react-dev-utils/openBrowser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function openBrowser(url) {
2828
// Fallback to opn
2929
// (It will always open new tab)
3030
try {
31-
opn(url);
31+
opn(url).catch(() => {}); // Prevent `unhandledRejection` error.
3232
return true;
3333
} catch (err) {
3434
return false;

Diff for: packages/react-dev-utils/openChrome.applescript

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on run argv
2323
set theTabIndex to 0
2424
repeat with theTab in every tab of theWindow
2525
set theTabIndex to theTabIndex + 1
26-
if theTab's URL is theURL then
26+
if theTab's URL as string contains theURL then
2727
set found to true
2828
exit repeat
2929
end if
@@ -38,6 +38,7 @@ on run argv
3838
tell theTab to reload
3939
set index of theWindow to 1
4040
set theWindow's active tab index to theTabIndex
41+
tell theWindow to activate
4142
else
4243
tell window 1
4344
activate

Diff for: packages/react-dev-utils/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"clearConsole.js",
1515
"checkRequiredFiles.js",
1616
"formatWebpackMessages.js",
17+
"getProcessForPort.js",
1718
"InterpolateHtmlPlugin.js",
1819
"openChrome.applescript",
1920
"openBrowser.js",
@@ -29,8 +30,5 @@
2930
"opn": "4.0.2",
3031
"sockjs-client": "1.0.3",
3132
"strip-ansi": "3.0.1"
32-
},
33-
"peerDependencies": {
34-
"webpack": "^1.13.2"
3533
}
3634
}

Diff for: packages/react-scripts/config/jest/transform.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
const babelJest = require('babel-jest');
1010

1111
module.exports = babelJest.createTransformer({
12-
presets: [require.resolve('babel-preset-react-app')]
12+
presets: [require.resolve('babel-preset-react-app')],
13+
babelrc: false
1314
});

Diff for: packages/react-scripts/config/paths.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
appIndexJs: resolveApp('src/index.js'),
4444
appPackageJson: resolveApp('package.json'),
4545
appSrc: resolveApp('src'),
46+
yarnLockFile: resolveApp('yarn.lock'),
4647
testsSetup: resolveApp('src/setupTests.js'),
4748
appNodeModules: resolveApp('node_modules'),
4849
ownNodeModules: resolveApp('node_modules'),
@@ -62,13 +63,13 @@ module.exports = {
6263
appIndexJs: resolveApp('src/index.js'),
6364
appPackageJson: resolveApp('package.json'),
6465
appSrc: resolveApp('src'),
66+
yarnLockFile: resolveApp('yarn.lock'),
6567
testsSetup: resolveApp('src/setupTests.js'),
6668
appNodeModules: resolveApp('node_modules'),
6769
// this is empty with npm3 but node resolution searches higher anyway:
6870
ownNodeModules: resolveOwn('../node_modules'),
6971
nodePaths: nodePaths
7072
};
71-
// @remove-on-eject-end
7273

7374
// config before publish: we're in ./packages/react-scripts/config/
7475
if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
@@ -79,9 +80,11 @@ if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1)
7980
appIndexJs: resolveOwn('../template/src/index.js'),
8081
appPackageJson: resolveOwn('../package.json'),
8182
appSrc: resolveOwn('../template/src'),
83+
yarnLockFile: resolveOwn('../template/yarn.lock'),
8284
testsSetup: resolveOwn('../template/src/setupTests.js'),
8385
appNodeModules: resolveOwn('../node_modules'),
8486
ownNodeModules: resolveOwn('../node_modules'),
8587
nodePaths: nodePaths
8688
};
8789
}
90+
// @remove-on-eject-end

0 commit comments

Comments
 (0)