Skip to content

Commit fa45985

Browse files
committed
# By Dan Abramov (5) and others # Via Dan Abramov * 'master' of https://github.com/facebookincubator/create-react-app: docs(readme): peer dependencies applied (facebook#818) Fix typos on ISSUE_TEMPLATE.md (facebook#817) Add explicit linebreaks (facebook#813) Fix typo (facebook#810) Fix some typos (facebook#809) Beaufity output of eject.js script (facebook#769) Define process.env as object (facebook#807) Typo fix in webpack.config.dev.js comments (facebook#777) Add Netlify to deploy instructions Fix usage example to match [email protected] API Relaxed eslint rule no-unused-expressions (facebook#724) Fix the doc Publish Add 0.6.1 changelog Moved Babel and ESLint config to package.json after ejecting (facebook#773) Conflicts: packages/react-scripts/package.json
2 parents f84d8b4 + 161c180 commit fa45985

File tree

9 files changed

+110
-57
lines changed

9 files changed

+110
-57
lines changed

config/env.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
var REACT_APP = /^REACT_APP_/i;
1616

1717
function getClientEnvironment(publicUrl) {
18-
return Object
18+
var processEnv = Object
1919
.keys(process.env)
2020
.filter(key => REACT_APP.test(key))
2121
.reduce((env, key) => {
22-
env['process.env.' + key] = JSON.stringify(process.env[key]);
22+
env[key] = JSON.stringify(process.env[key]);
2323
return env;
2424
}, {
2525
// Useful for determining whether we’re running in production mode.
2626
// Most importantly, it switches React into the correct mode.
27-
'process.env.NODE_ENV': JSON.stringify(
27+
'NODE_ENV': JSON.stringify(
2828
process.env.NODE_ENV || 'development'
2929
),
3030
// Useful for resolving the correct path to static assets in `public`.
3131
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
3232
// This should only be used as an escape hatch. Normally you would put
3333
// images into the `src` and `import` them in code to get their paths.
34-
'process.env.PUBLIC_URL': JSON.stringify(publicUrl)
34+
'PUBLIC_URL': JSON.stringify(publicUrl)
3535
});
36+
return {'process.env': processEnv};
3637
}
3738

3839
module.exports = getClientEnvironment;

config/webpack.config.dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ var getCustomConfig = require('./get-custom-config');
2626
var publicPath = '/';
2727
// `publicUrl` is just like `publicPath`, but we will provide it to our app
2828
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
29-
// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
29+
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
3030
var publicUrl = '';
31-
// Get enrivonment variables to inject into our app.
31+
// Get environment variables to inject into our app.
3232
var env = getClientEnvironment(publicUrl);
3333
//Get custom configuration for injecting plugins, presets and loaders
3434
var customConfig = getCustomConfig(false);

config/webpack.config.prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ var publicPath = ensureSlash(homepagePathname, true);
4545
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
4646
// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
4747
var publicUrl = ensureSlash(homepagePathname, false);
48-
// Get enrivonment variables to inject into our app.
48+
// Get environment variables to inject into our app.
4949
var env = getClientEnvironment(publicUrl);
5050
//Get custom configuration for injecting plugins, presets and loaders
5151
var customConfig = getCustomConfig(true);
5252

5353
// Assert this just to be safe.
5454
// Development builds of React are slow and not intended for production.
55-
if (env['process.env.NODE_ENV'] !== '"production"') {
55+
if (env['process.env'].NODE_ENV !== '"production"') {
5656
throw new Error('Production builds must have NODE_ENV=production.');
5757
}
5858

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"path-exists": "2.1.0",
6464
"postcss-loader": "0.13.0",
6565
"promise": "7.1.1",
66-
"react-dev-utils": "^0.2.0",
66+
"react-dev-utils": "^0.2.1",
6767
"recursive-readdir": "2.1.0",
6868
"rimraf": "2.5.4",
6969
"strip-ansi": "3.0.1",

scripts/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Do this as the first thing so that any code reading it knows the right env.
1313
process.env.NODE_ENV = 'production';
1414

15-
// Load environment variables from .env file. Surpress warnings using silent
15+
// Load environment variables from .env file. Suppress warnings using silent
1616
// if this file is missing. dotenv will never modify any environment variables
1717
// that have already been set.
1818
// https://github.com/motdotla/dotenv

scripts/eject.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ var path = require('path');
1313
var prompt = require('react-dev-utils/prompt');
1414
var rimrafSync = require('rimraf').sync;
1515
var spawnSync = require('cross-spawn').sync;
16+
var chalk = require('chalk');
17+
var green = chalk.green;
18+
var cyan = chalk.cyan;
1619

1720
prompt(
1821
'Are you sure you want to eject? This action is permanent.',
1922
false
2023
).then(shouldEject => {
2124
if (!shouldEject) {
22-
console.log('Close one! Eject aborted.');
25+
console.log(cyan('Close one! Eject aborted.'));
2326
process.exit(1);
2427
}
2528

2629
console.log('Ejecting...');
27-
console.log();
2830

2931
var ownPath = path.join(__dirname, '..');
3032
var appPath = path.join(ownPath, '..', '..');
3133
var files = [
32-
'.babelrc',
33-
'.eslintrc',
3434
path.join('config', 'env.js'),
3535
path.join('config', 'paths.js'),
3636
path.join('config', 'polyfills.js'),
@@ -61,8 +61,10 @@ prompt(
6161
fs.mkdirSync(path.join(appPath, 'config', 'jest'));
6262
fs.mkdirSync(path.join(appPath, 'scripts'));
6363

64+
console.log();
65+
console.log('Copying files to ' + cyan(appPath));
6466
files.forEach(function(file) {
65-
console.log('Copying ' + file + ' to ' + appPath);
67+
console.log(' Copying ' + cyan(file));
6668
var content = fs
6769
.readFileSync(path.join(ownPath, file), 'utf8')
6870
// Remove dead code from .js files on eject
@@ -76,48 +78,68 @@ prompt(
7678

7779
var ownPackage = require(path.join(ownPath, 'package.json'));
7880
var appPackage = require(path.join(appPath, 'package.json'));
81+
var babelConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.babelrc'), 'utf8'));
82+
var eslintConfig = JSON.parse(fs.readFileSync(path.join(ownPath, '.eslintrc'), 'utf8'));
7983

84+
console.log(cyan('Updating dependencies...'));
8085
var ownPackageName = ownPackage.name;
81-
console.log('Removing dependency: ' + ownPackageName);
86+
console.log(' Removing dependency: ' + cyan(ownPackageName));
8287
delete appPackage.devDependencies[ownPackageName];
8388

8489
Object.keys(ownPackage.dependencies).forEach(function (key) {
8590
// For some reason optionalDependencies end up in dependencies after install
8691
if (ownPackage.optionalDependencies[key]) {
8792
return;
8893
}
89-
console.log('Adding dependency: ' + key);
94+
console.log(' Adding dependency: ' + cyan(key));
9095
appPackage.devDependencies[key] = ownPackage.dependencies[key];
9196
});
92-
93-
console.log('Updating scripts');
97+
console.log();
98+
console.log(cyan('Updating scripts...'));
9499
delete appPackage.scripts['eject'];
95100
Object.keys(appPackage.scripts).forEach(function (key) {
96101
appPackage.scripts[key] = appPackage.scripts[key]
97102
.replace(/react-scripts (\w+)/g, 'node scripts/$1.js');
103+
console.log(
104+
' Replacing ' +
105+
cyan('\"react-scripts ' + key + '\"') +
106+
' with ' +
107+
cyan('\"' + appPackage.scripts[key] + '\"')
108+
);
98109
});
99110

111+
console.log();
112+
console.log(cyan('Adding configuration to ') + 'package.json' + cyan('...'));
100113
// Add Jest config
114+
console.log(' Adding ' + cyan('Jest') + ' configuration');
101115
appPackage.jest = createJestConfig(
102116
filePath => path.join('<rootDir>', filePath),
103117
null,
104118
true
105119
);
106120

107-
console.log('Writing package.json');
121+
// Add Babel config
122+
123+
console.log(' Adding ' + cyan('Babel') + ' preset');
124+
appPackage.babel = babelConfig;
125+
126+
// Add ESlint config
127+
console.log(' Adding ' + cyan('ESLint') +' configuration');
128+
appPackage.eslintConfig = eslintConfig;
129+
108130
fs.writeFileSync(
109131
path.join(appPath, 'package.json'),
110132
JSON.stringify(appPackage, null, 2)
111133
);
112134
console.log();
113135

114-
console.log('Running npm install...');
136+
console.log(cyan('Running npm install...'));
115137
rimrafSync(ownPath);
116138
spawnSync('npm', ['install'], {stdio: 'inherit'});
117-
console.log('Ejected successfully!');
139+
console.log(green('Ejected successfully!'));
118140
console.log();
119141

120-
console.log('Please consider sharing why you ejected in this survey:');
121-
console.log(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1');
122-
console.log();
123-
});
142+
console.log(green('Please consider sharing why you ejected in this survey:'));
143+
console.log(green(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1'));
144+
console.log()
145+
})

scripts/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
process.env.NODE_ENV = 'development';
1313

14-
// Load environment variables from .env file. Surpress warnings using silent
14+
// Load environment variables from .env file. Suppress warnings using silent
1515
// if this file is missing. dotenv will never modify any environment variables
1616
// that have already been set.
1717
// https://github.com/motdotla/dotenv

scripts/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
process.env.NODE_ENV = 'test';
1313
process.env.PUBLIC_URL = '';
1414

15-
// Load environment variables from .env file. Surpress warnings using silent
15+
// Load environment variables from .env file. Suppress warnings using silent
1616
// if this file is missing. dotenv will never modify any environment variables
1717
// that have already been set.
1818
// https://github.com/motdotla/dotenv

0 commit comments

Comments
 (0)