@ttsc/wasm 0.12.3 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/ttsc-wasm/main.go +101 -89
- package/cmd/ttsc-wasm/main_wasm.go +6 -4
- package/dist/ttsc.wasm +0 -0
- package/host/api.go +154 -145
- package/host/doc.go +12 -12
- package/host/host.go +236 -225
- package/host/host_native.go +5 -2
- package/host/plugin.go +31 -31
- package/lib/src/MemFS.d.ts +35 -0
- package/lib/src/MemFS.js +57 -4
- package/lib/src/MemFS.js.map +1 -1
- package/lib/src/api.d.ts +46 -13
- package/lib/src/api.js +7 -4
- package/lib/src/api.js.map +1 -1
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +10 -3
- package/lib/src/index.js.map +1 -1
- package/lib/src/instantiate.d.ts +10 -7
- package/lib/src/instantiate.js +20 -3
- package/lib/src/instantiate.js.map +1 -1
- package/package.json +2 -2
- package/shim-vendor/shim/ast/shim.go +24 -0
- package/shim-vendor/shim/checker/shim.go +35 -0
- package/shim-vendor/shim/core/shim.go +17 -0
- package/shim-vendor/shim/diagnosticwriter/shim.go +4 -0
- package/shim-vendor/shim/lsp/shim.go +3 -3
- package/shim-vendor/shim/printer/shim.go +20 -0
- package/src/MemFS.ts +92 -7
- package/src/api.ts +46 -13
- package/src/index.ts +1 -5
- package/src/instantiate.ts +37 -14
package/src/instantiate.ts
CHANGED
|
@@ -7,39 +7,43 @@
|
|
|
7
7
|
// The boot helper is parameterized by `apiName` so any wasm built with
|
|
8
8
|
// `host.Expose(...)` can be loaded the same way. The base wasm uses "ttsc";
|
|
9
9
|
// downstream consumers pick their own (e.g. "ttscPlayground", "ttscTypia").
|
|
10
|
-
|
|
11
|
-
import { createMemFS, type IMemFSHost } from "./MemFS";
|
|
10
|
+
import { type IMemFSHost, createMemFS } from "./MemFS";
|
|
12
11
|
import type { ITtscApi } from "./api";
|
|
13
12
|
|
|
14
13
|
declare const importScripts: (...urls: string[]) => void;
|
|
15
14
|
|
|
15
|
+
/** Options for `bootTtsc`. All fields except `wasmUrl` have sensible defaults. */
|
|
16
16
|
export interface IBootTtscOptions {
|
|
17
17
|
/** URL of the .wasm to fetch. */
|
|
18
18
|
wasmUrl: string;
|
|
19
19
|
/** URL of wasm_exec.js. Defaults to the same directory as wasmUrl. */
|
|
20
20
|
wasmExecUrl?: string;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* "ttsc".
|
|
22
|
+
* GlobalThis property name the wasm binds. Must match the value the wasm was
|
|
23
|
+
* built with (the `apiName` passed to `host.Expose`). Defaults to "ttsc".
|
|
25
24
|
*/
|
|
26
25
|
apiName?: string;
|
|
27
26
|
/**
|
|
28
|
-
* Optional pre-existing MemFS host. When omitted, a fresh one is created
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
27
|
+
* Optional pre-existing MemFS host. When omitted, a fresh one is created and
|
|
28
|
+
* stored on the returned BootResult. Pass an existing host when you want to
|
|
29
|
+
* boot multiple wasms over the same filesystem (e.g. base ttsc + a typia
|
|
30
|
+
* wasm) so they share project sources.
|
|
32
31
|
*/
|
|
33
32
|
host?: IMemFSHost;
|
|
34
33
|
}
|
|
35
34
|
|
|
35
|
+
/** Handle returned by `bootTtsc` once the wasm is ready. */
|
|
36
36
|
export interface IBootResult {
|
|
37
|
+
/** The typed API proxy bound by the wasm to `globalThis[apiName]`. */
|
|
37
38
|
api: ITtscApi;
|
|
39
|
+
/** The MemFS instance shared with the wasm's virtual filesystem. */
|
|
38
40
|
host: IMemFSHost;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
|
|
42
|
-
export async function bootTtsc(
|
|
44
|
+
export async function bootTtsc(
|
|
45
|
+
options: IBootTtscOptions,
|
|
46
|
+
): Promise<IBootResult> {
|
|
43
47
|
const wasmUrl = options.wasmUrl;
|
|
44
48
|
const wasmExecUrl = options.wasmExecUrl ?? defaultWasmExecUrl(wasmUrl);
|
|
45
49
|
const apiName = options.apiName ?? "ttsc";
|
|
@@ -64,11 +68,12 @@ export async function bootTtsc(options: IBootTtscOptions): Promise<IBootResult>
|
|
|
64
68
|
|
|
65
69
|
const response = await fetch(wasmUrl);
|
|
66
70
|
if (!response.ok) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`,
|
|
69
|
-
);
|
|
71
|
+
throw new Error(`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`);
|
|
70
72
|
}
|
|
71
|
-
const wasm = await WebAssembly.instantiateStreaming(
|
|
73
|
+
const wasm = await WebAssembly.instantiateStreaming(
|
|
74
|
+
response,
|
|
75
|
+
go.importObject,
|
|
76
|
+
);
|
|
72
77
|
// go.run never resolves until the wasm exits; we don't await it.
|
|
73
78
|
void go.run(wasm.instance);
|
|
74
79
|
await ready;
|
|
@@ -81,17 +86,35 @@ export async function bootTtsc(options: IBootTtscOptions): Promise<IBootResult>
|
|
|
81
86
|
return { api, host };
|
|
82
87
|
}
|
|
83
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Derive the `wasm_exec.js` URL from the wasm URL by replacing the filename.
|
|
91
|
+
*
|
|
92
|
+
* If `wasmUrl` has no directory component, returns `"wasm_exec.js"` (same
|
|
93
|
+
* directory as the caller's base URL).
|
|
94
|
+
*/
|
|
84
95
|
function defaultWasmExecUrl(wasmUrl: string): string {
|
|
85
96
|
const slash = wasmUrl.lastIndexOf("/");
|
|
86
97
|
if (slash < 0) return "wasm_exec.js";
|
|
87
98
|
return wasmUrl.slice(0, slash + 1) + "wasm_exec.js";
|
|
88
99
|
}
|
|
89
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Minimal shape of the `Go` constructor that `wasm_exec.js` exports on
|
|
103
|
+
* `globalThis`. Only the members we actually use are typed here.
|
|
104
|
+
*/
|
|
90
105
|
interface IGoInstance {
|
|
91
106
|
importObject: WebAssembly.Imports;
|
|
92
107
|
run(instance: WebAssembly.Instance): Promise<void>;
|
|
93
108
|
}
|
|
94
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Minimal `process` shim required by `wasm_exec.js` in non-Node environments.
|
|
112
|
+
*
|
|
113
|
+
* Go's js/wasm bridge reads `process.pid`, `process.ppid`, and calls
|
|
114
|
+
* `process.cwd()`. `getuid`/`getgid` and friends return `-1` (root-less).
|
|
115
|
+
* `umask` and `getgroups` are never exercised by the compiler but are included
|
|
116
|
+
* for completeness so unexpected calls surface as clear errors.
|
|
117
|
+
*/
|
|
95
118
|
function createProcessShim(): Record<string, unknown> {
|
|
96
119
|
return {
|
|
97
120
|
getuid: () => -1,
|