Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cdpath bug #166

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
});
}

Expand Down
9 changes: 6 additions & 3 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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;
Expand Down