From a6118d0dba9aec89c40b57dbeb67c1ce8135df06 Mon Sep 17 00:00:00 2001 From: Reinier Hartog Date: Thu, 9 Nov 2017 15:31:26 +0100 Subject: [PATCH 1/2] Use `resolve-from` to respect `node_modules` hierarchy in `createReactApp.js` --- packages/create-react-app/createReactApp.js | 22 +++++++++------------ packages/create-react-app/package.json | 1 + 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/create-react-app/createReactApp.js b/packages/create-react-app/createReactApp.js index 9ff7c08cf9e..36204a6154f 100755 --- a/packages/create-react-app/createReactApp.js +++ b/packages/create-react-app/createReactApp.js @@ -47,6 +47,7 @@ const tmp = require('tmp'); const unpack = require('tar-pack').unpack; const url = require('url'); const hyperquest = require('hyperquest'); +const resolveFrom = require('resolve-from'); const packageJson = require('./package.json'); @@ -292,15 +293,12 @@ function run( ); }) .then(packageName => { - checkNodeVersion(packageName); + checkNodeVersion(root, packageName); setCaretRangeForRuntimeDeps(packageName); - const scriptsPath = path.resolve( - process.cwd(), - 'node_modules', - packageName, - 'scripts', - 'init.js' + const scriptsPath = resolveFrom( + root, + path.join(packageName, 'scripts', 'init.js') ); const init = require(scriptsPath); init(root, appName, verbose, originalDirectory, template); @@ -478,12 +476,10 @@ function checkNpmVersion() { }; } -function checkNodeVersion(packageName) { - const packageJsonPath = path.resolve( - process.cwd(), - 'node_modules', - packageName, - 'package.json' +function checkNodeVersion(root, packageName) { + const packageJsonPath = resolveFrom( + root, + path.join(packageName, 'package.json') ); const packageJson = require(packageJsonPath); if (!packageJson.engines || !packageJson.engines.node) { diff --git a/packages/create-react-app/package.json b/packages/create-react-app/package.json index 569985f5c07..cf445df6f1e 100644 --- a/packages/create-react-app/package.json +++ b/packages/create-react-app/package.json @@ -26,6 +26,7 @@ "cross-spawn": "^4.0.0", "fs-extra": "^1.0.0", "hyperquest": "^2.1.2", + "resolve-from": "^4.0.0", "semver": "^5.0.3", "tar-pack": "^3.4.0", "tmp": "0.0.31", From bd7216fb9c7c9324da2a9568baaa01580c15c354 Mon Sep 17 00:00:00 2001 From: Reinier Hartog Date: Fri, 10 Nov 2017 08:19:25 +0100 Subject: [PATCH 2/2] Resolve `ownPath` in `init.js` using `resolve-from` --- packages/react-scripts/scripts/init.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index b283bad6ee6..eed9b340de5 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -18,6 +18,7 @@ const fs = require('fs-extra'); const path = require('path'); const chalk = require('chalk'); const spawn = require('react-dev-utils/crossSpawn'); +const resolveFrom = require('resolve-from'); module.exports = function( appPath, @@ -28,7 +29,10 @@ module.exports = function( ) { const ownPackageName = require(path.join(__dirname, '..', 'package.json')) .name; - const ownPath = path.join(appPath, 'node_modules', ownPackageName); + const ownPath = path.join( + resolveFrom(appPath, path.join(ownPackageName, 'package.json')), + '..' + ); const appPackage = require(path.join(appPath, 'package.json')); const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));