Skip to content

Commit b8511cf

Browse files
tuchk4randycoulman
authored andcommitted
Fix eject for linked react-scripts (facebook#1736)
* fix eject for linked react-scripts * path.resolve => resolveApp
1 parent c1a72e9 commit b8511cf

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/react-scripts/config/paths.js

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

120-
var reactScriptsPath = path.resolve('node_modules/react-scripts');
120+
var ownPackageJson = require('../package.json');
121+
var reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
121122
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
122123

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

packages/react-scripts/scripts/eject.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,17 @@ prompt(
152152
);
153153
console.log();
154154

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

165168
if (fs.existsSync(paths.yarnLockFile)) {

0 commit comments

Comments
 (0)