Skip to content

Commit

Permalink
Pass AbortSignal to Execa
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Sep 22, 2023
1 parent b107a8c commit 7f1b68b
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 7f1b68b

Please sign in to comment.