@ttsc/wasm 0.13.1 → 0.14.0-dev.20250530.1

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.
Files changed (159) hide show
  1. package/README.md +60 -15
  2. package/dist/ttsc.wasm +0 -0
  3. package/host/api.go +5 -4
  4. package/host/doc.go +7 -5
  5. package/host/fountain.go +505 -0
  6. package/host/host.go +64 -10
  7. package/host/plugin.go +6 -5
  8. package/lib/src/MemFSError.d.ts +15 -0
  9. package/lib/src/MemFSError.js +47 -0
  10. package/lib/src/MemFSError.js.map +1 -0
  11. package/lib/src/bootTtsc.d.ts +21 -0
  12. package/lib/src/bootTtsc.js +179 -0
  13. package/lib/src/bootTtsc.js.map +1 -0
  14. package/lib/src/createMemFS.d.ts +11 -0
  15. package/lib/src/{MemFS.js → createMemFS.js} +28 -63
  16. package/lib/src/createMemFS.js.map +1 -0
  17. package/lib/src/index.d.ts +5 -6
  18. package/lib/src/index.js +19 -8
  19. package/lib/src/index.js.map +1 -1
  20. package/lib/src/parseResult.d.ts +8 -0
  21. package/lib/src/parseResult.js +20 -0
  22. package/lib/src/parseResult.js.map +1 -0
  23. package/lib/src/structures/IBootResult.d.ts +9 -0
  24. package/lib/src/structures/IBootResult.js +3 -0
  25. package/lib/src/structures/IBootResult.js.map +1 -0
  26. package/lib/src/{instantiate.d.ts → structures/IBootTtscOptions.d.ts} +2 -12
  27. package/lib/src/structures/IBootTtscOptions.js +3 -0
  28. package/lib/src/structures/IBootTtscOptions.js.map +1 -0
  29. package/lib/src/structures/IFileStats.d.ts +23 -0
  30. package/lib/src/structures/IFileStats.js +3 -0
  31. package/lib/src/structures/IFileStats.js.map +1 -0
  32. package/lib/src/structures/IMemFSHost.d.ts +21 -0
  33. package/lib/src/structures/IMemFSHost.js +3 -0
  34. package/lib/src/structures/IMemFSHost.js.map +1 -0
  35. package/lib/src/structures/ITtscApi.d.ts +86 -0
  36. package/lib/src/structures/ITtscApi.js +3 -0
  37. package/lib/src/structures/ITtscApi.js.map +1 -0
  38. package/lib/src/structures/ITtscBuildOpts.d.ts +7 -0
  39. package/lib/src/structures/ITtscBuildOpts.js +3 -0
  40. package/lib/src/structures/ITtscBuildOpts.js.map +1 -0
  41. package/lib/src/structures/ITtscCompileResult.d.ts +11 -0
  42. package/lib/src/structures/ITtscCompileResult.js +3 -0
  43. package/lib/src/structures/ITtscCompileResult.js.map +1 -0
  44. package/lib/src/structures/ITtscDiagnostic.d.ts +14 -0
  45. package/lib/src/structures/ITtscDiagnostic.js +3 -0
  46. package/lib/src/structures/ITtscDiagnostic.js.map +1 -0
  47. package/lib/src/structures/ITtscFileQuery.d.ts +6 -0
  48. package/lib/src/structures/ITtscFileQuery.js +3 -0
  49. package/lib/src/structures/ITtscFileQuery.js.map +1 -0
  50. package/lib/src/structures/ITtscFountainDiagnosticsResult.d.ts +5 -0
  51. package/lib/src/structures/ITtscFountainDiagnosticsResult.js +3 -0
  52. package/lib/src/structures/ITtscFountainDiagnosticsResult.js.map +1 -0
  53. package/lib/src/structures/ITtscNodeAtPositionResult.d.ts +6 -0
  54. package/lib/src/structures/ITtscNodeAtPositionResult.js +3 -0
  55. package/lib/src/structures/ITtscNodeAtPositionResult.js.map +1 -0
  56. package/lib/src/structures/ITtscNodeInfo.d.ts +13 -0
  57. package/lib/src/structures/ITtscNodeInfo.js +3 -0
  58. package/lib/src/structures/ITtscNodeInfo.js.map +1 -0
  59. package/lib/src/structures/ITtscPluginOpts.d.ts +13 -0
  60. package/lib/src/structures/ITtscPluginOpts.js +3 -0
  61. package/lib/src/structures/ITtscPluginOpts.js.map +1 -0
  62. package/lib/src/structures/ITtscPositionQuery.d.ts +12 -0
  63. package/lib/src/structures/ITtscPositionQuery.js +3 -0
  64. package/lib/src/structures/ITtscPositionQuery.js.map +1 -0
  65. package/lib/src/structures/ITtscReleaseSnapshotResult.d.ts +5 -0
  66. package/lib/src/structures/ITtscReleaseSnapshotResult.js +3 -0
  67. package/lib/src/structures/ITtscReleaseSnapshotResult.js.map +1 -0
  68. package/lib/src/structures/ITtscResult.d.ts +15 -0
  69. package/lib/src/structures/ITtscResult.js +3 -0
  70. package/lib/src/structures/ITtscResult.js.map +1 -0
  71. package/lib/src/structures/ITtscSnapshotHandle.d.ts +5 -0
  72. package/lib/src/structures/ITtscSnapshotHandle.js +3 -0
  73. package/lib/src/structures/ITtscSnapshotHandle.js.map +1 -0
  74. package/lib/src/structures/ITtscSnapshotResult.d.ts +5 -0
  75. package/lib/src/structures/ITtscSnapshotResult.js +3 -0
  76. package/lib/src/structures/ITtscSnapshotResult.js.map +1 -0
  77. package/lib/src/structures/ITtscSnapshotsResult.d.ts +4 -0
  78. package/lib/src/structures/ITtscSnapshotsResult.js +3 -0
  79. package/lib/src/structures/ITtscSnapshotsResult.js.map +1 -0
  80. package/lib/src/structures/ITtscSourceFileTextResult.d.ts +5 -0
  81. package/lib/src/structures/ITtscSourceFileTextResult.js +3 -0
  82. package/lib/src/structures/ITtscSourceFileTextResult.js.map +1 -0
  83. package/lib/src/structures/ITtscSourceFilesResult.d.ts +5 -0
  84. package/lib/src/structures/ITtscSourceFilesResult.js +3 -0
  85. package/lib/src/structures/ITtscSourceFilesResult.js.map +1 -0
  86. package/lib/src/structures/ITtscSymbolAtPositionResult.d.ts +6 -0
  87. package/lib/src/structures/ITtscSymbolAtPositionResult.js +3 -0
  88. package/lib/src/structures/ITtscSymbolAtPositionResult.js.map +1 -0
  89. package/lib/src/structures/ITtscSymbolDeclaration.d.ts +7 -0
  90. package/lib/src/structures/ITtscSymbolDeclaration.js +3 -0
  91. package/lib/src/structures/ITtscSymbolDeclaration.js.map +1 -0
  92. package/lib/src/structures/ITtscSymbolInfo.d.ts +14 -0
  93. package/lib/src/structures/ITtscSymbolInfo.js +3 -0
  94. package/lib/src/structures/ITtscSymbolInfo.js.map +1 -0
  95. package/lib/src/structures/ITtscTransformResult.d.ts +12 -0
  96. package/lib/src/structures/ITtscTransformResult.js +3 -0
  97. package/lib/src/structures/ITtscTransformResult.js.map +1 -0
  98. package/lib/src/structures/ITtscTypeAtPositionResult.d.ts +6 -0
  99. package/lib/src/structures/ITtscTypeAtPositionResult.js +3 -0
  100. package/lib/src/structures/ITtscTypeAtPositionResult.js.map +1 -0
  101. package/lib/src/structures/ITtscTypeInfo.d.ts +7 -0
  102. package/lib/src/structures/ITtscTypeInfo.js +3 -0
  103. package/lib/src/structures/ITtscTypeInfo.js.map +1 -0
  104. package/lib/src/structures/ITtscVersion.d.ts +9 -0
  105. package/lib/src/structures/ITtscVersion.js +3 -0
  106. package/lib/src/structures/ITtscVersion.js.map +1 -0
  107. package/lib/src/{MemFS.d.ts → structures/IWasmExecFS.d.ts} +7 -66
  108. package/lib/src/structures/IWasmExecFS.js +3 -0
  109. package/lib/src/structures/IWasmExecFS.js.map +1 -0
  110. package/lib/src/structures/index.d.ts +29 -0
  111. package/lib/src/structures/index.js +46 -0
  112. package/lib/src/structures/index.js.map +1 -0
  113. package/package.json +2 -2
  114. package/shim-vendor/shim/ast/lint.go +1 -1
  115. package/shim-vendor/shim/checker/shim.go +3 -0
  116. package/shim-vendor/shim/core/shim.go +11 -0
  117. package/src/MemFSError.ts +43 -0
  118. package/src/bootTtsc.ts +212 -0
  119. package/src/{MemFS.ts → createMemFS.ts} +12 -231
  120. package/src/index.ts +5 -17
  121. package/src/parseResult.ts +16 -0
  122. package/src/structures/IBootResult.ts +10 -0
  123. package/src/structures/IBootTtscOptions.ts +21 -0
  124. package/src/structures/IFileStats.ts +23 -0
  125. package/src/structures/IMemFSHost.ts +18 -0
  126. package/src/structures/ITtscApi.ts +101 -0
  127. package/src/structures/ITtscBuildOpts.ts +7 -0
  128. package/src/structures/ITtscCompileResult.ts +12 -0
  129. package/src/structures/ITtscDiagnostic.ts +14 -0
  130. package/src/structures/ITtscFileQuery.ts +7 -0
  131. package/src/structures/ITtscFountainDiagnosticsResult.ts +6 -0
  132. package/src/structures/ITtscNodeAtPositionResult.ts +7 -0
  133. package/src/structures/ITtscNodeInfo.ts +13 -0
  134. package/src/structures/ITtscPluginOpts.ts +13 -0
  135. package/src/structures/ITtscPositionQuery.ts +13 -0
  136. package/src/structures/ITtscReleaseSnapshotResult.ts +5 -0
  137. package/src/structures/ITtscResult.ts +15 -0
  138. package/src/structures/ITtscSnapshotHandle.ts +5 -0
  139. package/src/structures/ITtscSnapshotResult.ts +5 -0
  140. package/src/structures/ITtscSnapshotsResult.ts +4 -0
  141. package/src/structures/ITtscSourceFileTextResult.ts +5 -0
  142. package/src/structures/ITtscSourceFilesResult.ts +5 -0
  143. package/src/structures/ITtscSymbolAtPositionResult.ts +7 -0
  144. package/src/structures/ITtscSymbolDeclaration.ts +7 -0
  145. package/src/structures/ITtscSymbolInfo.ts +15 -0
  146. package/src/structures/ITtscTransformResult.ts +13 -0
  147. package/src/structures/ITtscTypeAtPositionResult.ts +7 -0
  148. package/src/structures/ITtscTypeInfo.ts +7 -0
  149. package/src/structures/ITtscVersion.ts +9 -0
  150. package/src/structures/IWasmExecFS.ts +150 -0
  151. package/src/structures/index.ts +29 -0
  152. package/lib/src/MemFS.js.map +0 -1
  153. package/lib/src/api.d.ts +0 -120
  154. package/lib/src/api.js +0 -23
  155. package/lib/src/api.js.map +0 -1
  156. package/lib/src/instantiate.js +0 -88
  157. package/lib/src/instantiate.js.map +0 -1
  158. package/src/api.ts +0 -145
  159. package/src/instantiate.ts +0 -137
