From 1bb1f69b6175d3a3636129f15a9e0ac4dc3c0b3e Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 23 Sep 2016 21:07:53 +0100 Subject: [PATCH] Don't hardcode react-scripts package name Fixes issue described in https://github.com/facebookincubator/create-react-app/issues/682#issuecomment-248781486. --- packages/react-scripts/scripts/eject.js | 10 +++++++--- packages/react-scripts/scripts/init.js | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 22c73ead726..0875c9c80ce 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -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 = require(path.join(__dirname, '..', 'package'.json)).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 diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 8bdf6163222..222902a7413 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -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(