Files
wehub-resource-sync 70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

58 lines
1.5 KiB
TypeScript

const modules = import.meta.glob("../src/**/*.ts");
export default {
async fetch(request) {
const { pathname } = new URL(request.url);
if (pathname === "/@alias/test") {
const { test } = await import("@alias/test");
return test();
}
if (pathname === "/optimize-deps/exclude") {
const { virtualExport } = await import(
// @ts-expect-error virtual module
"@playground/module-resolution-excludes"
);
return new Response(virtualExport);
}
const filePath = `${pathname.replace(/^\//, "./")}.ts`;
if (modules[filePath]) {
const mod = await modules[filePath]();
return Response.json((mod as { default: unknown }).default);
}
const html = `<!DOCTYPE html>
<body>
<h1>Module Resolution App</h1>
<p>
This app is an example/test for dependencies module resolution being performed in the Cloudflare environment (inside the workerd runtime)
</p>
<hr />
<h2>Available Routes</h2>
<ul>
${[
...Object.keys(modules),
"/@alias/test",
"optimize-deps/exclude",
]
.map((path) => path.replace(/^\.\//, "/").replace(/\.ts$/, ""))
.map(
(route) =>
` <li><a href="${route}">${route}</a></li>`
)
.join("\n")}
</ul>
</body>`;
return new Response(html, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
},
} satisfies ExportedHandler;