env-runner 0.1.12 → 0.1.14
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
|
@@ -310,6 +310,45 @@ const response = await runner.fetch("http://localhost/api");
|
|
|
310
310
|
|
|
311
311
|
The `miniflareOptions` object is passed directly to the [Miniflare constructor](https://developers.cloudflare.com/workers/testing/miniflare/) — you can configure bindings, KV, D1, Durable Objects, and any other Miniflare option.
|
|
312
312
|
|
|
313
|
+
When you don't set a `compatibilityDate` (via `miniflareOptions` or a wrangler config), it defaults to the date supported by the installed `workerd` binary rather than today's date — the binary always lags the calendar slightly, and pinning a future date makes `workerd` refuse to start.
|
|
314
|
+
|
|
315
|
+
#### Wrangler Config
|
|
316
|
+
|
|
317
|
+
Set the `wrangler` option to load a Cloudflare [Wrangler config](https://developers.cloudflare.com/workers/wrangler/configuration/) (`wrangler.json` / `wrangler.jsonc` / `wrangler.toml`) into the Miniflare options — compatibility date/flags and bindings (`vars`, KV, R2, D1, Durable Objects, queues):
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
import { MiniflareEnvRunner } from "env-runner/runners/miniflare";
|
|
321
|
+
|
|
322
|
+
await using runner = new MiniflareEnvRunner({
|
|
323
|
+
name: "my-worker",
|
|
324
|
+
data: { entry: "./worker.ts" },
|
|
325
|
+
wrangler: true, // auto-discover wrangler.{json,jsonc,toml} next to the entry, then cwd
|
|
326
|
+
// wrangler: "./config/wrangler.toml", // or an explicit path
|
|
327
|
+
// wranglerEnv: "production", // select a `[env.production]` block
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
`wranglerEnv` selects a named Wrangler environment (`--env`). When omitted, it defaults to the `CLOUDFLARE_ENV` environment variable, so `CLOUDFLARE_ENV=production` selects the `production` env without passing the option.
|
|
332
|
+
|
|
333
|
+
You can also pass an **inline** config object (raw `wrangler.json` shape) instead of (or in addition to) a file — handy for programmatic setups:
|
|
334
|
+
|
|
335
|
+
```ts
|
|
336
|
+
await using runner = new MiniflareEnvRunner({
|
|
337
|
+
name: "my-worker",
|
|
338
|
+
data: { entry: "./worker.ts" },
|
|
339
|
+
wrangler: {
|
|
340
|
+
compatibility_date: "2024-09-01",
|
|
341
|
+
compatibility_flags: ["nodejs_compat"],
|
|
342
|
+
vars: { GREETING: "hello" },
|
|
343
|
+
kv_namespaces: [{ binding: "MY_KV", id: "..." }],
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
When an inline config is passed, a `wrangler.{json,jsonc,toml}` file is still auto-discovered (next to the entry, then cwd) and loaded, and the inline config is **merged on top of it** — inline values win per key, binding records (e.g. `vars`) merge, and `compatibilityFlags` are unioned. This lets you keep a committed `wrangler` file and override a few fields programmatically.
|
|
349
|
+
|
|
350
|
+
When the [`wrangler`](https://www.npmjs.com/package/wrangler) package is installed (an optional peer dependency), it is used for full fidelity — TOML, `env` inheritance, `.dev.vars`, and every binding type. When `wrangler` is **not** installed, a built-in minimal reader handles plain JSON files and inline objects (common fields only) and logs a one-time warning; JSONC and TOML files are skipped with a warning (they need `wrangler` to parse). Values you pass in `miniflareOptions` always take precedence over config-derived ones — binding records (e.g. `bindings`) merge per key, and `compatibilityFlags` are merged.
|
|
351
|
+
|
|
313
352
|
#### Module Transform Pipeline
|
|
314
353
|
|
|
315
354
|
Pass a `transformRequest` callback to route module resolution through Vite's (or any) transform pipeline. This enables TS, JSX, and other non-JS formats to be compiled on-the-fly inside the Workers runtime without pre-bundling:
|
|
@@ -30,7 +30,9 @@ var BaseEnvRunner = class {
|
|
|
30
30
|
}
|
|
31
31
|
async upgrade(context) {
|
|
32
32
|
if (!this.ready || !this._address) return;
|
|
33
|
-
|
|
33
|
+
try {
|
|
34
|
+
await proxyUpgrade(this._address, context.node.req, context.node.socket, context.node.head);
|
|
35
|
+
} catch {}
|
|
34
36
|
}
|
|
35
37
|
onMessage(listener) {
|
|
36
38
|
this._messageListeners.add(listener);
|
|
@@ -2,6 +2,8 @@ import { WorkerHooks } from "./types.mjs";
|
|
|
2
2
|
import { BaseEnvRunner, EnvRunnerData } from "./common-base-runner.mjs";
|
|
3
3
|
import { IncomingMessage } from "node:http";
|
|
4
4
|
import { Socket } from "node:net";
|
|
5
|
+
/** Raw (snake_case) Wrangler config object, mirroring `wrangler.json` contents. */
|
|
6
|
+
type WranglerInlineConfig = Record<string, unknown>;
|
|
5
7
|
/** Result from a module transform (compatible with Vite's `TransformResult`). */
|
|
6
8
|
interface TransformResult {
|
|
7
9
|
code: string;
|
|
@@ -52,6 +54,35 @@ interface MiniflareEnvRunnerOptions {
|
|
|
52
54
|
* Defaults to `["workerd", "worker"]`.
|
|
53
55
|
*/
|
|
54
56
|
exportConditions?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Load a Cloudflare `wrangler` config to populate Miniflare options
|
|
59
|
+
* (compatibility date/flags and bindings: `vars`, KV, R2, D1, Durable
|
|
60
|
+
* Objects, queues).
|
|
61
|
+
*
|
|
62
|
+
* - `true` — auto-discover `wrangler.{json,jsonc,toml}` next to the entry
|
|
63
|
+
* file, then in the current working directory.
|
|
64
|
+
* - `string` — explicit path to a wrangler config file.
|
|
65
|
+
* - `object` — an inline raw (snake_case) wrangler config, as you would
|
|
66
|
+
* write in `wrangler.json` (no file needed). A config file is still
|
|
67
|
+
* auto-discovered (next to the entry, then cwd) and the inline config is
|
|
68
|
+
* merged on top of it (inline wins per key, binding records merge,
|
|
69
|
+
* `compatibilityFlags` are unioned).
|
|
70
|
+
*
|
|
71
|
+
* The installed `wrangler` package is preferred (full fidelity: TOML,
|
|
72
|
+
* `env` inheritance, `.dev.vars`, every binding type; an inline config is
|
|
73
|
+
* normalized through a short-lived temp file). When `wrangler` is not
|
|
74
|
+
* installed, a built-in minimal reader handles plain JSON files and inline
|
|
75
|
+
* objects (common fields only) and a one-time warning is logged. JSONC and
|
|
76
|
+
* TOML files without `wrangler` are skipped with a warning. Values from
|
|
77
|
+
* `miniflareOptions` always win over config-derived ones; binding records
|
|
78
|
+
* (e.g. `bindings`) merge per key and `compatibilityFlags` are unioned.
|
|
79
|
+
*/
|
|
80
|
+
wrangler?: boolean | string | WranglerInlineConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Wrangler environment (`--env`) to select when loading the config.
|
|
83
|
+
* Defaults to the `CLOUDFLARE_ENV` environment variable.
|
|
84
|
+
*/
|
|
85
|
+
wranglerEnv?: string;
|
|
55
86
|
}
|
|
56
87
|
declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
57
88
|
#private;
|
|
@@ -93,4 +124,4 @@ declare class MiniflareEnvRunner extends BaseEnvRunner {
|
|
|
93
124
|
};
|
|
94
125
|
}): Promise<void>;
|
|
95
126
|
}
|
|
96
|
-
export { MiniflareEnvRunner, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult };
|
|
127
|
+
export { MiniflareEnvRunner, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult, WranglerInlineConfig };
|
|
@@ -6,9 +6,10 @@ import { isVirtualSpecifier } from "./common-worker-utils.mjs";
|
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { proxyUpgrade } from "httpxy";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { readFileSync } from "node:fs";
|
|
10
|
-
import { basename, dirname, isAbsolute, resolve } from "node:path";
|
|
9
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { basename, dirname, extname, isAbsolute, join, resolve } from "node:path";
|
|
11
11
|
import { resolveModulePath } from "exsolve";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
12
13
|
const IPC_PATH = "/__env_runner_ipc";
|
|
13
14
|
const IPC_BINDING = "__ENV_RUNNER_IPC";
|
|
14
15
|
function generateWrapper(entryPath, opts) {
|
|
@@ -179,6 +180,180 @@ export default {
|
|
|
179
180
|
};
|
|
180
181
|
`;
|
|
181
182
|
}
|
|
183
|
+
let _warnedNoWrangler = false;
|
|
184
|
+
const WRANGLER_CONFIG_FILENAMES = [
|
|
185
|
+
"wrangler.json",
|
|
186
|
+
"wrangler.jsonc",
|
|
187
|
+
"wrangler.toml"
|
|
188
|
+
];
|
|
189
|
+
const WRANGLER_OPTION_DENYLIST = new Set([
|
|
190
|
+
"name",
|
|
191
|
+
"script",
|
|
192
|
+
"scriptPath",
|
|
193
|
+
"modules",
|
|
194
|
+
"modulesRoot",
|
|
195
|
+
"modulesRules",
|
|
196
|
+
"unsafeDirectSockets",
|
|
197
|
+
"unsafeEvalBinding",
|
|
198
|
+
"unsafeModuleFallbackService",
|
|
199
|
+
"unsafeUseModuleFallbackService"
|
|
200
|
+
]);
|
|
201
|
+
function isPlainObject(value) {
|
|
202
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
203
|
+
}
|
|
204
|
+
function isInlineWranglerConfig(opt) {
|
|
205
|
+
return isPlainObject(opt);
|
|
206
|
+
}
|
|
207
|
+
async function loadWranglerConfig(opt, env, entryPath) {
|
|
208
|
+
if (!opt) return;
|
|
209
|
+
const inline = isInlineWranglerConfig(opt) ? opt : void 0;
|
|
210
|
+
let configPath;
|
|
211
|
+
if (typeof opt === "string") {
|
|
212
|
+
configPath = resolve(opt);
|
|
213
|
+
if (!existsSync(configPath)) {
|
|
214
|
+
console.warn(`[env-runner] wrangler config requested but not found at "${configPath}"`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
} else if (opt === true) {
|
|
218
|
+
configPath = findWranglerConfig(entryPath);
|
|
219
|
+
if (!configPath) {
|
|
220
|
+
console.warn("[env-runner] wrangler config requested but none found near the entry or cwd");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
} else configPath = findWranglerConfig(entryPath);
|
|
224
|
+
let wrangler;
|
|
225
|
+
try {
|
|
226
|
+
wrangler = await import("wrangler");
|
|
227
|
+
} catch {
|
|
228
|
+
if (!_warnedNoWrangler) {
|
|
229
|
+
_warnedNoWrangler = true;
|
|
230
|
+
console.warn("[env-runner] 'wrangler' is not installed; using the built-in minimal config reader (plain JSON, common fields only). Install 'wrangler' for full fidelity (JSONC, TOML, env inheritance, all binding types).");
|
|
231
|
+
}
|
|
232
|
+
return mergeWranglerMiniflareOptions(configPath ? readWranglerConfigMinimal(configPath, env) : void 0, inline ? mapWranglerConfigToMiniflare(applyWranglerEnv(inline, env)) : void 0);
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
return mergeWranglerMiniflareOptions(configPath ? pickWranglerMiniflareOptions(wrangler.unstable_getMiniflareWorkerOptions(wrangler.unstable_readConfig({
|
|
236
|
+
config: configPath,
|
|
237
|
+
env
|
|
238
|
+
}, { hideWarnings: true }), env).workerOptions) : void 0, inline ? pickWranglerMiniflareOptions(wrangler.unstable_getMiniflareWorkerOptions(readInlineWranglerConfig(wrangler, inline, env), env).workerOptions) : void 0);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
const desc = [configPath && `"${configPath}"`, inline && "(inline)"].filter(Boolean).join(" + ");
|
|
241
|
+
console.warn(`[env-runner] failed to load wrangler config ${desc}: ${error.message}`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function mergeWranglerMiniflareOptions(base, override) {
|
|
246
|
+
if (!base) return override;
|
|
247
|
+
if (!override) return base;
|
|
248
|
+
const out = { ...base };
|
|
249
|
+
for (const [key, value] of Object.entries(override)) {
|
|
250
|
+
const prev = out[key];
|
|
251
|
+
if (Array.isArray(value) && Array.isArray(prev)) out[key] = [...new Set([...prev, ...value])];
|
|
252
|
+
else if (isPlainObject(value) && isPlainObject(prev)) out[key] = {
|
|
253
|
+
...prev,
|
|
254
|
+
...value
|
|
255
|
+
};
|
|
256
|
+
else out[key] = value;
|
|
257
|
+
}
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
function readInlineWranglerConfig(wrangler, inline, env) {
|
|
261
|
+
const dir = mkdtempSync(join(tmpdir(), "env-runner-wrangler-"));
|
|
262
|
+
const file = join(dir, "wrangler.json");
|
|
263
|
+
try {
|
|
264
|
+
writeFileSync(file, JSON.stringify(inline));
|
|
265
|
+
return wrangler.unstable_readConfig({
|
|
266
|
+
config: file,
|
|
267
|
+
env
|
|
268
|
+
}, { hideWarnings: true });
|
|
269
|
+
} finally {
|
|
270
|
+
rmSync(dir, {
|
|
271
|
+
recursive: true,
|
|
272
|
+
force: true
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function findWranglerConfig(entryPath) {
|
|
277
|
+
const dirs = [];
|
|
278
|
+
if (entryPath) {
|
|
279
|
+
const resolved = isAbsolute(entryPath) ? entryPath : resolve(entryPath);
|
|
280
|
+
dirs.push(dirname(resolved));
|
|
281
|
+
}
|
|
282
|
+
dirs.push(process.cwd());
|
|
283
|
+
for (const dir of dirs) for (const name of WRANGLER_CONFIG_FILENAMES) {
|
|
284
|
+
const candidate = join(dir, name);
|
|
285
|
+
if (existsSync(candidate)) return candidate;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function pickWranglerMiniflareOptions(workerOptions) {
|
|
289
|
+
const out = {};
|
|
290
|
+
for (const [key, value] of Object.entries(workerOptions)) {
|
|
291
|
+
if (value === void 0 || WRANGLER_OPTION_DENYLIST.has(key)) continue;
|
|
292
|
+
out[key] = value;
|
|
293
|
+
}
|
|
294
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
295
|
+
}
|
|
296
|
+
function readWranglerConfigMinimal(configPath, env) {
|
|
297
|
+
if (extname(configPath).toLowerCase() !== ".json") {
|
|
298
|
+
console.warn(`[env-runner] reading "${basename(configPath)}" requires the 'wrangler' package; the built-in reader supports plain JSON only (install 'wrangler' for JSONC/TOML).`);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
let raw;
|
|
302
|
+
try {
|
|
303
|
+
raw = readFileSync(configPath, "utf8");
|
|
304
|
+
} catch {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
let config;
|
|
308
|
+
try {
|
|
309
|
+
config = JSON.parse(raw);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.warn(`[env-runner] failed to parse wrangler config "${configPath}": ${error.message}`);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
return mapWranglerConfigToMiniflare(applyWranglerEnv(config, env));
|
|
315
|
+
}
|
|
316
|
+
function applyWranglerEnv(config, env) {
|
|
317
|
+
return env && config.env?.[env] ? {
|
|
318
|
+
...config,
|
|
319
|
+
...config.env[env]
|
|
320
|
+
} : config;
|
|
321
|
+
}
|
|
322
|
+
function mapWranglerConfigToMiniflare(config) {
|
|
323
|
+
const out = {};
|
|
324
|
+
if (typeof config.compatibility_date === "string") out.compatibilityDate = config.compatibility_date;
|
|
325
|
+
if (Array.isArray(config.compatibility_flags)) out.compatibilityFlags = config.compatibility_flags;
|
|
326
|
+
if (config.vars && typeof config.vars === "object") out.bindings = { ...config.vars };
|
|
327
|
+
const kv = mapBindingArray(config.kv_namespaces, "binding", (n) => n.id ?? n.binding);
|
|
328
|
+
if (kv) out.kvNamespaces = kv;
|
|
329
|
+
const r2 = mapBindingArray(config.r2_buckets, "binding", (n) => n.bucket_name ?? n.binding);
|
|
330
|
+
if (r2) out.r2Buckets = r2;
|
|
331
|
+
const d1 = mapBindingArray(config.d1_databases, "binding", (n) => n.database_id ?? n.preview_database_id ?? n.binding);
|
|
332
|
+
if (d1) out.d1Databases = d1;
|
|
333
|
+
const queues = mapBindingArray(config.queues?.producers, "binding", (n) => n.queue);
|
|
334
|
+
if (queues) out.queueProducers = queues;
|
|
335
|
+
if (Array.isArray(config.durable_objects?.bindings)) {
|
|
336
|
+
const dos = {};
|
|
337
|
+
for (const b of config.durable_objects.bindings) {
|
|
338
|
+
if (!b?.name || !b?.class_name) continue;
|
|
339
|
+
dos[b.name] = b.script_name ? {
|
|
340
|
+
className: b.class_name,
|
|
341
|
+
scriptName: b.script_name
|
|
342
|
+
} : b.class_name;
|
|
343
|
+
}
|
|
344
|
+
if (Object.keys(dos).length > 0) out.durableObjects = dos;
|
|
345
|
+
}
|
|
346
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
347
|
+
}
|
|
348
|
+
function mapBindingArray(arr, keyField, value) {
|
|
349
|
+
if (!Array.isArray(arr)) return;
|
|
350
|
+
const out = {};
|
|
351
|
+
for (const entry of arr) {
|
|
352
|
+
const key = entry?.[keyField];
|
|
353
|
+
if (typeof key === "string") out[key] = value(entry);
|
|
354
|
+
}
|
|
355
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
356
|
+
}
|
|
182
357
|
const _miniflareCache = /* @__PURE__ */ new Map();
|
|
183
358
|
var MiniflareEnvRunner = class extends BaseEnvRunner {
|
|
184
359
|
#miniflare;
|
|
@@ -194,6 +369,8 @@ var MiniflareEnvRunner = class extends BaseEnvRunner {
|
|
|
194
369
|
#exports;
|
|
195
370
|
#captureErrors;
|
|
196
371
|
#exportConditions;
|
|
372
|
+
#wrangler;
|
|
373
|
+
#wranglerEnv;
|
|
197
374
|
constructor(opts) {
|
|
198
375
|
super({
|
|
199
376
|
...opts,
|
|
@@ -205,6 +382,8 @@ var MiniflareEnvRunner = class extends BaseEnvRunner {
|
|
|
205
382
|
this.#exports = opts.exports ?? {};
|
|
206
383
|
this.#captureErrors = opts.captureErrors ?? true;
|
|
207
384
|
this.#exportConditions = opts.exportConditions ?? ["workerd", "worker"];
|
|
385
|
+
this.#wrangler = opts.wrangler ?? false;
|
|
386
|
+
this.#wranglerEnv = opts.wranglerEnv ?? process.env.CLOUDFLARE_ENV;
|
|
208
387
|
this._initWithVirtualData(() => this.#init());
|
|
209
388
|
}
|
|
210
389
|
static async disposeAll() {
|
|
@@ -313,10 +492,12 @@ var MiniflareEnvRunner = class extends BaseEnvRunner {
|
|
|
313
492
|
}
|
|
314
493
|
const mfUrl = await this.#miniflare.unsafeGetDirectURL();
|
|
315
494
|
const address = new URL(mfUrl);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
495
|
+
try {
|
|
496
|
+
await proxyUpgrade({
|
|
497
|
+
host: address.hostname,
|
|
498
|
+
port: Number(address.port)
|
|
499
|
+
}, context.node.req, context.node.socket, context.node.head);
|
|
500
|
+
} catch {}
|
|
320
501
|
}
|
|
321
502
|
async #prepareVirtualModules() {
|
|
322
503
|
const virtual = this._data?.virtual;
|
|
@@ -333,22 +514,36 @@ var MiniflareEnvRunner = class extends BaseEnvRunner {
|
|
|
333
514
|
});
|
|
334
515
|
}
|
|
335
516
|
async #initAsync() {
|
|
336
|
-
const { Miniflare } = await import("miniflare");
|
|
517
|
+
const { Miniflare, supportedCompatibilityDate } = await import("miniflare");
|
|
337
518
|
const entryPath = this._data?.entry;
|
|
338
519
|
const virtual = await this.#prepareVirtualModules();
|
|
339
520
|
this.#virtual = virtual;
|
|
521
|
+
const wranglerOptions = await loadWranglerConfig(this.#wrangler, this.#wranglerEnv, entryPath);
|
|
340
522
|
const userFlags = this.#miniflareOptions.compatibilityFlags || [];
|
|
523
|
+
const wranglerFlags = wranglerOptions?.compatibilityFlags || [];
|
|
341
524
|
const userDirectSockets = this.#miniflareOptions.unsafeDirectSockets || [];
|
|
342
525
|
const options = {
|
|
343
|
-
compatibilityDate:
|
|
526
|
+
compatibilityDate: supportedCompatibilityDate,
|
|
344
527
|
modules: true,
|
|
528
|
+
...wranglerOptions,
|
|
345
529
|
...this.#miniflareOptions,
|
|
346
|
-
compatibilityFlags: [...new Set([
|
|
530
|
+
compatibilityFlags: [...new Set([
|
|
531
|
+
"nodejs_compat",
|
|
532
|
+
...wranglerFlags,
|
|
533
|
+
...userFlags
|
|
534
|
+
])],
|
|
347
535
|
unsafeDirectSockets: [{
|
|
348
536
|
host: "127.0.0.1",
|
|
349
537
|
port: 0
|
|
350
538
|
}, ...userDirectSockets]
|
|
351
539
|
};
|
|
540
|
+
if (wranglerOptions) for (const [key, wValue] of Object.entries(wranglerOptions)) {
|
|
541
|
+
const uValue = this.#miniflareOptions[key];
|
|
542
|
+
if (isPlainObject(wValue) && isPlainObject(uValue)) options[key] = {
|
|
543
|
+
...wValue,
|
|
544
|
+
...uValue
|
|
545
|
+
};
|
|
546
|
+
}
|
|
352
547
|
if (entryPath && !options.script && !options.scriptPath) {
|
|
353
548
|
const entryIsVirtual = isVirtualSpecifier(entryPath, virtual);
|
|
354
549
|
const resolvedEntry = entryIsVirtual ? entryPath : resolve(entryPath);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { EnvRunnerData } from "../../_chunks/common-base-runner.mjs";
|
|
2
|
-
import { MiniflareEnvRunner, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult } from "../../_chunks/miniflare-runner.mjs";
|
|
3
|
-
export { MiniflareEnvRunner, type EnvRunnerData as MiniflareEnvRunnerData, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult };
|
|
2
|
+
import { MiniflareEnvRunner, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult, WranglerInlineConfig } from "../../_chunks/miniflare-runner.mjs";
|
|
3
|
+
export { MiniflareEnvRunner, type EnvRunnerData as MiniflareEnvRunnerData, MiniflareEnvRunnerOptions, MiniflareExportInfo, TransformResult, type WranglerInlineConfig };
|
|
@@ -18,11 +18,15 @@ var SelfEnvRunner = class extends BaseEnvRunner {
|
|
|
18
18
|
}
|
|
19
19
|
async upgrade(context) {
|
|
20
20
|
if (!this.#entry || this.closed) return;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
try {
|
|
22
|
+
if (this.#entry.websocket) {
|
|
23
|
+
await (await this.#resolveWSAdapter()).handleUpgrade(context.node.req, context.node.socket, context.node.head);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.#entry.upgrade?.(context);
|
|
27
|
+
} catch {
|
|
28
|
+
if (!context.node.socket.destroyed) context.node.socket.destroy();
|
|
24
29
|
}
|
|
25
|
-
this.#entry.upgrade?.(context);
|
|
26
30
|
}
|
|
27
31
|
sendMessage(message) {
|
|
28
32
|
if (!this.#active) throw new Error("Self env runner should be initialized before sending messages.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "env-runner",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Generic environment runner for JavaScript runtimes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "unjs/env-runner",
|
|
@@ -64,12 +64,14 @@
|
|
|
64
64
|
"oxfmt": "^0.51.0",
|
|
65
65
|
"oxlint": "^1.69.0",
|
|
66
66
|
"typescript": "^6.0.3",
|
|
67
|
-
"vitest": "^4.1.8"
|
|
67
|
+
"vitest": "^4.1.8",
|
|
68
|
+
"wrangler": "^4.99.0"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@netlify/runtime": "^4.1.23",
|
|
71
72
|
"@vercel/queue": "^0.2.0",
|
|
72
|
-
"miniflare": "^4.20260515.0"
|
|
73
|
+
"miniflare": "^4.20260515.0",
|
|
74
|
+
"wrangler": "^4.0.0"
|
|
73
75
|
},
|
|
74
76
|
"peerDependenciesMeta": {
|
|
75
77
|
"miniflare": {
|
|
@@ -80,6 +82,9 @@
|
|
|
80
82
|
},
|
|
81
83
|
"@vercel/queue": {
|
|
82
84
|
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"wrangler": {
|
|
87
|
+
"optional": true
|
|
83
88
|
}
|
|
84
89
|
},
|
|
85
90
|
"packageManager": "pnpm@11.5.2"
|