Skip to content

Commit

Permalink
fix: add asset binding to typegen (#6779)
Browse files Browse the repository at this point in the history
  • Loading branch information
emily-shen authored Sep 20, 2024
1 parent 7655505 commit 3e75612
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-colts-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: include asset binding in `wrangler types`
5 changes: 5 additions & 0 deletions packages/wrangler/src/__tests__/type-generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ const bindingsConfigMock: Omit<
{ type: "CompiledWasm", globs: ["**/*.wasm"], fallthrough: true },
],
pipelines: [],
experimental_assets: {
binding: "ASSETS_BINDING",
directory: "/assets",
},
};

describe("generateTypes()", () => {
Expand Down Expand Up @@ -355,6 +359,7 @@ describe("generateTypes()", () => {
BROWSER_BINDING: Fetcher;
AI_BINDING: Ai;
VERSION_METADATA_BINDING: { id: string; tag: string };
ASSETS_BINDING: Fetcher;
}
declare module \\"*.txt\\" {
const value: string;
Expand Down
7 changes: 7 additions & 0 deletions packages/wrangler/src/type-generation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export async function typesHandler(
ai: config.ai,
version_metadata: config.version_metadata,
secrets,
experimental_assets: config.experimental_assets,
};

await generateTypes(
Expand Down Expand Up @@ -406,6 +407,12 @@ async function generateTypes(
);
}

if (configToDTS.experimental_assets?.binding) {
envTypeStructure.push(
constructType(configToDTS.experimental_assets.binding, "Fetcher")
);
}

const modulesTypeStructure: string[] = [];
if (configToDTS.rules) {
const moduleTypeMap = {
Expand Down

0 comments on commit 3e75612

Please sign in to comment.