Skip to content

Commit

Permalink
update code after review:
Browse files Browse the repository at this point in the history
- remove utils/isReactScriptsLinked
- add appPath and ownPath to paths.js (but only for "before eject" export case)
  • Loading branch information
tuchk4 committed Feb 15, 2017
1 parent 4e91cb3 commit d654784
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
42 changes: 23 additions & 19 deletions packages/react-scripts/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ var path = require('path');
var fs = require('fs');
var url = require('url');

// @remove-on-eject-begin
var isReactScriptsLinked = require('../utils/isReactScriptsLinked');
// @remove-on-eject-end

// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
var appDirectory = fs.realpathSync(process.cwd());
Expand Down Expand Up @@ -95,11 +91,13 @@ module.exports = {

// @remove-on-eject-begin
function resolveOwn(relativePath) {
return path.resolve(__dirname, relativePath);
return path.resolve(__dirname, '..', relativePath);
}

// config before eject: we're in ./node_modules/react-scripts/config/
module.exports = {
appPath: resolveApp('.'),
ownPath: resolveOwn('.'),
appBuild: resolveApp('build'),
appPublic: resolveApp('public'),
appHtml: resolveApp('public/index.html'),
Expand All @@ -110,28 +108,34 @@ module.exports = {
testsSetup: resolveApp('src/setupTests.js'),
appNodeModules: resolveApp('node_modules'),
// this is empty with npm3 but node resolution searches higher anyway:
ownNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('node_modules'),
nodePaths: nodePaths,
publicUrl: getPublicUrl(resolveApp('package.json')),
servedPath: getServedPath(resolveApp('package.json'))
};


var reactScriptsPath = path.resolve('node_modules/react-scripts');
var reactScriptsLinked = fs.existsSync(reactScriptsPath) && fs.lstatSync(reactScriptsPath).isSymbolicLink();

// config before publish: we're in ./packages/react-scripts/config/
if (!isReactScriptsLinked() && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) {
module.exports = {
appBuild: resolveOwn('../../../build'),
appPublic: resolveOwn('../template/public'),
appHtml: resolveOwn('../template/public/index.html'),
appIndexJs: resolveOwn('../template/src/index.js'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
yarnLockFile: resolveOwn('../template/yarn.lock'),
testsSetup: resolveOwn('../template/src/setupTests.js'),
appNodeModules: resolveOwn('../node_modules'),
ownNodeModules: resolveOwn('../node_modules'),
appPath: resolveApp('.'),
ownPath: resolveOwn('.'),
appBuild: resolveOwn('../../build'),
appPublic: resolveOwn('template/public'),
appHtml: resolveOwn('template/public/index.html'),
appIndexJs: resolveOwn('template/src/index.js'),
appPackageJson: resolveOwn('package.json'),
appSrc: resolveOwn('template/src'),
yarnLockFile: resolveOwn('template/yarn.lock'),
testsSetup: resolveOwn('template/src/setupTests.js'),
appNodeModules: resolveOwn('node_modules'),
ownNodeModules: resolveOwn('node_modules'),
nodePaths: nodePaths,
publicUrl: getPublicUrl(resolveOwn('../package.json')),
servedPath: getServedPath(resolveOwn('../package.json'))
publicUrl: getPublicUrl(resolveOwn('package.json')),
servedPath: getServedPath(resolveOwn('package.json'))
};
}
// @remove-on-eject-end
10 changes: 4 additions & 6 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var createJestConfig = require('../utils/createJestConfig');
var fs = require('fs-extra');
var path = require('path');
var paths = require('../config/paths');
var reactScriptsLinked = require('../utils/isReactScriptsLinked')();
var prompt = require('react-dev-utils/prompt');
var spawnSync = require('cross-spawn').sync;
var chalk = require('chalk');
Expand All @@ -29,9 +28,8 @@ prompt(

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

// NOTE: get ownPath and appPath from config/paths.js ?
var ownPath = path.join(__dirname, '..');
var appPath = reactScriptsLinked ? path.resolve('.') : path.join(ownPath, '..', '..');
var ownPath = paths.ownPath;
var appPath = paths.appPath;

function verifyAbsent(file) {
if (fs.existsSync(path.join(appPath, file))) {
Expand Down Expand Up @@ -152,13 +150,13 @@ prompt(

if (fs.existsSync(paths.yarnLockFile)) {
console.log(cyan('Running yarn...'));
if (!reactScriptsLinked) {
if (ownPath.indexOf(appPath) !== -1) {
fs.removeSync(ownPath);
}
spawnSync('yarnpkg', [], {stdio: 'inherit'});
} else {
console.log(cyan('Running npm install...'));
if (!reactScriptsLinked) {
if (ownPath.indexOf(appPath) !== -1) {
fs.removeSync(ownPath);
}
spawnSync('npm', ['install'], {stdio: 'inherit'});
Expand Down
7 changes: 0 additions & 7 deletions packages/react-scripts/utils/isReactScriptsLinked.js

This file was deleted.

0 comments on commit d654784

Please sign in to comment.