Skip to content

Commit 00889ec

Browse files
Update examples
1 parent cf82323 commit 00889ec

File tree

9 files changed

+15
-51
lines changed

9 files changed

+15
-51
lines changed

Examples/Basic/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<body>
1616
<script type="module">
17-
import { instantiate } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
18-
await instantiate(fetch("./.build/plugins/PackageToJS/outputs/Package/main.wasm"));
17+
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
18+
await init(fetch("./.build/plugins/PackageToJS/outputs/Package/main.wasm"));
1919
</script>
2020
</body>
2121

Examples/Embedded/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
<body>
1616
<script type="module">
17-
import { instantiate } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
18-
await instantiate(fetch("./.build/plugins/PackageToJS/outputs/Package/main.wasm"));
17+
import { init } from "./.build/plugins/PackageToJS/outputs/Package/index.js";
18+
await init(fetch("./.build/plugins/PackageToJS/outputs/Package/main.wasm"));
1919
</script>
2020
</body>
2121

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { NodeRunner, BrowserRunner } from "../test.js"
1+
import { NodeRunner } from "../test.js"
22

3-
const runners = {
4-
"node": NodeRunner,
5-
"browser": BrowserRunner,
6-
}
7-
const runner = new runners[process.env.TEST_RUNNER || "node"]()
3+
const runner = new NodeRunner()
84
await runner.run()

Plugins/PackageToJS/Templates/index.d.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/**
2-
* The path to the WebAssembly module relative to the root of the package
3-
*/
4-
export declare const MODULE_PATH: string;
1+
import type { Import, Export } from './instantiate.js'
52

63
export type Options = {
74
/**
@@ -26,9 +23,3 @@ export declare function init(
2623
instance: WebAssembly.Instance,
2724
exports: Export
2825
}>
29-
30-
export declare function runTest(
31-
moduleSource: WebAssembly.Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike<Response>,
32-
imports: Import,
33-
options: Options | undefined
34-
): Promise<{ exitCode: number }>

Plugins/PackageToJS/Templates/index.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @ts-check
22
import { WASI, WASIProcExit, File, OpenFile, ConsoleStdout, PreopenDirectory } from '@bjorn3/browser_wasi_shim';
3-
import { instantiate } from './instantiate.js';
4-
export const MODULE_PATH = "@PACKAGE_TO_JS_MODULE_PATH@";
3+
import { instantiate, MODULE_PATH } from './instantiate.js';
54

65
/** @type {import('./index.d').init} */
76
export async function init(
@@ -29,20 +28,3 @@ export async function init(
2928
exports,
3029
}
3130
}
32-
33-
/** @type {import('./index.d').runTest} */
34-
export async function runTest(
35-
moduleSource,
36-
imports,
37-
options
38-
) {
39-
try {
40-
const { instance, exports } = await init(moduleSource, imports, options);
41-
return { exitCode: 0 };
42-
} catch (error) {
43-
if (error instanceof WASIProcExit) {
44-
return { exitCode: error.code };
45-
}
46-
throw error;
47-
}
48-
}

Plugins/PackageToJS/Templates/instantiate.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export type Export = {
55
// TODO: Generate type from .swift files
66
}
77

8+
/**
9+
* The path to the WebAssembly module relative to the root of the package
10+
*/
11+
export declare const MODULE_PATH: string;
12+
813
/**
914
* Low-level interface to create an instance of a WebAssembly module
1015
*

Plugins/PackageToJS/Templates/instantiate.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// @ts-ignore
33
import { SwiftRuntime } from "./runtime.js"
44

5+
export const MODULE_PATH = "@PACKAGE_TO_JS_MODULE_PATH@";
6+
57
/** @type {import('./instantiate.d').createInstantiator} */
68
export async function createInstantiator(
79
imports,

Plugins/PackageToJS/Templates/test.d.ts

-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ export declare class NodeRunner {
22
constructor()
33
run(): Promise<void>
44
}
5-
6-
export declare class BrowserRunner {
7-
constructor()
8-
run(): Promise<void>
9-
}

Plugins/PackageToJS/Templates/test.js

-7
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,3 @@ Please ensure you are using Node.js v18.x or newer.
4545
swift.main()
4646
}
4747
}
48-
49-
export class BrowserRunner {
50-
constructor() { }
51-
52-
async run() {
53-
}
54-
}

0 commit comments

Comments
 (0)