Skip to content

Commit d654784

Browse files
committed
update code after review:
- remove utils/isReactScriptsLinked - add appPath and ownPath to paths.js (but only for "before eject" export case)
1 parent 4e91cb3 commit d654784

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

packages/react-scripts/config/paths.js

+23-19
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ var path = require('path');
1313
var fs = require('fs');
1414
var url = require('url');
1515

16-
// @remove-on-eject-begin
17-
var isReactScriptsLinked = require('../utils/isReactScriptsLinked');
18-
// @remove-on-eject-end
19-
2016
// Make sure any symlinks in the project folder are resolved:
2117
// https://github.com/facebookincubator/create-react-app/issues/637
2218
var appDirectory = fs.realpathSync(process.cwd());
@@ -95,11 +91,13 @@ module.exports = {
9591

9692
// @remove-on-eject-begin
9793
function resolveOwn(relativePath) {
98-
return path.resolve(__dirname, relativePath);
94+
return path.resolve(__dirname, '..', relativePath);
9995
}
10096

10197
// config before eject: we're in ./node_modules/react-scripts/config/
10298
module.exports = {
99+
appPath: resolveApp('.'),
100+
ownPath: resolveOwn('.'),
103101
appBuild: resolveApp('build'),
104102
appPublic: resolveApp('public'),
105103
appHtml: resolveApp('public/index.html'),
@@ -110,28 +108,34 @@ module.exports = {
110108
testsSetup: resolveApp('src/setupTests.js'),
111109
appNodeModules: resolveApp('node_modules'),
112110
// this is empty with npm3 but node resolution searches higher anyway:
113-
ownNodeModules: resolveOwn('../node_modules'),
111+
ownNodeModules: resolveOwn('node_modules'),
114112
nodePaths: nodePaths,
115113
publicUrl: getPublicUrl(resolveApp('package.json')),
116114
servedPath: getServedPath(resolveApp('package.json'))
117115
};
118116

117+
118+
var reactScriptsPath = path.resolve('node_modules/react-scripts');
119+
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();
120+
119121
// config before publish: we're in ./packages/react-scripts/config/
120-
if (!isReactScriptsLinked() && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
122+
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
121123
module.exports = {
122-
appBuild: resolveOwn('../../../build'),
123-
appPublic: resolveOwn('../template/public'),
124-
appHtml: resolveOwn('../template/public/index.html'),
125-
appIndexJs: resolveOwn('../template/src/index.js'),
126-
appPackageJson: resolveOwn('../package.json'),
127-
appSrc: resolveOwn('../template/src'),
128-
yarnLockFile: resolveOwn('../template/yarn.lock'),
129-
testsSetup: resolveOwn('../template/src/setupTests.js'),
130-
appNodeModules: resolveOwn('../node_modules'),
131-
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'),
132136
nodePaths: nodePaths,
133-
publicUrl: getPublicUrl(resolveOwn('../package.json')),
134-
servedPath: getServedPath(resolveOwn('../package.json'))
137+
publicUrl: getPublicUrl(resolveOwn('package.json')),
138+
servedPath: getServedPath(resolveOwn('package.json'))
135139
};
136140
}
137141
// @remove-on-eject-end

packages/react-scripts/scripts/eject.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var createJestConfig = require('../utils/createJestConfig');
1111
var fs = require('fs-extra');
1212
var path = require('path');
1313
var paths = require('../config/paths');
14-
var reactScriptsLinked = require('../utils/isReactScriptsLinked')();
1514
var prompt = require('react-dev-utils/prompt');
1615
var spawnSync = require('cross-spawn').sync;
1716
var chalk = require('chalk');
@@ -29,9 +28,8 @@ prompt(
2928

3029
console.log('Ejecting...');
3130

32-
// NOTE: get ownPath and appPath from config/paths.js ?
33-
var ownPath = path.join(__dirname, '..');
34-
var appPath = reactScriptsLinked ? path.resolve('.') : path.join(ownPath, '..', '..');
31+
var ownPath = paths.ownPath;
32+
var appPath = paths.appPath;
3533

3634
function verifyAbsent(file) {
3735
if (fs.existsSync(path.join(appPath, file))) {
@@ -152,13 +150,13 @@ prompt(
152150

153151
if (fs.existsSync(paths.yarnLockFile)) {
154152
console.log(cyan('Running yarn...'));
155-
if (!reactScriptsLinked) {
153+
if (ownPath.indexOf(appPath) !== -1) {
156154
fs.removeSync(ownPath);
157155
}
158156
spawnSync('yarnpkg', [], {stdio: 'inherit'});
159157
} else {
160158
console.log(cyan('Running npm install...'));
161-
if (!reactScriptsLinked) {
159+
if (ownPath.indexOf(appPath) !== -1) {
162160
fs.removeSync(ownPath);
163161
}
164162
spawnSync('npm', ['install'], {stdio: 'inherit'});

packages/react-scripts/utils/isReactScriptsLinked.js

-7
This file was deleted.

0 commit comments

Comments
 (0)