Skip to content
This repository has been archived by the owner on Dec 3, 2018. It is now read-only.

Commit

Permalink
Don't hardcode react-scripts package name (#728)
Browse files Browse the repository at this point in the history
* Don't hardcode react-scripts package name

Fixes issue described in facebook/create-react-app#682 (comment).

* Update eject.js
  • Loading branch information
gaearon authored Sep 23, 2016
1 parent 9741dde commit 9521c95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 9521c95

Please sign in to comment.