Skip to content

Commit a2b3992

Browse files
chore(docs): add comments to API type in README (#261)
This commit fills out the API types in the README with the comments that are present in `types.d.ts`, to add more context for every option.
1 parent eb2e910 commit a2b3992

File tree

2 files changed

+177
-43
lines changed

2 files changed

+177
-43
lines changed

README.md

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,115 @@ object. Using the `fetchEvent` requires enabling the `http` feature.
212212

213213
```ts
214214
export function componentize(opts: {
215-
sourcePath: string,
216-
witPath: string,
217-
worldName: string,
218-
debug?: bool,
219-
debugBuild?: bool,
220-
engine?: string,
221-
preview2Adapter?: string,
222-
disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http', 'fetch-event')[],
223-
}): {
224-
component: Uint8Array,
225-
imports: string[]
226-
}
215+
/**
216+
* The path to the file to componentize.
217+
*
218+
* This file must be a valid JavaScript module, and can import other modules using relative paths.
219+
*/
220+
sourcePath: string;
221+
/**
222+
* Path to WIT file or folder
223+
*/
224+
witPath?: string;
225+
/**
226+
* Target world name for componentization
227+
*/
228+
worldName?: string;
229+
/**
230+
* Path to custom ComponentizeJS engine build to use
231+
*/
232+
engine?: string;
233+
/**
234+
* Path to custom weval cache to use
235+
*/
236+
aotCache?: string;
237+
/**
238+
* Enable AoT using weval
239+
*/
240+
enableAot?: boolean;
241+
/**
242+
* Use a pre-existing path to the `weval` binary, if present
243+
*/
244+
wevalBin?: string;
245+
/**
246+
* Use a pre-existing path to the `wizer` binary, if present
247+
*/
248+
wizerBin?: string;
249+
/**
250+
* Path to custom Preview2 Adapter
251+
*/
252+
preview2Adapter?: string;
253+
/**
254+
* Disable WASI features in the base engine
255+
* Disabling all features results in a pure component with no WASI dependence
256+
*
257+
* - stdio: console.log(), console.error and errors are provided to stderr
258+
* - random: Math.random() and crypto.randomBytes()
259+
* - clocks: Date.now(), performance.now()
260+
* - http: fetch() support
261+
*
262+
*/
263+
disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http' | 'fetch-event')[];
264+
/**
265+
* Enable WASI features in the base engine
266+
* (no experimental subsystems currently supported)
267+
*/
268+
enableFeatures?: [];
269+
/**
270+
* Pass environment variables to the spawned Wizer or Weval Process
271+
* If set to true, all host environment variables are passed
272+
* To pass only a subset, provide an object with the desired variables
273+
*/
274+
env?: boolean | Record<string, string>;
275+
/**
276+
* Runtime arguments to provide to the StarlingMonkey engine initialization
277+
* (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h)
278+
*/
279+
runtimeArgs?: string;
280+
/**
281+
* Use a debug build
282+
* Note that the debug build only includes the names section only for size optimization, and not DWARF
283+
* debugging sections, due to a lack of support in Node.js for these debugging workflows currently.
284+
*/
285+
debugBuild?: boolean;
286+
/**
287+
* Debug options
288+
*/
289+
debug?: {
290+
/** Whether to enable bindings-specific debugging */
291+
bindings?: boolean;
292+
/** Path to debug bindings to use */
293+
bindingsDir?: string;
294+
/** Whether to enable binary-specific debugging */
295+
binary?: boolean;
296+
/** Path to enable binary-specific debugging */
297+
binaryPath?: string;
298+
/** Whether to enable wizer logging */
299+
wizerLogging: false;
300+
}
301+
}): Promise<{
302+
/**
303+
* Component binary
304+
*/
305+
component: Uint8Array;
306+
/**
307+
* Used guest imports in JavaScript (excluding those from StarlingMonkey engine)
308+
*/
309+
imports: [[string, string]][];
310+
/**
311+
* Debugging output (only present if enabled)
312+
*/
313+
debug?: {
314+
/** Whether bindings debugging was enabled */
315+
bindings?: boolean;
316+
/** Work directory used during processing */
317+
workDir?: string;
318+
/** Whether binary debugging was enabled */
319+
binary?: boolean;
320+
/** Path to the produced binary */
321+
binaryPath?: string;
322+
};
323+
}>
227324
```
228325

229326
Converts a JS source into a component binary.

types.d.ts

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,108 @@ interface ComponentizeOptions {
44
*
55
* This file must be a valid JavaScript module, and can import other modules using relative paths.
66
*/
7-
sourcePath: string,
7+
sourcePath: string;
88
/**
9-
* Use a debug build
10-
* Note that the debug build only includes the names section only for size optimization, and not DWARF
11-
* debugging sections, due to a lack of support in Node.js for these debugging workflows currently.
9+
* Path to WIT file or folder
1210
*/
13-
debugBuild?: boolean,
11+
witPath?: string;
12+
/**
13+
* Target world name for componentization
14+
*/
15+
worldName?: string;
1416
/**
1517
* Path to custom ComponentizeJS engine build to use
1618
*/
17-
engine?: string,
19+
engine?: string;
1820
/**
1921
* Path to custom weval cache to use
2022
*/
21-
aotCache?: string,
23+
aotCache?: string;
2224
/**
2325
* Enable AoT using weval
2426
*/
25-
enableAot?: boolean,
27+
enableAot?: boolean;
2628
/**
2729
* Use a pre-existing path to the `weval` binary, if present
2830
*/
29-
wevalBin?: string,
31+
wevalBin?: string;
3032
/**
3133
* Use a pre-existing path to the `wizer` binary, if present
3234
*/
33-
wizerBin?: string,
35+
wizerBin?: string;
3436
/**
3537
* Path to custom Preview2 Adapter
3638
*/
37-
preview2Adapter?: string,
38-
/**
39-
* Path to WIT file or folder
40-
*/
41-
witPath?: string,
42-
/**
43-
* Target world name for componentization
44-
*/
45-
worldName?: string,
39+
preview2Adapter?: string;
4640
/**
4741
* Disable WASI features in the base engine
4842
* Disabling all features results in a pure component with no WASI dependence
49-
*
43+
*
5044
* - stdio: console.log(), console.error and errors are provided to stderr
5145
* - random: Math.random() and crypto.randomBytes()
5246
* - clocks: Date.now(), performance.now()
5347
* - http: fetch() support
54-
*
48+
*
5549
*/
56-
disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http')[],
50+
disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http' | 'fetch-event')[];
5751
/**
5852
* Enable WASI features in the base engine
5953
* (no experimental subsystems currently supported)
6054
*/
61-
enableFeatures?: [],
55+
enableFeatures?: [];
6256
/**
6357
* Pass environment variables to the spawned Wizer or Weval Process
6458
* If set to true, all host environment variables are passed
6559
* To pass only a subset, provide an object with the desired variables
6660
*/
67-
env?: boolean | Record<string, string>,
61+
env?: boolean | Record<string, string>;
6862
/**
6963
* Runtime arguments to provide to the StarlingMonkey engine initialization
7064
* (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h)
7165
*/
72-
runtimeArgs?: string,
66+
runtimeArgs?: string;
67+
/**
68+
* Use a debug build
69+
* Note that the debug build only includes the names section only for size optimization, and not DWARF
70+
* debugging sections, due to a lack of support in Node.js for these debugging workflows currently.
71+
*/
72+
debugBuild?: boolean;
73+
/**
74+
* Debug options
75+
*/
76+
debug?: {
77+
/** Whether to enable bindings-specific debugging */
78+
bindings?: boolean;
79+
/** Path to debug bindings to use */
80+
bindingsDir?: string;
81+
/** Whether to enable binary-specific debugging */
82+
binary?: boolean;
83+
/** Path to the binary that was output */
84+
binaryPath?: string;
85+
/** Whether to enable wizer logging */
86+
wizerLogging: false;
87+
};
7388
}
7489

7590
/**
7691
* Componentize a JavaScript module to a WebAssembly component
7792
*
7893
* @param opts Componentize options
7994
*/
80-
export function componentize(opts: ComponentizeOptions): Promise<ComponentizeOutput>
95+
export function componentize(
96+
opts: ComponentizeOptions,
97+
): Promise<ComponentizeOutput>;
8198

8299
/**
83100
* @deprecated Use `componentize(opts)` instead
84101
*
85102
* @param source Source code of JavaScript module to componentize
86103
* @param opts Componentize options
87104
*/
88-
export function componentize(source: string, opts: ComponentizeOptions): Promise<ComponentizeOutput>
105+
export function componentize(
106+
source: string,
107+
opts: ComponentizeOptions,
108+
): Promise<ComponentizeOutput>;
89109

90110
/**
91111
* @deprecated Use `componentize(opts)` instead
@@ -94,20 +114,37 @@ export function componentize(source: string, opts: ComponentizeOptions): Promise
94114
* @param witWorld Inline WIT string to componentize to
95115
* @param opts Componentize options
96116
*/
97-
export function componentize(source: string, witWorld: string, opts?: ComponentizeOptions): Promise<ComponentizeOutput>
117+
export function componentize(
118+
source: string,
119+
witWorld: string,
120+
opts?: ComponentizeOptions,
121+
): Promise<ComponentizeOutput>;
98122

99123
interface ComponentizeOutput {
100124
/**
101125
* Component binary
102126
*/
103-
component: Uint8Array,
127+
component: Uint8Array;
104128
/**
105129
* Used guest imports in JavaScript (excluding those from StarlingMonkey engine)
106130
*/
107-
imports: [[string, string]][]
131+
imports: [[string, string]][];
132+
/**
133+
* Debugging output (only present if enabled)
134+
*/
135+
debug?: {
136+
/** Whether bindings debugging was enabled */
137+
bindings?: boolean;
138+
/** Work directory used during processing */
139+
workDir?: string;
140+
/** Whether binary debugging was enabled */
141+
binary?: boolean;
142+
/** Path to the produced binary */
143+
binaryPath?: string;
144+
};
108145
}
109146

110147
/**
111148
* ComponentizeJS version string
112149
*/
113-
export const version: string
150+
export const version: string;

0 commit comments

Comments
 (0)