Skip to content

Commit d66f3fd

Browse files
committed
add npm-link support
1 parent 9c33f60 commit d66f3fd

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

packages/react-scripts/config/paths.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ 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+
1620
// Make sure any symlinks in the project folder are resolved:
1721
// https://github.com/facebookincubator/create-react-app/issues/637
1822
var appDirectory = fs.realpathSync(process.cwd());
@@ -113,7 +117,7 @@ module.exports = {
113117
};
114118

115119
// config before publish: we're in ./packages/react-scripts/config/
116-
if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
120+
if (!isReactScriptsLinked() && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
117121
module.exports = {
118122
appBuild: resolveOwn('../../../build'),
119123
appPublic: resolveOwn('../template/public'),

packages/react-scripts/scripts/eject.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ var createJestConfig = require('../utils/createJestConfig');
1111
var fs = require('fs-extra');
1212
var path = require('path');
1313
var paths = require('../config/paths');
14+
var isReactScriptsLinked = require('../utils/isReactScriptsLinked');
1415
var prompt = require('react-dev-utils/prompt');
1516
var spawnSync = require('cross-spawn').sync;
1617
var chalk = require('chalk');
1718
var green = chalk.green;
1819
var cyan = chalk.cyan;
1920

21+
var reactScriptsLinked = isReactScriptsLinked();
22+
2023
prompt(
2124
'Are you sure you want to eject? This action is permanent.',
2225
false
@@ -28,8 +31,15 @@ prompt(
2831

2932
console.log('Ejecting...');
3033

34+
// NOTE: get ownPath and appPath from config/paths.js ?
3135
var ownPath = path.join(__dirname, '..');
32-
var appPath = path.join(ownPath, '..', '..');
36+
var appPath;
37+
38+
if (reactScriptsLinked) {
39+
appPath = path.resolve('.');
40+
} else {
41+
appPath = path.join(ownPath, '..', '..');
42+
}
3343

3444
function verifyAbsent(file) {
3545
if (fs.existsSync(path.join(appPath, file))) {
@@ -135,7 +145,6 @@ prompt(
135145
);
136146

137147
// Add Babel config
138-
139148
console.log(' Adding ' + cyan('Babel') + ' preset');
140149
appPackage.babel = babelConfig;
141150

@@ -151,11 +160,15 @@ prompt(
151160

152161
if (fs.existsSync(paths.yarnLockFile)) {
153162
console.log(cyan('Running yarn...'));
154-
fs.removeSync(ownPath);
163+
if (!reactScriptsLinked) {
164+
fs.removeSync(ownPath);
165+
}
155166
spawnSync('yarnpkg', [], {stdio: 'inherit'});
156167
} else {
157168
console.log(cyan('Running npm install...'));
158-
fs.removeSync(ownPath);
169+
if (!reactScriptsLinked) {
170+
fs.removeSync(ownPath);
171+
}
159172
spawnSync('npm', ['install'], {stdio: 'inherit'});
160173
}
161174
console.log(green('Ejected successfully!'));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var path = require('path');
2+
var fs = require('fs');
3+
4+
module.exports = () => {
5+
var localReactScriptsPath = path.resolve('node_modules/react-scripts');
6+
return fs.existsSync(localReactScriptsPath) && fs.lstatSync(localReactScriptsPath).isSymbolicLink();
7+
};

0 commit comments

Comments
 (0)