From 469edf10849a34e82dcf67c8e502708010893a39 Mon Sep 17 00:00:00 2001 From: Valerii Sorokobatko Date: Fri, 24 Feb 2017 18:51:16 +0200 Subject: [PATCH] Fix workflow if react-scripts package is linked via npm-link (#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 --- packages/react-scripts/config/paths.js | 37 +++++++++++++++---------- packages/react-scripts/scripts/eject.js | 5 ++-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 88d35c1386c..08b59ffccea 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -94,11 +94,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: resolveApp('node_modules/react-scripts'), appBuild: resolveApp(buildPath), appPublic: resolveApp('client/public'), appHtml: resolveApp('client/public/index.html'), @@ -109,28 +111,33 @@ module.exports = { testsSetup: resolveApp('client/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 (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) { +if (!reactScriptsLinked && __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) { module.exports = { - appBuild: resolveOwn('../../../' + buildPath), - appPublic: resolveOwn('../template/client/public'), - appHtml: resolveOwn('../template/client/public/index.html'), - appIndexJs: resolveOwn('../template/client/index.js'), - appPackageJson: resolveOwn('../package.json'), - appSrc: resolveOwn('../template/client'), - yarnLockFile: resolveOwn('../template/yarn.lock'), - testsSetup: resolveOwn('../template/client/setupTests.js'), - appNodeModules: resolveOwn('../node_modules'), - ownNodeModules: resolveOwn('../node_modules'), + appPath: resolveApp('.'), + ownPath: resolveOwn('.'), + appBuild: resolveOwn('../../' + buildPath), + appPublic: resolveOwn('template/client/public'), + appHtml: resolveOwn('template/client/public/index.html'), + appIndexJs: resolveOwn('template/client/index.js'), + appPackageJson: resolveOwn('package.json'), + appSrc: resolveOwn('template/client'), + yarnLockFile: resolveOwn('template/yarn.lock'), + testsSetup: resolveOwn('template/client/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 a8ee0fc3102..473a40da4e1 100644 --- a/packages/react-scripts/scripts/eject.js +++ b/packages/react-scripts/scripts/eject.js @@ -28,8 +28,8 @@ prompt( console.log('Ejecting...'); - var ownPath = path.join(__dirname, '..'); - var appPath = path.join(ownPath, '..', '..'); + var ownPath = paths.ownPath; + var appPath = paths.appPath; function verifyAbsent(file) { if (fs.existsSync(path.join(appPath, file))) { @@ -135,7 +135,6 @@ prompt( ); // Add Babel config - console.log(' Adding ' + cyan('Babel') + ' preset'); appPackage.babel = babelConfig;