Skip to content

Commit 06df2ec

Browse files
author
Kevin Lacker
authored
Merge pull request #166 from lacker/master
fix cdpath bug
2 parents 458d3f9 + 511668c commit 06df2ec

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

global-cli/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ function createApp(name, verbose, version) {
8888
private: true,
8989
};
9090
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson));
91+
var originalDirectory = process.cwd();
9192
process.chdir(root);
9293

9394
console.log('Installing packages. This might take a couple minutes.');
9495
console.log('Installing react-scripts from npm...');
9596

96-
run(root, appName, version, verbose);
97+
run(root, appName, version, verbose, originalDirectory);
9798
}
9899

99-
function run(root, appName, version, verbose) {
100+
function run(root, appName, version, verbose, originalDirectory) {
100101
var args = [
101102
'install',
102103
verbose && '--verbose',
@@ -121,7 +122,7 @@ function run(root, appName, version, verbose) {
121122
'init.js'
122123
);
123124
var init = require(scriptsPath);
124-
init(root, appName, verbose);
125+
init(root, appName, verbose, originalDirectory);
125126
});
126127
}
127128

scripts/init.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var fs = require('fs-extra');
1111
var path = require('path');
1212
var spawn = require('cross-spawn');
1313

14-
module.exports = function(hostPath, appName, verbose) {
14+
module.exports = function(hostPath, appName, verbose, originalDirectory) {
1515
var selfPath = path.join(hostPath, 'node_modules', 'react-scripts');
1616

1717
var hostPackage = require(path.join(hostPath, 'package.json'));
@@ -60,9 +60,12 @@ module.exports = function(hostPath, appName, verbose) {
6060
return;
6161
}
6262

63-
// Make sure to display the right way to cd
63+
// Display the most elegant way to cd.
64+
// This needs to handle an undefined originalDirectory for
65+
// backward compatibility with old global-cli's.
6466
var cdpath;
65-
if (path.join(process.cwd(), appName) === hostPath) {
67+
if (originalDirectory &&
68+
path.join(originalDirectory, appName) === hostPath) {
6669
cdpath = appName;
6770
} else {
6871
cdpath = hostPath;

0 commit comments

Comments
 (0)