Skip to content

Commit 469edf1

Browse files
tuchk4randycoulman
authored andcommitted
Fix workflow if react-scripts package is linked via npm-link (facebook#1356)
* add npm-link support * - remove extra veriable - simplify condition * update code after review: - remove utils/isReactScriptsLinked - add appPath and ownPath to paths.js (but only for "before eject" export case) * update code after review: - remove utils/isReactScriptsLinked - add appPath and ownPath to paths.js (but only for "before eject" export case) * update code after review: - remove utils/isReactScriptsLinked - add appPath and ownPath to paths.js (but only for "before eject" export case) - remove "if" block for fs.removeSync(ownPath) at ejec.tjs * change ownPath value
1 parent 8a1139d commit 469edf1

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

packages/react-scripts/config/paths.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ module.exports = {
9494

9595
// @remove-on-eject-begin
9696
function resolveOwn(relativePath) {
97-
return path.resolve(__dirname, relativePath);
97+
return path.resolve(__dirname, '..', relativePath);
9898
}
9999

100100
// config before eject: we're in ./node_modules/react-scripts/config/
101101
module.exports = {
102+
appPath: resolveApp('.'),
103+
ownPath: resolveApp('node_modules/react-scripts'),
102104
appBuild: resolveApp(buildPath),
103105
appPublic: resolveApp('client/public'),
104106
appHtml: resolveApp('client/public/index.html'),
@@ -109,28 +111,33 @@ module.exports = {
109111
testsSetup: resolveApp('client/setupTests.js'),
110112
appNodeModules: resolveApp('node_modules'),
111113
// this is empty with npm3 but node resolution searches higher anyway:
112-
ownNodeModules: resolveOwn('../node_modules'),
114+
ownNodeModules: resolveOwn('node_modules'),
113115
nodePaths: nodePaths,
114116
publicUrl: getPublicUrl(resolveApp('package.json')),
115117
servedPath: getServedPath(resolveApp('package.json'))
116118
};
117119

120+
var reactScriptsPath = path.resolve('node_modules/react-scripts');
121+
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
122+
118123
// config before publish: we're in ./packages/react-scripts/config/
119-
if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
124+
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
120125
module.exports = {
121-
appBuild: resolveOwn('../../../' + buildPath),
122-
appPublic: resolveOwn('../template/client/public'),
123-
appHtml: resolveOwn('../template/client/public/index.html'),
124-
appIndexJs: resolveOwn('../template/client/index.js'),
125-
appPackageJson: resolveOwn('../package.json'),
126-
appSrc: resolveOwn('../template/client'),
127-
yarnLockFile: resolveOwn('../template/yarn.lock'),
128-
testsSetup: resolveOwn('../template/client/setupTests.js'),
129-
appNodeModules: resolveOwn('../node_modules'),
130-
ownNodeModules: resolveOwn('../node_modules'),
126+
appPath: resolveApp('.'),
127+
ownPath: resolveOwn('.'),
128+
appBuild: resolveOwn('../../' + buildPath),
129+
appPublic: resolveOwn('template/client/public'),
130+
appHtml: resolveOwn('template/client/public/index.html'),
131+
appIndexJs: resolveOwn('template/client/index.js'),
132+
appPackageJson: resolveOwn('package.json'),
133+
appSrc: resolveOwn('template/client'),
134+
yarnLockFile: resolveOwn('template/yarn.lock'),
135+
testsSetup: resolveOwn('template/client/setupTests.js'),
136+
appNodeModules: resolveOwn('node_modules'),
137+
ownNodeModules: resolveOwn('node_modules'),
131138
nodePaths: nodePaths,
132-
publicUrl: getPublicUrl(resolveOwn('../package.json')),
133-
servedPath: getServedPath(resolveOwn('../package.json'))
139+
publicUrl: getPublicUrl(resolveOwn('package.json')),
140+
servedPath: getServedPath(resolveOwn('package.json'))
134141
};
135142
}
136143
// @remove-on-eject-end

packages/react-scripts/scripts/eject.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ prompt(
2828

2929
console.log('Ejecting...');
3030

31-
var ownPath = path.join(__dirname, '..');
32-
var appPath = path.join(ownPath, '..', '..');
31+
var ownPath = paths.ownPath;
32+
var appPath = paths.appPath;
3333

3434
function verifyAbsent(file) {
3535
if (fs.existsSync(path.join(appPath, file))) {
@@ -135,7 +135,6 @@ prompt(
135135
);
136136

137137
// Add Babel config
138-
139138
console.log(' Adding ' + cyan('Babel') + ' preset');
140139
appPackage.babel = babelConfig;
141140

0 commit comments

Comments
 (0)