Skip to content

Commit

Permalink
fix: ignore nodejs_compat flags in runtime type generation (#6554)
Browse files Browse the repository at this point in the history
* fix: ignore nodejs_compat flags in runtime type generation

* chore: add changeset

* tests: create tests for getNodeCompatMode

* chore: extract node compat helper to own file

* chore: remove spurious files

* chore: undo refactoring

* chore: tidy up

---------

Co-authored-by: Andy Jessop <ajessop@cloudflare.com>
  • Loading branch information
andyjessop and Andy Jessop committed Aug 26, 2024
1 parent 439e63a commit 46aee5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
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")
),
});

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

0 comments on commit 46aee5d

Please sign in to comment.