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: should infer package manager from config if there's no lockfile in the project #5150

Merged
merged 2 commits into from Feb 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use findup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes more sense.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we force the package manager?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -m / --packageManager option of vue create. Maybe we should add this option for vue add and vue invoke too?

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