From 6ee55f5c5c2e5f291fbb726995ce63caded9fbf9 Mon Sep 17 00:00:00 2001 From: Tabrez Mohammed Date: Thu, 1 Dec 2016 01:00:26 -0800 Subject: [PATCH 1/3] fix module.exports for react-scripts add support for installing react-scripts via npm link --- packages/react-scripts/config/paths.js | 44 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index d15b16a0544..f17be16bb86 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -55,24 +55,34 @@ function resolveOwn(relativePath) { return path.resolve(__dirname, relativePath); } -// config before eject: we're in ./node_modules/react-scripts/config/ -module.exports = { - appBuild: resolveApp('build'), - appPublic: resolveApp('public'), - appHtml: resolveApp('public/index.html'), - appIndexJs: resolveApp('src/index.js'), - appPackageJson: resolveApp('package.json'), - appSrc: resolveApp('src'), - yarnLockFile: resolveApp('yarn.lock'), - testsSetup: resolveApp('src/setupTests.js'), - appNodeModules: resolveApp('node_modules'), - // this is empty with npm3 but node resolution searches higher anyway: - ownNodeModules: resolveOwn('../node_modules'), - nodePaths: nodePaths -}; +// We set up module.exports depending on how react-scripts is run. The current +// directory path will contain `packages/react-scripts` when running from +// create-react-app, and `node_modules/react-scripts` when installed from +// another project. Note that when installing this package using `npm link`, +// the current directory path contains `packages/react-scripts`. There is a +// specific condition to handle this case so that it doesn't conflict with +// other scripts (like `build` or `publish`) or running the smoke test. +var isRunningFromApp = __dirname.indexOf(path.join('node_modules', 'react-scripts', 'config')) !== -1; +var isRunningFromOwn = __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1; +var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1); +var isRunningFromAppUsingLink = (process.env.npm_lifecycle_event === 'start') && isRunningFromOwn && !isSmokeTest -// config before publish: we're in ./packages/react-scripts/config/ -if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) { +if (isRunningFromApp || isRunningFromAppUsingLink) { + module.exports = { + appBuild: resolveApp('build'), + appPublic: resolveApp('public'), + appHtml: resolveApp('public/index.html'), + appIndexJs: resolveApp('src/index.js'), + appPackageJson: resolveApp('package.json'), + appSrc: resolveApp('src'), + yarnLockFile: resolveApp('yarn.lock'), + testsSetup: resolveApp('src/setupTests.js'), + appNodeModules: resolveApp('node_modules'), + // this is empty with npm3 but node resolution searches higher anyway: + ownNodeModules: resolveOwn('../node_modules'), + nodePaths: nodePaths + }; +} else { module.exports = { appBuild: resolveOwn('../../../build'), appPublic: resolveOwn('../template/public'), From fd4f81b93b329f95f4aa75d11ae93291a6326c92 Mon Sep 17 00:00:00 2001 From: Tabrez Mohammed Date: Thu, 1 Dec 2016 01:33:43 -0800 Subject: [PATCH 2/3] don't hardcode react-scripts module name --- packages/react-scripts/config/paths.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index f17be16bb86..3e22d23acfa 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -55,19 +55,20 @@ function resolveOwn(relativePath) { return path.resolve(__dirname, relativePath); } -// We set up module.exports depending on how react-scripts is run. The current -// directory path will contain `packages/react-scripts` when running from -// create-react-app, and `node_modules/react-scripts` when installed from -// another project. Note that when installing this package using `npm link`, -// the current directory path contains `packages/react-scripts`. There is a -// specific condition to handle this case so that it doesn't conflict with -// other scripts (like `build` or `publish`) or running the smoke test. -var isRunningFromApp = __dirname.indexOf(path.join('node_modules', 'react-scripts', 'config')) !== -1; +// Set up module.exports depending on how react-scripts is run. The current +// path will contain `packages/react-scripts` when running from create-react-app. +// We don't make assumptions about the path when this package is installed from +// another app since it could've be renamed. +// Note that when installing this package using `npm link`, the current +// directory path contains `packages/react-scripts` (instead of, for example, +// `node_modules/react-scripts`). There is a specific condition to handle this +// case so that it doesn't conflict with other scripts (like `build` or +// `publish`) or running the smoke test. var isRunningFromOwn = __dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1; var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1); var isRunningFromAppUsingLink = (process.env.npm_lifecycle_event === 'start') && isRunningFromOwn && !isSmokeTest -if (isRunningFromApp || isRunningFromAppUsingLink) { +if (!isRunningFromOwn || isRunningFromAppUsingLink) { module.exports = { appBuild: resolveApp('build'), appPublic: resolveApp('public'), From 737c20bac194005f20f62eb5b79dded7adfa156c Mon Sep 17 00:00:00 2001 From: Tabrez Mohammed Date: Thu, 1 Dec 2016 10:12:59 -0800 Subject: [PATCH 3/3] Update paths.js nit: grammar fix in comment --- packages/react-scripts/config/paths.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 3e22d23acfa..544b72202fc 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -58,7 +58,8 @@ function resolveOwn(relativePath) { // Set up module.exports depending on how react-scripts is run. The current // path will contain `packages/react-scripts` when running from create-react-app. // We don't make assumptions about the path when this package is installed from -// another app since it could've be renamed. +// another app since it could've been renamed. + // Note that when installing this package using `npm link`, the current // directory path contains `packages/react-scripts` (instead of, for example, // `node_modules/react-scripts`). There is a specific condition to handle this