Improve create-astro
error handling (#6266)
* fix(create-astro): improve error handling for tasks that use spinner display * refactor: timeout after 60s * chore: remove unused file
This commit is contained in:
parent
fb4e79bf1f
commit
066b4b4efc
6 changed files with 30 additions and 8 deletions
5
.changeset/tall-geese-end.md
Normal file
5
.changeset/tall-geese-end.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'create-astro': patch
|
||||
---
|
||||
|
||||
Improve error handling during tasks that display a spinner
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 9a401ddf2e7896d7928eea910c61b5d5a29481a1
|
|
@ -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'>
|
||||
|
@ -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(
|
||||
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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'))) {
|
||||
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue