Skip to content

Commit 002acf5

Browse files
committed
# By Dan Abramov (2) and others # Via Dan Abramov * 'master' of https://github.com/facebookincubator/create-react-app: Correct a comment mistype in webpack production config (facebook#855) load setupTests file at setupTestFramework stage (facebook#846) Spell check (facebook#845) Tweak readme Update instructions on publishing to GitHub pages (facebook#841) Make webpackHotDevClient support webpack 2 too (facebook#840) Tweak eject output Promote "React must be in scope" to be an error (facebook#822) Fix script name to open chrome (facebook#831)
2 parents 6727a98 + 5c3ab84 commit 002acf5

File tree

9 files changed

+68
-40
lines changed

9 files changed

+68
-40
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ module.exports = {
196196
'react/no-deprecated': 'warn',
197197
'react/no-direct-mutation-state': 'warn',
198198
'react/no-is-mounted': 'warn',
199-
'react/react-in-jsx-scope': 'warn',
199+
'react/react-in-jsx-scope': 'error',
200200
'react/require-render-return': 'warn',
201201
'react/style-prop-object': 'warn',
202202

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function openBrowser(url) {
1717
// on OS X Google Chrome with AppleScript
1818
execSync('ps cax | grep "Google Chrome"');
1919
execSync(
20-
'osascript chrome.applescript ' + url,
20+
'osascript openChrome.applescript ' + url,
2121
{cwd: __dirname, stdio: 'ignore'}
2222
);
2323
return true;

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
272272
return;
273273
}
274274

275-
// https://webpack.github.io/docs/hot-module-replacement.html#check
276-
module.hot.check(/* autoApply */true, function(err, updatedModules) {
275+
function handleApplyUpdates(err, updatedModules) {
277276
if (err || !updatedModules) {
278277
window.location.reload();
279278
return;
@@ -288,5 +287,20 @@ function tryApplyUpdates(onHotUpdateSuccess) {
288287
// While we were updating, there was a new update! Do it again.
289288
tryApplyUpdates();
290289
}
291-
});
290+
}
291+
292+
// https://webpack.github.io/docs/hot-module-replacement.html#check
293+
var result = module.hot.check(/* autoApply */true, handleApplyUpdates);
294+
295+
// // Webpack 2 returns a Promise instead of invoking a callback
296+
if (result && result.then) {
297+
result.then(
298+
function(updatedModules) {
299+
handleApplyUpdates(null, updatedModules);
300+
},
301+
function(err) {
302+
handleApplyUpdates(err, null);
303+
}
304+
);
305+
}
292306
};

Diff for: packages/react-scripts/config/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var homepagePathname = homepagePath ? url.parse(homepagePath).pathname : '/';
4343
var publicPath = ensureSlash(homepagePathname, true);
4444
// `publicUrl` is just like `publicPath`, but we will provide it to our app
4545
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
46-
// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
46+
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
4747
var publicUrl = ensureSlash(homepagePathname, false);
4848
// Get environment variables to inject into our app.
4949
var env = getClientEnvironment(publicUrl);

Diff for: packages/react-scripts/scripts/build.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,19 @@ function build(previousSizeMap) {
147147
console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
148148
console.log('To publish it at ' + chalk.green(homepagePath) + ', run:');
149149
console.log();
150-
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Save local changes"'));
151-
console.log(' ' + chalk.cyan('git') + ' checkout -B gh-pages');
152-
console.log(' ' + chalk.cyan('git') + ' add -f build');
153-
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Rebuild website"'));
154-
console.log(' ' + chalk.cyan('git') + ' filter-branch -f --prune-empty --subdirectory-filter build');
155-
console.log(' ' + chalk.cyan('git') + ' push -f origin gh-pages');
156-
console.log(' ' + chalk.cyan('git') + ' checkout -');
150+
console.log(' ' + chalk.cyan('npm') + ' install --save-dev gh-pages');
151+
console.log();
152+
console.log('Add the following script in your ' + chalk.cyan('package.json') + '.');
153+
console.log();
154+
console.log(' ' + chalk.dim('// ...'));
155+
console.log(' ' + chalk.yellow('"scripts"') + ': {');
156+
console.log(' ' + chalk.dim('// ...'));
157+
console.log(' ' + chalk.yellow('"deploy"') + ': ' + chalk.yellow('"gh-pages -d build"'));
158+
console.log(' }');
159+
console.log();
160+
console.log('Then run:');
161+
console.log();
162+
console.log(' ' + chalk.cyan('npm') + ' run deploy');
157163
console.log();
158164
} else if (publicPath !== '/') {
159165
// "homepage": "http://mywebsite.com/project"

Diff for: packages/react-scripts/scripts/eject.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ prompt(
6464
fs.mkdirSync(path.join(appPath, 'scripts'));
6565

6666
console.log();
67-
console.log('Copying files to ' + cyan(appPath));
67+
console.log(cyan('Copying files into ' + appPath));
6868
files.forEach(function(file) {
69-
console.log(' Copying ' + cyan(file));
69+
console.log(' Adding ' + cyan(file) + ' to the project');
7070
var content = fs
7171
.readFileSync(path.join(ownPath, file), 'utf8')
7272
// Remove dead code from .js files on eject
@@ -83,35 +83,35 @@ prompt(
8383
var babelConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.babelrc'), 'utf8'));
8484
var eslintConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.eslintrc'), 'utf8'));
8585

86-
console.log(cyan('Updating dependencies...'));
86+
console.log(cyan('Updating the dependencies'));
8787
var ownPackageName = ownPackage.name;
88-
console.log(' Removing dependency: ' + cyan(ownPackageName));
88+
console.log(' Removing ' + cyan(ownPackageName) + ' from devDependencies');
8989
delete appPackage.devDependencies[ownPackageName];
9090

9191
Object.keys(ownPackage.dependencies).forEach(function (key) {
9292
// For some reason optionalDependencies end up in dependencies after install
9393
if (ownPackage.optionalDependencies[key]) {
9494
return;
9595
}
96-
console.log(' Adding dependency: ' + cyan(key));
96+
console.log(' Adding ' + cyan(key) + ' to devDependencies');
9797
appPackage.devDependencies[key] = ownPackage.dependencies[key];
9898
});
9999
console.log();
100-
console.log(cyan('Updating scripts...'));
100+
console.log(cyan('Updating the scripts'));
101101
delete appPackage.scripts['eject'];
102102
Object.keys(appPackage.scripts).forEach(function (key) {
103103
appPackage.scripts[key] = appPackage.scripts[key]
104104
.replace(/react-scripts (\w+)/g, 'node scripts/$1.js');
105105
console.log(
106106
' Replacing ' +
107-
cyan('\"react-scripts ' + key + '\"') +
107+
cyan('"react-scripts ' + key + '"') +
108108
' with ' +
109-
cyan('\"' + appPackage.scripts[key] + '\"')
109+
cyan('"node scripts/' + key + '.js"')
110110
);
111111
});
112112

113113
console.log();
114-
console.log(cyan('Adding configuration to ') + 'package.json' + cyan('...'));
114+
console.log(cyan('Configuring package.json'));
115115
// Add Jest config
116116
console.log(' Adding ' + cyan('Jest') + ' configuration');
117117
appPackage.jest = createJestConfig(

Diff for: packages/react-scripts/template/README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,29 @@ Open your `package.json` and add a `homepage` field:
885885
**The above step is important!**<br>
886886
Create React App uses the `homepage` field to determine the root URL in the built HTML file.
887887
888-
Now, whenever you run `npm run build`, you will see a cheat sheet with a sequence of commands to deploy to GitHub pages:
888+
Now, whenever you run `npm run build`, you will see a cheat sheet with instructions on how to deploy to GitHub pages.
889+
890+
To publish it at [http://myusername.github.io/my-app](http://myusername.github.io/my-app), run:
889891
890892
```sh
891-
git commit -am "Save local changes"
892-
git checkout -B gh-pages
893-
git add -f build
894-
git commit -am "Rebuild website"
895-
git filter-branch -f --prune-empty --subdirectory-filter build
896-
git push -f origin gh-pages
897-
git checkout -
893+
npm install --save-dev gh-pages
894+
```
895+
896+
Add the following script in your `package.json`:
897+
898+
```js
899+
// ...
900+
"scripts": {
901+
// ...
902+
"deploy": "gh-pages -d build"
903+
}
898904
```
899905
900-
You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.
906+
Then run:
907+
908+
```sh
909+
npm run deploy
910+
```
901911
902912
Note that GitHub Pages doesn't support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is because when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions:
903913
* You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#histories) about different history implementations in React Router.
@@ -931,7 +941,7 @@ With this setup Netlify will build and deploy when you push to git or open a pul
931941
2. Pick your Git hosting service and select your repository
932942
3. Click `Build your site`
933943
934-
**Support for client site routing:**
944+
**Support for client-side routing:**
935945
936946
To support `pushState`, make sure to create a `public/_redirects` file with the following rewrite rules:
937947

Diff for: packages/react-scripts/template/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
It will be replaced with the URL of the `public` folder during the build.
1010
Only files inside the `public` folder can be referenced from the HTML.
1111
12-
Unlike "/favicon.ico" or "favico.ico", "%PUBLIC_URL%/favicon.ico" will
12+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
1313
work correctly both with client-side routing and a non-root public URL.
1414
Learn how to configure a non-root public URL by running `npm run build`.
1515
-->

Diff for: packages/react-scripts/utils/createJestConfig.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ const pathExists = require('path-exists');
1313
const paths = require('../config/paths');
1414

1515
module.exports = (resolve, rootDir, isEjecting) => {
16-
const setupFiles = [resolve('config/polyfills.js')];
17-
if (pathExists.sync(paths.testsSetup)) {
18-
// Use this instead of `paths.testsSetup` to avoid putting
19-
// an absolute filename into configuration after ejecting.
20-
setupFiles.push('<rootDir>/src/setupTests.js');
21-
}
16+
// Use this instead of `paths.testsSetup` to avoid putting
17+
// an absolute filename into configuration after ejecting.
18+
const setupTestsFile = pathExists.sync(paths.testsSetup) ? '<rootDir>/src/setupTests.js' : undefined;
2219

2320
const config = {
2421
moduleFileExtensions: ['jsx', 'js', 'json'],
2522
moduleNameMapper: {
2623
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': resolve('config/jest/FileStub.js'),
2724
'^.+\\.css$': resolve('config/jest/CSSStub.js')
2825
},
29-
setupFiles: setupFiles,
26+
setupFiles: [resolve('config/polyfills.js')],
27+
setupTestFrameworkScriptFile: setupTestsFile,
3028
testPathIgnorePatterns: ['<rootDir>/(build|docs|node_modules)/'],
3129
testEnvironment: 'node',
3230
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(js|jsx)$',

0 commit comments

Comments
 (0)