From a0197dfd35b462c80b2f11250223cf4189ec45ca Mon Sep 17 00:00:00 2001 From: Valerii Sorokobatko Date: Mon, 6 Mar 2017 12:36:04 +0200 Subject: [PATCH 1/2] fix eject for linked react-scripts --- packages/react-scripts/config/paths.js | 3 ++- packages/react-scripts/scripts/eject.js | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index cf4b762a4cf..fea162cf5cd 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 = path.resolve(`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)) { From 759b131778e3a65677441ce3a28429becabeccae Mon Sep 17 00:00:00 2001 From: Valerii Sorokobatko Date: Mon, 6 Mar 2017 15:27:39 +0200 Subject: [PATCH 2/2] path.resolve => resolveApp --- packages/react-scripts/config/paths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index fea162cf5cd..83f234d6c62 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -115,7 +115,7 @@ module.exports = { }; var ownPackageJson = require('../package.json'); -var reactScriptsPath = path.resolve(`node_modules/${ownPackageJson.name}`); +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/