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
No related merge requests found
Showing with 13 additions and 9 deletions
+13 -9
......@@ -77,8 +77,9 @@ prompt(
var ownPackage = require(path.join(ownPath, 'package.json'));
var appPackage = require(path.join(appPath, 'package.json'));
console.log('Removing dependency: react-scripts');
delete appPackage.devDependencies['react-scripts'];
var ownPackageName = ownPackage.name;
console.log('Removing dependency: ' + ownPackageName);
delete appPackage.devDependencies[ownPackageName];
Object.keys(ownPackage.dependencies).forEach(function (key) {
// For some reason optionalDependencies end up in dependencies after install
......@@ -93,7 +94,10 @@ prompt(
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');
.replace(
new RegExp(ownPackageName + ' (\w+)', 'g'),
'node scripts/$1.js'
);
});
// Add Jest config
......
......@@ -14,8 +14,8 @@ var pathExists = require('path-exists');
var chalk = require('chalk');
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'));
// Copy over some of the devDependencies
......@@ -24,10 +24,10 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
// Setup the script rules
appPackage.scripts = {
'start': 'react-scripts start',
'build': 'react-scripts build',
'test': 'react-scripts test --env=jsdom',
'eject': 'react-scripts eject'
'start': ownPackageName + ' start',
'build': ownPackageName + ' build',
'test': ownPackageName + ' test --env=jsdom',
'eject': ownPackageName + ' eject'
};
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