tswasm 0.1.0-alpha.0

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.
@@ -0,0 +1,589 @@
1
+ // Copyright 2018 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ "use strict";
6
+
7
+ (() => {
8
+ const enosys = () => {
9
+ const err = new Error("not implemented");
10
+ err.code = "ENOSYS";
11
+ return err;
12
+ };
13
+
14
+ if (!globalThis.fs) {
15
+ let outputBuf = "";
16
+ globalThis.fs = {
17
+ constants: { O_WRONLY: -1, O_RDWR: -1, O_CREAT: -1, O_TRUNC: -1, O_APPEND: -1, O_EXCL: -1, O_DIRECTORY: -1 }, // unused
18
+ writeSync(fd, buf) {
19
+ outputBuf += decoder.decode(buf);
20
+ const nl = outputBuf.lastIndexOf("\n");
21
+ if (nl != -1) {
22
+ console.log(outputBuf.substring(0, nl));
23
+ outputBuf = outputBuf.substring(nl + 1);
24
+ }
25
+ return buf.length;
26
+ },
27
+ write(fd, buf, offset, length, position, callback) {
28
+ if (offset !== 0 || length !== buf.length || position !== null) {
29
+ callback(enosys());
30
+ return;
31
+ }
32
+ const n = this.writeSync(fd, buf);
33
+ callback(null, n);
34
+ },
35
+ chmod(path, mode, callback) { callback(enosys()); },
36
+ chown(path, uid, gid, callback) { callback(enosys()); },
37
+ close(fd, callback) { callback(enosys()); },
38
+ fchmod(fd, mode, callback) { callback(enosys()); },
39
+ fchown(fd, uid, gid, callback) { callback(enosys()); },
40
+ fstat(fd, callback) { callback(enosys()); },
41
+ fsync(fd, callback) { callback(null); },
42
+ ftruncate(fd, length, callback) { callback(enosys()); },
43
+ lchown(path, uid, gid, callback) { callback(enosys()); },
44
+ link(path, link, callback) { callback(enosys()); },
45
+ lstat(path, callback) { callback(enosys()); },
46
+ mkdir(path, perm, callback) { callback(enosys()); },
47
+ open(path, flags, mode, callback) { callback(enosys()); },
48
+ read(fd, buffer, offset, length, position, callback) { callback(enosys()); },
49
+ readdir(path, callback) { callback(enosys()); },
50
+ readlink(path, callback) { callback(enosys()); },
51
+ rename(from, to, callback) { callback(enosys()); },
52
+ rmdir(path, callback) { callback(enosys()); },
53
+ stat(path, callback) { callback(enosys()); },
54
+ symlink(path, link, callback) { callback(enosys()); },
55
+ truncate(path, length, callback) { callback(enosys()); },
56
+ unlink(path, callback) { callback(enosys()); },
57
+ utimes(path, atime, mtime, callback) { callback(enosys()); },
58
+ };
59
+ }
60
+
61
+ if (!globalThis.process) {
62
+ globalThis.process = {
63
+ getuid() { return -1; },
64
+ getgid() { return -1; },
65
+ geteuid() { return -1; },
66
+ getegid() { return -1; },
67
+ getgroups() { throw enosys(); },
68
+ pid: -1,
69
+ ppid: -1,
70
+ umask() { throw enosys(); },
71
+ cwd() { throw enosys(); },
72
+ chdir() { throw enosys(); },
73
+ }
74
+ }
75
+
76
+ if (!globalThis.path) {
77
+ globalThis.path = {
78
+ resolve(...pathSegments) {
79
+ return pathSegments.join("/");
80
+ }
81
+ }
82
+ }
83
+
84
+ if (!globalThis.crypto?.getRandomValues) {
85
+ const nodeCrypto = globalThis.process?.getBuiltinModule?.("crypto");
86
+ if (nodeCrypto?.webcrypto?.getRandomValues) {
87
+ globalThis.crypto = nodeCrypto.webcrypto;
88
+ } else {
89
+ let seed = 0x12345678;
90
+ globalThis.crypto = {
91
+ getRandomValues(target) {
92
+ for (let i = 0; i < target.length; i++) {
93
+ seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
94
+ target[i] = seed & 0xff;
95
+ }
96
+ return target;
97
+ },
98
+ };
99
+ }
100
+ }
101
+
102
+ if (!globalThis.performance) {
103
+ throw new Error("globalThis.performance is not available, polyfill required (performance.now only)");
104
+ }
105
+
106
+ if (!globalThis.TextEncoder) {
107
+ throw new Error("globalThis.TextEncoder is not available, polyfill required");
108
+ }
109
+
110
+ if (!globalThis.TextDecoder) {
111
+ throw new Error("globalThis.TextDecoder is not available, polyfill required");
112
+ }
113
+
114
+ const encoder = new TextEncoder("utf-8");
115
+ const decoder = new TextDecoder("utf-8");
116
+
117
+ globalThis.Go = class {
118
+ constructor() {
119
+ this.argv = ["js"];
120
+ this.env = {};
121
+ this.exit = (code) => {
122
+ if (code !== 0) {
123
+ console.warn("exit code:", code);
124
+ }
125
+ };
126
+ this._exitPromise = new Promise((resolve) => {
127
+ this._resolveExitPromise = resolve;
128
+ });
129
+ this._pendingEvent = null;
130
+ this._scheduledTimeouts = new Map();
131
+ this._nextCallbackTimeoutID = 1;
132
+
133
+ const setInt64 = (addr, v) => {
134
+ this.mem.setUint32(addr + 0, v, true);
135
+ this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
136
+ }
137
+
138
+ const setInt32 = (addr, v) => {
139
+ this.mem.setUint32(addr + 0, v, true);
140
+ }
141
+
142
+ const getInt64 = (addr) => {
143
+ const low = this.mem.getUint32(addr + 0, true);
144
+ const high = this.mem.getInt32(addr + 4, true);
145
+ return low + high * 4294967296;
146
+ }
147
+
148
+ const loadValue = (addr) => {
149
+ const f = this.mem.getFloat64(addr, true);
150
+ if (f === 0) {
151
+ return undefined;
152
+ }
153
+ if (!isNaN(f)) {
154
+ return f;
155
+ }
156
+
157
+ const id = this.mem.getUint32(addr, true);
158
+ return this._values[id];
159
+ }
160
+
161
+ const storeValue = (addr, v) => {
162
+ const nanHead = 0x7FF80000;
163
+
164
+ if (typeof v === "number" && v !== 0) {
165
+ if (isNaN(v)) {
166
+ this.mem.setUint32(addr + 4, nanHead, true);
167
+ this.mem.setUint32(addr, 0, true);
168
+ return;
169
+ }
170
+ this.mem.setFloat64(addr, v, true);
171
+ return;
172
+ }
173
+
174
+ if (v === undefined) {
175
+ this.mem.setFloat64(addr, 0, true);
176
+ return;
177
+ }
178
+
179
+ let id = this._ids.get(v);
180
+ if (id === undefined) {
181
+ id = this._idPool.pop();
182
+ if (id === undefined) {
183
+ id = this._values.length;
184
+ }
185
+ this._values[id] = v;
186
+ this._goRefCounts[id] = 0;
187
+ this._ids.set(v, id);
188
+ }
189
+ this._goRefCounts[id]++;
190
+ let typeFlag = 0;
191
+ switch (typeof v) {
192
+ case "object":
193
+ if (v !== null) {
194
+ typeFlag = 1;
195
+ }
196
+ break;
197
+ case "string":
198
+ typeFlag = 2;
199
+ break;
200
+ case "symbol":
201
+ typeFlag = 3;
202
+ break;
203
+ case "function":
204
+ typeFlag = 4;
205
+ break;
206
+ }
207
+ this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
208
+ this.mem.setUint32(addr, id, true);
209
+ }
210
+
211
+ const loadSlice = (addr) => {
212
+ const array = getInt64(addr + 0);
213
+ const len = getInt64(addr + 8);
214
+ return new Uint8Array(this._inst.exports.mem.buffer, array, len);
215
+ }
216
+
217
+ const loadSliceOfValues = (addr) => {
218
+ const array = getInt64(addr + 0);
219
+ const len = getInt64(addr + 8);
220
+ const a = new Array(len);
221
+ for (let i = 0; i < len; i++) {
222
+ a[i] = loadValue(array + i * 8);
223
+ }
224
+ return a;
225
+ }
226
+
227
+ const loadString = (addr) => {
228
+ const saddr = getInt64(addr + 0);
229
+ const len = getInt64(addr + 8);
230
+ return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
231
+ }
232
+
233
+ const testCallExport = (a, b) => {
234
+ this._inst.exports.testExport0();
235
+ return this._inst.exports.testExport(a, b);
236
+ }
237
+
238
+ const timeOrigin = Date.now() - performance.now();
239
+ this.importObject = {
240
+ _gotest: {
241
+ add: (a, b) => a + b,
242
+ callExport: testCallExport,
243
+ },
244
+ gojs: {
245
+ // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
246
+ // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
247
+ // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
248
+ // This changes the SP, thus we have to update the SP used by the imported function.
249
+
250
+ // func wasmExit(code int32)
251
+ "runtime.wasmExit": (sp) => {
252
+ sp >>>= 0;
253
+ const code = this.mem.getInt32(sp + 8, true);
254
+ this.exited = true;
255
+ delete this._inst;
256
+ delete this._values;
257
+ delete this._goRefCounts;
258
+ delete this._ids;
259
+ delete this._idPool;
260
+ this.exit(code);
261
+ },
262
+
263
+ // func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
264
+ "runtime.wasmWrite": (sp) => {
265
+ sp >>>= 0;
266
+ const fd = getInt64(sp + 8);
267
+ const p = getInt64(sp + 16);
268
+ const n = this.mem.getInt32(sp + 24, true);
269
+ fs.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
270
+ },
271
+
272
+ // func resetMemoryDataView()
273
+ "runtime.resetMemoryDataView": (sp) => {
274
+ sp >>>= 0;
275
+ this.mem = new DataView(this._inst.exports.mem.buffer);
276
+ },
277
+
278
+ // func nanotime1() int64
279
+ "runtime.nanotime1": (sp) => {
280
+ sp >>>= 0;
281
+ setInt64(sp + 8, (timeOrigin + performance.now()) * 1000000);
282
+ },
283
+
284
+ // func walltime() (sec int64, nsec int32)
285
+ "runtime.walltime": (sp) => {
286
+ sp >>>= 0;
287
+ const msec = (new Date).getTime();
288
+ setInt64(sp + 8, msec / 1000);
289
+ this.mem.setInt32(sp + 16, (msec % 1000) * 1000000, true);
290
+ },
291
+
292
+ // func scheduleTimeoutEvent(delay int64) int32
293
+ "runtime.scheduleTimeoutEvent": (sp) => {
294
+ sp >>>= 0;
295
+ const id = this._nextCallbackTimeoutID;
296
+ this._nextCallbackTimeoutID++;
297
+ this._scheduledTimeouts.set(id, setTimeout(
298
+ () => {
299
+ this._resume();
300
+ while (this._scheduledTimeouts.has(id)) {
301
+ // for some reason Go failed to register the timeout event, log and try again
302
+ // (temporary workaround for https://github.com/golang/go/issues/28975)
303
+ console.warn("scheduleTimeoutEvent: missed timeout event");
304
+ this._resume();
305
+ }
306
+ },
307
+ getInt64(sp + 8),
308
+ ));
309
+ this.mem.setInt32(sp + 16, id, true);
310
+ },
311
+
312
+ // func clearTimeoutEvent(id int32)
313
+ "runtime.clearTimeoutEvent": (sp) => {
314
+ sp >>>= 0;
315
+ const id = this.mem.getInt32(sp + 8, true);
316
+ clearTimeout(this._scheduledTimeouts.get(id));
317
+ this._scheduledTimeouts.delete(id);
318
+ },
319
+
320
+ // func getRandomData(r []byte)
321
+ "runtime.getRandomData": (sp) => {
322
+ sp >>>= 0;
323
+ crypto.getRandomValues(loadSlice(sp + 8));
324
+ },
325
+
326
+ // func finalizeRef(v ref)
327
+ "syscall/js.finalizeRef": (sp) => {
328
+ sp >>>= 0;
329
+ const id = this.mem.getUint32(sp + 8, true);
330
+ this._goRefCounts[id]--;
331
+ if (this._goRefCounts[id] === 0) {
332
+ const v = this._values[id];
333
+ this._values[id] = null;
334
+ this._ids.delete(v);
335
+ this._idPool.push(id);
336
+ }
337
+ },
338
+
339
+ // func stringVal(value string) ref
340
+ "syscall/js.stringVal": (sp) => {
341
+ sp >>>= 0;
342
+ storeValue(sp + 24, loadString(sp + 8));
343
+ },
344
+
345
+ // func valueGet(v ref, p string) ref
346
+ "syscall/js.valueGet": (sp) => {
347
+ sp >>>= 0;
348
+ const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
349
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
350
+ storeValue(sp + 32, result);
351
+ },
352
+
353
+ // func valueSet(v ref, p string, x ref)
354
+ "syscall/js.valueSet": (sp) => {
355
+ sp >>>= 0;
356
+ Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
357
+ },
358
+
359
+ // func valueDelete(v ref, p string)
360
+ "syscall/js.valueDelete": (sp) => {
361
+ sp >>>= 0;
362
+ Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
363
+ },
364
+
365
+ // func valueIndex(v ref, i int) ref
366
+ "syscall/js.valueIndex": (sp) => {
367
+ sp >>>= 0;
368
+ storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
369
+ },
370
+
371
+ // valueSetIndex(v ref, i int, x ref)
372
+ "syscall/js.valueSetIndex": (sp) => {
373
+ sp >>>= 0;
374
+ Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
375
+ },
376
+
377
+ // func valueCall(v ref, m string, args []ref) (ref, bool)
378
+ "syscall/js.valueCall": (sp) => {
379
+ sp >>>= 0;
380
+ try {
381
+ const v = loadValue(sp + 8);
382
+ const m = Reflect.get(v, loadString(sp + 16));
383
+ const args = loadSliceOfValues(sp + 32);
384
+ const result = Reflect.apply(m, v, args);
385
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
386
+ storeValue(sp + 56, result);
387
+ this.mem.setUint8(sp + 64, 1);
388
+ } catch (err) {
389
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
390
+ storeValue(sp + 56, err);
391
+ this.mem.setUint8(sp + 64, 0);
392
+ }
393
+ },
394
+
395
+ // func valueInvoke(v ref, args []ref) (ref, bool)
396
+ "syscall/js.valueInvoke": (sp) => {
397
+ sp >>>= 0;
398
+ try {
399
+ const v = loadValue(sp + 8);
400
+ const args = loadSliceOfValues(sp + 16);
401
+ const result = Reflect.apply(v, undefined, args);
402
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
403
+ storeValue(sp + 40, result);
404
+ this.mem.setUint8(sp + 48, 1);
405
+ } catch (err) {
406
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
407
+ storeValue(sp + 40, err);
408
+ this.mem.setUint8(sp + 48, 0);
409
+ }
410
+ },
411
+
412
+ // func valueNew(v ref, args []ref) (ref, bool)
413
+ "syscall/js.valueNew": (sp) => {
414
+ sp >>>= 0;
415
+ try {
416
+ const v = loadValue(sp + 8);
417
+ const args = loadSliceOfValues(sp + 16);
418
+ const result = Reflect.construct(v, args);
419
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
420
+ storeValue(sp + 40, result);
421
+ this.mem.setUint8(sp + 48, 1);
422
+ } catch (err) {
423
+ sp = this._inst.exports.getsp() >>> 0; // see comment above
424
+ storeValue(sp + 40, err);
425
+ this.mem.setUint8(sp + 48, 0);
426
+ }
427
+ },
428
+
429
+ // func valueLength(v ref) int
430
+ "syscall/js.valueLength": (sp) => {
431
+ sp >>>= 0;
432
+ setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
433
+ },
434
+
435
+ // valuePrepareString(v ref) (ref, int)
436
+ "syscall/js.valuePrepareString": (sp) => {
437
+ sp >>>= 0;
438
+ const str = encoder.encode(String(loadValue(sp + 8)));
439
+ storeValue(sp + 16, str);
440
+ setInt64(sp + 24, str.length);
441
+ },
442
+
443
+ // valueLoadString(v ref, b []byte)
444
+ "syscall/js.valueLoadString": (sp) => {
445
+ sp >>>= 0;
446
+ const str = loadValue(sp + 8);
447
+ loadSlice(sp + 16).set(str);
448
+ },
449
+
450
+ // func valueInstanceOf(v ref, t ref) bool
451
+ "syscall/js.valueInstanceOf": (sp) => {
452
+ sp >>>= 0;
453
+ this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
454
+ },
455
+
456
+ // func copyBytesToGo(dst []byte, src ref) (int, bool)
457
+ "syscall/js.copyBytesToGo": (sp) => {
458
+ sp >>>= 0;
459
+ const dst = loadSlice(sp + 8);
460
+ const src = loadValue(sp + 32);
461
+ if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
462
+ this.mem.setUint8(sp + 48, 0);
463
+ return;
464
+ }
465
+ const toCopy = src.subarray(0, dst.length);
466
+ dst.set(toCopy);
467
+ setInt64(sp + 40, toCopy.length);
468
+ this.mem.setUint8(sp + 48, 1);
469
+ },
470
+
471
+ // func copyBytesToJS(dst ref, src []byte) (int, bool)
472
+ "syscall/js.copyBytesToJS": (sp) => {
473
+ sp >>>= 0;
474
+ const dst = loadValue(sp + 8);
475
+ const src = loadSlice(sp + 16);
476
+ if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
477
+ this.mem.setUint8(sp + 48, 0);
478
+ return;
479
+ }
480
+ const toCopy = src.subarray(0, dst.length);
481
+ dst.set(toCopy);
482
+ setInt64(sp + 40, toCopy.length);
483
+ this.mem.setUint8(sp + 48, 1);
484
+ },
485
+
486
+ "debug": (value) => {
487
+ console.log(value);
488
+ },
489
+ }
490
+ };
491
+ }
492
+
493
+ async run(instance) {
494
+ if (!(instance instanceof WebAssembly.Instance)) {
495
+ throw new Error("Go.run: WebAssembly.Instance expected");
496
+ }
497
+ this._inst = instance;
498
+ this.mem = new DataView(this._inst.exports.mem.buffer);
499
+ this._values = [ // JS values that Go currently has references to, indexed by reference id
500
+ NaN,
501
+ 0,
502
+ null,
503
+ true,
504
+ false,
505
+ globalThis,
506
+ this,
507
+ ];
508
+ this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
509
+ this._ids = new Map([ // mapping from JS values to reference ids
510
+ [0, 1],
511
+ [null, 2],
512
+ [true, 3],
513
+ [false, 4],
514
+ [globalThis, 5],
515
+ [this, 6],
516
+ ]);
517
+ this._idPool = []; // unused ids that have been garbage collected
518
+ this.exited = false; // whether the Go program has exited
519
+
520
+ // Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
521
+ let offset = 4096;
522
+
523
+ const strPtr = (str) => {
524
+ const ptr = offset;
525
+ const bytes = encoder.encode(str + "\0");
526
+ new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
527
+ offset += bytes.length;
528
+ if (offset % 8 !== 0) {
529
+ offset += 8 - (offset % 8);
530
+ }
531
+ return ptr;
532
+ };
533
+
534
+ const argc = this.argv.length;
535
+
536
+ const argvPtrs = [];
537
+ this.argv.forEach((arg) => {
538
+ argvPtrs.push(strPtr(arg));
539
+ });
540
+ argvPtrs.push(0);
541
+
542
+ const keys = Object.keys(this.env).sort();
543
+ keys.forEach((key) => {
544
+ argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
545
+ });
546
+ argvPtrs.push(0);
547
+
548
+ const argv = offset;
549
+ argvPtrs.forEach((ptr) => {
550
+ this.mem.setUint32(offset, ptr, true);
551
+ this.mem.setUint32(offset + 4, 0, true);
552
+ offset += 8;
553
+ });
554
+
555
+ // The linker guarantees global data starts from at least wasmMinDataAddr.
556
+ // Keep in sync with cmd/link/internal/ld/data.go:wasmMinDataAddr.
557
+ const wasmMinDataAddr = 4096 + 8192;
558
+ if (offset >= wasmMinDataAddr) {
559
+ throw new Error("total length of command line and environment variables exceeds limit");
560
+ }
561
+
562
+ this._inst.exports.run(argc, argv);
563
+ if (this.exited) {
564
+ this._resolveExitPromise();
565
+ }
566
+ await this._exitPromise;
567
+ }
568
+
569
+ _resume() {
570
+ if (this.exited) {
571
+ throw new Error("Go program has already exited");
572
+ }
573
+ this._inst.exports.resume();
574
+ if (this.exited) {
575
+ this._resolveExitPromise();
576
+ }
577
+ }
578
+
579
+ _makeFuncWrapper(id) {
580
+ const go = this;
581
+ return function () {
582
+ const event = { id: id, this: this, args: arguments };
583
+ go._pendingEvent = event;
584
+ go._resume();
585
+ return event.result;
586
+ };
587
+ }
588
+ }
589
+ })();
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "tswasm",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Embeddable TypeScript compilation via typescript-go compiled to wasm.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/iterate/tswasm.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/iterate/tswasm/issues"
13
+ },
14
+ "homepage": "https://github.com/iterate/tswasm#readme",
15
+ "keywords": [
16
+ "typescript",
17
+ "typescript-go",
18
+ "tsgo",
19
+ "wasm",
20
+ "webassembly",
21
+ "compiler",
22
+ "cloudflare-workers"
23
+ ],
24
+ "packageManager": "pnpm@10.14.0",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./tswasm.wasm": {
34
+ "types": "./tswasm.wasm.d.ts",
35
+ "default": "./dist/tswasm.wasm"
36
+ },
37
+ "./package.json": {
38
+ "default": "./package.json"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist/index.d.ts",
43
+ "dist/index.js",
44
+ "dist/tswasm.wasm",
45
+ "dist/wasm_exec.js",
46
+ "LICENSE",
47
+ "NOTICE",
48
+ "THIRD_PARTY_NOTICES.md",
49
+ "tswasm.wasm.d.ts",
50
+ "README.md"
51
+ ],
52
+ "scripts": {
53
+ "clean": "rm -rf dist",
54
+ "build:wasm": "tsx scripts/build-wasm.ts",
55
+ "build:js": "tsc -p tsconfig.json",
56
+ "build": "pnpm run clean && pnpm run build:wasm && pnpm run build:js",
57
+ "bench": "pnpm run build && tsx bench/compile.bench.ts",
58
+ "bench:quick": "pnpm run build && tsx bench/compile.bench.ts --quick",
59
+ "bench:profile": "pnpm run build && tsx bench/compile.bench.ts --quick --include-internals",
60
+ "size": "pnpm run build && tsx scripts/size-report.ts",
61
+ "test": "pnpm run build && vitest run test",
62
+ "test:browser": "pnpm run build && TSWASM_BROWSER_TEST=1 vitest run test/browser.test.ts",
63
+ "test:cloudflare": "pnpm run build && vitest run test/cloudflare-worker.test.ts",
64
+ "test:expo": "pnpm run build && TSWASM_EXPO_TEST=1 vitest run test/expo.test.ts",
65
+ "release:check": "pnpm test && pnpm run size && npm pack --dry-run --json",
66
+ "prepublishOnly": "pnpm run release:check"
67
+ },
68
+ "devDependencies": {
69
+ "@types/node": "^24.10.2",
70
+ "esbuild": "^0.28.1",
71
+ "execa": "^9.6.1",
72
+ "miniflare": "^4.20260617.0",
73
+ "playwright": "^1.61.0",
74
+ "tinybench": "^6.0.2",
75
+ "ts-morph": "^28.0.0",
76
+ "tsx": "^4.20.6",
77
+ "typescript": "^5.9.3",
78
+ "vitest": "^4.0.15"
79
+ }
80
+ }
@@ -0,0 +1,3 @@
1
+ declare const wasm: WebAssembly.Module | URL | string;
2
+
3
+ export default wasm;