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

add project name validation #1662

Merged
merged 2 commits into from
Feb 28, 2017
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
18 changes: 17 additions & 1 deletion packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'use strict';

var chalk = require('chalk');
var validateProjectName = require("validate-npm-package-name");

var currentNodeVersion = process.versions.node;
if (currentNodeVersion.split('.')[0] < 4) {
Expand Down Expand Up @@ -97,6 +98,14 @@ if (typeof projectName === 'undefined') {
process.exit(1);
}

function printValidationResults(results) {
if (typeof results !== 'undefined') {
results.forEach(function (error) {
console.error(chalk.red(' * ' + error));
});
}
}

var hiddenProgram = new commander.Command()
.option('--internal-testing-template <path-to-template>', '(internal usage only, DO NOT RELY ON THIS) ' +
'use a non-standard application template')
Expand Down Expand Up @@ -303,11 +312,18 @@ function checkNodeVersion(packageName) {
}

function checkAppName(appName) {
var validationResult = validateProjectName(appName);
if (!validationResult.validForNewPackages) {
console.error('Could not create a project called ' + chalk.red('"' + appName + '"') + ' because of npm naming restrictions:');
printValidationResults(validationResult.errors);
printValidationResults(validationResult.warnings);
process.exit(1);
}

// 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(
Expand Down
3 changes: 2 additions & 1 deletion packages/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"commander": "^2.9.0",
"cross-spawn": "^4.0.0",
"fs-extra": "^1.0.0",
"semver": "^5.0.3"
"semver": "^5.0.3",
"validate-npm-package-name": "^3.0.0"
}
}