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

Don't use yarn if a package-lock.json file is found #31926

Merged
merged 3 commits into from Feb 5, 2022
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
14 changes: 11 additions & 3 deletions packages/next/lib/helpers/should-use-yarn.ts
@@ -1,13 +1,21 @@
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'

export function shouldUseYarn(): boolean {
export function shouldUseYarn(baseDir: string): boolean {
try {
const userAgent = process.env.npm_config_user_agent
if (userAgent) {
return Boolean(userAgent && userAgent.startsWith('yarn'))
} else {
if (fs.existsSync(path.join(baseDir, 'yarn.lock'))) {
return true
} else if (fs.existsSync(path.join(baseDir, 'package-lock.json'))) {
return false
}
execSync('yarnpkg --version', { stdio: 'ignore' })
return true
}
execSync('yarnpkg --version', { stdio: 'ignore' })
return true
} catch (e) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/lib/install-dependencies.ts
Expand Up @@ -15,7 +15,7 @@ export async function installDependencies(
deps: any,
dev: boolean = false
) {
const useYarn = shouldUseYarn()
const useYarn = shouldUseYarn(baseDir)
const isOnline = !useYarn || (await getOnline())

if (deps.length) {
Expand Down