mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-02 10:00:47 -05:00
fix: add pnpm v4 support (#4677)
* fix: add pnpm v4 support in pnpm v4 the option '--loglevel' is no longer available instead '--reporter' is used. * refactor: remove 'v' from PNPM constants for linting * refactor: rename variable * fix: typo in _hasPnpm4orLater Co-Authored-By: Pavan Kumar Sunkara <pavan.sss1991@gmail.com> * refactor: reduce the amount of duplicate code for pnpm version check * refactor: remove return-assignment * refactor: add explicit return value instead of using array access Co-Authored-By: Pavan Kumar Sunkara <pavan.sss1991@gmail.com> * fix: remove return value from checkPnpmVersion * fix: pnpmVersion variable * refactor: cache pnpm version number * refactor: fix function name and revert api break * fix: function call correction * refactor: export hasPnpmVersionOrLater and use this in favor of hasPnpm4OrLater * refactor: move cache getter into getPnpmVersion * refactor: add comment * refactor: remove comment
This commit is contained in:
@@ -79,32 +79,37 @@ exports.hasProjectGit = (cwd) => {
|
||||
}
|
||||
|
||||
let _hasPnpm
|
||||
let _hasPnpm3orLater
|
||||
let _pnpmVersion
|
||||
const _pnpmProjects = new LRU({
|
||||
max: 10,
|
||||
maxAge: 1000
|
||||
})
|
||||
|
||||
exports.hasPnpm3OrLater = () => {
|
||||
if (process.env.VUE_CLI_TEST) {
|
||||
return true
|
||||
}
|
||||
if (_hasPnpm3orLater != null) {
|
||||
return _hasPnpm3orLater
|
||||
function getPnpmVersion () {
|
||||
if (_pnpmVersion != null) {
|
||||
return _pnpmVersion
|
||||
}
|
||||
try {
|
||||
const pnpmVersion = execSync('pnpm --version', {
|
||||
_pnpmVersion = execSync('pnpm --version', {
|
||||
stdio: ['pipe', 'pipe', 'ignore']
|
||||
}).toString()
|
||||
// there's a critical bug in pnpm 2
|
||||
// https://github.com/pnpm/pnpm/issues/1678#issuecomment-469981972
|
||||
// so we only support pnpm >= 3.0.0
|
||||
_hasPnpm = true
|
||||
_hasPnpm3orLater = semver.gte(pnpmVersion, '3.0.0')
|
||||
return _hasPnpm3orLater
|
||||
} catch (e) {
|
||||
return (_hasPnpm3orLater = false)
|
||||
} catch (e) {}
|
||||
return _pnpmVersion || '0.0.0'
|
||||
}
|
||||
|
||||
exports.hasPnpmVersionOrLater = (version) => {
|
||||
if (process.env.VUE_CLI_TEST) {
|
||||
return true
|
||||
}
|
||||
return semver.gte(getPnpmVersion(), version)
|
||||
}
|
||||
|
||||
exports.hasPnpm3OrLater = () => {
|
||||
return this.hasPnpmVersionOrLater('3.0.0')
|
||||
}
|
||||
|
||||
exports.hasProjectPnpm = (cwd) => {
|
||||
|
||||
@@ -11,6 +11,7 @@ const {
|
||||
hasYarn,
|
||||
hasProjectYarn,
|
||||
hasPnpm3OrLater,
|
||||
hasPnpmVersionOrLater,
|
||||
hasProjectPnpm
|
||||
} = require('@vue/cli-shared-utils/lib/env')
|
||||
const { isOfficialPlugin, resolvePluginId } = require('@vue/cli-shared-utils/lib/pluginResolution')
|
||||
@@ -32,6 +33,18 @@ const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
|
||||
|
||||
const TAOBAO_DIST_URL = 'https://npm.taobao.org/dist'
|
||||
const SUPPORTED_PACKAGE_MANAGERS = ['yarn', 'pnpm', 'npm']
|
||||
const PACKAGE_MANAGER_PNPM4_CONFIG = {
|
||||
install: ['install', '--reporter', 'silent', '--shamefully-hoist'],
|
||||
add: ['install', '--reporter', 'silent', '--shamefully-hoist'],
|
||||
upgrade: ['update', '--reporter', 'silent'],
|
||||
remove: ['uninstall', '--reporter', 'silent']
|
||||
}
|
||||
const PACKAGE_MANAGER_PNPM3_CONFIG = {
|
||||
install: ['install', '--loglevel', 'error', '--shamefully-flatten'],
|
||||
add: ['install', '--loglevel', 'error', '--shamefully-flatten'],
|
||||
upgrade: ['update', '--loglevel', 'error'],
|
||||
remove: ['uninstall', '--loglevel', 'error']
|
||||
}
|
||||
const PACKAGE_MANAGER_CONFIG = {
|
||||
npm: {
|
||||
install: ['install', '--loglevel', 'error'],
|
||||
@@ -39,12 +52,7 @@ const PACKAGE_MANAGER_CONFIG = {
|
||||
upgrade: ['update', '--loglevel', 'error'],
|
||||
remove: ['uninstall', '--loglevel', 'error']
|
||||
},
|
||||
pnpm: {
|
||||
install: ['install', '--loglevel', 'error', '--shamefully-flatten'],
|
||||
add: ['install', '--loglevel', 'error', '--shamefully-flatten'],
|
||||
upgrade: ['update', '--loglevel', 'error'],
|
||||
remove: ['uninstall', '--loglevel', 'error']
|
||||
},
|
||||
pnpm: hasPnpmVersionOrLater('4.0.0') ? PACKAGE_MANAGER_PNPM4_CONFIG : PACKAGE_MANAGER_PNPM3_CONFIG,
|
||||
yarn: {
|
||||
install: [],
|
||||
add: ['add'],
|
||||
|
||||
Reference in New Issue
Block a user