From d65478491440a3d4304ebd3d104aa0d91c5e14ec Mon Sep 17 00:00:00 2001 From: Valerii Sorokobatko Date: Wed, 15 Feb 2017 13:38:00 +0200 Subject: [PATCH] update code after review: - remove utils/isReactScriptsLinked - add appPath and ownPath to paths.js (but only for "before eject" export case) --- packages/react-scripts/config/paths.js | 42 ++++++++++--------- packages/react-scripts/scripts/eject.js | 10 ++--- .../utils/isReactScriptsLinked.js | 7 ---- 3 files changed, 27 insertions(+), 32 deletions(-) delete mode 100644 packages/react-scripts/utils/isReactScriptsLinked.js diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index af66869b309..d8d67ee8bd2 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -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()); @@ -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'), @@ -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 diff --git a/packages/react-scripts/scripts/eject.js b/packages/react-scripts/scripts/eject.js index 79b217bb0d7..ccc9cee5c35 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -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'); @@ -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))) { @@ -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'}); diff --git a/packages/react-scripts/utils/isReactScriptsLinked.js b/packages/react-scripts/utils/isReactScriptsLinked.js deleted file mode 100644 index 65dd375fe7d..00000000000 --- a/packages/react-scripts/utils/isReactScriptsLinked.js +++ /dev/null @@ -1,7 +0,0 @@ -var path = require('path'); -var fs = require('fs'); - -module.exports = () => { - var localReactScriptsPath = path.resolve('node_modules/react-scripts'); - return fs.existsSync(localReactScriptsPath) && fs.lstatSync(localReactScriptsPath).isSymbolicLink(); -};