diff --git a/packages/create-app/index.js b/packages/create-app/index.js index 382cfb504a2157..dfe32742fb5b1d 100755 --- a/packages/create-app/index.js +++ b/packages/create-app/index.js @@ -13,6 +13,7 @@ const { lightRed, stripColors } = require('kolorist') +const validatePackageName = require('validate-npm-package-name') const cwd = process.cwd() @@ -45,9 +46,11 @@ async function init() { message: `Project name:`, initial: 'vite-project' }) - if (!projectNameRE.test(name)) { + const validateResult = validatePackageName(name) + if (!validateResult.validForNewPackages) { console.error( - `Project name "${name}" should only contain letters, numbers, underscores and dashes.` + // Only one name to be validated, so there will be only one error + validateResult.errors.length && validateResult.errors[0] ) process.exit(1) } diff --git a/packages/create-app/package.json b/packages/create-app/package.json index b246019763dc36..1f7e4c1cfe24e1 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -30,6 +30,7 @@ "dependencies": { "enquirer": "^2.3.6", "kolorist": "^1.2.9", - "minimist": "^1.2.5" + "minimist": "^1.2.5", + "validate-npm-package-name": "^3.0.0" } } diff --git a/yarn.lock b/yarn.lock index 324fcea97657eb..29848050b40716 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1803,6 +1803,11 @@ builtin-modules@^3.1.0, builtin-modules@^3.2.0: resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887" integrity sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA== +builtins@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88" + integrity sha1-y5T662HIaWRR2zZTThQi+U8K7og= + bytes@3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" @@ -7833,6 +7838,13 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" +validate-npm-package-name@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz#5fa912d81eb7d0c74afc140de7317f0ca7df437e" + integrity sha1-X6kS2B630MdK/BQN5zF/DKffQ34= + dependencies: + builtins "^1.0.3" + validator@^8.0.0: version "8.2.0" resolved "https://registry.yarnpkg.com/validator/-/validator-8.2.0.tgz#3c1237290e37092355344fef78c231249dab77b9"