Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
B4rtware authored and sodatea committed Oct 16, 2019
1 parent b65b24e commit badf63d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
29 changes: 17 additions & 12 deletions packages/@vue/cli-shared-utils/lib/env.js
Expand Up @@ -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) => {
Expand Down
20 changes: 14 additions & 6 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Expand Up @@ -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')
Expand All @@ -32,19 +33,26 @@ 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'],
add: ['install', '--loglevel', 'error'],
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'],
Expand Down

0 comments on commit badf63d

Please sign in to comment.