Skip to content
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

fix: add pnpm v4 support #4677

Merged
merged 16 commits into from
Oct 16, 2019
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: 17 additions & 12 deletions packages/@vue/cli-shared-utils/lib/env.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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