Skip to content
Closed
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
10 changes: 10 additions & 0 deletions packages/create-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
lightRed,
stripColors
} = require('kolorist')
const validatePackageName = require('validate-npm-package-name')

const cwd = process.cwd()

Expand All @@ -31,6 +32,7 @@ const TEMPLATES = [
const renameFiles = {
_gitignore: '.gitignore'
}
const projectNameRE = /^[A-Za-z0-9_-]*$/
Copy link
Contributor

Choose a reason for hiding this comment

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

This is totally incorrect. Please use something like validate-npm-package-name

Vite depends on resolve.exports which wouldn't pass your regex, for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const projectNameRE = /^[A-Za-z0-9_-]*$/

This is no longer used.


async function init() {
let targetDir = argv._[0]
Expand All @@ -44,6 +46,14 @@ async function init() {
message: `Project name:`,
initial: 'vite-project'
})
const { errors } = validatePackageName(name)
if (errors) {
errors.unshift(`Invalid package name: "${name}"`)
// Multiple errors may be returned even for one name.
// For example the "foobar "
console.error(errors.join('\n - '))
process.exit(1)
}
targetDir = name
}

Expand Down
3 changes: 2 additions & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down