Skip to content

Commit 66c9608

Browse files
tuchk4SpaceK33z
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 # Conflicts: # packages/react-cy-scripts/config/paths.js
1 parent 976871d commit 66c9608

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ module.exports = {
9292

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

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

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

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

Lines changed: 2 additions & 3 deletions
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)