Skip to content

Commit 05d4d6d

Browse files
committed
fix(cli): preserve non-dotted flow lock filenames
1 parent b6da492 commit 05d4d6d

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

cli/src/commands/flow/flow_metadata.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ import { FlowFile } from "./flow.ts";
2929
import { FlowValue } from "../../../gen/types.gen.ts";
3030
import { replaceInlineScripts } from "../../../windmill-utils-internal/src/inline-scripts/replacer.ts";
3131
import { workspaceDependenciesLanguages } from "../../utils/script_common.ts";
32-
import { extractNameFromFolder, getFolderSuffix } from "../../utils/resource_folders.ts";
32+
import {
33+
extractNameFromFolder,
34+
getNonDottedPaths,
35+
} from "../../utils/resource_folders.ts";
3336

3437
const TOP_HASH = "__flow_hash";
3538
async function generateFlowHash(
@@ -157,7 +160,9 @@ export async function generateFlowLockInternal(
157160
filteredDeps
158161
);
159162

160-
const lockAssigner = newPathAssigner(opts.defaultTs ?? "bun");
163+
const lockAssigner = newPathAssigner(opts.defaultTs ?? "bun", {
164+
skipInlineScriptSuffix: getNonDottedPaths(),
165+
});
161166
const inlineScripts = extractInlineScriptsForFlows(
162167
flowValue.value.modules,
163168
{},

cli/test/unified_generate_metadata.test.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { expect, test, describe } from "bun:test";
99
import { withTestBackend } from "./test_backend.ts";
1010
import { addWorkspace } from "../workspace.ts";
11-
import { writeFile } from "node:fs/promises";
11+
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
1212
import {
1313
createLocalScript,
1414
createLocalFlow,
@@ -19,7 +19,12 @@ import {
1919
/**
2020
* Helper to set up a workspace with wmill.yaml
2121
*/
22-
async function setupWorkspace(backend: any, tempDir: string, workspaceName: string) {
22+
async function setupWorkspace(
23+
backend: any,
24+
tempDir: string,
25+
workspaceName: string,
26+
nonDottedPaths = false
27+
) {
2328
const testWorkspace = {
2429
remote: backend.baseUrl,
2530
workspaceId: backend.workspace,
@@ -29,11 +34,52 @@ async function setupWorkspace(backend: any, tempDir: string, workspaceName: stri
2934
await addWorkspace(testWorkspace, { force: true, configDir: backend.testConfigDir });
3035

3136
await writeFile(`${tempDir}/wmill.yaml`, `defaultTs: bun
32-
includes:
37+
${nonDottedPaths ? "nonDottedPaths: true\n" : ""}includes:
3338
- "**"
3439
excludes: []`, "utf-8");
3540
}
3641

42+
async function createLocalNonDottedFlow(tempDir: string, name: string) {
43+
const flowDir = `${tempDir}/f/test/${name}__flow`;
44+
await mkdir(flowDir, { recursive: true });
45+
46+
await writeFile(
47+
`${flowDir}/a.ts`,
48+
`export async function main() {\n return "Hello from flow ${name}";\n}`,
49+
"utf-8"
50+
);
51+
52+
await writeFile(
53+
`${flowDir}/flow.yaml`,
54+
`summary: "${name} flow"
55+
description: "A flow for testing"
56+
value:
57+
modules:
58+
- id: a
59+
value:
60+
type: rawscript
61+
content: "!inline a.ts"
62+
language: bun
63+
input_transforms: {}
64+
schema:
65+
$schema: "https://json-schema.org/draft/2020-12/schema"
66+
type: object
67+
properties: {}
68+
required: []
69+
`,
70+
"utf-8"
71+
);
72+
}
73+
74+
async function fileExists(filePath: string): Promise<boolean> {
75+
try {
76+
await stat(filePath);
77+
return true;
78+
} catch {
79+
return false;
80+
}
81+
}
82+
3783
// =============================================================================
3884
// Main test: processes scripts, flows, and apps together
3985
// =============================================================================
@@ -156,6 +202,32 @@ describe("generate-metadata flags", () => {
156202
});
157203
});
158204

205+
test("--lock-only preserves non-dotted flow filenames", async () => {
206+
await withTestBackend(async (backend, tempDir) => {
207+
await setupWorkspace(backend, tempDir, "lock_only_non_dotted_test", true);
208+
209+
await createLocalNonDottedFlow(tempDir, "my_flow");
210+
211+
const result = await backend.runCLICommand(
212+
["generate-metadata", "--yes", "--lock-only"],
213+
tempDir,
214+
"lock_only_non_dotted_test"
215+
);
216+
217+
expect(result.code).toEqual(0);
218+
219+
const flowDir = `${tempDir}/f/test/my_flow__flow`;
220+
const flowYaml = await readFile(`${flowDir}/flow.yaml`, "utf-8");
221+
222+
expect(flowYaml).toContain("!inline a.ts");
223+
expect(flowYaml).toContain("!inline a.lock");
224+
expect(flowYaml).not.toContain(".inline_script.");
225+
expect(await fileExists(`${flowDir}/a.lock`)).toEqual(true);
226+
expect(await fileExists(`${flowDir}/a.inline_script.ts`)).toEqual(false);
227+
expect(await fileExists(`${flowDir}/a.inline_script.lock`)).toEqual(false);
228+
});
229+
});
230+
159231
test("--schema-only only processes scripts (skips flows and apps)", async () => {
160232
await withTestBackend(async (backend, tempDir) => {
161233
await setupWorkspace(backend, tempDir, "schema_only_test");

0 commit comments

Comments
 (0)