@tsrs/wasm 0.0.0-stage → 0.16.0-ts7.1.0-dev.20260929

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/node-run.js ADDED
@@ -0,0 +1,55 @@
1
+ // One tsc run on the current thread: the request, the file system (real or in-memory) and the output streams.
2
+ import fs from "node:fs";
3
+ import { makeRequest, memoryFileSystem, parseReply, runTsc } from "./core.js";
4
+ import { isCaseInsensitive, nodeFileSystem } from "./node-fs.js";
5
+
6
+ const SLEEP = new Int32Array(new SharedArrayBuffer(4));
7
+
8
+ /** Writes all of `chunk` to `fd`, waiting out EAGAIN (a non-blocking pipe) and dropping the rest on EPIPE. */
9
+ export function writeAll(fd, chunk) {
10
+ let off = 0;
11
+ while (off < chunk.length) {
12
+ try {
13
+ off += fs.writeSync(fd, chunk, off, chunk.length - off);
14
+ } catch (e) {
15
+ if (e.code === "EAGAIN") {
16
+ Atomics.wait(SLEEP, 0, 0, 1);
17
+ continue;
18
+ }
19
+ if (e.code === "EPIPE") return;
20
+ throw e;
21
+ }
22
+ }
23
+ }
24
+
25
+ function sink(mode, fd, chunks) {
26
+ if (mode === "inherit") return (chunk) => writeAll(fd, chunk);
27
+ return (chunk) => chunks.push(chunk);
28
+ }
29
+
30
+ /** hooks: { beforeRun(memory), afterRun(memory) } (see core.js runTsc). */
31
+ export function run(module, options, hooks = {}) {
32
+ const caseInsensitive = options.caseInsensitive ?? (options.files ? false : isCaseInsensitive());
33
+ const memory = options.files ? memoryFileSystem(options.files, { caseInsensitive }) : null;
34
+ const host = memory ?? nodeFileSystem();
35
+ const cwd = options.cwd ?? (memory ? "/" : process.cwd());
36
+ const json = options.diagnostics === "json";
37
+ const out = [];
38
+ const err = [];
39
+ const request = makeRequest(options.args, { cwd, json, caseInsensitive, tty: !!options.tty });
40
+ const result = runTsc(module, request, host, {
41
+ env: options.env ?? {},
42
+ stdout: sink(options.stdout, 1, out),
43
+ stderr: sink(options.stderr, 2, err),
44
+ ...hooks,
45
+ });
46
+ const text = (chunks) => Buffer.concat(chunks).toString("utf8");
47
+ return {
48
+ exitCode: result.exitCode,
49
+ stdout: text(out),
50
+ stderr: text(err),
51
+ diagnostics: json ? parseReply(result.reply) : undefined,
52
+ files: memory ? Object.fromEntries(memory.written) : undefined,
53
+ memoryBytes: result.memoryBytes,
54
+ };
55
+ }
package/node-worker.js ADDED
@@ -0,0 +1,5 @@
1
+ // Runs one tsc request in a worker thread (node.js posts the compiled module and the options).
2
+ import { parentPort, workerData } from "node:worker_threads";
3
+ import { run } from "./node-run.js";
4
+
5
+ parentPort.postMessage(run(workerData.module, workerData.options));
package/node.js ADDED
@@ -0,0 +1,50 @@
1
+ // Node entry point: `tsc(args, options)` runs tsrs.wasm in a fresh worker thread per call (the checker recurses
2
+ // deeply; a worker gets a large native stack through `resourceLimits.stackSizeMb`). The module is compiled once per
3
+ // process. Under Bun, which ignores the worker stack limit, the run stays on the calling thread.
4
+
5
+ import fs from "node:fs";
6
+ import { Worker } from "node:worker_threads";
7
+ import { run } from "./node-run.js";
8
+
9
+ export const DEFAULT_STACK_SIZE_MB = 256;
10
+
11
+ let compiled;
12
+
13
+ /** The compiled module (tsrs.wasm next to this file, or `TSRS_WASM` if set). */
14
+ export function loadModule() {
15
+ compiled ??= new WebAssembly.Module(fs.readFileSync(process.env.TSRS_WASM || new URL("./tsrs.wasm", import.meta.url)));
16
+ return compiled;
17
+ }
18
+
19
+ /**
20
+ * Runs tsc. options: { cwd, files, env, diagnostics: "text" | "json", tty, stdout, stderr ("inherit" to write to
21
+ * this process's fd 1 / 2; collected otherwise), caseInsensitive, stackSizeMb }.
22
+ * Resolves to { exitCode, stdout, stderr, diagnostics?, files?, memoryBytes }.
23
+ */
24
+ export function tsc(args, options = {}) {
25
+ const module = loadModule();
26
+ const opts = { ...options, args: [...args] };
27
+ if (typeof Bun !== "undefined") {
28
+ return Promise.resolve().then(() => run(module, opts));
29
+ }
30
+ return new Promise((resolve, reject) => {
31
+ const worker = new Worker(new URL("./node-worker.js", import.meta.url), {
32
+ workerData: { module, options: opts },
33
+ resourceLimits: { stackSizeMb: options.stackSizeMb ?? DEFAULT_STACK_SIZE_MB },
34
+ stdout: false,
35
+ stderr: false,
36
+ });
37
+ let settled = false;
38
+ worker.once("message", (result) => {
39
+ settled = true;
40
+ resolve(result);
41
+ });
42
+ worker.once("error", (e) => {
43
+ settled = true;
44
+ reject(e);
45
+ });
46
+ worker.once("exit", (code) => {
47
+ if (!settled) reject(new Error(`tsrs-wasm worker exited with code ${code}`));
48
+ });
49
+ });
50
+ }
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@tsrs/wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.16.0-ts7.1.0-dev.20260929",
4
+ "license": "Apache-2.0",
5
+ "description": "tsrs (a Rust port of the TypeScript 7 compiler) as a WebAssembly module: tsc for Node and browsers, single-threaded",
6
+ "keywords": [
7
+ "TypeScript",
8
+ "tsc",
9
+ "typecheck",
10
+ "wasm",
11
+ "webassembly",
12
+ "rust",
13
+ "compiler"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/oxc-project/tsrs.git",
18
+ "directory": "npm/tsrs-wasm"
19
+ },
20
+ "type": "module",
21
+ "engines": {
22
+ "node": ">=22"
23
+ },
24
+ "bin": {
25
+ "tsrs-wasm": "bin/tsrs-wasm.js"
26
+ },
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": {
30
+ "types": "./index.d.ts",
31
+ "node": "./node.js",
32
+ "default": "./browser.js"
33
+ },
34
+ "./core": {
35
+ "types": "./core.d.ts",
36
+ "default": "./core.js"
37
+ },
38
+ "./tsrs.wasm": "./tsrs.wasm"
39
+ },
40
+ "files": [
41
+ "bin",
42
+ "core.js",
43
+ "core.d.ts",
44
+ "node.js",
45
+ "node-run.js",
46
+ "node-worker.js",
47
+ "node-fs.js",
48
+ "browser.js",
49
+ "index.d.ts",
50
+ "tsrs.wasm",
51
+ "README.md",
52
+ "NOTICE.txt"
53
+ ],
54
+ "tsrs": {
55
+ "typescriptVersion": "7.1.0-dev.20260929",
56
+ "typescriptCommit": "b85298b6a81f772d080b0455de0ca9d744cd6fd6"
57
+ },
58
+ "scripts": {
59
+ "test": "node --test test/*.test.mjs"
60
+ }
6
61
  }
package/tsrs.wasm ADDED
Binary file