From 5f7ea0d08c202f6c30047ef3e2df5bb25cb20236 Mon Sep 17 00:00:00 2001 From: Thibaut Sabot Date: Mon, 29 Nov 2021 15:55:57 +0100 Subject: [PATCH 1/2] Don't use yarn if a package-lock.json file is found --- packages/next/lib/helpers/should-use-yarn.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/next/lib/helpers/should-use-yarn.ts b/packages/next/lib/helpers/should-use-yarn.ts index c305361517f0b2e..5f5018c0dbc5f77 100644 --- a/packages/next/lib/helpers/should-use-yarn.ts +++ b/packages/next/lib/helpers/should-use-yarn.ts @@ -1,13 +1,20 @@ import { execSync } from 'child_process' +import fs from 'fs' export function shouldUseYarn(): boolean { try { const userAgent = process.env.npm_config_user_agent if (userAgent) { return Boolean(userAgent && userAgent.startsWith('yarn')) + } else { + if (fs.existsSync('yarn.lock')) { + return true + } else if (fs.existsSync('package-lock.json')) { + return false + } + execSync('yarnpkg --version', { stdio: 'ignore' }) + return true } - execSync('yarnpkg --version', { stdio: 'ignore' }) - return true } catch (e) { return false } From 6472406d395f85950002acfd9eb0c0cc057bda39 Mon Sep 17 00:00:00 2001 From: Thibaut Sabot Date: Mon, 29 Nov 2021 16:06:34 +0100 Subject: [PATCH 2/2] use baseDir to find lock files --- packages/next/lib/helpers/should-use-yarn.ts | 7 ++++--- packages/next/lib/install-dependencies.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/next/lib/helpers/should-use-yarn.ts b/packages/next/lib/helpers/should-use-yarn.ts index 5f5018c0dbc5f77..27c15b1dbac7da2 100644 --- a/packages/next/lib/helpers/should-use-yarn.ts +++ b/packages/next/lib/helpers/should-use-yarn.ts @@ -1,15 +1,16 @@ 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('yarn.lock')) { + if (fs.existsSync(path.join(baseDir, 'yarn.lock'))) { return true - } else if (fs.existsSync('package-lock.json')) { + } else if (fs.existsSync(path.join(baseDir, 'package-lock.json'))) { return false } execSync('yarnpkg --version', { stdio: 'ignore' }) diff --git a/packages/next/lib/install-dependencies.ts b/packages/next/lib/install-dependencies.ts index 79184113e14f87b..a27133b472c6db6 100644 --- a/packages/next/lib/install-dependencies.ts +++ b/packages/next/lib/install-dependencies.ts @@ -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) {