Skip to content

Commit

Permalink
fix: should infer package manager from config if there's no lockfile …
Browse files Browse the repository at this point in the history
…in the project (vuejs#5150)

* fix: should infer package manager from config if there's no lockfile in the project

* fixup! fix: should infer package manager from config if there's no lockfile in the project
  • Loading branch information
sodatea authored and mactanxin committed Feb 11, 2020
1 parent 4aa8aff commit 648531f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/@vue/cli-shared-utils/lib/env.js
Expand Up @@ -130,6 +130,21 @@ function checkPnpm (result) {
return result
}

const _npmProjects = new LRU({
max: 10,
maxAge: 1000
})
exports.hasProjectNpm = (cwd) => {
if (_npmProjects.has(cwd)) {
return true
}

const lockFile = path.join(cwd, 'package-lock.json')
const result = fs.existsSync(lockFile)
_npmProjects.set(cwd, result)
return result
}

// OS
exports.isWindows = process.platform === 'win32'
exports.isMacintosh = process.platform === 'darwin'
Expand Down
14 changes: 12 additions & 2 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Expand Up @@ -18,6 +18,7 @@ const {
hasPnpm3OrLater,
hasPnpmVersionOrLater,
hasProjectPnpm,
hasProjectNpm,

isOfficialPlugin,
resolvePluginId,
Expand Down Expand Up @@ -88,8 +89,17 @@ class PackageManager {
if (forcePackageManager) {
this.bin = forcePackageManager
} else if (context) {
this.bin = hasProjectYarn(context) ? 'yarn' : hasProjectPnpm(context) ? 'pnpm' : 'npm'
} else {
if (hasProjectYarn(context)) {
this.bin = 'yarn'
} else if (hasProjectPnpm(context)) {
this.bin = 'pnpm'
} else if (hasProjectNpm(context)) {
this.bin = 'npm'
}
}

// if no package managers specified, and no lockfile exists
if (!this.bin) {
this.bin = loadOptions().packageManager || (hasYarn() ? 'yarn' : hasPnpm3OrLater() ? 'pnpm' : 'npm')
}

Expand Down

0 comments on commit 648531f

Please sign in to comment.