From a0bc0ee318a21de77be191c8ee987a645e26a6aa Mon Sep 17 00:00:00 2001 From: centdix <40307056+centdix@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:56:37 +0200 Subject: [PATCH] fix path assigner for nested calls (#6732) --- cli/build.sh | 6 ++- .../src/inline-scripts/extractor.ts | 37 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cli/build.sh b/cli/build.sh index 0da1c343a3..79f352409c 100755 --- a/cli/build.sh +++ b/cli/build.sh @@ -16,4 +16,8 @@ set -e echo "Running dnt..." deno run -A dnt.ts -echo "Build complete!" \ No newline at end of file +# Remove .ts extensions after building to go back to the original state +./windmill-utils-internal/remove-ts-ext.sh + +echo "Build complete!" + diff --git a/cli/windmill-utils-internal/src/inline-scripts/extractor.ts b/cli/windmill-utils-internal/src/inline-scripts/extractor.ts index b64e7ca789..b3b10bcad4 100644 --- a/cli/windmill-utils-internal/src/inline-scripts/extractor.ts +++ b/cli/windmill-utils-internal/src/inline-scripts/extractor.ts @@ -1,4 +1,4 @@ -import { newPathAssigner } from "../path-utils/path-assigner"; +import { newPathAssigner, PathAssigner } from "../path-utils/path-assigner"; import { FlowModule } from "../gen/types.gen"; /** @@ -17,20 +17,25 @@ interface InlineScript { * * @param modules - Array of flow modules to process * @param mapping - Optional mapping of module IDs to custom file paths + * @param separator - Path separator to use * @param defaultTs - Default TypeScript runtime to use ("bun" or "deno") + * @param pathAssigner - Optional path assigner to reuse (for nested calls) * @returns Array of inline scripts with their paths and content */ export function extractInlineScripts( modules: FlowModule[], mapping: Record = {}, separator: string = "/", - defaultTs?: "bun" | "deno" + defaultTs?: "bun" | "deno", + pathAssigner?: PathAssigner ): InlineScript[] { - const pathAssigner = newPathAssigner(defaultTs ?? "bun"); + // Create pathAssigner only if not provided (top-level call), but reuse it for nested calls + const assigner = pathAssigner ?? newPathAssigner(defaultTs ?? "bun"); + return modules.flatMap((m) => { if (m.value.type == "rawscript") { let basePath, ext; - [basePath, ext] = pathAssigner.assignPath(m.summary, m.value.language); + [basePath, ext] = assigner.assignPath(m.summary, m.value.language); const path = mapping[m.id] ?? basePath + ext; const content = m.value.content; const r = [{ path: path, content: content }]; @@ -47,25 +52,39 @@ export function extractInlineScripts( m.value.modules, mapping, separator, - defaultTs + defaultTs, + assigner ); } else if (m.value.type == "branchall") { return m.value.branches.flatMap((b) => - extractInlineScripts(b.modules, mapping, separator, defaultTs) + extractInlineScripts(b.modules, mapping, separator, defaultTs, assigner) ); } else if (m.value.type == "whileloopflow") { return extractInlineScripts( m.value.modules, mapping, separator, - defaultTs + defaultTs, + assigner ); } else if (m.value.type == "branchone") { return [ ...m.value.branches.flatMap((b) => - extractInlineScripts(b.modules, mapping, separator, defaultTs) + extractInlineScripts( + b.modules, + mapping, + separator, + defaultTs, + assigner + ) + ), + ...extractInlineScripts( + m.value.default, + mapping, + separator, + defaultTs, + assigner ), - ...extractInlineScripts(m.value.default, mapping, separator, defaultTs), ]; } else { return [];