diff --git a/packages/react-cy-scripts/config/paths.js b/packages/react-cy-scripts/config/paths.js index f3b23683422..d544acb7b74 100644 --- a/packages/react-cy-scripts/config/paths.js +++ b/packages/react-cy-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-cy-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-cy-scripts/scripts/eject.js b/packages/react-cy-scripts/scripts/eject.js index 1974f22079f..2b6d02fec8e 100644 --- a/packages/react-cy-scripts/scripts/eject.js +++ b/packages/react-cy-scripts/scripts/eject.js @@ -157,13 +157,18 @@ 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) {} + // "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)) { console.log(cyan('Running yarn...'));