diff --git a/.changeset/thin-planes-cover.md b/.changeset/thin-planes-cover.md new file mode 100644 index 00000000000..229f87ce8ed --- /dev/null +++ b/.changeset/thin-planes-cover.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/account": patch +"fuels": patch +--- + +fix: unable to kill `fuels dev` with `pnpm` diff --git a/packages/account/src/test-utils/launchNode.ts b/packages/account/src/test-utils/launchNode.ts index 2e24f9ce4ee..c68e7b13ca8 100644 --- a/packages/account/src/test-utils/launchNode.ts +++ b/packages/account/src/test-utils/launchNode.ts @@ -41,6 +41,7 @@ export type LaunchNodeOptions = { * */ snapshotConfig?: SnapshotConfigs; includeInitialState?: boolean; + killProcessOnExit?: boolean; }; export type LaunchNodeResult = Promise<{ @@ -143,6 +144,7 @@ export const launchNode = async ({ basePath, snapshotConfig = defaultSnapshotConfigs, includeInitialState = false, + killProcessOnExit = false, }: LaunchNodeOptions = {}): LaunchNodeResult => // eslint-disable-next-line no-async-promise-executor new Promise(async (resolve, reject) => { @@ -241,16 +243,15 @@ export const launchNode = async ({ }); } - const removeSideffects = () => { + const removeChildListeners = () => { child.stderr.removeAllListeners(); + }; + const removeTempDir = () => { if (existsSync(tempDir)) { rmSync(tempDir, { recursive: true }); } }; - child.on('error', removeSideffects); - child.on('exit', removeSideffects); - const childState = { isDead: false, }; @@ -261,7 +262,8 @@ export const launchNode = async ({ } childState.isDead = true; - removeSideffects(); + removeChildListeners(); + if (child.pid !== undefined) { try { process.kill(-child.pid); @@ -284,6 +286,7 @@ export const launchNode = async ({ // eslint-disable-next-line no-console console.error('No PID available for the child process, unable to kill launched node'); } + removeTempDir(); }; // Look for a specific graphql start point in the output. @@ -331,5 +334,16 @@ export const launchNode = async ({ process.on('beforeExit', cleanup); process.on('uncaughtException', cleanup); - child.on('error', reject); + child.on('exit', (code: number | null, _signal: NodeJS.Signals | null) => { + removeChildListeners(); + removeTempDir(); + if (killProcessOnExit) { + process.exit(code); + } + }); + child.on('error', (err: Error) => { + removeChildListeners(); + removeTempDir(); + reject(err); + }); }); diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts index 3853682c678..234a68831df 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts @@ -38,6 +38,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => { basePath: config.basePath, fuelCorePath: config.fuelCorePath, includeInitialState: true, + killProcessOnExit: true, }); fuelCore = {