@andreiltd/componentize-qjs-binding-linux-x64-musl 0.3.0 → 0.4.1
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/README.md +34 -6
- package/componentize-qjs.linux-x64-musl.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -119,6 +119,7 @@ componentize-qjs [OPTIONS] --wit <WIT> --js <JS>
|
|
|
119
119
|
| `--wit <PATH>` | `-w` | Path to the WIT file or directory |
|
|
120
120
|
| `--js <PATH>` | `-j` | Path to the JavaScript source file |
|
|
121
121
|
| `--output <PATH>` | `-o` | Output path (default: `output.wasm`) |
|
|
122
|
+
| `--module-root <PATH>` | | Root directory exposed read-only during Wizer for resolving JavaScript imports |
|
|
122
123
|
| `--world <NAME>` | `-n` | World name when the WIT defines multiple worlds |
|
|
123
124
|
| `--stub-wasi` | | Replace all WASI imports with trap stubs |
|
|
124
125
|
| `--minify` | `-m` | Minify JS source before embedding |
|
|
@@ -169,6 +170,13 @@ export function doubleAdd(a, b) {
|
|
|
169
170
|
}
|
|
170
171
|
```
|
|
171
172
|
|
|
173
|
+
JavaScript modules imported by the entry file are resolved during Wizer
|
|
174
|
+
initialization. Relative imports are resolved from the entry file path passed to
|
|
175
|
+
`--js`; bare package imports are resolved under the read-only module root. By
|
|
176
|
+
default the CLI uses the current directory when the entry file is under it, or
|
|
177
|
+
the entry file's parent directory otherwise. Use `--module-root <PATH>` to expose
|
|
178
|
+
a project root that contains shared files or `node_modules`.
|
|
179
|
+
|
|
172
180
|
## WIT Type Mappings
|
|
173
181
|
|
|
174
182
|
### Primitive Types
|
|
@@ -190,13 +198,33 @@ export function doubleAdd(a, b) {
|
|
|
190
198
|
| `list<T>` | `Array` | `[1, 2, 3]` |
|
|
191
199
|
| `list<u8>` | `Uint8Array` or `Array` | `new Uint8Array([1, 2, 3])` |
|
|
192
200
|
| `tuple<T, U, ...>` | `Array` | `[42, "hello"]` |
|
|
193
|
-
| `option<T>` | `T \| null \|
|
|
194
|
-
| `result<T, E>` | `{ tag: "ok"\|"err", val?: T\|E }` | `
|
|
201
|
+
| `option<T>` | `T \| null` (nested: `{ tag: "some"\|"none", val }`) | `null` for none; `option<option<T>>` is wrapped |
|
|
202
|
+
| `result<T, E>` | top-level function result: return `T` or throw `E`; nested result: `{ tag: "ok"\|"err", val?: T\|E }` | `return 42` / `throw "error"` |
|
|
195
203
|
| `record { ... }` | `object` (camelCase keys) | `{ myField: 1 }` |
|
|
196
|
-
| `variant` | `{ tag:
|
|
197
|
-
| `enum` | `
|
|
198
|
-
| `flags` | `
|
|
199
|
-
| `own<R>`, `borrow<R>` |
|
|
204
|
+
| `variant` | `{ tag: string, val?: T }` | `{ tag: "circle", val: 2.5 }` |
|
|
205
|
+
| `enum` | `string` (case name) | `"red"` |
|
|
206
|
+
| `flags` | `object` (camelCase booleans) | `{ read: true, write: false }` |
|
|
207
|
+
| `own<R>`, `borrow<R>` | resource object (methods on its prototype) | `input.blockingRead(n)` |
|
|
208
|
+
|
|
209
|
+
### Imported Resources
|
|
210
|
+
|
|
211
|
+
Imported resources are exposed as JavaScript classes. Resource methods are
|
|
212
|
+
called on the handle:
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
import stdin from "wasi:cli/stdin@0.2.10";
|
|
216
|
+
import stdout from "wasi:cli/stdout@0.2.10";
|
|
217
|
+
|
|
218
|
+
const input = stdin.getStdin(); // an InputStream
|
|
219
|
+
const output = stdout.getStdout(); // an OutputStream
|
|
220
|
+
|
|
221
|
+
// Methods whose WIT return type is result<...> return the ok payload or throw.
|
|
222
|
+
const chunk = input.blockingRead(4096); // method on the resource (len is a number)
|
|
223
|
+
output.blockingWriteAndFlush(chunk);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`[static]` methods are exposed on the resource class and `[constructor]` makes
|
|
227
|
+
the class callable with `new`.
|
|
200
228
|
|
|
201
229
|
### Async Exports
|
|
202
230
|
|
|
Binary file
|