From a2533baa660e458fcf2f4a53ea4a5ce246e28c99 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Thu, 2 Apr 2026 18:29:54 +0200 Subject: [PATCH] Local driver layer resolution wipe partial local layers relicas (#19267) # Introduction Wipe partial layer local driver relicas that do not implem a node_modules folder --- .../drivers/local.driver.ts | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local.driver.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local.driver.ts index 9216f29643..3e71d85513 100644 --- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local.driver.ts +++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/local.driver.ts @@ -28,6 +28,16 @@ export interface LocalDriverOptions { sdkClientArchiveService: SdkClientArchiveService; } +const pathExists = async (targetPath: string): Promise => { + try { + await fs.access(targetPath); + + return true; + } catch { + return false; + } +}; + export class LocalDriver implements LogicFunctionDriver { private readonly logicFunctionResourceService: LogicFunctionResourceService; private readonly sdkClientArchiveService: SdkClientArchiveService; @@ -65,15 +75,17 @@ export class LocalDriver implements LogicFunctionDriver { applicationUniversalIdentifier: string; }): Promise { const depsLayerPath = this.getDepsLayerPath(flatApplication); + const depsNodeModulesPath = join(depsLayerPath, 'node_modules'); - try { - await fs.access(depsLayerPath); + const nodeModulesExist = await pathExists(depsNodeModulesPath); + if (nodeModulesExist) { return; - } catch { - // Layer doesn't exist yet } + // Wipe any partial leftovers from a previously failed build + await fs.rm(depsLayerPath, { recursive: true, force: true }); + await this.logicFunctionResourceService.copyDependenciesInMemory({ applicationUniversalIdentifier, workspaceId: flatApplication.workspaceId, @@ -93,23 +105,17 @@ export class LocalDriver implements LogicFunctionDriver { workspaceId: flatApplication.workspaceId, applicationUniversalIdentifier, }); + const sdkNodeModulesPath = join(sdkLayerPath, 'node_modules'); - const layerExists = await fs - .access(sdkLayerPath) - .then(() => true) - .catch(() => false); + const nodeModulesExist = await pathExists(sdkNodeModulesPath); - if (layerExists && !flatApplication.isSdkLayerStale) { + if (nodeModulesExist && !flatApplication.isSdkLayerStale) { return; } await fs.rm(sdkLayerPath, { recursive: true, force: true }); - const sdkPackagePath = join( - sdkLayerPath, - 'node_modules', - 'twenty-client-sdk', - ); + const sdkPackagePath = join(sdkNodeModulesPath, 'twenty-client-sdk'); await this.sdkClientArchiveService.downloadAndExtractToPackage({ workspaceId: flatApplication.workspaceId,