From 7f1b68bae07e7e32aec543c1bbe9015a9e146420 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Fri, 22 Sep 2023 13:35:03 +0200 Subject: [PATCH] Pass AbortSignal to Execa --- node-src/tasks/build.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/node-src/tasks/build.ts b/node-src/tasks/build.ts index 11a74f16a..de3d69ce1 100644 --- a/node-src/tasks/build.ts +++ b/node-src/tasks/build.ts @@ -69,22 +69,15 @@ export const buildStorybook = async (ctx: Context) => { logFile.on('error', reject); }); - const { experimental_abortSignal: abortSignal } = ctx.options; - + const { experimental_abortSignal: signal } = ctx.options; try { const { command } = ctx.spawnParams; ctx.log.debug('Using spawnParams:', JSON.stringify(ctx.spawnParams, null, 2)); - let subprocess = null; - if (abortSignal) { - abortSignal.onabort = () => { - subprocess?.kill('SIGTERM', { forceKillAfterTimeout: 2000 }); - }; - } - subprocess = execaCommand(command, { stdio: [null, logFile, logFile] }); + const subprocess = execaCommand(command, { stdio: [null, logFile, logFile], signal }); await Promise.race([subprocess, timeoutAfter(ctx.env.STORYBOOK_BUILD_TIMEOUT)]); } catch (e) { - abortSignal?.throwIfAborted(); + signal?.throwIfAborted(); const buildLog = readFileSync(ctx.buildLogFile, 'utf8'); ctx.log.error(buildFailed(ctx, e, buildLog));