@moku-labs/worker 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -507,6 +507,26 @@ const runWranglerInherit = (args) => {
507
507
  /** Convention build script auto-detected when no webBuild/buildCommand is configured. */
508
508
  const AUTO_DETECT = "scripts/build.ts";
509
509
  /**
510
+ * Opportunistically read a numeric `files` count off an arbitrary web build result. A real web
511
+ * build returns its own summary shape (the worker framework cannot know it), so anything without a
512
+ * numeric `files` field reports 0.
513
+ *
514
+ * @param result - The resolved value of a {@link WebBuild} hook (any shape).
515
+ * @returns The `files` count when present and numeric, else 0.
516
+ * @example
517
+ * ```ts
518
+ * fileCountOf({ files: 12 }); // 12
519
+ * fileCountOf({ outDir: "dist", pageCount: 4 }); // 0
520
+ * ```
521
+ */
522
+ const fileCountOf = (result) => {
523
+ if (typeof result === "object" && result !== null && "files" in result) {
524
+ const { files } = result;
525
+ return typeof files === "number" ? files : 0;
526
+ }
527
+ return 0;
528
+ };
529
+ /**
510
530
  * Run a shell build command, resolving on a zero exit and rejecting otherwise.
511
531
  *
512
532
  * @param command - The shell command to run (the consumer's own configured build).
@@ -552,7 +572,7 @@ const runShellBuild = (command) => {
552
572
  */
553
573
  const buildSite = async (ctx, webBuild) => {
554
574
  const hook = webBuild ?? ctx.config.webBuild;
555
- if (hook !== void 0) return { files: (await hook())?.files ?? 0 };
575
+ if (hook !== void 0) return { files: fileCountOf(await hook()) };
556
576
  const command = ctx.config.buildCommand || ((0, node_fs.existsSync)(AUTO_DETECT) ? `bun run ${AUTO_DETECT}` : "");
557
577
  if (command === "") {
558
578
  ctx.emit("dev:error", { message: "No site build configured (pass webBuild or set buildCommand); serving worker only." });
package/dist/cli.d.cts CHANGED
@@ -4,19 +4,19 @@ import { PluginCtx, PluginInstance } from "@moku-labs/core";
4
4
  /**
5
5
  * A web-site build hook wired in from the consumer's deploy/dev script — e.g.
6
6
  * `() => webApp.cli.build()`. This is the seam that lets one small app-side script compose a
7
- * Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site
8
- * before serving or deploying. May resolve a `{ files }` count (surfaced in `dev:rebuilt`) or
9
- * nothing.
7
+ * Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site before
8
+ * serving or deploying. The hook may resolve ANYTHING `void`, the web app's own build summary, or
9
+ * a `{ files }` count; when the resolved value carries a numeric `files` field it is surfaced in
10
+ * `dev:rebuilt`, otherwise the count is reported as 0. Returning `Promise<unknown>` keeps the hook
11
+ * assignable from any real build function (whose return type the worker framework cannot know).
10
12
  *
11
- * @returns Resolves when the web build completes; optionally a rebuilt-file count.
13
+ * @returns Resolves when the web build completes (the value is read opportunistically for `files`).
12
14
  * @example
13
15
  * ```ts
14
16
  * await server.cli.dev({ webBuild: () => web.cli.build() });
15
17
  * ```
16
18
  */
17
- type WebBuild = () => Promise<void> | Promise<{
18
- files?: number;
19
- }>;
19
+ type WebBuild = () => Promise<unknown>;
20
20
  /** deploy plugin configuration. Flat; complete defaults so omission never yields undefined. */
21
21
  type Config$1 = {
22
22
  /**
package/dist/cli.d.mts CHANGED
@@ -4,19 +4,19 @@ import { PluginCtx, PluginInstance } from "@moku-labs/core";
4
4
  /**
5
5
  * A web-site build hook wired in from the consumer's deploy/dev script — e.g.
6
6
  * `() => webApp.cli.build()`. This is the seam that lets one small app-side script compose a
7
- * Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site
8
- * before serving or deploying. May resolve a `{ files }` count (surfaced in `dev:rebuilt`) or
9
- * nothing.
7
+ * Moku Web app with this Worker framework: `dev` / `deploy` invoke it to (re)build the site before
8
+ * serving or deploying. The hook may resolve ANYTHING `void`, the web app's own build summary, or
9
+ * a `{ files }` count; when the resolved value carries a numeric `files` field it is surfaced in
10
+ * `dev:rebuilt`, otherwise the count is reported as 0. Returning `Promise<unknown>` keeps the hook
11
+ * assignable from any real build function (whose return type the worker framework cannot know).
10
12
  *
11
- * @returns Resolves when the web build completes; optionally a rebuilt-file count.
13
+ * @returns Resolves when the web build completes (the value is read opportunistically for `files`).
12
14
  * @example
13
15
  * ```ts
14
16
  * await server.cli.dev({ webBuild: () => web.cli.build() });
15
17
  * ```
16
18
  */
17
- type WebBuild = () => Promise<void> | Promise<{
18
- files?: number;
19
- }>;
19
+ type WebBuild = () => Promise<unknown>;
20
20
  /** deploy plugin configuration. Flat; complete defaults so omission never yields undefined. */
21
21
  type Config$1 = {
22
22
  /**
package/dist/cli.mjs CHANGED
@@ -483,6 +483,26 @@ const runWranglerInherit = (args) => {
483
483
  /** Convention build script auto-detected when no webBuild/buildCommand is configured. */
484
484
  const AUTO_DETECT = "scripts/build.ts";
485
485
  /**
486
+ * Opportunistically read a numeric `files` count off an arbitrary web build result. A real web
487
+ * build returns its own summary shape (the worker framework cannot know it), so anything without a
488
+ * numeric `files` field reports 0.
489
+ *
490
+ * @param result - The resolved value of a {@link WebBuild} hook (any shape).
491
+ * @returns The `files` count when present and numeric, else 0.
492
+ * @example
493
+ * ```ts
494
+ * fileCountOf({ files: 12 }); // 12
495
+ * fileCountOf({ outDir: "dist", pageCount: 4 }); // 0
496
+ * ```
497
+ */
498
+ const fileCountOf = (result) => {
499
+ if (typeof result === "object" && result !== null && "files" in result) {
500
+ const { files } = result;
501
+ return typeof files === "number" ? files : 0;
502
+ }
503
+ return 0;
504
+ };
505
+ /**
486
506
  * Run a shell build command, resolving on a zero exit and rejecting otherwise.
487
507
  *
488
508
  * @param command - The shell command to run (the consumer's own configured build).
@@ -528,7 +548,7 @@ const runShellBuild = (command) => {
528
548
  */
529
549
  const buildSite = async (ctx, webBuild) => {
530
550
  const hook = webBuild ?? ctx.config.webBuild;
531
- if (hook !== void 0) return { files: (await hook())?.files ?? 0 };
551
+ if (hook !== void 0) return { files: fileCountOf(await hook()) };
532
552
  const command = ctx.config.buildCommand || (existsSync(AUTO_DETECT) ? `bun run ${AUTO_DETECT}` : "");
533
553
  if (command === "") {
534
554
  ctx.emit("dev:error", { message: "No site build configured (pass webBuild or set buildCommand); serving worker only." });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moku-labs/worker",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Cloudflare Worker framework for Moku — Durable Objects, Queues, R2, D1, and KV plugins that compose with Moku Web.",
5
5
  "repository": {
6
6
  "type": "git",