@moku-labs/worker 0.5.1 → 0.7.0

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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Two design facts shape everything below:
10
10
 
11
- 1. **Runtime vs. node-only split.** The request-time surface is imported from `@moku-labs/worker`; the build-time deploy/CLI surface is imported from `@moku-labs/worker/cli`. The `./cli` entry reaches for `node:child_process` and `node:fs`, so it must never enter the deployed Worker bundlethe two entry points enforce that boundary.
11
+ 1. **Runtime vs. node-only surface.** Everything ships from `@moku-labs/worker`, including the build-time `deployPlugin`/`cliPlugin` (the `@moku-labs/worker/cli` subpath remains as a back-compat alias). Those two reach for `node:child_process`/`node:fs`, so they enter a bundle **only when a consumer actually lists them in `createApp({ plugins })`** `"sideEffects": false` tree-shakes them out of any request-time Worker bundle that doesn't.
12
12
  2. **Env per request, never stored.** One Cloudflare isolate serves concurrent requests. Bindings (`env`) are threaded as a **call argument** to every plugin method and live only on the call stack — they are never captured in plugin state, so concurrent requests cannot leak each other's bindings.
13
13
 
14
14
  This framework supplies the **server-side** Cloudflare primitives. Moku Web (`@moku-labs/web`) supplies the request/island layer; the two compose.
@@ -68,7 +68,7 @@ bun add @moku-labs/worker
68
68
  | `@moku-labs/core@0.1.4` | The micro-kernel this framework is built on. Installed transitively. |
69
69
  | `@moku-labs/common@0.1.1` | Supplies the `log` and `env` core plugins. Installed transitively. |
70
70
  | `@cloudflare/workers-types` (dev) | Ambient Cloudflare runtime types (`KVNamespace`, `D1Database`, `R2Bucket`, `Queue`, `DurableObjectNamespace`, `ExecutionContext`, …). Type-only — never bundled. Add to your tsconfig `types`. |
71
- | `wrangler` (peer/dev) | Required **only** for the node-only deploy/CLI path (`@moku-labs/worker/cli`). Invoked as a subprocess; never bundled. |
71
+ | `wrangler` (peer/dev) | Required **only** when you add the node-only `deployPlugin`/`cliPlugin`. Invoked as a subprocess; never bundled. |
72
72
 
73
73
  Requires Node `>=24` for the build/deploy tooling and bun `>=1.3.14`.
74
74
 
@@ -170,8 +170,8 @@ Plugin **name strings** are bare (`"server"`, `"kv"`, `"durableObjects"`); the *
170
170
  | [`storage`](src/plugins/storage/README.md) | R2 object storage behind a provider-adapter seam. | Complex | `@moku-labs/worker` | `get`, `put`, `delete`, `list`, `deployManifest` |
171
171
  | [`durableObjects`](src/plugins/durable-objects/README.md) | Resolves DO stubs off `env`; ships `defineDurableObject` base-class helper. | Standard | `@moku-labs/worker` | `get`, `deployManifest`, `defineDurableObject` |
172
172
  | [`stage`](src/plugins/stage/README.md) | Deployment-stage / dev-mode detection. Core plugin, flat-injected as `ctx.stage`. | Nano | `@moku-labs/worker` | `isDev`, `isProduction`, `current` |
173
- | [`deploy`](src/plugins/deploy/README.md) | Build-time deploy orchestrator: detect → provision → wrangler-config → upload → deploy. **Node-only.** | Complex | `@moku-labs/worker/cli` | `run`, `dev`, `init` |
174
- | [`cli`](src/plugins/cli/README.md) | Developer-facing `dev` / `deploy` verbs + live progress TUI. Thin passthroughs to `deploy`. **Node-only.** | Standard | `@moku-labs/worker/cli` | `dev`, `deploy` |
173
+ | [`deploy`](src/plugins/deploy/README.md) | Build-time deploy orchestrator: detect → provision → wrangler-config → upload → deploy. **Node-only.** | Complex | `@moku-labs/worker` (`./cli` alias) | `run`, `dev`, `init` |
174
+ | [`cli`](src/plugins/cli/README.md) | Developer-facing `dev` / `deploy` verbs + live progress TUI. Thin passthroughs to `deploy`. **Node-only.** | Standard | `@moku-labs/worker` (`./cli` alias) | `dev`, `deploy` |
175
175
 
176
176
  > The `log` and `env` **core plugins are not authored here** — they come from `@moku-labs/common` and are re-exported (`logPlugin`, `envPlugin`) for completeness. `env` is environment-**variable** access (`get`/`require`/`has`), distinct from `stage` (dev/production detection).
177
177
 
@@ -299,20 +299,21 @@ deploy → app.deploy.run
299
299
  ### Runtime vs. node-only boundary
300
300
 
301
301
  ```
302
- @moku-labs/worker (. → src/index.ts) runtime ships in the Worker bundle
302
+ @moku-labs/worker (. → src/index.ts) one entry for everything
303
303
  createApp, createPlugin
304
304
  bindingsPlugin, serverPlugin, kvPlugin, d1Plugin,
305
305
  queuesPlugin, storagePlugin, durableObjectsPlugin, stagePlugin
306
306
  endpoint, defineDurableObject
307
307
  envPlugin, logPlugin
308
308
  WorkerConfig, WorkerEvents, WorkerEnv, + type namespaces (Server, D1, Queues, Storage, DurableObjects)
309
-
310
- @moku-labs/worker/cli (./cli → src/cli.ts) node-only — NEVER in the Worker bundle
311
- deployPlugin, cliPlugin
309
+ deployPlugin, cliPlugin node-only — tree-shaken unless you add them
312
310
  ExternalManifest, ResourceManifest
311
+
312
+ @moku-labs/worker/cli (./cli → src/cli.ts) back-compat alias for the two node-only plugins
313
+ deployPlugin, cliPlugin, ExternalManifest, ResourceManifest
313
314
  ```
314
315
 
315
- `deploy` and `cli` import `node:child_process` / `node:fs`, which cannot run in the Cloudflare isolate. The `./cli` entry exists to keep those Node built-ins out of the deployed bundle (design constraint HC11). Importing `deployPlugin` from `@moku-labs/worker` is intentionally impossible. The specs reference a `@moku-labs/worker/worker` subpath — it does **not** exist; the real entries are `.` and `./cli`.
316
+ `deploy` and `cli` import `node:child_process` / `node:fs`, which cannot run in the Cloudflare isolate but they reach a bundle **only** when a consumer lists them in `createApp({ plugins })`. Because the package is `"sideEffects": false`, a request-time Worker that imports `createApp` (and never adds those two) tree-shakes them away, so the Node built-ins stay out of the deployed bundle without a separate entry point. The `./cli` subpath remains as a back-compat alias. The specs reference a `@moku-labs/worker/worker` subpath — it does **not** exist; the real entries are `.` and `./cli`.
316
317
 
317
318
  ## Development
318
319