Skip to content

Commit

Permalink
feat: convert project name to lowercase and warn on creation
Browse files Browse the repository at this point in the history
closes vuejs#2547
closes vuejs#5032

I'm still very hesitant on adding this feature, though.

First, this change allows project creation in a folder with uppercase
letters in its name. It is strongly discouraged and may cause many
weird issues all over the ecosystem.

For example, vuejs#5022, vuejs#4424, vuejs#3665, vuejs#4174#issuecomment-569709494 are all
caused by case issues. Adding support for uppercase project names will
only worsen this situation.

Secondly, it adds a lot of maintenance burden to us. As noted in the
comments, these prompts are hard to test right now (because
`createTestProject` runs in another process so it's hard to intercept
the prompts). Even if such test utilities are added in the future, it's
still very tedious to take care of all the case issues in the test
suite.

What's worse is that we can affect the project folders created by
@vue/cli by converting the project name to lower case. But for
`vue create .`, we cannot change the current folder's name. So, we'll
have another edge case to test.
  • Loading branch information
haoqunjiang committed Jan 20, 2020
1 parent 8fcea22 commit e504f43
Showing 1 changed file with 20 additions and 2 deletions.
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

0 comments on commit e504f43

Please sign in to comment.