Skip to content

Commit e504f43

Browse files
committed
feat: convert project name to lowercase and warn on creation
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.
1 parent 8fcea22 commit e504f43

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

packages/@vue/cli/lib/create.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ const { getPromptModules } = require('./util/createTools')
77
const { chalk, error, stopSpinner, exit } = require('@vue/cli-shared-utils')
88
const validateProjectName = require('validate-npm-package-name')
99

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

1516
const cwd = options.cwd || process.cwd()
1617
const inCurrent = projectName === '.'
17-
const name = inCurrent ? path.relative('../', cwd) : projectName
18-
const targetDir = path.resolve(cwd, projectName || '.')
1918

19+
const originalName = inCurrent ? path.relative('../', cwd) : projectName
20+
const name = originalName.toLowerCase()
21+
22+
// TODO: should also implement this logic in the UI
2023
const result = validateProjectName(name)
2124
if (!result.validForNewPackages) {
2225
console.error(chalk.red(`Invalid project name: "${name}"`))
@@ -29,6 +32,21 @@ async function create (projectName, options) {
2932
exit(1)
3033
}
3134

35+
if (name !== originalName) {
36+
const { continueWithLowerCase } = await inquirer.prompt([
37+
{
38+
name: 'continueWithLowerCase',
39+
type: 'confirm',
40+
message: `Uppercase is not allowed in an npm package. Continue with the name ${chalk.yellow(name)}?`
41+
}
42+
])
43+
44+
if (!continueWithLowerCase) {
45+
return
46+
}
47+
}
48+
49+
const targetDir = path.resolve(cwd, inCurrent ? '.' : name)
3250
if (fs.existsSync(targetDir) && !options.merge) {
3351
if (options.force) {
3452
await fs.remove(targetDir)

0 commit comments

Comments
 (0)