Skip to content

Commit bec009c

Browse files
tuchk4Timer
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 67d0d49 commit bec009c

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
@@ -91,11 +91,13 @@ module.exports = {
9191

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

9797
// config before eject: we're in ./node_modules/react-scripts/config/
9898
module.exports = {
99+
appPath: resolveApp('.'),
100+
ownPath: resolveApp('node_modules/react-scripts'),
99101
appBuild: resolveApp('build'),
100102
appPublic: resolveApp('public'),
101103
appHtml: resolveApp('public/index.html'),
@@ -106,28 +108,33 @@ module.exports = {
106108
testsSetup: resolveApp('src/setupTests.js'),
107109
appNodeModules: resolveApp('node_modules'),
108110
// this is empty with npm3 but node resolution searches higher anyway:
109-
ownNodeModules: resolveOwn('../node_modules'),
111+
ownNodeModules: resolveOwn('node_modules'),
110112
nodePaths: nodePaths,
111113
publicUrl: getPublicUrl(resolveApp('package.json')),
112114
servedPath: getServedPath(resolveApp('package.json'))
113115
};
114116

117+
var reactScriptsPath = path.resolve('node_modules/react-scripts');
118+
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
119+
115120
// config before publish: we're in ./packages/react-scripts/config/
116-
if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
121+
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
117122
module.exports = {
118-
appBuild: resolveOwn('../../../build'),
119-
appPublic: resolveOwn('../template/public'),
120-
appHtml: resolveOwn('../template/public/index.html'),
121-
appIndexJs: resolveOwn('../template/src/index.js'),
122-
appPackageJson: resolveOwn('../package.json'),
123-
appSrc: resolveOwn('../template/src'),
124-
yarnLockFile: resolveOwn('../template/yarn.lock'),
125-
testsSetup: resolveOwn('../template/src/setupTests.js'),
126-
appNodeModules: resolveOwn('../node_modules'),
127-
ownNodeModules: resolveOwn('../node_modules'),
123+
appPath: resolveApp('.'),
124+
ownPath: resolveOwn('.'),
125+
appBuild: resolveOwn('../../build'),
126+
appPublic: resolveOwn('template/public'),
127+
appHtml: resolveOwn('template/public/index.html'),
128+
appIndexJs: resolveOwn('template/src/index.js'),
129+
appPackageJson: resolveOwn('package.json'),
130+
appSrc: resolveOwn('template/src'),
131+
yarnLockFile: resolveOwn('template/yarn.lock'),
132+
testsSetup: resolveOwn('template/src/setupTests.js'),
133+
appNodeModules: resolveOwn('node_modules'),
134+
ownNodeModules: resolveOwn('node_modules'),
128135
nodePaths: nodePaths,
129-
publicUrl: getPublicUrl(resolveOwn('../package.json')),
130-
servedPath: getServedPath(resolveOwn('../package.json'))
136+
publicUrl: getPublicUrl(resolveOwn('package.json')),
137+
servedPath: getServedPath(resolveOwn('package.json'))
131138
};
132139
}
133140
// @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)