Skip to content

feat: convert project name to lowercase and warn on creation #5096

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

Closed
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
22 changes: 20 additions & 2 deletions packages/@vue/cli/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ const { getPromptModules } = require('./util/createTools')
const { chalk, error, stopSpinner, exit } = require('@vue/cli-shared-utils')
const validateProjectName = require('validate-npm-package-name')

// TODO: add test cases for prompts in this file
async function create (projectName, options) {
if (options.proxy) {
process.env.HTTP_PROXY = options.proxy
}

const cwd = options.cwd || process.cwd()
const inCurrent = projectName === '.'
const name = inCurrent ? path.relative('../', cwd) : projectName
const targetDir = path.resolve(cwd, projectName || '.')

const originalName = inCurrent ? path.relative('../', cwd) : projectName
const name = originalName.toLowerCase()

// TODO: should also implement this logic in the UI
const result = validateProjectName(name)
if (!result.validForNewPackages) {
console.error(chalk.red(`Invalid project name: "${name}"`))
Expand All @@ -29,6 +32,21 @@ async function create (projectName, options) {
exit(1)
}

if (name !== originalName) {
const { continueWithLowerCase } = await inquirer.prompt([
{
name: 'continueWithLowerCase',
type: 'confirm',
message: `Uppercase is not allowed in an npm package. Continue with the name ${chalk.yellow(name)}?`
}
])

if (!continueWithLowerCase) {
return
}
}

const targetDir = path.resolve(cwd, inCurrent ? '.' : name)
if (fs.existsSync(targetDir) && !options.merge) {
if (options.force) {
await fs.remove(targetDir)
Expand Down