@ttsc/wasm 0.11.0-dev.20260517

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/build/build-wasm.cjs +240 -0
  4. package/build/pack-prepare.cjs +68 -0
  5. package/cmd/ttsc-wasm/main.go +130 -0
  6. package/cmd/ttsc-wasm/main_wasm.go +17 -0
  7. package/dist/go.mod +54 -0
  8. package/dist/ttsc.wasm +0 -0
  9. package/dist/wasm_exec.js +575 -0
  10. package/go.mod +54 -0
  11. package/go.sum +26 -0
  12. package/host/api.go +205 -0
  13. package/host/doc.go +31 -0
  14. package/host/host.go +317 -0
  15. package/host/host_native.go +12 -0
  16. package/host/plugin.go +59 -0
  17. package/lib/src/MemFS.d.ts +68 -0
  18. package/lib/src/MemFS.js +384 -0
  19. package/lib/src/MemFS.js.map +1 -0
  20. package/lib/src/api.d.ts +87 -0
  21. package/lib/src/api.js +20 -0
  22. package/lib/src/api.js.map +1 -0
  23. package/lib/src/index.d.ts +6 -0
  24. package/lib/src/index.js +10 -0
  25. package/lib/src/index.js.map +1 -0
  26. package/lib/src/instantiate.d.ts +27 -0
  27. package/lib/src/instantiate.js +71 -0
  28. package/lib/src/instantiate.js.map +1 -0
  29. package/package.json +49 -0
  30. package/src/MemFS.ts +566 -0
  31. package/src/api.ts +112 -0
  32. package/src/index.ts +28 -0
  33. package/src/instantiate.ts +114 -0
  34. package/vendor/shim/ast/extra-shim.json +4 -0
  35. package/vendor/shim/ast/go.mod +5 -0
  36. package/vendor/shim/ast/lint.go +328 -0
  37. package/vendor/shim/ast/shim.go +220 -0
  38. package/vendor/shim/ast/surface.go +685 -0
  39. package/vendor/shim/bundled/extra-shim.json +1 -0
  40. package/vendor/shim/bundled/go.mod +5 -0
  41. package/vendor/shim/bundled/shim.go +23 -0
  42. package/vendor/shim/checker/extra-shim.json +31 -0
  43. package/vendor/shim/checker/go.mod +5 -0
  44. package/vendor/shim/checker/shim.go +174 -0
  45. package/vendor/shim/compiler/extra-shim.json +4 -0
  46. package/vendor/shim/compiler/go.mod +5 -0
  47. package/vendor/shim/compiler/shim.go +65 -0
  48. package/vendor/shim/core/extra-shim.json +4 -0
  49. package/vendor/shim/core/go.mod +5 -0
  50. package/vendor/shim/core/shim.go +29 -0
  51. package/vendor/shim/diagnosticwriter/go.mod +5 -0
  52. package/vendor/shim/diagnosticwriter/lint.go +145 -0
  53. package/vendor/shim/diagnosticwriter/shim.go +29 -0
  54. package/vendor/shim/lsp/extra-shim.json +4 -0
  55. package/vendor/shim/lsp/go.mod +16 -0
  56. package/vendor/shim/lsp/go.sum +26 -0
  57. package/vendor/shim/lsp/shim.go +42 -0
  58. package/vendor/shim/parser/extra-shim.json +4 -0
  59. package/vendor/shim/parser/go.mod +5 -0
  60. package/vendor/shim/parser/shim.go +61 -0
  61. package/vendor/shim/printer/go.mod +5 -0
  62. package/vendor/shim/printer/shim.go +23 -0
  63. package/vendor/shim/scanner/extra-shim.json +4 -0
  64. package/vendor/shim/scanner/go.mod +5 -0
  65. package/vendor/shim/scanner/shim.go +134 -0
  66. package/vendor/shim/tsoptions/extra-shim.json +4 -0
  67. package/vendor/shim/tsoptions/go.mod +5 -0
  68. package/vendor/shim/tsoptions/shim.go +173 -0
  69. package/vendor/shim/tspath/extra-shim.json +4 -0
  70. package/vendor/shim/tspath/go.mod +5 -0
  71. package/vendor/shim/tspath/shim.go +236 -0
  72. package/vendor/shim/vfs/cachedvfs/extra-shim.json +4 -0
  73. package/vendor/shim/vfs/cachedvfs/go.mod +5 -0
  74. package/vendor/shim/vfs/cachedvfs/shim.go +12 -0
  75. package/vendor/shim/vfs/extra-shim.json +4 -0
  76. package/vendor/shim/vfs/go.mod +5 -0
  77. package/vendor/shim/vfs/osvfs/extra-shim.json +4 -0
  78. package/vendor/shim/vfs/osvfs/go.mod +5 -0
  79. package/vendor/shim/vfs/osvfs/shim.go +13 -0
  80. package/vendor/shim/vfs/shim.go +22 -0
