Skip to content

Commit 168f514

Browse files
gaearonSpaceK33z
authored andcommitted
Fix ejecting from a scoped fork (facebook#1727)
* Read script names from own bin instead of guessing This fixes ejecting from a fork that uses a different bin script name. * Fix ejecting for a scoped react-scripts fork We shouldn't hardcode react-scripts because fork name might differ. We also shouldn't rely on it being an immediate child because scoped packages are a level deeper. * Clarify that own* properties only exist before ejecting # Conflicts: # packages/react-cy-scripts/scripts/eject.js
1 parent 357941a commit 168f514

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ module.exports = {
8484
yarnLockFile: resolveApp('yarn.lock'),
8585
testsSetup: resolveApp('src/setupTests.js'),
8686
appNodeModules: resolveApp('node_modules'),
87-
ownNodeModules: resolveApp('node_modules'),
8887
nodePaths: nodePaths,
8988
publicUrl: getPublicUrl(resolveApp('package.json')),
9089
servedPath: getServedPath(resolveApp('package.json'))
@@ -98,7 +97,6 @@ function resolveOwn(relativePath) {
9897
// config before eject: we're in ./node_modules/react-cy-scripts/config/
9998
module.exports = {
10099
appPath: resolveApp('.'),
101-
ownPath: resolveApp('node_modules/react-scripts'),
102100
appBuild: resolveApp('build'),
103101
appPublic: resolveApp('public'),
104102
appHtml: resolveApp('public/index.html'),
@@ -108,11 +106,12 @@ module.exports = {
108106
yarnLockFile: resolveApp('yarn.lock'),
109107
testsSetup: resolveApp('src/setupTests.js'),
110108
appNodeModules: resolveApp('node_modules'),
111-
// this is empty with npm3 but node resolution searches higher anyway:
112-
ownNodeModules: resolveOwn('node_modules'),
113109
nodePaths: nodePaths,
114110
publicUrl: getPublicUrl(resolveApp('package.json')),
115-
servedPath: getServedPath(resolveApp('package.json'))
111+
servedPath: getServedPath(resolveApp('package.json')),
112+
// These properties only exist before ejecting:
113+
ownPath: resolveOwn('.'),
114+
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
116115
};
117116

118117
var reactScriptsPath = path.resolve('node_modules/react-cy-scripts');
@@ -122,7 +121,6 @@ var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactSc
122121
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-cy-scripts', 'config')) !== -1) {
123122
module.exports = {
124123
appPath: resolveApp('.'),
125-
ownPath: resolveOwn('.'),
126124
appBuild: resolveOwn('../../build'),
127125
appPublic: resolveOwn('template/public'),
128126
appHtml: resolveOwn('template/public/index.html'),
@@ -132,10 +130,12 @@ if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-cy-scr
132130
yarnLockFile: resolveOwn('template/yarn.lock'),
133131
testsSetup: resolveOwn('template/src/setupTests.js'),
134132
appNodeModules: resolveOwn('node_modules'),
135-
ownNodeModules: resolveOwn('node_modules'),
136133
nodePaths: nodePaths,
137134
publicUrl: getPublicUrl(resolveOwn('package.json')),
138-
servedPath: getServedPath(resolveOwn('package.json'))
135+
servedPath: getServedPath(resolveOwn('package.json')),
136+
// These properties only exist before ejecting:
137+
ownPath: resolveOwn('.'),
138+
ownNodeModules: resolveOwn('node_modules'),
139139
};
140140
}
141141
// @remove-on-eject-end

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ prompt(
120120
console.log(cyan('Updating the scripts'));
121121
delete appPackage.scripts['eject'];
122122
Object.keys(appPackage.scripts).forEach(function (key) {
123-
appPackage.scripts[key] = appPackage.scripts[key]
124-
.replace(/react-cy-scripts (\w+)/g, 'node scripts/$1.js');
125-
console.log(
126-
' Replacing ' +
127-
cyan('"react-cy-scripts ' + key + '"') +
128-
' with ' +
129-
cyan('"node scripts/' + key + '.js"')
130-
);
123+
Object.keys(ownPackage.bin).forEach(function (binKey) {
124+
var regex = new RegExp(binKey + ' (\\w+)', 'g');
125+
appPackage.scripts[key] = appPackage.scripts[key]
126+
.replace(regex, 'node scripts/$1.js');
127+
console.log(
128+
' Replacing ' +
129+
cyan('"' + binKey + ' ' + key + '"') +
130+
' with ' +
131+
cyan('"node scripts/' + key + '.js"')
132+
);
133+
});
131134
});
132135

133136
console.log();

0 commit comments

Comments
 (0)