Skip to content

Commit

Permalink
Don't use yarn if a package-lock.json file is found (#31926)
Browse files Browse the repository at this point in the history
Fixes #31755
  • Loading branch information
thibautsabot committed Feb 5, 2022
1 parent 1aeb230 commit 2ea2c81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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

0 comments on commit 2ea2c81

Please sign in to comment.