UNPKG

3.44 kBTypeScriptView Raw
1declare module 'node:wasi' {
2 export * from 'wasi';
3}
4
5declare module 'wasi' {
6 interface WASIOptions {
7 /**
8 * An array of strings that the WebAssembly application will
9 * see as command line arguments. The first argument is the virtual path to the
10 * WASI command itself.
11 */
12 args?: string[];
13
14 /**
15 * An object similar to `process.env` that the WebAssembly
16 * application will see as its environment.
17 */
18 env?: object;
19
20 /**
21 * This object represents the WebAssembly application's
22 * sandbox directory structure. The string keys of `preopens` are treated as
23 * directories within the sandbox. The corresponding values in `preopens` are
24 * the real paths to those directories on the host machine.
25 */
26 preopens?: NodeJS.Dict<string>;
27
28 /**
29 * By default, WASI applications terminate the Node.js
30 * process via the `__wasi_proc_exit()` function. Setting this option to `true`
31 * causes `wasi.start()` to return the exit code rather than terminate the
32 * process.
33 * @default false
34 */
35 returnOnExit?: boolean;
36
37 /**
38 * The file descriptor used as standard input in the WebAssembly application.
39 * @default 0
40 */
41 stdin?: number;
42
43 /**
44 * The file descriptor used as standard output in the WebAssembly application.
45 * @default 1
46 */
47 stdout?: number;
48
49 /**
50 * The file descriptor used as standard error in the WebAssembly application.
51 * @default 2
52 */
53 stderr?: number;
54 }
55
56 class WASI {
57 constructor(options?: WASIOptions);
58 /**
59 *
60 * Attempt to begin execution of `instance` by invoking its `_start()` export.
61 * If `instance` does not contain a `_start()` export, then `start()` attempts to
62 * invoke the `__wasi_unstable_reactor_start()` export. If neither of those exports
63 * is present on `instance`, then `start()` does nothing.
64 *
65 * `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named
66 * `memory`. If `instance` does not have a `memory` export an exception is thrown.
67 *
68 * If `start()` is called more than once, an exception is thrown.
69 */
70 start(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
71
72 /**
73 * Attempt to initialize `instance` as a WASI reactor by invoking its `_initialize()` export, if it is present.
74 * If `instance` contains a `_start()` export, then an exception is thrown.
75 *
76 * `start()` requires that `instance` exports a [`WebAssembly.Memory`][] named
77 * `memory`. If `instance` does not have a `memory` export an exception is thrown.
78 *
79 * If `initialize()` is called more than once, an exception is thrown.
80 */
81 initialize(instance: object): void; // TODO: avoid DOM dependency until WASM moved to own lib.
82
83 /**
84 * Is an object that implements the WASI system call API. This object
85 * should be passed as the `wasi_snapshot_preview1` import during the instantiation of a
86 * [`WebAssembly.Instance`][].
87 */
88 readonly wasiImport: NodeJS.Dict<any>; // TODO: Narrow to DOM types
89 }
90}