Skip to content

Commit 3f2a046

Browse files
committed
Add support for running initialization scripts before content
This adds the ability to run a script in a separate global before content gets run. This code has access to additional abilities, notably including the `defineBuiltinModule` function. Building on this will allow us to change ComponentizeJS to support content using imports from `wasi:package-name` module names without rewriting the code first. That in turn will enable support for non-bundled content code.
1 parent cd72251 commit 3f2a046

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stdout [0] :: Log: foo
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { func } from "builtinMod";
2+
async function handle(event) {
3+
console.log(func());
4+
return new Response(func());
5+
}
6+
7+
//@ts-ignore
8+
addEventListener('fetch', (event) => { event.respondWith(handle(event)) });

tests/e2e/init-script/init.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const builtinMod = {
2+
func() {
3+
return 'foo';
4+
}
5+
}
6+
7+
defineBuiltinModule('builtinMod', builtinMod);
8+
print("initialization done");

0 commit comments

Comments
 (0)