8000 fix: add pnpm v4 support by B4rtware · Pull Request #4677 · vuejs/vue-cli · GitHub
[go: up one dir, main page]

Skip to content

fix: add pnpm v4 support #4677

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 16 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: fix function name and revert api break
  • Loading branch information
B4rtware committed Oct 14, 2019
commit 7157ff75872cdb2266a5aeacb6 8000 6eb84fee1c482f
12 changes: 10 additions & 2 deletions packages/@vue/cli-shared-utils/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function getPnpmVersion () {
return _pnpmVersion || '0.0.0'
}

exports.hasPnpmXOrLater = (version) => {
function hasPnpmVersionOrLater (version) {
if (process.env.VUE_CLI_TEST) {
return true
}
Expand All @@ -108,6 +108,14 @@ exports.hasPnpmXOrLater = (version) => {
return semver.gte(getPnpmVersion(), version)
}

exports.hasPnpm3OrLater = () => {
return hasPnpmVersionOrLater('3.0.0')
}

exports.hasPnpm4OrLater = () => {
return hasPnpmVersionOrLater('4.0.0')
}

exports.hasProjectPnpm = (cwd) => {
if (_pnpmProjects.has(cwd)) {
return checkPnpm(_pnpmProjects.get(cwd))
Expand All @@ -120,7 +128,7 @@ exports.hasProjectPnpm = (cwd) => {
}

function checkPnpm (result) {
if (result && !exports.hasPnpmXOrLater('3.0.0')) {
if (result && !exports.hasPnpm3OrLater()) {
throw new Error(`The project seems to require pnpm${_hasPnpm ? ' >= 3' : ''} but it's not installed.`)
}
return result
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-ui/apollo-server/util/command.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const {
hasYarn,
hasProjectYarn,
hasPnpmXOrLater,
hasPnpm3OrLater,
hasProjectPnpm
} = require('@vue/cli-shared-utils')
const { loadOptions } = require('@vue/cli/lib/options')

exports.getCommand = function (cwd = undefined) {
if (!cwd) {
return loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpmXOrLater('3.0.0') ? 'pnpm' : 'npm')
return loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpm3OrLater() ? 'pnpm' : 'npm')
}
return hasProjectYarn(cwd) ? 'yarn' : hasProjectPnpm(cwd) ? 'pnpm' : 'npm'
}
8 changes: 4 additions & 4 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const {
hasGit,
hasProjectGit,
hasYarn,
hasPnpmXOrLater,
hasPnpm3OrLater,
logWithSpinner,
stopSpinner,
exit,
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = class Creator extends EventEmitter {
cliOptions.packageManager ||
loadOptions().packageManager ||
(hasYarn() ? 'yarn' : null) ||
(hasPnpmXOrLater('3.0.0') ? 'pnpm' : 'npm')
(hasPnpm3OrLater() ? 'pnpm' : 'npm')
)
const pm = new PackageManager({ context, forcePackageManager: packageManager })

Expand Down Expand Up @@ -448,7 +448,7 @@ module.exports = class Creator extends EventEmitter {

// ask for packageManager once
const savedOptions = loadOptions()
if (!savedOptions.packageManager && (hasYarn() || hasPnpmXOrLater('3.0.0'))) {
if (!savedOptions.packageManager && (hasYarn() || hasPnpm3OrLater())) {
const packageManagerChoices = []

if (hasYarn()) {
Expand All @@ -459,7 +459,7 @@ module.exports = class Creator extends EventEmitter {
})
}

if (hasPnpmXOrLater('3.0.0')) {
if (hasPnpm3OrLater()) {
packageManagerChoices.push({
name: 'Use PNPM',
value: 'pnpm',
Expand Down
7 changes: 4 additions & 3 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const chalk = require('chalk')
const {
hasYarn,
hasProjectYarn,
hasPnpmXOrLater,
hasPnpm3OrLater,
hasPnpm4OrLater,
hasProjectPnpm
} = require('@vue/cli-shared-utils/lib/env')
const { isOfficialPlugin, resolvePluginId } = require('@vue/cli-shared-utils/lib/pluginResolution')
Expand Down Expand Up @@ -51,7 +52,7 @@ const PACKAGE_MANAGER_CONFIG = {
upgrade: ['update', '--loglevel', 'error'],
remove: ['uninstall', '--loglevel', 'error']
},
pnpm: hasPnpmXOrLater('4.0.0') ? PACKAGE_MANAGER_PNPM4_CONFIG : PACKAGE_MANAGER_PNPM3_CONFIG,
pnpm: hasPnpm4OrLater ? PACKAGE_MANAGER_PNPM4_CONFIG : PACKAGE_MANAGER_PNPM3_CONFIG,
yarn: {
install: [],
add: ['add'],
Expand Down Expand Up @@ -81,7 +82,7 @@ class PackageManager {
} else if (context) {
this.bin = hasProjectYarn(context) ? 'yarn' : hasProjectPnpm(context) ? 'pnpm' : 'npm'
} else {
this.bin = loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpmXOrLater('3.0.0') ? 'pnpm' : 'npm')
this.bin = loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpm3OrLater() ? 'pnpm' : 'npm')
}

if (!SUPPORTED_PACKAGE_MANAGERS.includes(this.bin)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const chalk = require('chalk')
const execa = require('execa')
const semver = require('semver')
const getVersions = require('./getVersions')
const { clearConsole, hasYarn, hasPnpmXOrLater } = require('@vue/cli-shared-utils')
const { clearConsole, hasYarn, hasPnpm3OrLater } = require('@vue/cli-shared-utils')

async function getInstallationCommand () {
if (hasYarn()) {
Expand All @@ -12,7 +12,7 @@ async function getInstallationCommand () {
}
}

if (hasPnpmXOrLater('3.0.0')) {
if (hasPnpm3OrLater()) {
const { stdout: pnpmGlobalPrefix } = await execa('pnpm', ['config', 'get', 'prefix'])
if (__dirname.includes(pnpmGlobalPrefix) && __dirname.includes('pnpm-global')) {
return `pnpm i -g`
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli/lib/util/loadCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module.exports = function loadCommand (commandName, moduleName) {
} catch (err2) {
if (isNotFoundError(err2)) {
const chalk = require('chalk')
const { hasYarn, hasPnpmXOrLater } = require('@vue/cli-shared-utils')
const { hasYarn, hasPnpm3OrLater } = require('@vue/cli-shared-utils')
let installCommand = `npm install -g`
if (hasYarn()) {
installCommand = `yarn global add`
} else if (hasPnpmXOrLater('3.0.0')) {
} else if (hasPnpm3OrLater()) {
installCommand = `pnpm install -g`
}
console.log()
Expand Down
0