env-runner 0.2.1 → 0.2.3
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 +65 -9
- package/dist/_chunks/common-base-runner.d.mts +21 -53
- package/dist/_chunks/common-base-runner.mjs +4 -1
- package/dist/_chunks/common-runtime-deps.d.mts +9 -33
- package/dist/_chunks/common-worker-utils.mjs +50 -1
- package/dist/_chunks/deno-process-runner.d.mts +2 -3
- package/dist/_chunks/deno-process-runner.mjs +14 -36
- package/dist/_chunks/libs/es-module-lexer.mjs +225 -65
- package/dist/_chunks/miniflare-runner.d.mts +53 -114
- package/dist/_chunks/miniflare-runner.mjs +669 -80
- package/dist/_chunks/netlify-runner.d.mts +6 -25
- package/dist/_chunks/node-worker-runner.d.mts +2 -3
- package/dist/_chunks/types.d.mts +13 -23
- package/dist/_chunks/vercel-runner.d.mts +2 -3
- package/dist/_chunks/vercel-runner.mjs +1 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +33 -53
- package/dist/index.mjs +2 -1
- package/dist/runners/bun-process/runner.d.mts +2 -2
- package/dist/runners/bun-process/runner.mjs +1 -1
- package/dist/runners/bun-process/worker.mjs +8 -11
- package/dist/runners/deno-process/worker.mjs +17 -42
- package/dist/runners/node-process/runner.d.mts +2 -2
- package/dist/runners/node-process/worker.mjs +8 -11
- package/dist/runners/node-worker/worker.mjs +8 -11
- package/dist/runners/self/runner.d.mts +2 -2
- package/dist/runners/vercel/queue-dev.d.mts +16 -53
- package/dist/vite.d.mts +6 -17
- package/package.json +11 -11
|
@@ -3,147 +3,100 @@ import { BaseEnvRunner, EnvRunnerData } from "./common-base-runner.mjs";
|
|
|
3
3
|
import { RuntimeDep } from "./common-runtime-deps.mjs";
|
|
4
4
|
import { IncomingMessage } from "node:http";
|
|
5
5
|
import { Socket } from "node:net";
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* `wrangler` is not a dependency of `env-runner` — pass the module namespace
|
|
10
|
-
* (`import * as wrangler from "wrangler"`) or a specifier for it, so the
|
|
11
|
-
* dependency stays owned by the application. It is only imported here as a
|
|
12
|
-
* fallback when neither is passed.
|
|
13
|
-
*/
|
|
14
|
-
interface WranglerModule {
|
|
6
|
+
/** The `wrangler` package namespace, as imported by the app. */
|
|
7
|
+
export interface WranglerModule {
|
|
15
8
|
unstable_readConfig?: (...args: any[]) => any;
|
|
16
9
|
unstable_getMiniflareWorkerOptions?: (...args: any[]) => any;
|
|
17
10
|
[key: string]: unknown;
|
|
18
11
|
}
|
|
19
12
|
/** Raw (snake_case) Wrangler config object, mirroring `wrangler.json` contents. */
|
|
20
|
-
type WranglerInlineConfig = Record<string, unknown>;
|
|
13
|
+
export type WranglerInlineConfig = Record<string, unknown>;
|
|
21
14
|
/** Result from a module transform (compatible with Vite's `TransformResult`). */
|
|
22
|
-
interface TransformResult {
|
|
15
|
+
export interface TransformResult {
|
|
23
16
|
code: string;
|
|
24
17
|
}
|
|
25
18
|
/** Detected or declared export for auto-wiring Durable Object / Entrypoint bindings. */
|
|
26
|
-
interface MiniflareExportInfo {
|
|
19
|
+
export interface MiniflareExportInfo {
|
|
27
20
|
type?: "DurableObject" | "WorkerEntrypoint" | "class";
|
|
28
21
|
}
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* `miniflare` is not a dependency of `env-runner` — pass the module namespace
|
|
33
|
-
* (`import * as miniflare from "miniflare"`) so the dependency stays owned by
|
|
34
|
-
* the application. The runner only falls back to importing it itself when this
|
|
35
|
-
* is omitted.
|
|
36
|
-
*/
|
|
37
|
-
interface MiniflareModule {
|
|
22
|
+
/** The `miniflare` package namespace, as imported by the app. */
|
|
23
|
+
export interface MiniflareModule {
|
|
38
24
|
Miniflare: new (options: any) => any;
|
|
39
|
-
/**
|
|
40
|
-
* Newest compatibility date supported by the installed `workerd` binary,
|
|
41
|
-
* clamped to today. Used as the default `compatibilityDate`.
|
|
42
|
-
*/
|
|
25
|
+
/** Newest date the installed `workerd` supports, clamped to today. */
|
|
43
26
|
supportedCompatibilityDate?: string;
|
|
44
27
|
[key: string]: unknown;
|
|
45
28
|
}
|
|
46
|
-
interface MiniflareEnvRunnerOptions {
|
|
29
|
+
export interface MiniflareEnvRunnerOptions {
|
|
47
30
|
name: string;
|
|
48
31
|
hooks?: WorkerHooks;
|
|
49
32
|
data?: EnvRunnerData;
|
|
50
33
|
/**
|
|
51
|
-
* The `miniflare` package
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* import * as miniflare from "miniflare";
|
|
55
|
-
* new MiniflareEnvRunner({ name: "app", miniflare, data: { entry } });
|
|
56
|
-
*
|
|
57
|
-
* // or, equivalently
|
|
58
|
-
* new MiniflareEnvRunner({ name: "app", miniflare: "miniflare", data: { entry } });
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* Passing it explicitly is preferred (`miniflare` is not a dependency of
|
|
62
|
-
* `env-runner`, so the version you install is the version that runs). Bare
|
|
63
|
-
* specifiers resolve from the current working directory. When omitted, the
|
|
64
|
-
* runner falls back to importing `miniflare` itself and only fails if that
|
|
65
|
-
* is unavailable too.
|
|
34
|
+
* The `miniflare` package (`import * as miniflare from "miniflare"`) or a
|
|
35
|
+
* specifier resolved from cwd. Omitted: imported optionally.
|
|
66
36
|
*/
|
|
67
37
|
miniflare?: RuntimeDep<MiniflareModule>;
|
|
68
38
|
/** Options passed directly to the Miniflare constructor. */
|
|
69
39
|
miniflareOptions?: Record<string, unknown>;
|
|
70
40
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* This enables integration with Vite's transform pipeline — pass
|
|
75
|
-
* `environment.transformRequest` to get TS/JSX/etc. compiled on the fly.
|
|
76
|
-
*
|
|
77
|
-
* @param id - Absolute file path of the module to transform
|
|
78
|
-
* @returns Transformed code, or null/undefined to fall back to raw disk read
|
|
41
|
+
* `"latest"` uses the installed workerd's newest date. Precedence:
|
|
42
|
+
* `miniflareOptions` > this > wrangler config > newest supported. Dates newer
|
|
43
|
+
* than workerd supports fall back with a warning (workerd refuses them).
|
|
79
44
|
*/
|
|
80
|
-
|
|
45
|
+
compatibilityDate?: "latest" | (string & {});
|
|
81
46
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* When set to `true`, `export class` declarations are auto-detected from
|
|
86
|
-
* the entry file. When set to a record, the listed exports are used
|
|
87
|
-
* (merged with auto-detected ones). Disabled by default.
|
|
47
|
+
* Transform modules served by the fallback service (e.g. Vite's
|
|
48
|
+
* `environment.transformRequest`). `id` is an absolute path; return nullish to
|
|
49
|
+
* read from disk.
|
|
88
50
|
*/
|
|
89
|
-
|
|
51
|
+
transformRequest?: (id: string) => Promise<TransformResult | null | undefined>;
|
|
90
52
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* keeps Miniflare alive. Call `dispose()` to fully destroy it.
|
|
53
|
+
* Named exports (Durable Objects, WorkerEntrypoints) to bind and re-export.
|
|
54
|
+
* `true` detects `export class`; a record merges with detected ones.
|
|
94
55
|
*/
|
|
56
|
+
exports?: Record<string, MiniflareExportInfo> | boolean;
|
|
57
|
+
/** Reuse the Miniflare instance across runner swaps; only `dispose()` destroys it. */
|
|
95
58
|
persistent?: boolean;
|
|
96
59
|
/** Wrap the user's `fetch` in a try/catch that returns structured JSON error responses. Default: `true`. */
|
|
97
60
|
captureErrors?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Export conditions for bare-specifier module resolution in the module
|
|
100
|
-
* fallback service. Ensures packages with conditional exports (e.g.
|
|
101
|
-
* `"workerd"`) resolve to the correct entry instead of the Node.js one.
|
|
102
|
-
*
|
|
103
|
-
* Defaults to `["workerd", "worker"]`.
|
|
104
|
-
*/
|
|
61
|
+
/** Export conditions for the fallback service (default `["workerd", "worker"]`). */
|
|
105
62
|
exportConditions?: string[];
|
|
106
63
|
/**
|
|
107
|
-
* Load a
|
|
108
|
-
* (compatibility date/flags and bindings: `vars`, KV, R2, D1, Durable
|
|
109
|
-
* Objects, queues).
|
|
64
|
+
* Load a wrangler config into Miniflare options (compat date/flags, bindings).
|
|
110
65
|
*
|
|
111
|
-
* - `true` — auto-discover `wrangler.{json,jsonc,toml}`
|
|
112
|
-
*
|
|
113
|
-
* - `
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* auto-discovered (next to the entry, then cwd) and the inline config is
|
|
117
|
-
* merged on top of it (inline wins per key, binding records merge,
|
|
118
|
-
* `compatibilityFlags` are unioned).
|
|
66
|
+
* - `true` — auto-discover `wrangler.{json,jsonc,toml}` near the entry or cwd
|
|
67
|
+
* - `string` — config file path
|
|
68
|
+
* - `object` — inline raw config merged over the file config (inline wins per
|
|
69
|
+
* key, binding records merge, flags union); its top level is used when it
|
|
70
|
+
* lacks the selected env
|
|
119
71
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* `
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* `miniflareOptions` always win over config-derived ones; binding records
|
|
127
|
-
* (e.g. `bindings`) merge per key and `compatibilityFlags` are unioned.
|
|
72
|
+
* Options a single dev worker can't run (`assets`, services, queue consumers,
|
|
73
|
+
* workflows, tails, other-script Durable Objects) are dropped with a warning.
|
|
74
|
+
* `defaultPersistRoot` defaults to `.wrangler/state/v3` next to the config
|
|
75
|
+
* (else cwd), shared with `wrangler dev`. The `wrangler` package gives full
|
|
76
|
+
* fidelity (and may run its npm update check); without it only plain JSON is
|
|
77
|
+
* read. `miniflareOptions` always win.
|
|
128
78
|
*/
|
|
129
79
|
wrangler?: boolean | string | WranglerInlineConfig;
|
|
130
80
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
81
|
+
* Config file instead of auto-discovery when `wrangler` is `true` or inline
|
|
82
|
+
* (resolved from cwd). Ignored when `wrangler` is a path.
|
|
133
83
|
*/
|
|
84
|
+
wranglerConfigPath?: string;
|
|
85
|
+
/** Wrangler `--env` to select (default: `CLOUDFLARE_ENV`). */
|
|
134
86
|
wranglerEnv?: string;
|
|
135
87
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
*
|
|
88
|
+
* `.env` files for dev vars (like `getPlatformProxy({ envFiles })`), resolved
|
|
89
|
+
* from the config dir; later files win. Non-empty skips `.dev.vars`; `[]`
|
|
90
|
+
* reads only `.dev.vars`. Requires the `wrangler` package.
|
|
91
|
+
*/
|
|
92
|
+
wranglerEnvFiles?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* The `wrangler` package for full-fidelity config parsing. Omitted: imported
|
|
95
|
+
* optionally. `false`: always use the minimal JSON reader.
|
|
143
96
|
*/
|
|
144
97
|
wranglerModule?: RuntimeDep<WranglerModule>;
|
|
145
98
|
}
|
|
146
|
-
declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
99
|
+
export declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
147
100
|
#private;
|
|
148
101
|
constructor(opts: MiniflareEnvRunnerOptions);
|
|
149
102
|
/** Dispose all persistent Miniflare instances from the cache. */
|
|
@@ -152,24 +105,11 @@ declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
|
152
105
|
dispose(): Promise<void>;
|
|
153
106
|
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
154
107
|
sendMessage(message: unknown): void;
|
|
155
|
-
/**
|
|
156
|
-
* Hot-reload the user entry module without recreating the Miniflare instance.
|
|
157
|
-
*
|
|
158
|
-
* Sends `reload-module` event over the WebSocket. The worker wrapper uses
|
|
159
|
-
* `unsafeEvalBinding` to re-import the entry with a cache-busting query string
|
|
160
|
-
* and responds with `module-reloaded` when done.
|
|
161
|
-
*/
|
|
108
|
+
/** Hot-reload the entry without recreating the Miniflare instance. */
|
|
162
109
|
reloadModule(timeout?: number): Promise<void>;
|
|
163
110
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* Host-side only (no worker round-trip): the module fallback service serves
|
|
167
|
-
* virtual sources from a live map, so re-running a factory source and
|
|
168
|
-
* bumping the per-specifier versions — the module plus its transitive
|
|
169
|
-
* virtual importers — is enough. Import specifiers in re-served module code
|
|
170
|
-
* are rewritten to the versioned form, giving workerd fresh module
|
|
171
|
-
* identities (it caches by name). A `persistent` instance is evicted from
|
|
172
|
-
* the cache, since its served sources no longer match the cache key.
|
|
111
|
+
* Host-side only: the fallback service serves a live map, so bumping versions
|
|
112
|
+
* (see {@link rewriteVirtualImports}) is enough.
|
|
173
113
|
*/
|
|
174
114
|
invalidateModule(specifier: string, _timeout?: number): Promise<void>;
|
|
175
115
|
protected _hasRuntime(): boolean;
|
|
@@ -182,5 +122,4 @@ declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
|
182
122
|
head: any;
|
|
183
123
|
};
|
|
184
124
|
}): Promise<void>;
|
|
185
|
-
}
|
|
186
|
-
export { MiniflareEnvRunner, MiniflareEnvRunnerOptions, MiniflareExportInfo, MiniflareModule, TransformResult, WranglerInlineConfig, WranglerModule };
|
|
125
|
+
}
|