Skip to content

Commit 7747830

Browse files
committed
Merge pull request #2
* pull2: Support Yarn (facebook#898) Fix chrome tab reuse (facebook#1035) Remove unnecessary transform plugins for object spread to work (facebook#1052) Clears the usage of react-jsx-source & react-jsx-self (facebook#992) Update babel-present-env and use node: 'current' as target (facebook#1051) Remove redundant `function` from export statement (facebook#996) Add Gatsby to alternatives (facebook#995) Allow webpack 2 as peerDependency in react-dev-utils (facebook#963) Remove custom babel-loader cache dir config (facebook#983) Check for presence of folders before continuing eject. Closes facebook#939. (facebook#951) Fixes facebook#952 (facebook#953) Always build before deploying to gh-pages (facebook#959) Add collectCoverageFrom option to collect coverage on files without any tests. (facebook#961) Catch and noop call to open web browser. (facebook#964) Gently nudge users towards https by default (facebook#974) Enable compression on webpack-dev-server (facebook#966) (facebook#968) Add next.js to Alternatives Point people to npm Windows instructions Encourage people to try recent npm # Conflicts: # packages/react-scripts/config/webpack.config.dev.js # packages/react-scripts/package.json # packages/react-scripts/utils/createJestConfig.js
2 parents 0017b5d + bcc469c commit 7747830

File tree

20 files changed

+185
-86
lines changed

20 files changed

+185
-86
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
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

ISSUE_TEMPLATE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.
22

3+
### Can you reproduce the problem with latest npm?
4+
5+
Many errors, especially related to "missing modules", are due to npm bugs.
6+
7+
If you're using Windows, [follow these instructions to update npm](https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows).
8+
9+
If you're using OS X or Linux, run this to update npm:
10+
11+
```
12+
npm install -g npm@latest
13+
14+
cd your_project_directory
15+
rm -rf node_modules
16+
npm install
17+
```
18+
19+
Then try to reproduce the issue again.
20+
21+
Can you still reproduce it?
22+
323
### Description
424

525
What are you reporting?

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ Some of the more popular and actively maintained ones are:
205205
* [insin/nwb](https://github.com/insin/nwb)
206206
* [mozilla/neo](https://github.com/mozilla/neo)
207207
* [NYTimes/kyt](https://github.com/NYTimes/kyt)
208+
* [zeit/next.js](https://github.com/zeit/next.js)
209+
* [gatsbyjs/gatsby](https://github.com/gatsbyjs/gatsby)
208210

209211
Notable alternatives also include:
210212

packages/babel-preset-react-app/index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ const plugins = [
2727
regenerator: true,
2828
// Resolve the Babel runtime relative to the config.
2929
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')
30+
}]
3931
];
4032

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

5648
if (env === 'development' || env === 'test') {
49+
// The following two plugins are currently necessary to make React warnings
50+
// include more valuable information. They are included here because they are
51+
// currently not enabled in babel-preset-react. See the below threads for more info:
52+
// https://github.com/babel/babel/issues/4702
53+
// https://github.com/babel/babel/pull/3540#issuecomment-228673661
54+
// https://github.com/facebookincubator/create-react-app/issues/989
5755
plugins.push.apply(plugins, [
5856
// Adds component stack to warning messages
5957
require.resolve('babel-plugin-transform-react-jsx-source'),
@@ -68,7 +66,7 @@ if (env === 'test') {
6866
// ES features necessary for user's Node version
6967
[require('babel-preset-env').default, {
7068
targets: {
71-
node: parseFloat(process.versions.node),
69+
node: 'current',
7270
},
7371
}],
7472
// JSX, Flow
@@ -99,4 +97,3 @@ if (env === 'test') {
9997
// ]);
10098
}
10199
}
102-

packages/babel-preset-react-app/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
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",
1917
"babel-plugin-transform-react-jsx-self": "6.11.0",
2018
"babel-plugin-transform-react-jsx-source": "6.9.0",
2119
"babel-plugin-transform-regenerator": "6.16.1",
2220
"babel-plugin-transform-runtime": "6.15.0",
23-
"babel-preset-env": "0.0.6",
21+
"babel-preset-env": "0.0.8",
2422
"babel-preset-latest": "6.16.0",
2523
"babel-preset-react": "6.16.0",
2624
"babel-runtime": "6.11.6"

packages/create-react-app/index.js

Lines changed: 40 additions & 12 deletions
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

packages/eslint-config-react-app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
settings: {
4545
'import/ignore': [
4646
'node_modules',
47-
'\\.(json|css|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$',
47+
'\\.(json|css|ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$',
4848
],
4949
'import/extensions': ['.js'],
5050
'import/resolver': {

packages/react-dev-utils/openBrowser.js

Lines changed: 1 addition & 1 deletion
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;

packages/react-dev-utils/openChrome.applescript

Lines changed: 2 additions & 1 deletion
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

packages/react-dev-utils/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,5 @@
2929
"opn": "4.0.2",
3030
"sockjs-client": "1.0.3",
3131
"strip-ansi": "3.0.1"
32-
},
33-
"peerDependencies": {
34-
"webpack": "^1.13.2"
3532
}
3633
}

packages/react-scripts/config/paths.js

Lines changed: 3 additions & 0 deletions
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,6 +63,7 @@ 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:
@@ -80,6 +82,7 @@ if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1)
8082
appIndexJs: resolveOwn('../template/src/index.js'),
8183
appPackageJson: resolveOwn('../package.json'),
8284
appSrc: resolveOwn('../template/src'),
85+
yarnLockFile: resolveOwn('../template/yarn.lock'),
8386
testsSetup: resolveOwn('../template/src/setupTests.js'),
8487
appNodeModules: resolveOwn('../node_modules'),
8588
ownNodeModules: resolveOwn('../node_modules'),

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var webpack = require('webpack');
1515
var nesting = require('postcss-nesting');
1616
var cssvariables = require('postcss-css-variables');
1717
var values = require('postcss-modules-values');
18-
var findCacheDir = require('find-cache-dir');
1918
var HtmlWebpackPlugin = require('html-webpack-plugin');
2019
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
2120
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
@@ -125,12 +124,9 @@ module.exports = {
125124
presets: [require.resolve('babel-preset-react-app')],
126125
// @remove-on-eject-end
127126
// This is a feature of `babel-loader` for webpack (not Babel itself).
128-
// It enables caching results in ./node_modules/.cache/react-scripts/
129-
// directory for faster rebuilds. We use findCacheDir() because of:
130-
// https://github.com/facebookincubator/create-react-app/issues/483
131-
cacheDirectory: findCacheDir({
132-
name: 'react-scripts'
133-
})
127+
// It enables caching results in ./node_modules/.cache/babel-loader/
128+
// directory for faster rebuilds.
129+
cacheDirectory: true
134130
}
135131
},
136132
{

packages/react-scripts/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"babel-core": "6.17.0",
2828
"babel-eslint": "7.0.0",
2929
"babel-jest": "16.0.0",
30-
"babel-loader": "6.2.5",
30+
"babel-loader": "6.2.7",
3131
"babel-plugin-transform-remove-console": "^6.8.0",
3232
"babel-preset-react-app": "^1.0.0",
3333
"case-sensitive-paths-webpack-plugin": "1.1.4",
@@ -48,7 +48,6 @@
4848
"extract-text-webpack-plugin": "1.0.1",
4949
"file-loader": "0.9.0",
5050
"filesize": "3.3.0",
51-
"find-cache-dir": "0.1.1",
5251
"fs-extra": "0.30.0",
5352
"gzip-size": "3.0.0",
5453
"html-webpack-plugin": "2.24.0",

packages/react-scripts/scripts/build.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require('dotenv').config({silent: true});
2121
var chalk = require('chalk');
2222
var fs = require('fs-extra');
2323
var path = require('path');
24+
var pathExists = require('path-exists');
2425
var filesize = require('filesize');
2526
var gzipSize = require('gzip-size').sync;
2627
var rimrafSync = require('rimraf').sync;
@@ -31,6 +32,8 @@ var checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
3132
var recursive = require('recursive-readdir');
3233
var stripAnsi = require('strip-ansi');
3334

35+
var useYarn = pathExists.sync(paths.yarnLockFile);
36+
3437
// Warn and crash if required files are missing
3538
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
3639
process.exit(1);
@@ -161,7 +164,11 @@ function build(previousSizeMap) {
161164
console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
162165
console.log('To publish it at ' + chalk.green(homepagePath) + ', run:');
163166
console.log();
164-
console.log(' ' + chalk.cyan('npm') + ' install --save-dev gh-pages');
167+
if (useYarn) {
168+
console.log(' ' + chalk.cyan('yarn') + ' add gh-pages');
169+
} else {
170+
console.log(' ' + chalk.cyan('npm') + ' install --save-dev gh-pages');
171+
}
165172
console.log();
166173
console.log('Add the following script in your ' + chalk.cyan('package.json') + '.');
167174
console.log();
@@ -173,7 +180,7 @@ function build(previousSizeMap) {
173180
console.log();
174181
console.log('Then run:');
175182
console.log();
176-
console.log(' ' + chalk.cyan('npm') + ' run deploy');
183+
console.log(' ' + chalk.cyan(useYarn ? 'yarn' : 'npm') + ' run deploy');
177184
console.log();
178185
} else if (publicPath !== '/') {
179186
// "homepage": "http://mywebsite.com/project"
@@ -200,7 +207,11 @@ function build(previousSizeMap) {
200207
console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
201208
console.log('You may also serve it locally with a static server:')
202209
console.log();
203-
console.log(' ' + chalk.cyan('npm') + ' install -g pushstate-server');
210+
if (useYarn) {
211+
console.log(' ' + chalk.cyan('yarn') + ' global add pushstate-server');
212+
} else {
213+
console.log(' ' + chalk.cyan('npm') + ' install -g pushstate-server');
214+
}
204215
console.log(' ' + chalk.cyan('pushstate-server') + ' build');
205216
console.log(' ' + chalk.cyan(openCommand) + ' http://localhost:9000');
206217
console.log();

0 commit comments

Comments
 (0)