Skip to content

Commit 276c0f1

Browse files
tuchk4SpaceK33z
authored andcommitted
Fix eject for linked react-scripts (facebook#1736)
* fix eject for linked react-scripts * path.resolve => resolveApp # Conflicts: # packages/react-cy-scripts/config/paths.js # packages/react-cy-scripts/scripts/eject.js
1 parent 4cdaf1a commit 276c0f1

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/react-cy-scripts/config/paths.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ module.exports = {
114114
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
115115
};
116116

117-
var reactScriptsPath = path.resolve('node_modules/react-cy-scripts');
117+
var ownPackageJson = require('../package.json');
118+
var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
118119
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
119120

120121
// config before publish: we're in ./packages/react-scripts/config/

packages/react-cy-scripts/scripts/eject.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,18 @@ prompt(
157157
);
158158
console.log();
159159

160-
try {
161-
// remove react-scripts and react-scripts binaries from app node_modules
162-
Object.keys(ownPackage.bin).forEach(function(binKey) {
163-
fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey));
164-
});
165-
fs.removeSync(ownPath);
166-
} catch(e) {}
160+
// "Don't destroy what isn't ours"
161+
if (ownPath.indexOf(appPath) === 0) {
162+
try {
163+
// remove react-scripts and react-scripts binaries from app node_modules
164+
Object.keys(ownPackage.bin).forEach(function(binKey) {
165+
fs.removeSync(path.join(appPath, 'node_modules', '.bin', binKey));
166+
});
167+
fs.removeSync(ownPath);
168+
} catch(e) {
169+
// It's not essential that this succeeds
170+
}
171+
}
167172

168173
if (fs.existsSync(paths.yarnLockFile)) {
169174
console.log(cyan('Running yarn...'));

0 commit comments

Comments
 (0)