I'm testing scriptc compilation of Native Messaging hosts I've already written and tested using other tools and environments.
Straight up TypeScript https://github.com/guest271314/NativeMessagingHosts/blob/main/nm_typescript.ts input compilation fails.
SCRIPTC_NO_CACHE=1 SCRIPTC_CC=zigcc SCRIPTC_TARGET=wasm32-wasi bun x scriptc build ~/native-messaging-typescript/nm_typescript.ts --keep-c --optimization release -o nm_typescript.wasm >/dev/null
/home/user/native-messaging-typescript/nm_typescript.ts:12:1 - error SC1010: the 'node:process' module is not supported yet
11 |
12 | import * as process from "node:process";
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 |
hint: relative imports (./file, ../dir/file), package.json-mediated project imports (#alias via the imports field, self-name references via exports), installed npm packages (their code runs under --dynamic), and the built-in fs, fs/promises, path, os, url, crypto, zlib, child_process, net, http, tls, https, http2, dgram, dns, util, util/types, string_decoder, querystring, readline, events, stream, stream/promises, stream/consumers, buffer, assert, assert/strict, worker_threads, cluster, tty, async_hooks, timers, timers/promises, diagnostics_channel, perf_hooks, and module modules (bare or node:-prefixed) and node:test (node:-prefixed only, like in Node) are supported
/home/user/native-messaging-typescript/nm_typescript.ts:16:21 - error SC0001: Namespace 'NodeJS' has no exported member 'ReadStream'.
15 |
16 | const stdin: NodeJS.ReadStream & { fd: 0 } = process.stdin;
| ^~~~~~~~~~
17 | const stdout: NodeJS.WriteStream & { fd: 1 } = process.stdout;
/home/user/native-messaging-typescript/nm_typescript.ts:17:22 - error SC0001: Namespace 'NodeJS' has no exported member 'WriteStream'.
16 | const stdin: NodeJS.ReadStream & { fd: 0 } = process.stdin;
17 | const stdout: NodeJS.WriteStream & { fd: 1 } = process.stdout;
| ^~~~~~~~~~~
18 | const exit: (n: number) => void = process.exit;
/home/user/native-messaging-typescript/nm_typescript.ts:33:3 - error SC0001: Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'Uint8Array<ArrayBuffer>'.
Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength
32 | function encodeMessage(message: object): Uint8Array<ArrayBuffer> {
33 | return encoder.encode(JSON.stringify(message));
| ^~~~~~
34 | }
4 errors.
Using Node.js fs.readSync() https://nodejs.org/api/fs.html#fsreadsyncfd-buffer-options and fs.writeSync() https://nodejs.org/api/fs.html#fswritesyncfd-buffer-offset-length-position, which work using js2wasm fails, too. Notice the error messages. There's more than one signature for readSync() and writeSync(); scriptc is only recognizing the 4-5 argument version and is expecting a string exclusively to writeSync() https://github.com/guest271314/js2/blob/main/examples/native-messaging/nm_js2wasm_node_fs.ts, https://github.com/guest271314/js2/blob/main/examples/native-messaging/nm_js2wasm_sync_framing.ts. After adjusting readSync() to the 4-5 argument version readSync(0, buf, 0, buf.length), writeSync() still fails, expecting only a string.
SCRIPTC_NO_CACHE=1 SCRIPTC_CC=zigcc SCRIPTC_TARGET=wasm32-wasi bun x scriptc build nm_js2wasm_node_fs.ts --keep-c --optimization release -o nm_node.wasm >/dev/null
/media/user/x/scriptc/nm_js2wasm_node_fs.ts:79:28 - error SC0001: Argument of type 'Uint8Array<ArrayBufferLike>' is not assignable to parameter of type 'string'.
78 | while (n < buf.length) {
79 | const w = writeSync(1, buf, n);
| ^~~
80 | if (w <= 0) return; // error; nothing more we can do on this frame
/media/user/x/scriptc/nm_js2wasm_node_fs.ts:144:28 - error SC0001: Argument of type 'Uint8Array<ArrayBuffer>' is not assignable to parameter of type 'string'.
143 | while (m < bytes.length) {
144 | const w = writeSync(2, bytes, m);
| ^~~~~
145 | if (w <= 0) return;
2 errors.
I'm testing
scriptccompilation of Native Messaging hosts I've already written and tested using other tools and environments.Straight up TypeScript https://github.com/guest271314/NativeMessagingHosts/blob/main/nm_typescript.ts input compilation fails.
Using Node.js
fs.readSync()https://nodejs.org/api/fs.html#fsreadsyncfd-buffer-options andfs.writeSync()https://nodejs.org/api/fs.html#fswritesyncfd-buffer-offset-length-position, which work usingjs2wasmfails, too. Notice the error messages. There's more than one signature forreadSync()andwriteSync();scriptcis only recognizing the 4-5 argument version and is expecting a string exclusively towriteSync()https://github.com/guest271314/js2/blob/main/examples/native-messaging/nm_js2wasm_node_fs.ts, https://github.com/guest271314/js2/blob/main/examples/native-messaging/nm_js2wasm_sync_framing.ts. After adjustingreadSync()to the 4-5 argument versionreadSync(0, buf, 0, buf.length),writeSync()still fails, expecting only a string.