Skip to content

Add ES5 version of path-exists to CLI #617

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 15 additions & 2 deletions global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var spawn = require('cross-spawn');
var chalk = require('chalk');
var semver = require('semver');
var argv = require('minimist')(process.argv.slice(2));
var pathExists = require('path-exists');

/**
* Arguments:
Expand Down Expand Up @@ -69,7 +68,7 @@ createApp(commands[0], argv.verbose, argv['scripts-version']);

function createApp(name, verbose, version) {
var root = path.resolve(name);
if (!pathExists.sync(name)) {
if (!pathExists(name)) {
fs.mkdirSync(root);
} else if (!isSafeToCreateProjectIn(root)) {
console.log('The directory `' + name + '` contains file(s) that could conflict. Aborting.');
Expand Down Expand Up @@ -179,3 +178,17 @@ function isSafeToCreateProjectIn(root) {
return validFiles.indexOf(file) >= 0;
});
}

// This is an ES5 version of https://github.com/sindresorhus/path-exists
// The reason it exists is so that the CLI doesn't break before being able to
// warn the user they're using an unsupported version of Node.
//
// See https://github.com/facebookincubator/create-react-app/issues/570
function pathExists(fp) {
try {
fs.accessSync(fp);
return true;
} catch (err) {
return false;
}
}