Skip to content

Commit

Permalink
Only load worker code in WorkerD
Browse files Browse the repository at this point in the history
  • Loading branch information
BarnabyShearer committed Mar 21, 2024
1 parent 04ae394 commit 63ab0cb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 8 additions & 3 deletions bin/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import fs from "fs";
import { cmd } from "../src/cmd.mjs";
import consumers from "stream/consumers";
import openapiTS from "openapi-typescript";
import { Miniflare } from "miniflare";

if (fs.existsSync("wrangler.toml")) {
await cmd("wrangler deploy --dry-run --outdir=dist");
const app = await import(`${process.cwd()}/dist/index.js`);
const request = await app.default.fetch(
{ url: "http://example.com/doc", method: "GET" },
const miniflare = new Miniflare({
modules: true,
scriptPath: "dist/index.js",
});
const request = await fetch(
`${await miniflare.ready}doc`,
{ SENTRY_DSN: null, SENTRY_ENVIRONMENT: null },
null,
);
const types = await openapiTS(await consumers.json(request.body));
await miniflare.dispose();
fs.writeFileSync("test/api.d.ts", types);
}
await cmd("vitest --globals --no-file-parallelism", [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "two-stroke",
"packageManager": "[email protected]",
"type": "module",
"version": "1.0.8",
"version": "1.0.9",
"devDependencies": {
"@types/eslint": "^8.56.5",
"@types/node": "^20.11.25",
Expand Down
9 changes: 8 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Toucan } from "toucan-js";
import { ZodObject, ZodSchema, z } from "zod";
export type Env = {
[k: string]: string | Queue | KVNamespace | R2Bucket | D1Database | Fetcher | Hyperdrive;
[k: string]:
| string
| Queue
| KVNamespace
| R2Bucket
| D1Database
| Fetcher
| Hyperdrive;
};
export type Route<T extends Env, A> =
| {
Expand Down

0 comments on commit 63ab0cb

Please sign in to comment.