From 8292c41311ec41d9d50921fbb2bdeed69e039443 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 10 Aug 2023 11:33:37 -0500 Subject: [PATCH] fix(#5637): fix yarn berry support for create-astro (#8028) --- .changeset/nasty-olives-rush.md | 5 +++++ packages/create-astro/src/actions/dependencies.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/nasty-olives-rush.md diff --git a/.changeset/nasty-olives-rush.md b/.changeset/nasty-olives-rush.md new file mode 100644 index 000000000000..cb78479f2bef --- /dev/null +++ b/.changeset/nasty-olives-rush.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Improve yarn berry support diff --git a/packages/create-astro/src/actions/dependencies.ts b/packages/create-astro/src/actions/dependencies.ts index ed19fe4853b2..32c8711b06dc 100644 --- a/packages/create-astro/src/actions/dependencies.ts +++ b/packages/create-astro/src/actions/dependencies.ts @@ -1,5 +1,7 @@ import { color } from '@astrojs/cli-kit'; import { execa } from 'execa'; +import path from 'node:path'; +import fs from 'node:fs'; import { error, info, spinner, title } from '../messages.js'; import type { Context } from './context'; @@ -46,10 +48,17 @@ export async function dependencies( } async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) { + if (pkgManager === 'yarn') await ensureYarnLock({ cwd }); const installExec = execa(pkgManager, ['install'], { cwd }); return new Promise((resolve, reject) => { - setTimeout(() => reject(`Request timed out after one minute`), 60_000); + setTimeout(() => reject(`Request timed out after 1m 30s`), 90_000); installExec.on('error', (e) => reject(e)); installExec.on('close', () => resolve()); }); } + +async function ensureYarnLock({ cwd }: { cwd: string }) { + const yarnLock = path.join(cwd, 'yarn.lock'); + if (fs.existsSync(yarnLock)) return; + return fs.promises.writeFile(yarnLock, '', { encoding: 'utf-8' }); +}