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

Improve create-astro error handling #6266

Merged
merged 3 commits into from
Feb 16, 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/tall-geese-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Improve error handling during tasks that display a spinner
1 change: 0 additions & 1 deletion packages/create-astro/grubby-group
Submodule grubby-group deleted from 9a401d
12 changes: 9 additions & 3 deletions packages/create-astro/src/actions/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Context } from './context';

import { execa } from 'execa';
import { info, spinner, title } from '../messages.js';
import { info, error, spinner, title } from '../messages.js';

export async function dependencies(
ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'pkgManager' | 'cwd' | 'dryRun'>
Expand All @@ -25,7 +25,12 @@ export async function dependencies(
await spinner({
start: `Dependencies installing with ${ctx.pkgManager}...`,
end: 'Dependencies installed',
while: () => install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }),
while: () =>
install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }).catch((e) => {
// eslint-disable-next-line no-console
error('error', e);
process.exit(1);
}),
});
} else {
await info(
Expand All @@ -38,7 +43,8 @@ export async function dependencies(
async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) {
const installExec = execa(pkgManager, ['install'], { cwd });
return new Promise<void>((resolve, reject) => {
installExec.on('error', (error) => reject(error));
setTimeout(() => reject(`Request timed out after one minute`), 60_000);
installExec.on('error', (e) => reject(e));
installExec.on('close', () => resolve());
});
}
8 changes: 6 additions & 2 deletions packages/create-astro/src/actions/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Context } from './context';

import { color } from '@astrojs/cli-kit';
import { execa } from 'execa';
import { info, spinner, title } from '../messages.js';
import { info, spinner, error, title } from '../messages.js';

export async function git(ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' | 'dryRun'>) {
if (fs.existsSync(path.join(ctx.cwd, '.git'))) {
Expand All @@ -29,7 +29,11 @@ export async function git(ctx: Pick<Context, 'cwd' | 'git' | 'yes' | 'prompt' |
await spinner({
start: 'Git initializing...',
end: 'Git initialized',
while: () => init({ cwd: ctx.cwd }),
while: () => init({ cwd: ctx.cwd }).catch((e) => {
// eslint-disable-next-line no-console
error('error', e);
process.exit(1);
}),
});
} else {
await info(
Expand Down
6 changes: 5 additions & 1 deletion packages/create-astro/src/actions/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export async function template(
await spinner({
start: 'Template copying...',
end: 'Template copied',
while: () => copyTemplate(ctx.template!, ctx as Context),
while: () => copyTemplate(ctx.template!, ctx as Context).catch((e) => {
// eslint-disable-next-line no-console
error('error', e);
process.exit(1);
}),
});
} else {
ctx.exit(1);
Expand Down
6 changes: 5 additions & 1 deletion packages/create-astro/src/actions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export async function typescript(
await spinner({
start: 'TypeScript customizing...',
end: 'TypeScript customized',
while: () => setupTypeScript(ts!, { cwd: ctx.cwd }),
while: () => setupTypeScript(ts!, { cwd: ctx.cwd }).catch((e) => {
// eslint-disable-next-line no-console
error('error', e);
process.exit(1);
}),
});
} else {
}
Expand Down