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

Check the app name before proceeding. #628

Merged
merged 6 commits into from
Sep 11, 2016
Merged
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
28 changes: 27 additions & 1 deletion global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ createApp(commands[0], argv.verbose, argv['scripts-version']);

function createApp(name, verbose, version) {
var root = path.resolve(name);
var appName = path.basename(root);

checkAppName(appName);

if (!pathExists.sync(name)) {
fs.mkdirSync(root);
} else if (!isSafeToCreateProjectIn(root)) {
console.log('The directory `' + name + '` contains file(s) that could conflict. Aborting.');
process.exit(1);
}

var appName = path.basename(root);
console.log(
'Creating a new React app in ' + root + '.'
);
Expand Down Expand Up @@ -167,6 +170,29 @@ function checkNodeVersion() {
}
}

function checkAppName(appName) {
// TODO: there should be a single place that holds the dependencies
var dependencies = ['react', 'react-dom'];
var devDependencies = ['react-scripts'];
var allDependencies = dependencies.concat(devDependencies).sort();

if (allDependencies.indexOf(appName) >= 0) {
console.error(
chalk.red(
`Can't use "${appName}" as the app name because a dependency with the same name exists.\n\n` +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can’t use template strings. It’s meant to be runnable in older nodes, at least until we warn about unsupported version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I'm very sorry. I've got confused by this line but now I realized it's for create-react-app project itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also requirement for Node >=4 is stated in the README. It is misleading. Shall we change that?
screen shot 2016-09-18 at 14 03 55

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mareksuscak The requirement for Node >= 4 is correct, however we want this entry point file to still run in older versions, so that instead of just crashing, we can show a warning, if someone tries to use an unsupported version.

This is what it looks like:
screen shot 2016-09-18 at 15 16 00

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good then. Didn't know. Thanks for explaining.

`Following names ${chalk.red.bold('must not')} be used:\n\n`
)

+

chalk.cyan(
allDependencies.map(depName => ` ${depName}`).join('\n')
)
);
process.exit(1);
}
}

// If project only contains files generated by GH, it’s safe.
// We also special case IJ-based products .idea because it integrates with CRA:
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
Expand Down