diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index bb1fab6fdec..cfdff5b6753 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -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) { @@ -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 ', '(internal usage only, DO NOT RELY ON THIS) ' + 'use a non-standard application template') @@ -304,11 +313,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( diff --git a/packages/create-react-app/package.json b/packages/create-react-app/package.json index e1eb1c45ef2..f26823f5b41 100644 --- a/packages/create-react-app/package.json +++ b/packages/create-react-app/package.json @@ -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" } }