Skip to content

Commit 4c80c78

Browse files
authored
Set preserveEntrySignatures: "strict" for Worker environments (#10544)
* Updated worker playground to fail * Add preserveEntrySignatures: 'strict' * Add changeset
1 parent fd73b69 commit 4c80c78

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

.changeset/bumpy-garlics-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
Set `preserveEntrySignatures: "strict"` for Worker environments. This ensures that no additional exports are added to the entry module.

packages/vite-plugin-cloudflare/playground/worker/__tests__/worker.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ test("basic hello-world functionality", async () => {
1717
);
1818
});
1919

20+
test("preserves entry signatures", async () => {
21+
expect(serverLogs.info.join()).toContain("__preserves-entry-signatures__");
22+
});
23+
2024
test("basic dev logging", async () => {
2125
expect(serverLogs.info.join()).toContain("__console log__");
2226
expect(serverLogs.errors.join()).toContain("__console error__");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const a = "__preserves-entry-signatures__";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { a } from "./a";
2+
3+
export function fn() {
4+
console.log(a);
5+
}

packages/vite-plugin-cloudflare/playground/worker/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { a } from "./a";
2+
13
export default {
24
async fetch(request) {
35
const url = new URL(request.url);
@@ -6,6 +8,10 @@ export default {
68
return new Response(request.headers.get("X-Forwarded-Host"));
79
}
810

11+
console.log(a);
12+
const { fn } = await import("./b");
13+
fn();
14+
915
console.log("__console log__");
1016
console.warn("__console warn__");
1117
console.error("__console error__");

packages/vite-plugin-cloudflare/src/cloudflare-environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export function createCloudflareEnvironmentOptions({
168168
ssr: true,
169169
rollupOptions: {
170170
input: workerConfig.main,
171+
// workerd checks the types of the exports so we need to ensure that additional exports are not added to the entry module
172+
preserveEntrySignatures: "strict",
171173
// rolldown-only option
172174
...("rolldownVersion" in vite ? ({ platform: "neutral" } as any) : {}),
173175
},

0 commit comments

Comments
 (0)