Skip to content

fix: more accurate warning message for missing global peer dependencies #5871

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

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
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
29 changes: 3 additions & 26 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
const getVersions = require('./getVersions')
const {
chalk,
execa,
semver,

clearConsole,

hasYarn,
hasPnpm3OrLater
clearConsole
} = require('@vue/cli-shared-utils')

async function getInstallationCommand () {
if (hasYarn()) {
const { stdout: yarnGlobalDir } = await execa('yarn', ['global', 'dir'])
if (__dirname.includes(yarnGlobalDir)) {
return 'yarn global add'
}
}

if (hasPnpm3OrLater()) {
const { stdout: pnpmGlobalPrefix } = await execa('pnpm', ['config', 'get', 'prefix'])
if (__dirname.includes(pnpmGlobalPrefix) && __dirname.includes('pnpm-global')) {
return `pnpm i -g`
}
}

const { stdout: npmGlobalPrefix } = await execa('npm', ['config', 'get', 'prefix'])
if (__dirname.includes(npmGlobalPrefix)) {
return `npm i -g`
}
}
const getGlobalInstallCommand = require('./getGlobalInstallCommand')

exports.generateTitle = async function (checkUpdate) {
const { current, latest, error } = await getVersions()
Expand All @@ -53,7 +30,7 @@ exports.generateTitle = async function (checkUpdate) {
let upgradeMessage = `New version available ${chalk.magenta(current)} → ${chalk.green(latest)}`

try {
const command = await getInstallationCommand()
const command = getGlobalInstallCommand()
let name = require('../../package.json').name
if (semver.prerelease(latest)) {
name += '@next'
Expand Down
22 changes: 22 additions & 0 deletions packages/@vue/cli/lib/util/getGlobalInstallCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { execa, hasYarn, hasPnpm3OrLater } = require('@vue/cli-shared-utils')

module.exports = function getGlobalInstallCommand () {
if (hasYarn()) {
const { stdout: yarnGlobalDir } = execa.sync('yarn', ['global', 'dir'])
if (__dirname.includes(yarnGlobalDir)) {
return 'yarn global add'
}
}

if (hasPnpm3OrLater()) {
const { stdout: pnpmGlobalPrefix } = execa.sync('pnpm', ['config', 'get', 'prefix'])
if (__dirname.includes(pnpmGlobalPrefix) && __dirname.includes('pnpm-global')) {
return `pnpm i -g`
}
}

const { stdout: npmGlobalPrefix } = execa.sync('npm', ['config', 'get', 'prefix'])
if (__dirname.includes(npmGlobalPrefix)) {
return `npm i -g`
}
}
11 changes: 4 additions & 7 deletions packages/@vue/cli/lib/util/loadCommand.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { chalk } = require('@vue/cli-shared-utils')
const getGlobalInstallCommand = require('./getGlobalInstallCommand')

module.exports = function loadCommand (commandName, moduleName) {
const isNotFoundError = err => {
return err.message.match(/Cannot find module/)
Expand All @@ -10,13 +13,7 @@ module.exports = function loadCommand (commandName, moduleName) {
return require('import-global')(moduleName)
} catch (err2) {
if (isNotFoundError(err2)) {
const { chalk, hasYarn, hasPnpm3OrLater } = require('@vue/cli-shared-utils')
let installCommand = `npm install -g`
if (hasYarn()) {
installCommand = `yarn global add`
} else if (hasPnpm3OrLater()) {
installCommand = `pnpm install -g`
}
const installCommand = getGlobalInstallCommand()
console.log()
console.log(
` Command ${chalk.cyan(`vue ${commandName}`)} requires a global addon to be installed.\n` +
Expand Down