@@ -0,0 +1,384 @@
1
+ // MemFS implements just enough of the wasm_exec.js fs interface for an
2
+ // in-browser ttsc wasm to run.
3
+ //
4
+ // Why this exists: wasm_exec.js routes Go's syscalls (open / stat / read /
5
+ // write / readdir / mkdir / ...) to `globalThis.fs`. In Node, that maps to the
6
+ // real fs module. In browsers we have to supply our own. The set we implement
7
+ // here is the smallest subset typescript-go actually exercises for a project
8
+ // compile of a tiny in-memory project.
9
+ //
10
+ // All callbacks follow the Node "errback" convention: callback(err, result).
11
+ // Errors carry a `code` (e.g. ENOENT, EBADF) so Go's os package sees them as
12
+ // proper os.PathError values.
13
+ //
14
+ // Files are stored as Uint8Array. Text files written via writeFile are
15
+ // encoded by the caller; reads return the raw bytes.
16
+ /** Mode bits exposed by stat. We only differentiate file vs directory. */
17
+ const S_IFDIR = 0o040000;
18
+ const S_IFREG = 0o100000;
19
+ const DEFAULT_FILE_MODE = S_IFREG | 0o644;
20
+ const DEFAULT_DIR_MODE = S_IFDIR | 0o755;
21
+ export class MemFSError extends Error {
22
+ code;
23
+ errno;
24
+ path;
25
+ syscall;
26
+ constructor(code, syscall, path) {
27
+ super(`${code}: ${syscall} ${path ?? ""}`.trim());
28
+ this.code = code;
29
+ this.errno = errnoForCode(code);
30
+ this.path = path;
31
+ this.syscall = syscall;
32
+ }
33
+ }
34
+ function errnoForCode(code) {
35
+ switch (code) {
36
+ case "ENOENT":
37
+ return -2;
38
+ case "EBADF":
39
+ return -9;
40
+ case "EEXIST":
41
+ return -17;
42
+ case "ENOTDIR":
43
+ return -20;
44
+ case "EISDIR":
45
+ return -21;
46
+ default:
47
+ return -1;
48
+ }
49
+ }
50
+ const encoder = new TextEncoder();
51
+ const decoder = new TextDecoder();
52
+ function normalize(p) {
53
+ if (!p)
54
+ return "/";
55
+ const parts = p.replace(/\\/g, "/").split("/").filter(Boolean);
56
+ const stack = [];
57
+ for (const part of parts) {
58
+ if (part === ".")
59
+ continue;
60
+ if (part === "..") {
61
+ stack.pop();
62
+ continue;
63
+ }
64
+ stack.push(part);
65
+ }
66
+ return "/" + stack.join("/");
67
+ }
68
+ export function createMemFS() {
69
+ const nodes = new Map();
70
+ nodes.set("/", { kind: "dir", data: new Uint8Array(), mtimeMs: Date.now() });
71
+ const stdout = { buffer: "" };
72
+ const stderr = { buffer: "" };
73
+ const fdTable = new Map();
74
+ let nextFd = 100;
75
+ // Reserve 1/2 for stdout/stderr writeSync routing.
76
+ fdTable.set(1, { path: "/dev/stdout", position: 0, isStdout: true });
77
+ fdTable.set(2, { path: "/dev/stderr", position: 0, isStderr: true });
78
+ function ensureParentDirs(p) {
79
+ const segments = normalize(p).split("/").filter(Boolean);
80
+ segments.pop();
81
+ let cursor = "";
82
+ for (const seg of segments) {
83
+ cursor += "/" + seg;
84
+ if (!nodes.has(cursor)) {
85
+ nodes.set(cursor, {
86
+ kind: "dir",
87
+ data: new Uint8Array(),
88
+ mtimeMs: Date.now(),
89
+ });
90
+ }
91
+ }
92
+ }
93
+ function mkdirp(p) {
94
+ const segments = normalize(p).split("/").filter(Boolean);
95
+ let cursor = "";
96
+ for (const seg of segments) {
97
+ cursor += "/" + seg;
98
+ const existing = nodes.get(cursor);
99
+ if (!existing) {
100
+ nodes.set(cursor, {
101
+ kind: "dir",
102
+ data: new Uint8Array(),
103
+ mtimeMs: Date.now(),
104
+ });
105
+ }
106
+ else if (existing.kind !== "dir") {
107
+ throw new MemFSError("ENOTDIR", "mkdir", cursor);
108
+ }
109
+ }
110
+ }
111
+ function writeFile(p, data) {
112
+ const norm = normalize(p);
113
+ ensureParentDirs(norm);
114
+ const bytes = typeof data === "string" ? encoder.encode(data) : data;
115
+ nodes.set(norm, { kind: "file", data: bytes, mtimeMs: Date.now() });
116
+ }
117
+ function readFile(p) {
118
+ const node = nodes.get(normalize(p));
119
+ if (!node || node.kind !== "file")
120
+ return null;
121
+ return node.data;
122
+ }
123
+ function readFileText(p) {
124
+ const bytes = readFile(p);
125
+ return bytes === null ? null : decoder.decode(bytes);
126
+ }
127
+ function exists(p) {
128
+ return nodes.has(normalize(p));
129
+ }
130
+ function statSync(p) {
131
+ const norm = normalize(p);
132
+ const node = nodes.get(norm);
133
+ if (!node)
134
+ throw new MemFSError("ENOENT", "stat", norm);
135
+ return makeStats(node);
136
+ }
137
+ function makeStats(node) {
138
+ const isDir = node.kind === "dir";
139
+ return {
140
+ isDirectory: () => isDir,
141
+ isFile: () => !isDir,
142
+ size: node.data.byteLength,
143
+ mode: isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE,
144
+ mtimeMs: node.mtimeMs,
145
+ atimeMs: node.mtimeMs,
146
+ ctimeMs: node.mtimeMs,
147
+ dev: 0,
148
+ ino: 0,
149
+ nlink: 1,
150
+ uid: 0,
151
+ gid: 0,
152
+ rdev: 0,
153
+ blksize: 4096,
154
+ blocks: Math.ceil(node.data.byteLength / 512),
155
+ };
156
+ }
157
+ function readdirSync(p) {
158
+ const norm = normalize(p);
159
+ const node = nodes.get(norm);
160
+ if (!node)
161
+ throw new MemFSError("ENOENT", "readdir", norm);
162
+ if (node.kind !== "dir")
163
+ throw new MemFSError("ENOTDIR", "readdir", norm);
164
+ const prefix = norm === "/" ? "/" : norm + "/";
165
+ const direct = new Set();
166
+ for (const key of nodes.keys()) {
167
+ if (!key.startsWith(prefix) || key === norm)
168
+ continue;
169
+ const rest = key.slice(prefix.length);
170
+ const cut = rest.indexOf("/");
171
+ direct.add(cut === -1 ? rest : rest.slice(0, cut));
172
+ }
173
+ return [...direct].sort();
174
+ }
175
+ const fs = {
176
+ constants: {
177
+ O_WRONLY: 1,
178
+ O_RDWR: 2,
179
+ O_CREAT: 64,
180
+ O_TRUNC: 512,
181
+ O_APPEND: 1024,
182
+ O_EXCL: 128,
183
+ O_DIRECTORY: 65536,
184
+ },
185
+ writeSync(fd, buf) {
186
+ const text = decoder.decode(buf);
187
+ if (fd === 1) {
188
+ stdout.buffer += text;
189
+ }
190
+ else if (fd === 2) {
191
+ stderr.buffer += text;
192
+ }
193
+ else {
194
+ stderr.buffer += text;
195
+ }
196
+ return buf.length;
197
+ },
198
+ write(fd, buf, offset, length, position, callback) {
199
+ try {
200
+ if (position !== null && position !== 0) {
201
+ callback(new MemFSError("ESPIPE", "write"), 0);
202
+ return;
203
+ }
204
+ const view = buf.subarray(offset, offset + length);
205
+ const written = this.writeSync(fd, view);
206
+ callback(null, written);
207
+ }
208
+ catch (err) {
209
+ callback(err, 0);
210
+ }
211
+ },
212
+ open(p, flags, _mode, callback) {
213
+ const norm = normalize(p);
214
+ const node = nodes.get(norm);
215
+ const creating = (flags & (this.constants.O_CREAT ?? 0)) !== 0;
216
+ if (!node) {
217
+ if (!creating) {
218
+ callback(new MemFSError("ENOENT", "open", norm), -1);
219
+ return;
220
+ }
221
+ ensureParentDirs(norm);
222
+ nodes.set(norm, {
223
+ kind: "file",
224
+ data: new Uint8Array(),
225
+ mtimeMs: Date.now(),
226
+ });
227
+ }
228
+ const fd = nextFd++;
229
+ fdTable.set(fd, { path: norm, position: 0 });
230
+ if ((flags & (this.constants.O_TRUNC ?? 0)) !== 0) {
231
+ nodes.set(norm, {
232
+ kind: "file",
233
+ data: new Uint8Array(),
234
+ mtimeMs: Date.now(),
235
+ });
236
+ }
237
+ callback(null, fd);
238
+ },
239
+ close(fd, callback) {
240
+ if (!fdTable.has(fd)) {
241
+ callback(new MemFSError("EBADF", "close"));
242
+ return;
243
+ }
244
+ if (fd > 2)
245
+ fdTable.delete(fd);
246
+ callback(null);
247
+ },
248
+ read(fd, buffer, offset, length, position, callback) {
249
+ const entry = fdTable.get(fd);
250
+ if (!entry) {
251
+ callback(new MemFSError("EBADF", "read"), 0);
252
+ return;
253
+ }
254
+ const node = nodes.get(entry.path);
255
+ if (!node || node.kind !== "file") {
256
+ callback(new MemFSError("ENOENT", "read", entry.path), 0);
257
+ return;
258
+ }
259
+ const start = position ?? entry.position;
260
+ const end = Math.min(start + length, node.data.byteLength);
261
+ const slice = node.data.subarray(start, end);
262
+ buffer.set(slice, offset);
263
+ if (position === null)
264
+ entry.position = end;
265
+ callback(null, slice.byteLength);
266
+ },
267
+ readdir(p, callback) {
268
+ try {
269
+ callback(null, readdirSync(p));
270
+ }
271
+ catch (err) {
272
+ callback(err, []);
273
+ }
274
+ },
275
+ mkdir(p, _perm, callback) {
276
+ try {
277
+ mkdirp(p);
278
+ callback(null);
279
+ }
280
+ catch (err) {
281
+ callback(err);
282
+ }
283
+ },
284
+ stat(p, callback) {
285
+ try {
286
+ callback(null, statSync(p));
287
+ }
288
+ catch (err) {
289
+ callback(err, undefined);
290
+ }
291
+ },
292
+ lstat(p, callback) {
293
+ this.stat(p, callback);
294
+ },
295
+ fstat(fd, callback) {
296
+ const entry = fdTable.get(fd);
297
+ if (!entry) {
298
+ callback(new MemFSError("EBADF", "fstat"), undefined);
299
+ return;
300
+ }
301
+ try {
302
+ callback(null, statSync(entry.path));
303
+ }
304
+ catch (err) {
305
+ callback(err, undefined);
306
+ }
307
+ },
308
+ fsync(_fd, callback) {
309
+ callback(null);
310
+ },
311
+ unlink(p, callback) {
312
+ const norm = normalize(p);
313
+ if (!nodes.has(norm)) {
314
+ callback(new MemFSError("ENOENT", "unlink", norm));
315
+ return;
316
+ }
317
+ nodes.delete(norm);
318
+ callback(null);
319
+ },
320
+ rename(from, to, callback) {
321
+ const src = normalize(from);
322
+ const node = nodes.get(src);
323
+ if (!node) {
324
+ callback(new MemFSError("ENOENT", "rename", src));
325
+ return;
326
+ }
327
+ const dest = normalize(to);
328
+ nodes.delete(src);
329
+ nodes.set(dest, node);
330
+ callback(null);
331
+ },
332
+ rmdir(p, callback) {
333
+ this.unlink(p, callback);
334
+ },
335
+ chmod(_p, _mode, callback) {
336
+ callback(null);
337
+ },
338
+ fchmod(_fd, _mode, callback) {
339
+ callback(null);
340
+ },
341
+ chown(_p, _uid, _gid, callback) {
342
+ callback(null);
343
+ },
344
+ fchown(_fd, _uid, _gid, callback) {
345
+ callback(null);
346
+ },
347
+ lchown(_p, _uid, _gid, callback) {
348
+ callback(null);
349
+ },
350
+ utimes(_p, _atime, _mtime, callback) {
351
+ callback(null);
352
+ },
353
+ link(_p, _link, callback) {
354
+ callback(new MemFSError("EPERM", "link"));
355
+ },
356
+ symlink(_p, _link, callback) {
357
+ callback(new MemFSError("EPERM", "symlink"));
358
+ },
359
+ readlink(_p, callback) {
360
+ callback(new MemFSError("EINVAL", "readlink"), "");
361
+ },
362
+ truncate(_p, _length, callback) {
363
+ callback(null);
364
+ },
365
+ ftruncate(_fd, _length, callback) {
366
+ callback(null);
367
+ },
368
+ };
369
+ return {
370
+ fs,
371
+ writeFile,
372
+ readFile,
373
+ readFileText,
374
+ exists,
375
+ mkdirp,
376
+ stdout,
377
+ stderr,
378
+ resetStdio() {
379
+ stdout.buffer = "";
380
+ stderr.buffer = "";
381
+ },
382
+ };
383
+ }
384
+ //# sourceMappingURL=MemFS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemFS.js","sourceRoot":"","sources":["../../src/MemFS.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,+BAA+B;AAC/B,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,uCAAuC;AACvC,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,8BAA8B;AAC9B,EAAE;AACF,uEAAuE;AACvE,qDAAqD;AAErD,0EAA0E;AAC1E,MAAM,OAAO,GAAG,QAAQ,CAAC;AACzB,MAAM,OAAO,GAAG,QAAQ,CAAC;AACzB,MAAM,iBAAiB,GAAG,OAAO,GAAG,KAAK,CAAC;AAC1C,MAAM,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AAmJzC,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC5B,IAAI,CAAS;IACb,KAAK,CAAS;IACd,IAAI,CAAU;IACd,OAAO,CAAU;IACxB,YAAY,IAAY,EAAE,OAAe,EAAE,IAAa;QACtD,KAAK,CAAC,GAAG,IAAI,KAAK,O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AC,CAAC;QAC/C,CAAC;QACD,QAAQ,CAAC,EAAE,EAAE,QAAQ;YACnB,QAAQ,CAAC,IAAI,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QACrD,CAAC;QACD,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ;YAC5B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QACD,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ;YAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;KACF,CAAC;IAEF,OAAO;QACL,EAAE;QACF,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,MAAM;QACN,MAAM;QACN,MAAM;QACN,MAAM;QACN,UAAU;YACR,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;YACnB,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,87 @@
1
+ export interface ITtscApi {
2
+ /** Build metadata reported by the wasm. Useful for diagnostics. */
3
+ version(): ITtscVersion;
4
+ /** Compile a project: typecheck + emit. `result` is JSON; `parseResult<ITtscCompileResult>` deserializes it. */
5
+ build(opts: ITtscBuildOpts): Promise<ITtscResult>;
6
+ /** Typecheck without emit. `result` is JSON; `parseResult<ITtscCompileResult>` deserializes it. */
7
+ check(opts: ITtscBuildOpts): Promise<ITtscResult>;
8
+ /**
9
+ * Return every source file the program saw, keyed by project-relative
10
+ * path. Used by playgrounds that want to render the TypeScript view after
11
+ * a source rewriter (e.g. paths) has run. `result` is JSON; use
12
+ * `parseResult<ITtscTransformResult>` to deserialize.
13
+ */
14
+ transform(opts: ITtscBuildOpts): Promise<ITtscResult>;
15
+ /**
16
+ * Dispatch a registered plugin's subcommand. Returns the captured stdout /
17
+ * stderr (the same streams the native sidecar binary would write to)
18
+ * together with the exit code.
19
+ */
20
+ plugin(opts: ITtscPluginOpts): Promise<ITtscResult>;
21
+ /** Names of the plugins this wasm was built with. */
22
+ plugins(): string[];
23
+ }
24
+ export interface ITtscVersion {
25
+ version: string;
26
+ commit: string;
27
+ date: string;
28
+ go: string;
29
+ goos: string;
30
+ goarch: string;
31
+ }
32
+ export interface ITtscBuildOpts {
33
+ /** Absolute virtual path the project lives at inside the MemFS. */
34
+ cwd: string;
35
+ /** tsconfig path, relative to `cwd`. Defaults to `tsconfig.json`. */
36
+ tsconfig?: string;
37
+ }
38
+ export interface ITtscPluginOpts {
39
+ /** Plugin id registered with `host.Expose` (e.g. `@ttsc/banner`). */
40
+ name: string;
41
+ /** Subcommand the plugin's Run will receive (e.g. `build`). */
42
+ command: string;
43
+ /** Forwarded as `--cwd=<value>`. */
44
+ cwd?: string;
45
+ /** Forwarded as `--tsconfig=<value>`. Defaults to `tsconfig.json`. */
46
+ tsconfig?: string;
47
+ /** Any extra key/value pairs map to `--key=value` argv entries. */
48
+ [key: string]: string | boolean | number | undefined;
49
+ }
50
+ export interface ITtscResult {
51
+ /** Exit code. 0 = success, 2 = usage error, 3 = runtime error. */
52
+ code: number;
53
+ /** Anything the wasm wrote to its stdout stream. */
54
+ stdout: string;
55
+ /** Anything the wasm wrote to its stderr stream. */
56
+ stderr: string;
57
+ /**
58
+ * For the base endpoints, the JSON-encoded compile/transform result. For
59
+ * the plugin endpoint, this is empty — the plugin's own output sits in
60
+ * stdout/stderr. Use `parseResult<T>` to deserialize.
61
+ */
62
+ result: string;
63
+ }
64
+ export interface ITtscCompileResult {
65
+ diagnostics?: ITtscDiagnostic[];
66
+ output: Record<string, string>;
67
+ }
68
+ export interface ITtscTransformResult {
69
+ diagnostics?: ITtscDiagnostic[];
70
+ typescript: Record<string, string>;
71
+ }
72
+ export interface ITtscDiagnostic {
73
+ file: string | null;
74
+ category: "error" | "warning";
75
+ code: number;
76
+ start?: number;
77
+ length?: number;
78
+ line?: number;
79
+ character?: number;
80
+ messageText: string;
81
+ }
82
+ /**
83
+ * Parse the `result` field of an ITtscResult into the structured payload.
84
+ * The wasm returns JSON as a string because js.ValueOf does not handle large
85
+ * nested maps efficiently. Callers JSON.parse exactly once at the boundary.
86
+ */
87
+ export declare function parseResult<T>(result: ITtscResult): T | null;
package/lib/src/api.js ADDED
@@ -0,0 +1,20 @@
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
+ * Parse the `result` field of an ITtscResult into the structured payload.
7
+ * The wasm returns JSON as a string because js.ValueOf does not handle large
8
+ * nested maps efficiently. Callers JSON.parse exactly once at the boundary.
9
+ */
10
+ export function parseResult(result) {
11
+ if (!result.result)
12
+ return null;
13
+ try {
14
+ return JSON.parse(result.result);
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,qEAAqE;AACrE,6EAA6E;AAC7E,oCAAoC;AAgGpC;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAI,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"}
@@ -0,0 +1,6 @@
1
+ export { bootTtsc } from "./instantiate";
2
+ export type { IBootTtscOptions, IBootResult } from "./instantiate";
3
+ export { createMemFS, MemFSError } from "./MemFS";
4
+ export type { IMemFSHost, IWasmExecFS, IFileStats, } from "./MemFS";
5
+ export type { ITtscApi, ITtscVersion, ITtscBuildOpts, ITtscPluginOpts, ITtscResult, ITtscCompileResult, ITtscTransformResult, ITtscDiagnostic, } from "./api";
6
+ export { parseResult } from "./api";
@@ -0,0 +1,10 @@
1
+ // Public entry point for `@ttsc/wasm`.
2
+ //
3
+ // Re-exports the boot helper, MemFS bridge, and typed API surface. Plugin
4
+ // authors and playground builders consume these. The Go-side scaffolding
5
+ // (`host/`) is shipped alongside on disk but loaded via `go build`, not
6
+ // imported from JS.
7
+ export { bootTtsc } from "./instantiate";
8
+ export { createMemFS, MemFSError } from "./MemFS";
9
+ export { parseResult } from "./api";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,wEAAwE;AACxE,oBAAoB;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAiBlD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type IMemFSHost } from "./MemFS";
2
+ import type { ITtscApi } from "./api";
3
+ export interface IBootTtscOptions {
4
+ /** URL of the .wasm to fetch. */
5
+ wasmUrl: string;
6
+ /** URL of wasm_exec.js. Defaults to the same directory as wasmUrl. */
7
+ wasmExecUrl?: string;
8
+ /**
9
+ * globalThis property name the wasm binds. Must match the value the wasm
10
+ * was built with (the `apiName` passed to `host.Expose`). Defaults to
11
+ * "ttsc".
12
+ */
13
+ apiName?: string;
14
+ /**
15
+ * Optional pre-existing MemFS host. When omitted, a fresh one is created
16
+ * and stored on the returned BootResult. Pass an existing host when you
17
+ * want to boot multiple wasms over the same filesystem (e.g. base ttsc +
18
+ * a typia wasm) so they share project sources.
19
+ */
20
+ host?: IMemFSHost;
21
+ }
22
+ export interface IBootResult {
23
+ api: ITtscApi;
24
+ host: IMemFSHost;
25
+ }
26
+ /** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
27
+ export declare function bootTtsc(options: IBootTtscOptions): Promise<IBootResult>;
@@ -0,0 +1,71 @@
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 { createMemFS } from "./MemFS";
11
+ /** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
12
+ export async function bootTtsc(options) {
13
+ const wasmUrl = options.wasmUrl;
14
+ const wasmExecUrl = options.wasmExecUrl ?? defaultWasmExecUrl(wasmUrl);
15
+ const apiName = options.apiName ?? "ttsc";
16
+ const host = options.host ?? createMemFS();
17
+ const globalAny = globalThis;
18
+ // Only install fs / process if they aren't already in place. A caller
19
+ // booting a second wasm over the same MemFS reuses the same shims.
20
+ if (!globalAny.fs)
21
+ globalAny.fs = host.fs;
22
+ if (!globalAny.process)
23
+ globalAny.process = createProcessShim();
24
+ // wasm_exec.js installs `globalThis.Go`. It also reads globalThis.fs at
25
+ // module-eval time, so this import must follow the assignment above.
26
+ importScripts(wasmExecUrl);
27
+ const ready = new Promise((resolve) => {
28
+ globalAny[apiName + "Ready"] = resolve;
29
+ });
30
+ const goCtor = globalAny.Go;
31
+ const go = new goCtor();
32
+ const response = await fetch(wasmUrl);
33
+ if (!response.ok) {
34
+ throw new Error(`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`);
35
+ }
36
+ const wasm = await WebAssembly.instantiateStreaming(response, go.importObject);
37
+ // go.run never resolves until the wasm exits; we don't await it.
38
+ void go.run(wasm.instance);
39
+ await ready;
40
+ const api = globalAny[apiName];
41
+ if (!api)
42
+ throw new Error(`bootTtsc: ${apiName} global was not set — was the wasm built with host.Expose(${JSON.stringify(apiName)}, ...)?`);
43
+ return { api, host };
44
+ }
45
+ function defaultWasmExecUrl(wasmUrl) {
46
+ const slash = wasmUrl.lastIndexOf("/");
47
+ if (slash < 0)
48
+ return "wasm_exec.js";
49
+ return wasmUrl.slice(0, slash + 1) + "wasm_exec.js";
50
+ }
51
+ function createProcessShim() {
52
+ return {
53
+ getuid: () => -1,
54
+ getgid: () => -1,
55
+ geteuid: () => -1,
56
+ getegid: () => -1,
57
+ getgroups: () => {
58
+ throw new Error("not implemented");
59
+ },
60
+ pid: -1,
61
+ ppid: -1,
62
+ umask: () => {
63
+ throw new Error("not implemented");
64
+ },
65
+ cwd: () => "/",
66
+ chdir: () => {
67
+ /* no-op; the workspace lives inside the MemFS */
68
+ },
69
+ };
70
+ }
71
+ //# sourceMappingURL=instantiate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantiate.js","sourceRoot":"","sources":["../../src/instantiate.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,uCAAuC;AACvC,EAAE;AACF,uEAAuE;AACvE,4EAA4E;AAC5E,4EAA4E;AAE5E,OAAO,EAAE,WAAW,EAAmB,MAAM,SAAS,CAAC;AA8BvD,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAyB;IACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC;IAE1C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC;IAC3C,MAAM,SAAS,GAAG,UAAqC,CAAC;IACxD,sEAAsE;IACtE,mEAAmE;IACnE,IAAI,CAAC,SAAS,CAAC,E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