Skip to content

Commit 99b1ae2

Browse files
authored
fix: wmill app generate-locks (#7288)
* all * fix(cli): wmill app generate-locks * handle raw reqs * handle raw reqs * rework paths
1 parent adfb7e8 commit 99b1ae2

File tree

8 files changed

+592
-204
lines changed

8 files changed

+592
-204
lines changed

cli/src/commands/app/app_metadata.ts

Lines changed: 405 additions & 51 deletions
Large diffs are not rendered by default.

cli/src/commands/app/apps.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,31 @@ export function repopulateFields(runnables: Record<string, any>) {
5252
}
5353
});
5454
}
55-
export function replaceInlineScripts(rec: any, localPath: string) {
55+
export function replaceInlineScripts(
56+
rec: any,
57+
localPath: string,
58+
addType: boolean
59+
) {
5660
if (!rec) {
5761
return;
5862
}
5963
if (typeof rec == "object") {
6064
return Object.entries(rec).flatMap(([k, v]) => {
6165
if (k == "runType") {
62-
if (isVersionsGeq1585()) {
63-
rec["type"] = "path";
64-
} else {
65-
rec["type"] = "runnableByPath";
66+
if (addType) {
67+
if (isVersionsGeq1585()) {
68+
rec["type"] = "path";
69+
} else {
70+
rec["type"] = "runnableByPath";
71+
}
6672
}
6773
} else if (k == "inlineScript" && typeof v == "object") {
68-
if (isVersionsGeq1585()) {
69-
rec["type"] = "inline";
70-
} else {
71-
rec["type"] = "runnableByName";
74+
if (addType) {
75+
if (isVersionsGeq1585()) {
76+
rec["type"] = "inline";
77+
} else {
78+
rec["type"] = "runnableByName";
79+
}
7280
}
7381
const o: Record<string, any> = v as any;
7482

@@ -81,7 +89,7 @@ export function replaceInlineScripts(rec: any, localPath: string) {
8189
o["lock"] = readInlinePathSync(basePath);
8290
}
8391
} else {
84-
replaceInlineScripts(v, localPath);
92+
replaceInlineScripts(v, localPath, addType);
8593
}
8694
});
8795
}
@@ -125,7 +133,7 @@ export async function pushApp(
125133
const path = localPath + "app.yaml";
126134
const localApp = (await yamlParseFile(path)) as AppFile;
127135

128-
replaceInlineScripts(localApp.value, localPath);
136+
replaceInlineScripts(localApp.value, localPath, true);
129137
await generatingPolicy(
130138
localApp,
131139
remotePath,
@@ -234,7 +242,7 @@ const command = new Command()
234242
"Default TypeScript runtime (bun or deno)"
235243
)
236244
.action(async (opts: any, appFolder: string | undefined) => {
237-
const { generateLocksCommand } = await import("./raw_apps.ts");
245+
const { generateLocksCommand } = await import("./app_metadata.ts");
238246
await generateLocksCommand(opts, appFolder);
239247
});
240248

cli/src/commands/app/dev.ts

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
open,
88
windmillUtils,
99
yamlParseFile,
10+
SEP,
1011
} from "../../../deps.ts";
1112
import { GlobalOptions } from "../../types.ts";
1213
import * as http from "node:http";
@@ -16,15 +17,23 @@ import process from "node:process";
1617
import { Buffer } from "node:buffer";
1718
import { writeFileSync } from "node:fs";
1819
import { WebSocketServer, WebSocket } from "npm:ws";
19-
import { getDevBuildOptions, ensureNodeModules, createFrameworkPlugins, detectFrameworks } from "./bundle.ts";
20+
import {
21+
getDevBuildOptions,
22+
ensureNodeModules,
23+
createFrameworkPlugins,
24+
detectFrameworks,
25+
} from "./bundle.ts";
2026
import { wmillTsDev as wmillTs } from "./wmillTsDev.ts";
2127
import * as wmill from "../../../gen/services.gen.ts";
2228
import { resolveWorkspace } from "../../core/context.ts";
2329
import { requireLogin } from "../../core/auth.ts";
2430
import { GLOBAL_CONFIG_OPT } from "../../core/conf.ts";
2531
import { replaceInlineScripts } from "./apps.ts";
2632
import { Runnable } from "./metadata.ts";
27-
import { inferRunnableSchemaFromFile } from "./app_metadata.ts";
33+
import {
34+
APP_BACKEND_FOLDER,
35+
inferRunnableSchemaFromFile,
36+
} from "./app_metadata.ts";
2837

2938
const DEFAULT_PORT = 4000;
3039
const DEFAULT_HOST = "localhost";
@@ -92,8 +101,8 @@ async function dev(opts: DevOptions) {
92101
log.error(
93102
colors.red(
94103
`Error: The dev command must be run inside a .raw_app folder.\n` +
95-
`Current directory: ${currentDirName}\n` +
96-
`Please navigate to a folder ending with '.raw_app' before running this command.`
104+
`Current directory: ${currentDirName}\n` +
105+
`Please navigate to a folder ending with '.raw_app' before running this command.`
97106
)
98107
);
99108
Deno.exit(1);
@@ -105,7 +114,7 @@ async function dev(opts: DevOptions) {
105114
log.error(
106115
colors.red(
107116
`Error: raw_app.yaml not found in current directory.\n` +
108-
`The dev command must be run in a .raw_app folder containing a raw_app.yaml file.`
117+
`The dev command must be run in a .raw_app folder containing a raw_app.yaml file.`
109118
)
110119
);
111120
Deno.exit(1);
@@ -133,7 +142,8 @@ async function dev(opts: DevOptions) {
133142

134143
// Detect frameworks to determine default entry point
135144
const frameworks = detectFrameworks(process.cwd());
136-
const defaultEntry = (frameworks.svelte || frameworks.vue) ? "index.ts" : "index.tsx";
145+
const defaultEntry =
146+
frameworks.svelte || frameworks.vue ? "index.ts" : "index.tsx";
137147
const entryPoint = opts.entry ?? defaultEntry;
138148

139149
// Verify entry point exists
@@ -206,7 +216,6 @@ async function dev(opts: DevOptions) {
206216
},
207217
};
208218

209-
210219
// Create esbuild context
211220
const ctx = await esbuild.context({
212221
...buildOptions,
@@ -242,7 +251,7 @@ async function dev(opts: DevOptions) {
242251
await ctx.rebuild();
243252

244253
// Watch runnables folder for changes
245-
const runnablesPath = path.join(process.cwd(), "runnables");
254+
const runnablesPath = path.join(process.cwd(), APP_BACKEND_FOLDER);
246255
let runnablesWatcher: Deno.FsWatcher | undefined;
247256

248257
if (fs.existsSync(runnablesPath)) {
@@ -262,7 +271,10 @@ async function dev(opts: DevOptions) {
262271
// Process each changed path with individual debouncing
263272
for (const changedPath of event.paths) {
264273
const relativePath = path.relative(process.cwd(), changedPath);
265-
const relativeToRunnables = path.relative(runnablesPath, changedPath);
274+
const relativeToRunnables = path.relative(
275+
runnablesPath,
276+
changedPath
277+
);
266278

267279
// Skip non-modify events for schema inference
268280
if (event.kind !== "modify" && event.kind !== "create") {
@@ -276,7 +288,9 @@ async function dev(opts: DevOptions) {
276288

277289
// Log the change event
278290
log.info(
279-
colors.cyan(`📝 Runnable changed [${event.kind}]: ${relativePath}`)
291+
colors.cyan(
292+
`📝 Runnable changed [${event.kind}]: ${relativePath}`
293+
)
280294
);
281295

282296
// Debounce schema inference per file (wait for typing to finish)
@@ -288,7 +302,9 @@ async function dev(opts: DevOptions) {
288302
delete schemaInferenceTimeouts[changedPath];
289303

290304
try {
291-
log.info(colors.cyan(`📝 Inferring schema for: ${relativeToRunnables}`));
305+
log.info(
306+
colors.cyan(`📝 Inferring schema for: ${relativeToRunnables}`)
307+
);
292308
// Infer schema for this runnable (returns schema in memory, doesn't write to file)
293309
const result = await inferRunnableSchemaFromFile(
294310
process.cwd(),
@@ -299,7 +315,15 @@ async function dev(opts: DevOptions) {
299315
// log.info(colors.green(` Runnable ID: ${result.runnableId}`));
300316
// Store inferred schema in memory
301317
inferredSchemas[result.runnableId] = result.schema;
302-
log.info(colors.green(` Inferred Schemas: ${JSON.stringify(inferredSchemas, null, 2)}`));
318+
log.info(
319+
colors.green(
320+
` Inferred Schemas: ${JSON.stringify(
321+
inferredSchemas,
322+
null,
323+
2
324+
)}`
325+
)
326+
);
303327
// Regenerate wmill.d.ts with updated schema from memory
304328
await genRunnablesTs(inferredSchemas);
305329
}
@@ -468,7 +492,9 @@ async function dev(opts: DevOptions) {
468492
case "backendAsync": {
469493
// Run a runnable asynchronously and return job ID immediately
470494
log.info(
471-
colors.blue(`[backendAsync] Running runnable async: ${runnable_id}`)
495+
colors.blue(
496+
`[backendAsync] Running runnable async: ${runnable_id}`
497+
)
472498
);
473499
try {
474500
const runnables = await loadRunnables();
@@ -628,7 +654,10 @@ const command = new Command()
628654
.option("--host <host:string>", "Host to bind the dev server to", {
629655
default: DEFAULT_HOST,
630656
})
631-
.option("--entry <entry:string>", "Entry point file (default: index.ts for Svelte/Vue, index.tsx otherwise)")
657+
.option(
658+
"--entry <entry:string>",
659+
"Entry point file (default: index.ts for Svelte/Vue, index.tsx otherwise)"
660+
)
632661
.option("--no-open", "Don't automatically open the browser")
633662
.action(dev as any);
634663

@@ -671,7 +700,11 @@ async function loadRunnables(): Promise<Record<string, Runnable>> {
671700
const rawApp = (await yamlParseFile(
672701
path.join(localPath, "raw_app.yaml")
673702
)) as any;
674-
replaceInlineScripts(rawApp.runnables, path.join(localPath, "runnables/"));
703+
replaceInlineScripts(
704+
rawApp.runnables,
705+
path.join(localPath, APP_BACKEND_FOLDER) + SEP,
706+
true
707+
);
675708

676709
return rawApp?.runnables ?? {};
677710
} catch (error: any) {
@@ -707,7 +740,10 @@ async function executeRunnable(
707740
}
708741
}
709742

710-
if ((runnable.type === "inline" || runnable.type === "runnableByName") && runnable.inlineScript) {
743+
if (
744+
(runnable.type === "inline" || runnable.type === "runnableByName") &&
745+
runnable.inlineScript
746+
) {
711747
const inlineScript = runnable.inlineScript;
712748
if (inlineScript.id !== undefined) {
713749
requestBody.id = inlineScript.id;
@@ -719,7 +755,10 @@ async function executeRunnable(
719755
lock: inlineScript.id === undefined ? inlineScript.lock : undefined,
720756
cache_ttl: inlineScript.cache_ttl,
721757
};
722-
} else if ((runnable.type === "path" || runnable.type === "runnableByPath") && runnable.path) {
758+
} else if (
759+
(runnable.type === "path" || runnable.type === "runnableByPath") &&
760+
runnable.path
761+
) {
723762
const runType = runnable.runType ?? "script";
724763
requestBody.path =
725764
runType !== "hubscript"

0 commit comments

Comments
 (0)