Commit fda91eba authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Don't hardcode react-scripts package name (#728)

* Don't hardcode react-scripts package name

Fixes issue described in https://github.com/facebookincubator/create-react-app/issues/682#issuecomment-248781486.

* Update eject.js
parent d8e9a0e2
Showing with 13 additions and 9 deletions
+13 -9
...@@ -77,8 +77,9 @@ prompt( ...@@ -77,8 +77,9 @@ prompt(
var ownPackage = require(path.join(ownPath, 'package.json')); var ownPackage = require(path.join(ownPath, 'package.json'));
var appPackage = require(path.join(appPath, 'package.json')); var appPackage = require(path.join(appPath, 'package.json'));
console.log('Removing dependency: react-scripts'); var ownPackageName = ownPackage.name;
delete appPackage.devDependencies['react-scripts']; console.log('Removing dependency: ' + ownPackageName);
delete appPackage.devDependencies[ownPackageName];
Object.keys(ownPackage.dependencies).forEach(function (key) { Object.keys(ownPackage.dependencies).forEach(function (key) {
// For some reason optionalDependencies end up in dependencies after install // For some reason optionalDependencies end up in dependencies after install
...@@ -93,7 +94,10 @@ prompt( ...@@ -93,7 +94,10 @@ prompt(
delete appPackage.scripts['eject']; delete appPackage.scripts['eject'];
Object.keys(appPackage.scripts).forEach(function (key) { Object.keys(appPackage.scripts).forEach(function (key) {
appPackage.scripts[key] = appPackage.scripts[key] appPackage.scripts[key] = appPackage.scripts[key]
.replace(/react-scripts (\w+)/g, 'node scripts/$1.js'); .replace(
new RegExp(ownPackageName + ' (\w+)', 'g'),
'node scripts/$1.js'
);
}); });
// Add Jest config // Add Jest config
......
...@@ -14,8 +14,8 @@ var pathExists = require('path-exists'); ...@@ -14,8 +14,8 @@ var pathExists = require('path-exists');
var chalk = require('chalk'); var chalk = require('chalk');
module.exports = function(appPath, appName, verbose, originalDirectory) { module.exports = function(appPath, appName, verbose, originalDirectory) {
var ownPath = path.join(appPath, 'node_modules', 'react-scripts'); var ownPackageName = require(path.join(__dirname, '..', 'package.json')).name;
var ownPath = path.join(appPath, 'node_modules', ownPackageName);
var appPackage = require(path.join(appPath, 'package.json')); var appPackage = require(path.join(appPath, 'package.json'));
// Copy over some of the devDependencies // Copy over some of the devDependencies
...@@ -24,10 +24,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory) { ...@@ -24,10 +24,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
// Setup the script rules // Setup the script rules
appPackage.scripts = { appPackage.scripts = {
'start': 'react-scripts start', 'start': ownPackageName + ' start',
'build': 'react-scripts build', 'build': ownPackageName + ' build',
'test': 'react-scripts test --env=jsdom', 'test': ownPackageName + ' test --env=jsdom',
'eject': 'react-scripts eject' 'eject': ownPackageName + ' eject'
}; };
fs.writeFileSync( fs.writeFileSync(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment