From e504f4344f0f58988095c1a80cc09b59b1b13be9 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 20 Jan 2020 19:04:06 +0800 Subject: [PATCH] feat: convert project name to lowercase and warn on creation closes #2547 closes #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, #5022, #4424, #3665, #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. --- packages/@vue/cli/lib/create.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli/lib/create.js b/packages/@vue/cli/lib/create.js index 1cbabdce32..75cf8eb82d 100644 --- a/packages/@vue/cli/lib/create.js +++ b/packages/@vue/cli/lib/create.js @@ -7,6 +7,7 @@ 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 @@ -14,9 +15,11 @@ async function create (projectName, options) { 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}"`)) @@ -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)