(request: Request)
| 174 | |
| 175 | export default class extends WorkerEntrypoint<Env> { |
| 176 | override async fetch(request: Request) { |
| 177 | const url = new URL(request.url); |
| 178 | const stub = this.env.HOST.get(this.env.HOST.idFromName("script-runner")); |
| 179 | |
| 180 | try { |
| 181 | if (url.pathname === "/module-probe") { |
| 182 | const worker = this.env.LOADER.load({ |
| 183 | compatibilityDate: "2026-06-17", |
| 184 | compatibilityFlags: ["nodejs_compat"], |
| 185 | mainModule: "runner.js", |
| 186 | modules: { |
| 187 | "runner.js": ` |
| 188 | import { WorkerEntrypoint } from "cloudflare:workers"; |
| 189 | import { install } from "workspace:capabilities"; |
| 190 | export default class extends WorkerEntrypoint { |
| 191 | async evaluate(bridge) { |
| 192 | install(bridge); |
| 193 | globalThis.__probeBridge = bridge; |
| 194 | const user = await import("./user.js"); |
| 195 | return user.default(); |
| 196 | } |
| 197 | } |
| 198 | `, |
| 199 | "workspace:capabilities": { |
| 200 | js: ` |
| 201 | let bridge; |
| 202 | export function install(value) { bridge = value; } |
| 203 | export function call(name, ...args) { |
| 204 | if (!bridge) throw new Error("Workspace capabilities are not installed"); |
| 205 | return bridge[name](...args); |
| 206 | } |
| 207 | `, |
| 208 | }, |
| 209 | "node:fs/promises": { |
| 210 | js: ` |
| 211 | export const tag = "trusted"; |
| 212 | export function readFile(path) { return globalThis.__probeBridge.read(path); } |
| 213 | `, |
| 214 | }, |
| 215 | "helper.js": `export const suffix = "relative";`, |
| 216 | "user.js": ` |
| 217 | import { readFile } from "node:fs/promises"; |
| 218 | import { suffix } from "./helper.js"; |
| 219 | export default async function run() { |
| 220 | const dynamic = await import("node:fs/promises"); |
| 221 | return [await readFile("/workspace/probe.txt"), suffix, dynamic.tag].join("|"); |
| 222 | } |
| 223 | `, |
| 224 | }, |
| 225 | globalOutbound: null, |
| 226 | }); |
| 227 | const entrypoint = worker.getEntrypoint() as unknown as { |
| 228 | evaluate(bridge: ModuleProbeBridge): Promise<string>; |
| 229 | [Symbol.dispose]?: () => void; |
| 230 | }; |
| 231 | try { |
| 232 | return new Response(await entrypoint.evaluate(new ModuleProbeBridge())); |
| 233 | } finally { |
nothing calls this directly
no test coverage detected