diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index cf4b762a4cf..83f234d6c62 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -114,7 +114,8 @@ module.exports = { ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3 }; -var reactScriptsPath = path.resolve('node_modules/react-scripts'); +var ownPackageJson = require('../package.json'); +var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`); var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink(); // config before publish: we're in ./packages/react-scripts/config/ diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 45ed8026711..39a40546bde 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -158,14 +158,17 @@ prompt( ); console.log(); - try { - // remove react-scripts and react-scripts binaries from app node_modules - Object.keys(ownPackage.bin).forEach(function(binKey) { - fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey)); - }); - fs.removeSync(ownPath); - } catch(e) { - // It's not essential that this succeeds + // "Don't destroy what isn't ours" + if (ownPath.indexOf(appPath) === 0) { + try { + // remove react-scripts and react-scripts binaries from app node_modules + Object.keys(ownPackage.bin).forEach(function(binKey) { + fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey)); + }); + fs.removeSync(ownPath); + } catch(e) { + // It's not essential that this succeeds + } } if (fs.existsSync(paths.yarnLockFile)) {