-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Changes from 5 commits
01b57c9
8aaa612
0669da8
03a0d8a
8b4f5b1
ddff528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 + '.' | ||
); | ||
|
@@ -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` + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a few semicolons here.