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

[create-astro] improve yarn berry support #8028

Merged
merged 1 commit into from
Aug 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-olives-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Improve yarn berry support
11 changes: 10 additions & 1 deletion packages/create-astro/src/actions/dependencies.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<void>((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' });
}