Skip to content

Commit

Permalink
fix: vitejs#2360. Add validation for project name.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkehappy committed Mar 5, 2021
1 parent 4364992 commit 486014c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/create-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TEMPLATES = [
const renameFiles = {
_gitignore: '.gitignore'
}
const projectNameRE = /^[A-Za-z0-9_-]*$/

async function init() {
let targetDir = argv._[0]
Expand All @@ -44,6 +45,12 @@ async function init() {
message: `Project name:`,
initial: 'vite-project'
})
if (!projectNameRE.test(name)) {
console.error(
`Project name "${name}" should only contain letters, numbers, underscores and dashs.`
)
process.exit(1)
}
targetDir = name
}

Expand Down

0 comments on commit 486014c

Please sign in to comment.