From 6cd245bfcade20960a9cfa25957fd17cdc023724 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 15:06:32 +0100 Subject: [PATCH] cli: refactor clean dist directory Signed-off-by: Vincenzo Scamporlino --- .../cli/src/commands/start/startBackend.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index acbcbe6b7a..a87d40fe76 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -36,12 +36,7 @@ export async function startBackend(options: StartBackendOptions) { await waitForExit(); } else { - // Cleaning dist/ before we start the dev process helps work around an issue - // where we end up with the entrypoint executing multiple times, causing - // a port bind conflict among other things. - await fs.remove(paths.resolveTarget('dist')); - - const waitForExit = await serveBackend({ + const waitForExit = await cleanDistAndServeBackend({ entry: 'src/index', checksEnabled: options.checksEnabled, inspectEnabled: options.inspectEnabled, @@ -78,12 +73,8 @@ Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, console.log(`src/run.ts is missing.`); return; } - // Cleaning dist/ before we start the dev process helps work around an issue - // where we end up with the entrypoint executing multiple times, causing - // a port bind conflict among other things. - await fs.remove(paths.resolveTarget('dist')); - const waitForExit = await serveBackend({ + const waitForExit = await cleanDistAndServeBackend({ entry: 'src/run', checksEnabled: options.checksEnabled, inspectEnabled: options.inspectEnabled, @@ -93,3 +84,17 @@ Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, await waitForExit(); } } + +async function cleanDistAndServeBackend(options: { + entry: string; + checksEnabled: boolean; + inspectEnabled: boolean; + inspectBrkEnabled: boolean; +}) { + // Cleaning dist/ before we start the dev process helps work around an issue + // where we end up with the entrypoint executing multiple times, causing + // a port bind conflict among other things. + await fs.remove(paths.resolveTarget('dist')); + + return serveBackend(options); +}