Skip to content

Commit 6a92156

Browse files
committed
Offer to set default browsers (facebook#3792)
* Offer to set browser defaults * Catch error on no * Add ending newlines * Ensure we re-check to prevent defaults from leaking * Reduce nesting * Add defaults message * More explicit
1 parent 1c62ba7 commit 6a92156

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

Diff for: package.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,16 @@
7070
"fsevents": "1.1.2"
7171
},
7272
"browserslist": {
73-
"development": "last 2 chrome versions",
74-
"production": [">1%", "last 4 versions", "Firefox ESR", "not ie < 11"]
73+
"development": [
74+
"last 2 chrome versions",
75+
"last 2 firefox versions",
76+
"last 2 edge versions"
77+
],
78+
"production": [
79+
">1%",
80+
"last 4 versions",
81+
"Firefox ESR",
82+
"not ie < 11"
83+
]
7584
}
7685
}

Diff for: scripts/build.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ const printHostingInstructions = require('react-dev-utils/printHostingInstructio
4141
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
4242
const printBuildError = require('react-dev-utils/printBuildError');
4343
const { printBrowsers } = require('react-dev-utils/browsersHelper');
44-
// @remove-on-eject-begin
45-
// Require browsers to be specified before you eject
46-
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
47-
if (!checkBrowsers(paths.appPath)) {
48-
process.exit(1);
49-
}
50-
// @remove-on-eject-end
5144

5245
const measureFileSizesBeforeBuild =
5346
FileSizeReporter.measureFileSizesBeforeBuild;
@@ -63,9 +56,15 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
6356
process.exit(1);
6457
}
6558

66-
// First, read the current file sizes in build directory.
67-
// This lets us display how much they changed later.
68-
measureFileSizesBeforeBuild(paths.appBuild)
59+
// We require that you explictly set browsers and do not fall back to
60+
// browserslist defaults.
61+
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
62+
checkBrowsers(paths.appPath)
63+
.then(() => {
64+
// First, read the current file sizes in build directory.
65+
// This lets us display how much they changed later.
66+
return measureFileSizesBeforeBuild(paths.appBuild);
67+
})
6968
.then(previousFileSizes => {
7069
// Remove all content but keep the directory so that
7170
// if you're in it, you don't end up in Trash
@@ -122,7 +121,13 @@ measureFileSizesBeforeBuild(paths.appBuild)
122121
printBuildError(err);
123122
process.exit(1);
124123
}
125-
);
124+
)
125+
.catch(err => {
126+
if (err && err.message) {
127+
console.log(err.message);
128+
}
129+
process.exit(1);
130+
});
126131

127132
// Create the production build and print the deployment instructions.
128133
function build(previousFileSizes) {

Diff for: scripts/eject.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const paths = require('../config/paths');
2222
const createJestConfig = require('./utils/createJestConfig');
2323
const inquirer = require('react-dev-utils/inquirer');
2424
const spawnSync = require('react-dev-utils/crossSpawn').sync;
25+
const os = require('os');
2526

2627
const green = chalk.green;
2728
const cyan = chalk.cyan;
@@ -218,7 +219,7 @@ inquirer
218219

219220
fs.writeFileSync(
220221
path.join(appPath, 'package.json'),
221-
JSON.stringify(appPackage, null, 2) + '\n'
222+
JSON.stringify(appPackage, null, 2) + os.EOL
222223
);
223224
console.log();
224225

Diff for: scripts/init.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const fs = require('fs-extra');
1818
const path = require('path');
1919
const chalk = require('chalk');
2020
const spawn = require('react-dev-utils/crossSpawn');
21+
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
22+
const os = require('os');
2123

2224
module.exports = function(
2325
appPath,
@@ -43,16 +45,11 @@ module.exports = function(
4345
eject: 'react-scripts eject',
4446
};
4547

46-
appPackage.browserslist = {
47-
development: ['chrome', 'firefox', 'edge'].map(
48-
browser => `last 2 ${browser} versions`
49-
),
50-
production: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 11'],
51-
};
48+
appPackage.browserslist = defaultBrowsers;
5249

5350
fs.writeFileSync(
5451
path.join(appPath, 'package.json'),
55-
JSON.stringify(appPackage, null, 2)
52+
JSON.stringify(appPackage, null, 2) + os.EOL
5653
);
5754

5855
const readmeExists = fs.existsSync(path.join(appPath, 'README.md'));

Diff for: scripts/start.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ const createDevServerConfig = require('../config/webpackDevServer.config');
4848

4949
const useYarn = fs.existsSync(paths.yarnLockFile);
5050
const isInteractive = process.stdout.isTTY;
51-
// @remove-on-eject-begin
52-
// Require browsers to be specified before you eject
53-
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
54-
if (!checkBrowsers(paths.appPath)) {
55-
process.exit(1);
56-
}
57-
// @remove-on-eject-end
5851

5952
// Warn and crash if required files are missing
6053
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
@@ -80,9 +73,15 @@ if (process.env.HOST) {
8073
console.log();
8174
}
8275

83-
// We attempt to use the default port but if it is busy, we offer the user to
84-
// run on a different port. `choosePort()` Promise resolves to the next free port.
85-
choosePort(HOST, DEFAULT_PORT)
76+
// We require that you explictly set browsers and do not fall back to
77+
// browserslist defaults.
78+
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
79+
checkBrowsers(paths.appPath)
80+
.then(() => {
81+
// We attempt to use the default port but if it is busy, we offer the user to
82+
// run on a different port. `choosePort()` Promise resolves to the next free port.
83+
return choosePort(HOST, DEFAULT_PORT);
84+
})
8685
.then(port => {
8786
if (port == null) {
8887
// We have not found a port.

0 commit comments

Comments
 (0)