Skip to content

Commit

Permalink
Fix eject for linked react-scripts (facebook#1736)
Browse files Browse the repository at this point in the history
* fix eject for linked react-scripts

* path.resolve => resolveApp

# Conflicts:
#   packages/react-cy-scripts/config/paths.js
#   packages/react-cy-scripts/scripts/eject.js
  • Loading branch information
tuchk4 authored and SpaceK33z committed Mar 7, 2017
1 parent 4cdaf1a commit 276c0f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/react-cy-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
19 changes: 12 additions & 7 deletions packages/react-cy-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...'));
Expand Down

0 comments on commit 276c0f1

Please sign in to comment.