Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore nodejs_compat flags in runtime type generation #6554

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-beers-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: nodejs_compat flags no longer error when running wrangler types --x-include-runtime
20 changes: 20 additions & 0 deletions packages/wrangler/e2e/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,24 @@ describe("types", () => {
`📣 It looks like you have some Node.js compatibility turned on in your project. You might want to consider adding Node.js typings with "npm i --save-dev @types/node@20.8.3". Please see the docs for more details: https://developers.cloudflare.com/workers/languages/typescript/#transitive-loading-of-typesnode-overrides-cloudflareworkers-types`
);
});

it("should not error with nodejs_compat flags", async () => {
const helper = new WranglerE2ETestHelper();
await helper.seed({
...seed,
"wrangler.toml": dedent`
name = "test-worker"
main = "src/index.ts"
compatibility_date = "2023-01-01"
compatibility_flags = ["nodejs_compat", "experimental:nodejs_compat_v2"]
`,
});

const output = await helper.run(
`wrangler types --x-include-runtime="./types.d.ts"`
);

expect(output.stderr).toBe("");
expect(output.status).toBe(0);
});
});
5 changes: 4 additions & 1 deletion packages/wrangler/src/type-generation/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export async function generateRuntimeTypes({

const types = await generate({
compatibilityDate: compatibility_date,
compatibilityFlags: compatibility_flags,
// Ignore nodejs compat flags as there is currently no mechanism to generate these dynamically.
compatibilityFlags: compatibility_flags.filter(
(flag) => !flag.includes("nodejs_compat")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--> This is the actual bug fix <---

),
});

await writeFile(outFile, types, "utf8");
Expand Down
Loading