-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudflare): "shared" wasm module imports (#249)
- Loading branch information
1 parent
38c32c9
commit 72fc8ac
Showing
7 changed files
with
216 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/cloudflare': patch | ||
--- | ||
|
||
Fixes build errors when wasm modules are imported from a file that is shared in both prerendered static pages and server side rendered pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/cloudflare/test/fixtures/wasm/src/pages/hybridshared.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { type APIContext } from 'astro'; | ||
|
||
import {add} from '../util/add'; | ||
|
||
export const prerender = true | ||
|
||
export async function GET( | ||
context: APIContext | ||
): Promise<Response> { | ||
return new Response(JSON.stringify({ answer: add(20, 1) }), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/cloudflare/test/fixtures/wasm/src/pages/shared/[a]/[b].ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type APIContext } from 'astro'; | ||
import { add } from '../../../util/add'; | ||
|
||
|
||
export const prerender = false; | ||
|
||
export async function GET( | ||
context: APIContext | ||
): Promise<Response> { | ||
const a = Number.parseInt(context.params.a ?? "0"); | ||
const b = Number.parseInt(context.params.b ?? "0"); | ||
return new Response(JSON.stringify({ answer: add(a, b) }), { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import mod from './add.wasm?module'; | ||
|
||
|
||
const addModule: any = new WebAssembly.Instance(mod); | ||
|
||
export function add(a, b) { | ||
return addModule.exports.add(a, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters