Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…react-app

# 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
  • Loading branch information
kitze committed Oct 3, 2016
2 parents f84d8b4 + 161c180 commit fa45985
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 57 deletions.
9 changes: 5 additions & 4 deletions config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
var REACT_APP = /^REACT_APP_/i;

function getClientEnvironment(publicUrl) {
return Object
var processEnv = Object
.keys(process.env)
.filter(key => REACT_APP.test(key))
.reduce((env, key) => {
env['process.env.' + key] = JSON.stringify(process.env[key]);
env[key] = JSON.stringify(process.env[key]);
return env;
}, {
// Useful for determining whether we’re running in production mode.
// Most importantly, it switches React into the correct mode.
'process.env.NODE_ENV': JSON.stringify(
'NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development'
),
// Useful for resolving the correct path to static assets in `public`.
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
'process.env.PUBLIC_URL': JSON.stringify(publicUrl)
'PUBLIC_URL': JSON.stringify(publicUrl)
});
return {'process.env': processEnv};
}

module.exports = getClientEnvironment;
4 changes: 2 additions & 2 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var getCustomConfig = require('./get-custom-config');
var publicPath = '/';
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
var publicUrl = '';
// Get enrivonment variables to inject into our app.
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl);
//Get custom configuration for injecting plugins, presets and loaders
var customConfig = getCustomConfig(false);
Expand Down
4 changes: 2 additions & 2 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ var publicPath = ensureSlash(homepagePathname, true);
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing shlash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
var publicUrl = ensureSlash(homepagePathname, false);
// Get enrivonment variables to inject into our app.
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl);
//Get custom configuration for injecting plugins, presets and loaders
var customConfig = getCustomConfig(true);

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"path-exists": "2.1.0",
"postcss-loader": "0.13.0",
"promise": "7.1.1",
"react-dev-utils": "^0.2.0",
"react-dev-utils": "^0.2.1",
"recursive-readdir": "2.1.0",
"rimraf": "2.5.4",
"strip-ansi": "3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// Do this as the first thing so that any code reading it knows the right env.
process.env.NODE_ENV = 'production';

// Load environment variables from .env file. Surpress warnings using silent
// Load environment variables from .env file. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.
// https://github.com/motdotla/dotenv
Expand Down
54 changes: 38 additions & 16 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ var path = require('path');
var prompt = require('react-dev-utils/prompt');
var rimrafSync = require('rimraf').sync;
var spawnSync = require('cross-spawn').sync;
var chalk = require('chalk');
var green = chalk.green;
var cyan = chalk.cyan;

prompt(
'Are you sure you want to eject? This action is permanent.',
false
).then(shouldEject => {
if (!shouldEject) {
console.log('Close one! Eject aborted.');
console.log(cyan('Close one! Eject aborted.'));
process.exit(1);
}

console.log('Ejecting...');
console.log();

var ownPath = path.join(__dirname, '..');
var appPath = path.join(ownPath, '..', '..');
var files = [
'.babelrc',
'.eslintrc',
path.join('config', 'env.js'),
path.join('config', 'paths.js'),
path.join('config', 'polyfills.js'),
Expand Down Expand Up @@ -61,8 +61,10 @@ prompt(
fs.mkdirSync(path.join(appPath, 'config', 'jest'));
fs.mkdirSync(path.join(appPath, 'scripts'));

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

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

console.log(cyan('Updating dependencies...'));
var ownPackageName = ownPackage.name;
console.log('Removing dependency: ' + ownPackageName);
console.log(' Removing dependency: ' + cyan(ownPackageName));
delete appPackage.devDependencies[ownPackageName];

Object.keys(ownPackage.dependencies).forEach(function (key) {
// For some reason optionalDependencies end up in dependencies after install
if (ownPackage.optionalDependencies[key]) {
return;
}
console.log('Adding dependency: ' + key);
console.log(' Adding dependency: ' + cyan(key));
appPackage.devDependencies[key] = ownPackage.dependencies[key];
});

console.log('Updating scripts');
console.log();
console.log(cyan('Updating scripts...'));
delete appPackage.scripts['eject'];
Object.keys(appPackage.scripts).forEach(function (key) {
appPackage.scripts[key] = appPackage.scripts[key]
.replace(/react-scripts (\w+)/g, 'node scripts/$1.js');
console.log(
' Replacing ' +
cyan('\"react-scripts ' + key + '\"') +
' with ' +
cyan('\"' + appPackage.scripts[key] + '\"')
);
});

console.log();
console.log(cyan('Adding configuration to ') + 'package.json' + cyan('...'));
// Add Jest config
console.log(' Adding ' + cyan('Jest') + ' configuration');
appPackage.jest = createJestConfig(
filePath => path.join('<rootDir>', filePath),
null,
true
);

console.log('Writing package.json');
// Add Babel config

console.log(' Adding ' + cyan('Babel') + ' preset');
appPackage.babel = babelConfig;

// Add ESlint config
console.log(' Adding ' + cyan('ESLint') +' configuration');
appPackage.eslintConfig = eslintConfig;

fs.writeFileSync(
path.join(appPath, 'package.json'),
JSON.stringify(appPackage, null, 2)
);
console.log();

console.log('Running npm install...');
console.log(cyan('Running npm install...'));
rimrafSync(ownPath);
spawnSync('npm', ['install'], {stdio: 'inherit'});
console.log('Ejected successfully!');
console.log(green('Ejected successfully!'));
console.log();

console.log('Please consider sharing why you ejected in this survey:');
console.log(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1');
console.log();
});
console.log(green('Please consider sharing why you ejected in this survey:'));
console.log(green(' http://goo.gl/forms/Bi6CZjk1EqsdelXk1'));
console.log()
})
2 changes: 1 addition & 1 deletion scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

process.env.NODE_ENV = 'development';

// Load environment variables from .env file. Surpress warnings using silent
// Load environment variables from .env file. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.
// https://github.com/motdotla/dotenv
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
process.env.NODE_ENV = 'test';
process.env.PUBLIC_URL = '';

// Load environment variables from .env file. Surpress warnings using silent
// Load environment variables from .env file. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.
// https://github.com/motdotla/dotenv
Expand Down
Loading

0 comments on commit fa45985

Please sign in to comment.