From 189953b7d5094db7a3dd3ca2866193fbb9806e2c Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 6 Dec 2023 09:51:41 -0500 Subject: [PATCH] fix(core): run-commands should handle signals correctly --- e2e/nx-misc/src/extras.test.ts | 2 +- .../executors/run-commands/run-commands.impl.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/e2e/nx-misc/src/extras.test.ts b/e2e/nx-misc/src/extras.test.ts index 9a845cca20e6bd..5db221fafc17cc 100644 --- a/e2e/nx-misc/src/extras.test.ts +++ b/e2e/nx-misc/src/extras.test.ts @@ -4,12 +4,12 @@ import { cleanupProject, isNotWindows, newProject, + readFile, readJson, runCLI, setMaxWorkers, uniq, updateFile, - readFile, updateJson, } from '@nx/e2e/utils'; import { join } from 'path'; diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts index ba6cf37c0cba83..355001ac116598 100644 --- a/packages/nx/src/executors/run-commands/run-commands.impl.ts +++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts @@ -20,7 +20,9 @@ async function loadEnvVars(path?: string) { } } -export type Json = { [k: string]: any }; +export type Json = { + [k: string]: any; +}; export interface RunCommandsOptions extends Json { command?: string; @@ -65,13 +67,17 @@ export interface NormalizedRunCommandsOptions extends RunCommandsOptions { command: string; forwardAllArgs?: boolean; }[]; - parsedArgs: { [k: string]: any }; + parsedArgs: { + [k: string]: any; + }; } export default async function ( options: RunCommandsOptions, context: ExecutorContext -): Promise<{ success: boolean }> { +): Promise<{ + success: boolean; +}> { await loadEnvVars(options.envFile); const normalized = normalizeOptions(options); @@ -215,7 +221,7 @@ function createProcess( /** * Ensure the child process is killed when the parent exits */ - const processExitListener = (signal?: number | NodeJS.Signals) => () => + const processExitListener = (signal?: number | NodeJS.Signals) => childProcess.kill(signal); process.on('exit', processExitListener);