package/lib/src/api.d.ts DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * API object that every host-built wasm binds to `globalThis[apiName]`.
3
- *
4
- * Obtain an instance via `bootTtsc`, which waits for the wasm to signal
5
- * readiness and returns the typed handle together with its `IMemFSHost`.
6
- */
7
- export interface ITtscApi {
8
- /** Build metadata reported by the wasm. Useful for diagnostics. */
9
- version(): ITtscVersion;
10
- /**
11
- * Compile a project: typecheck + emit. `result` is JSON;
12
- * `parseResult<ITtscCompileResult>` deserializes it.
13
- */
14
- build(opts: ITtscBuildOpts): Promise<ITtscResult>;
15
- /**
16
- * Typecheck without emit. `result` is JSON; `parseResult<ITtscCompileResult>`
17
- * deserializes it.
18
- */
19
- check(opts: ITtscBuildOpts): Promise<ITtscResult>;
20
- /**
21
- * Return every source file the program saw, keyed by project-relative path.
22
- * Used by playgrounds that want to render the TypeScript view after a source
23
- * rewriter (e.g. paths) has run. `result` is JSON; use
24
- * `parseResult<ITtscTransformResult>` to deserialize.
25
- */
26
- transform(opts: ITtscBuildOpts): Promise<ITtscResult>;
27
- /**
28
- * Dispatch a registered plugin's subcommand. Returns the captured stdout /
29
- * stderr (the same streams the native sidecar binary would write to) together
30
- * with the exit code.
31
- */
32
- plugin(opts: ITtscPluginOpts): Promise<ITtscResult>;
33
- /** Names of the plugins this wasm was built with. */
34
- plugins(): string[];
35
- }
36
- /** Build metadata embedded in the wasm by the Go linker at compile time. */
37
- export interface ITtscVersion {
38
- version: string;
39
- commit: string;
40
- date: string;
41
- go: string;
42
- goos: string;
43
- goarch: string;
44
- }
45
- /** Options shared by `build`, `check`, and `transform`. */
46
- export interface ITtscBuildOpts {
47
- /** Absolute virtual path the project lives at inside the MemFS. */
48
- cwd: string;
49
- /** Tsconfig path, relative to `cwd`. Defaults to `tsconfig.json`. */
50
- tsconfig?: string;
51
- }
52
- /** Options for dispatching a named plugin subcommand via `api.plugin`. */
53
- export interface ITtscPluginOpts {
54
- /** Plugin id registered with `host.Expose` (e.g. `@ttsc/banner`). */
55
- name: string;
56
- /** Subcommand the plugin's Run will receive (e.g. `build`). */
57
- command: string;
58
- /** Forwarded as `--cwd=<value>`. */
59
- cwd?: string;
60
- /** Forwarded as `--tsconfig=<value>`. Defaults to `tsconfig.json`. */
61
- tsconfig?: string;
62
- /** Any extra key/value pairs map to `--key=value` argv entries. */
63
- [key: string]: string | boolean | number | undefined;
64
- }
65
- /** Envelope returned by every `ITtscApi` method. */
66
- export interface ITtscResult {
67
- /** Exit code. 0 = success, 2 = usage error, 3 = runtime error. */
68
- code: number;
69
- /** Anything the wasm wrote to its stdout stream. */
70
- stdout: string;
71
- /** Anything the wasm wrote to its stderr stream. */
72
- stderr: string;
73
- /**
74
- * For the base endpoints, the JSON-encoded compile/transform result. For the
75
- * plugin endpoint, this is empty — the plugin's own output sits in
76
- * stdout/stderr. Use `parseResult<T>` to deserialize.
77
- */
78
- result: string;
79
- }
80
- /**
81
- * Structured payload inside `ITtscResult.result` for `build` and `check`.
82
- *
83
- * `output` maps emit-destination paths (relative to `outDir`) to file contents.
84
- * It is empty when `check` is called without emit.
85
- */
86
- export interface ITtscCompileResult {
87
- diagnostics?: ITtscDiagnostic[];
88
- output: Record<string, string>;
89
- }
90
- /**
91
- * Structured payload inside `ITtscResult.result` for `transform`.
92
- *
93
- * `typescript` maps source file paths (relative to `cwd`) to their
94
- * post-transform TypeScript text — useful for playgrounds that want to show the
95
- * rewritten source before it is emitted.
96
- */
97
- export interface ITtscTransformResult {
98
- diagnostics?: ITtscDiagnostic[];
99
- typescript: Record<string, string>;
100
- }
101
- /**
102
- * A single TypeScript compiler diagnostic emitted during `build`, `check`, or
103
- * `transform`. `line` and `character` are 0-based.
104
- */
105
- export interface ITtscDiagnostic {
106
- file: string | null;
107
- category: "error" | "warning";
108
- code: number;
109
- start?: number;
110
- length?: number;
111
- line?: number;
112
- character?: number;
113
- messageText: string;
114
- }
115
- /**
116
- * Parse the `result` field of an ITtscResult into the structured payload. The
117
- * wasm returns JSON as a string because js.ValueOf does not handle large nested
118
- * maps efficiently. Callers JSON.parse exactly once at the boundary.
119
- */
120
- export declare function parseResult<T>(result: ITtscResult): T | null;
package/lib/src/api.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- // Type-safe wrapper around the `globalThis[apiName]` object a host-built wasm
3
- // installs. Every consumer wasm (the base `ttsc.wasm`, the website's
4
- // `playground.wasm`, typia's `ttsc-typia.wasm`) exposes the same surface, so
5
- // one set of types covers them all.
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.parseResult = parseResult;
8
- /**
9
- * Parse the `result` field of an ITtscResult into the structured payload. The
10
- * wasm returns JSON as a string because js.ValueOf does not handle large nested
11
- * maps efficiently. Callers JSON.parse exactly once at the boundary.
12
- */
13
- function parseResult(result) {
14
- if (!result.result)
15
- return null;
16
- try {
17
- return JSON.parse(result.result);
18
- }
19
- catch {
20
- return null;
21
- }
22
- }
23
- //# sourceMappingURL=api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,qEAAqE;AACrE,6EAA6E;AAC7E,oCAAoC;;;AAiIpC;;;;GAIG;AACH,qBAA+B,MAAmB;IAChD,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAM,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bootTtsc = bootTtsc;
4
- // Boots a host-built wasm and returns the JS-side handle.
5
- //
6
- // Order of operations matters: wasm_exec.js installs default no-op fs/process
7
- // shims if `globalThis.fs` is missing at load time, so we must install our
8
- // MemFS BEFORE importing wasm_exec.js.
9
- //
10
- // The boot helper is parameterized by `apiName` so any wasm built with
11
- // `host.Expose(...)` can be loaded the same way. The base wasm uses "ttsc";
12
- // downstream consumers pick their own (e.g. "ttscPlayground", "ttscTypia").
13
- const MemFS_1 = require("./MemFS");
14
- /** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
15
- async function bootTtsc(options) {
16
- const wasmUrl = options.wasmUrl;
17
- const wasmExecUrl = options.wasmExecUrl ?? defaultWasmExecUrl(wasmUrl);
18
- const apiName = options.apiName ?? "ttsc";
19
- const host = options.host ?? (0, MemFS_1.createMemFS)();
20
- const globalAny = globalThis;
21
- // Only install fs / process if they aren't already in place. A caller
22
- // booting a second wasm over the same MemFS reuses the same shims.
23
- if (!globalAny.fs)
24
- globalAny.fs = host.fs;
25
- if (!globalAny.process)
26
- globalAny.process = createProcessShim();
27
- // wasm_exec.js installs `globalThis.Go`. It also reads globalThis.fs at
28
- // module-eval time, so this import must follow the assignment above.
29
- importScripts(wasmExecUrl);
30
- const ready = new Promise((resolve) => {
31
- globalAny[apiName + "Ready"] = resolve;
32
- });
33
- const goCtor = globalAny.Go;
34
- const go = new goCtor();
35
- const response = await fetch(wasmUrl);
36
- if (!response.ok) {
37
- throw new Error(`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`);
38
- }
39
- const wasm = await WebAssembly.instantiateStreaming(response, go.importObject);
40
- // go.run never resolves until the wasm exits; we don't await it.
41
- void go.run(wasm.instance);
42
- await ready;
43
- const api = globalAny[apiName];
44
- if (!api)
45
- throw new Error(`bootTtsc: ${apiName} global was not set — was the wasm built with host.Expose(${JSON.stringify(apiName)}, ...)?`);
46
- return { api, host };
47
- }
48
- /**
49
- * Derive the `wasm_exec.js` URL from the wasm URL by replacing the filename.
50
- *
51
- * If `wasmUrl` has no directory component, returns `"wasm_exec.js"` (same
52
- * directory as the caller's base URL).
53
- */
54
- function defaultWasmExecUrl(wasmUrl) {
55
- const slash = wasmUrl.lastIndexOf("/");
56
- if (slash < 0)
57
- return "wasm_exec.js";
58
- return wasmUrl.slice(0, slash + 1) + "wasm_exec.js";
59
- }
60
- /**
61
- * Minimal `process` shim required by `wasm_exec.js` in non-Node environments.
62
- *
63
- * Go's js/wasm bridge reads `process.pid`, `process.ppid`, and calls
64
- * `process.cwd()`. `getuid`/`getgid` and friends return `-1` (root-less).
65
- * `umask` and `getgroups` are never exercised by the compiler but are included
66
- * for completeness so unexpected calls surface as clear errors.
67
- */
68
- function createProcessShim() {
69
- return {
70
- getuid: () => -1,
71
- getgid: () => -1,
72
- geteuid: () => -1,
73
- getegid: () => -1,
74
- getgroups: () => {
75
- throw new Error("not implemented");
76
- },
77
- pid: -1,
78
- ppid: -1,
79
- umask: () => {
80
- throw new Error("not implemented");
81
- },
82
- cwd: () => "/",
83
- chdir: () => {
84
- /* no-op; the workspace lives inside the MemFS */
85
- },
86
- };
87
- }
88
- //# sourceMappingURL=instantiate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instantiate.js","sourceRoot":"","sources":["../../src/instantiate.ts"],"names":[],"mappings":"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"}
package/src/api.ts DELETED
@@ -1,145 +0,0 @@
1
- // Type-safe wrapper around the `globalThis[apiName]` object a host-built wasm
2
- // installs. Every consumer wasm (the base `ttsc.wasm`, the website's
3
- // `playground.wasm`, typia's `ttsc-typia.wasm`) exposes the same surface, so
4
- // one set of types covers them all.
5
-
6
- /**
7
- * API object that every host-built wasm binds to `globalThis[apiName]`.
8
- *
9
- * Obtain an instance via `bootTtsc`, which waits for the wasm to signal
10
- * readiness and returns the typed handle together with its `IMemFSHost`.
11
- */
12
- export interface ITtscApi {
13
- /** Build metadata reported by the wasm. Useful for diagnostics. */
14
- version(): ITtscVersion;
15
-
16
- /**
17
- * Compile a project: typecheck + emit. `result` is JSON;
18
- * `parseResult<ITtscCompileResult>` deserializes it.
19
- */
20
- build(opts: ITtscBuildOpts): Promise<ITtscResult>;
21
-
22
- /**
23
- * Typecheck without emit. `result` is JSON; `parseResult<ITtscCompileResult>`
24
- * deserializes it.
25
- */
26
- check(opts: ITtscBuildOpts): Promise<ITtscResult>;
27
-
28
- /**
29
- * Return every source file the program saw, keyed by project-relative path.
30
- * Used by playgrounds that want to render the TypeScript view after a source
31
- * rewriter (e.g. paths) has run. `result` is JSON; use
32
- * `parseResult<ITtscTransformResult>` to deserialize.
33
- */
34
- transform(opts: ITtscBuildOpts): Promise<ITtscResult>;
35
-
36
- /**
37
- * Dispatch a registered plugin's subcommand. Returns the captured stdout /
38
- * stderr (the same streams the native sidecar binary would write to) together
39
- * with the exit code.
40
- */
41
- plugin(opts: ITtscPluginOpts): Promise<ITtscResult>;
42
-
43
- /** Names of the plugins this wasm was built with. */
44
- plugins(): string[];
45
- }
46
-
47
- /** Build metadata embedded in the wasm by the Go linker at compile time. */
48
- export interface ITtscVersion {
49
- version: string;
50
- commit: string;
51
- date: string;
52
- go: string;
53
- goos: string;
54
- goarch: string;
55
- }
56
-
57
- /** Options shared by `build`, `check`, and `transform`. */
58
- export interface ITtscBuildOpts {
59
- /** Absolute virtual path the project lives at inside the MemFS. */
60
- cwd: string;
61
- /** Tsconfig path, relative to `cwd`. Defaults to `tsconfig.json`. */
62
- tsconfig?: string;
63
- }
64
-
65
- /** Options for dispatching a named plugin subcommand via `api.plugin`. */
66
- export interface ITtscPluginOpts {
67
- /** Plugin id registered with `host.Expose` (e.g. `@ttsc/banner`). */
68
- name: string;
69
- /** Subcommand the plugin's Run will receive (e.g. `build`). */
70
- command: string;
71
- /** Forwarded as `--cwd=<value>`. */
72
- cwd?: string;
73
- /** Forwarded as `--tsconfig=<value>`. Defaults to `tsconfig.json`. */
74
- tsconfig?: string;
75
- /** Any extra key/value pairs map to `--key=value` argv entries. */
76
- [key: string]: string | boolean | number | undefined;
77
- }
78
-
79
- /** Envelope returned by every `ITtscApi` method. */
80
- export interface ITtscResult {
81
- /** Exit code. 0 = success, 2 = usage error, 3 = runtime error. */
82
- code: number;
83
- /** Anything the wasm wrote to its stdout stream. */
84
- stdout: string;
85
- /** Anything the wasm wrote to its stderr stream. */
86
- stderr: string;
87
- /**
88
- * For the base endpoints, the JSON-encoded compile/transform result. For the
89
- * plugin endpoint, this is empty — the plugin's own output sits in
90
- * stdout/stderr. Use `parseResult<T>` to deserialize.
91
- */
92
- result: string;
93
- }
94
-
95
- /**
96
- * Structured payload inside `ITtscResult.result` for `build` and `check`.
97
- *
98
- * `output` maps emit-destination paths (relative to `outDir`) to file contents.
99
- * It is empty when `check` is called without emit.
100
- */
101
- export interface ITtscCompileResult {
102
- diagnostics?: ITtscDiagnostic[];
103
- output: Record<string, string>;
104
- }
105
-
106
- /**
107
- * Structured payload inside `ITtscResult.result` for `transform`.
108
- *
109
- * `typescript` maps source file paths (relative to `cwd`) to their
110
- * post-transform TypeScript text — useful for playgrounds that want to show the
111
- * rewritten source before it is emitted.
112
- */
113
- export interface ITtscTransformResult {
114
- diagnostics?: ITtscDiagnostic[];
115
- typescript: Record<string, string>;
116
- }
117
-
118
- /**
119
- * A single TypeScript compiler diagnostic emitted during `build`, `check`, or
120
- * `transform`. `line` and `character` are 0-based.
121
- */
122
- export interface ITtscDiagnostic {
123
- file: string | null;
124
- category: "error" | "warning";
125
- code: number;
126
- start?: number;
127
- length?: number;
128
- line?: number;
129
- character?: number;
130
- messageText: string;
131
- }
132
-
133
- /**
134
- * Parse the `result` field of an ITtscResult into the structured payload. The
135
- * wasm returns JSON as a string because js.ValueOf does not handle large nested
136
- * maps efficiently. Callers JSON.parse exactly once at the boundary.
137
- */
138
- export function parseResult<T>(result: ITtscResult): T | null {
139
- if (!result.result) return null;
140
- try {
141
- return JSON.parse(result.result) as T;
142
- } catch {
143
- return null;
144
- }
145
- }
@@ -1,137 +0,0 @@
1
- // Boots a host-built wasm and returns the JS-side handle.
2
- //
3
- // Order of operations matters: wasm_exec.js installs default no-op fs/process
4
- // shims if `globalThis.fs` is missing at load time, so we must install our
5
- // MemFS BEFORE importing wasm_exec.js.
6
- //
7
- // The boot helper is parameterized by `apiName` so any wasm built with
8
- // `host.Expose(...)` can be loaded the same way. The base wasm uses "ttsc";
9
- // downstream consumers pick their own (e.g. "ttscPlayground", "ttscTypia").
10
- import { type IMemFSHost, createMemFS } from "./MemFS";
11
- import type { ITtscApi } from "./api";
12
-
13
- declare const importScripts: (...urls: string[]) => void;
14
-
15
- /** Options for `bootTtsc`. All fields except `wasmUrl` have sensible defaults. */
16
- export interface IBootTtscOptions {
17
- /** URL of the .wasm to fetch. */
18
- wasmUrl: string;
19
- /** URL of wasm_exec.js. Defaults to the same directory as wasmUrl. */
20
- wasmExecUrl?: string;
21
- /**
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".
24
- */
25
- apiName?: string;
26
- /**
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.
31
- */
32
- host?: IMemFSHost;
33
- }
34
-
35
- /** Handle returned by `bootTtsc` once the wasm is ready. */
36
- export interface IBootResult {
37
- /** The typed API proxy bound by the wasm to `globalThis[apiName]`. */
38
- api: ITtscApi;
39
- /** The MemFS instance shared with the wasm's virtual filesystem. */
40
- host: IMemFSHost;
41
- }
42
-
43
- /** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
44
- export async function bootTtsc(
45
- options: IBootTtscOptions,
46
- ): Promise<IBootResult> {
47
- const wasmUrl = options.wasmUrl;
48
- const wasmExecUrl = options.wasmExecUrl ?? defaultWasmExecUrl(wasmUrl);
49
- const apiName = options.apiName ?? "ttsc";
50
-
51
- const host = options.host ?? createMemFS();
52
- const globalAny = globalThis as Record<string, unknown>;
53
- // Only install fs / process if they aren't already in place. A caller
54
- // booting a second wasm over the same MemFS reuses the same shims.
55
- if (!globalAny.fs) globalAny.fs = host.fs;
56
- if (!globalAny.process) globalAny.process = createProcessShim();
57
-
58
- // wasm_exec.js installs `globalThis.Go`. It also reads globalThis.fs at
59
- // module-eval time, so this import must follow the assignment above.
60
- importScripts(wasmExecUrl);
61
-
62
- const ready = new Promise<void>((resolve) => {
63
- globalAny[apiName + "Ready"] = resolve;
64
- });
65
-
66
- const goCtor = (globalAny as { Go: new () => IGoInstance }).Go;
67
- const go = new goCtor();
68
-
69
- const response = await fetch(wasmUrl);
70
- if (!response.ok) {
71
- throw new Error(`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`);
72
- }
73
- const wasm = await WebAssembly.instantiateStreaming(
74
- response,
75
- go.importObject,
76
- );
77
- // go.run never resolves until the wasm exits; we don't await it.
78
- void go.run(wasm.instance);
79
- await ready;
80
-
81
- const api = (globalAny as Record<string, ITtscApi | undefined>)[apiName];
82
- if (!api)
83
- throw new Error(
84
- `bootTtsc: ${apiName} global was not set — was the wasm built with host.Expose(${JSON.stringify(apiName)}, ...)?`,
85
- );
86
- return { api, host };
87
- }
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
- */
95
- function defaultWasmExecUrl(wasmUrl: string): string {
96
- const slash = wasmUrl.lastIndexOf("/");
97
- if (slash < 0) return "wasm_exec.js";
98
- return wasmUrl.slice(0, slash + 1) + "wasm_exec.js";
99
- }
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
- */
105
- interface IGoInstance {
106
- importObject: WebAssembly.Imports;
107
- run(instance: WebAssembly.Instance): Promise<void>;
108
- }
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
- */
118
- function createProcessShim(): Record<string, unknown> {
119
- return {
120
- getuid: () => -1,
121
- getgid: () => -1,
122
- geteuid: () => -1,
123
- getegid: () => -1,
124
- getgroups: () => {
125
- throw new Error("not implemented");
126
- },
127
- pid: -1,
128
- ppid: -1,
129
- umask: () => {
130
- throw new Error("not implemented");
131
- },
132
- cwd: () => "/",
133
- chdir: () => {
134
- /* no-op; the workspace lives inside the MemFS */
135
- },
136
- };
137
- }