diff --git a/global-cli/index.js b/global-cli/index.js index bb2dfe6ec5745a6a56d00e3a6ff2af2d32889a35..1de8897636ffcee6512298410e8721d3edfbbe90 100644 --- a/global-cli/index.js +++ b/global-cli/index.js @@ -88,15 +88,16 @@ function createApp(name, verbose, version) { private: true, }; fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson)); + var originalDirectory = process.cwd(); process.chdir(root); console.log('Installing packages. This might take a couple minutes.'); console.log('Installing react-scripts from npm...'); - run(root, appName, version, verbose); + run(root, appName, version, verbose, originalDirectory); } -function run(root, appName, version, verbose) { +function run(root, appName, version, verbose, originalDirectory) { var args = [ 'install', verbose && '--verbose', @@ -121,7 +122,7 @@ function run(root, appName, version, verbose) { 'init.js' ); var init = require(scriptsPath); - init(root, appName, verbose); + init(root, appName, verbose, originalDirectory); }); } diff --git a/scripts/init.js b/scripts/init.js index fdcdc92cd67545805b8d62ce044d8e0b16fe78ef..b821bae58efe6148abfe88b43a9d7216ddacd7f0 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -11,7 +11,7 @@ var fs = require('fs-extra'); var path = require('path'); var spawn = require('cross-spawn'); -module.exports = function(hostPath, appName, verbose) { +module.exports = function(hostPath, appName, verbose, originalDirectory) { var selfPath = path.join(hostPath, 'node_modules', 'react-scripts'); var hostPackage = require(path.join(hostPath, 'package.json')); @@ -60,9 +60,12 @@ module.exports = function(hostPath, appName, verbose) { return; } - // Make sure to display the right way to cd + // Display the most elegant way to cd. + // This needs to handle an undefined originalDirectory for + // backward compatibility with old global-cli's. var cdpath; - if (path.join(process.cwd(), appName) === hostPath) { + if (originalDirectory && + path.join(originalDirectory, appName) === hostPath) { cdpath = appName; } else { cdpath = hostPath;