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

fix: #2360. Add validation for project name. #2385

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
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_-]*$/
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 +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 dashes.`
antfu marked this conversation as resolved.
Show resolved Hide resolved
)
process.exit(1)
}
targetDir = name
}

Expand Down