@bytecodealliance/jco 0.13.3 → 0.14.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.
Files changed (44) hide show
  1. package/README.md +23 -21
  2. package/lib/wasi_snapshot_preview1.command.wasm +0 -0
  3. package/lib/wasi_snapshot_preview1.reactor.wasm +0 -0
  4. package/obj/interfaces/wasi-filesystem-types.d.ts +1 -6
  5. package/obj/interfaces/wasi-io-error.d.ts +6 -0
  6. package/obj/interfaces/wasi-io-streams.d.ts +7 -9
  7. package/obj/js-component-bindgen-component.component.wasm +0 -0
  8. package/obj/js-component-bindgen-component.core.wasm +0 -0
  9. package/obj/js-component-bindgen-component.core2.wasm +0 -0
  10. package/obj/js-component-bindgen-component.d.ts +11 -2
  11. package/obj/js-component-bindgen-component.js +478 -453
  12. package/obj/wasm-tools.component.wasm +0 -0
  13. package/obj/wasm-tools.core.wasm +0 -0
  14. package/obj/wasm-tools.core2.wasm +0 -0
  15. package/obj/wasm-tools.d.ts +1 -0
  16. package/obj/wasm-tools.js +408 -420
  17. package/package.json +7 -5
  18. package/src/api.d.ts +42 -0
  19. package/src/api.d.ts.map +1 -0
  20. package/src/browser.d.ts +3 -0
  21. package/src/browser.d.ts.map +1 -0
  22. package/src/browser.js +11 -3
  23. package/src/cmd/componentize.d.ts +2 -0
  24. package/src/cmd/componentize.d.ts.map +1 -0
  25. package/src/cmd/componentize.js +1 -0
  26. package/src/cmd/opt.d.ts +15 -0
  27. package/src/cmd/opt.d.ts.map +1 -0
  28. package/src/cmd/run.d.ts +2 -0
  29. package/src/cmd/run.d.ts.map +1 -0
  30. package/src/cmd/run.js +22 -6
  31. package/src/cmd/transpile.d.ts +44 -0
  32. package/src/cmd/transpile.d.ts.map +1 -0
  33. package/src/cmd/transpile.js +206 -47
  34. package/src/cmd/wasm-tools.d.ts +8 -0
  35. package/src/cmd/wasm-tools.d.ts.map +1 -0
  36. package/src/cmd/wasm-tools.js +3 -2
  37. package/src/common.d.ts +16 -0
  38. package/src/common.d.ts.map +1 -0
  39. package/src/common.js +3 -0
  40. package/src/jco.d.ts +3 -0
  41. package/src/jco.d.ts.map +1 -0
  42. package/src/jco.js +9 -4
  43. package/src/ora-shim.d.ts +7 -0
  44. package/src/ora-shim.d.ts.map +1 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <h1><code>jco</code></h1>
3
3
 
4
4
  <p>
5
- <strong>JavaScript component toolchain for working with <a href="https://github.com/WebAssembly/component-model">WebAssembly Components</a></strong>
5
+ <strong>JavaScript toolchain for working with <a href="https://github.com/WebAssembly/component-model">WebAssembly Components</a></strong>
6
6
  </p>
7
7
 
8
8
  <strong>A <a href="https://bytecodealliance.org/">Bytecode Alliance</a> project</strong>
@@ -14,18 +14,18 @@
14
14
 
15
15
  ## Overview
16
16
 
17
- `jco` is a fully native JS tool for working with the emerging [WebAssembly Components](https://github.com/WebAssembly/component-model) specification in JavaScript.
17
+ `jco` is a fully native JS tool for working with [WebAssembly Components](https://github.com/WebAssembly/component-model) in JavaScript.
18
18
 
19
19
  Features include:
20
20
 
21
21
  * "Transpiling" Wasm Component binaries into ES modules that can run in any JS environment.
22
- * Optimization helpers for Components via Binaryen.
23
- * Component builds of [Wasm Tools](https://github.com/bytecodealliance/wasm-tools) helpers, available for use as a library or CLI commands for use in native JS environments.
24
- * "Componentize" for WebAssembly Components from JavaScript sources and a WIT world
22
+ * WASI Preview2 support in Node.js ([undergoing stabilization](https://github.com/bytecodealliance/jco/milestone/1)) & browsers (experimental).
23
+ * Component builds of [Wasm Tools](https://github.com/bytecodealliance/wasm-tools) helpers, available for use as a library or CLI commands for use in native JS environments, as well as optimization helper for Components via Binaryen.
24
+ * "Componentize" command to easily create components written in JavaScript (wrapper of [ComponentizeJS](https://github.com/bytecodealliance/ComponentizeJS)).
25
25
 
26
26
  For creating components in other languages, see the [Cargo Component](https://github.com/bytecodealliance/cargo-Component) project for Rust and [Wit Bindgen](https://github.com/bytecodealliance/wit-bindgen) for various guest bindgen helpers.
27
27
 
28
- > **Note**: This is an experimental project, no guarantees are provided for stability or support and breaking changes may be made in future.
28
+ > **Note**: This is an experimental project, no guarantees are provided for stability, security or support and breaking changes may be made without notice.
29
29
 
30
30
  ## Installation
31
31
 
@@ -33,7 +33,7 @@ For creating components in other languages, see the [Cargo Component](https://gi
33
33
  npm install @bytecodealliance/jco
34
34
  ```
35
35
 
36
- jco can be used as either a library or as a CLI via the `jco` CLI command.
36
+ jco can be used as either a library or a CLI via the `jco` CLI command.
37
37
 
38
38
  ## Example
39
39
 
@@ -101,13 +101,27 @@ Options include:
101
101
  * `--no-wasi-shim`: Disable the WASI shim mapping to `@bytecodealliance/preview2-shim`.
102
102
  * `--map`: Provide custom mappings for world imports. Supports both wildcard mappings (`*` similarly as in the package.json "exports" field) as well as `#` mappings for targetting exported interfaces. For example, the WASI mappings are internally defined with mappings like `--map wasi:filesystem/*=@bytecodealliance/preview2-shim/filesystem#*` to map `import as * filesystem from 'wasi:filesystem/types'` to `import { types } from '@bytecodealliance/preview2-shim/filesystem`.
103
103
  * `--no-nodejs-compat`: Disables Node.js compat in the output to load core Wasm with FS methods.
104
- * `--instantiation`: Instead of a direct ES module, export an `instantiate` function which can take the imports as an argument instead of implicit imports.
104
+ * `--instantiation [mode]`: Instead of a direct ES module, export an `instantiate` function which can take the imports as an argument instead of implicit imports. The `instantiate` function can be async (with `--instantiation` or `--instantiation async`), or sync (with `--instantiation sync`).
105
105
  * `--valid-lifting-optimization`: Internal validations are removed assuming that core Wasm binaries are valid components, providing a minor output size saving.
106
+ * `--tracing`: Emit tracing calls for all function entry and exits.
107
+ * `--no-namespaced-exports`: Removes exports of the type `test as "test:flavorful/test"` which are not compatible with typescript
106
108
 
107
109
  #### Bindgen Crate
108
110
 
109
111
  To directly call into the transpilation in Rust, the bindgen used in jco is also available on crates.io as [js-component-bindgen](https://crates.io/crates/js-component-bindgen).
110
112
 
113
+ ### Run
114
+
115
+ For Wasm components that implement the WASI Command world, a `jco run` utility is provided to run these applications in Node.js:
116
+
117
+ ```
118
+ jco run cowasy.component.wasm hello
119
+ ```
120
+
121
+ Using the preview2-shim WASI implementation, full access to the underlying system primitives is provided, including filesystem and environment variable permissions.
122
+
123
+ > [preview2-shim](packages/preview2-shim) is currently being stabilized in Node.js, tracking in https://github.com/bytecodealliance/jco/milestone/1.
124
+
111
125
  ### Componentize
112
126
 
113
127
  To componentize a JS file run:
@@ -122,19 +136,7 @@ Currently requires an explicit install of the componentize-js engine via `npm in
122
136
 
123
137
  See [ComponentizeJS](https://github.com/bytecodealliance/componentize-js) for more details on this process.
124
138
 
125
- > Additional engines may be supported in future via an `--engine` field or otherwise.
126
-
127
- ### Run
128
-
129
- For Wasm components that implement the WASI Command world, a `jco run` utility is provided to run these applications in Node.js:
130
-
131
- ```
132
- jco run cowasy.component.wasm hello
133
- ```
134
-
135
- Using the preview2-shim WASI implementation, full access to the underlying system primitives is provided, including filesystem and environment variable permissions.
136
-
137
- > Since [preview2-shim](packages/preview2-shim) is an experimental work-in-progress implementation, there will likely be bugs.
139
+ > Additional engines might be supported in future via an `--engine` field or otherwise.
138
140
 
139
141
  ## API
140
142
 
@@ -134,11 +134,6 @@ export interface DescriptorFlags {
134
134
  requestedWriteSync?: boolean,
135
135
  mutateDirectory?: boolean,
136
136
  }
137
- export interface Modes {
138
- readable?: boolean,
139
- writable?: boolean,
140
- executable?: boolean,
141
- }
142
137
  export interface MetadataHashValue {
143
138
  lower: bigint,
144
139
  upper: bigint,
@@ -155,6 +150,6 @@ export class Descriptor {
155
150
  appendViaStream(): OutputStream;
156
151
  getType(): DescriptorType;
157
152
  stat(): DescriptorStat;
158
- openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
153
+ openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags): Descriptor;
159
154
  metadataHash(): MetadataHashValue;
160
155
  }
@@ -0,0 +1,6 @@
1
+ export namespace WasiIoError {
2
+ export { Error };
3
+ }
4
+
5
+ export class Error {
6
+ }
@@ -1,8 +1,9 @@
1
1
  export namespace WasiIoStreams {
2
2
  export { InputStream };
3
3
  export { OutputStream };
4
- export { Error };
5
4
  }
5
+ import type { Error } from '../interfaces/wasi-io-error.js';
6
+ export { Error };
6
7
  export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
7
8
  export interface StreamErrorLastOperationFailed {
8
9
  tag: 'last-operation-failed',
@@ -12,17 +13,14 @@ export interface StreamErrorClosed {
12
13
  tag: 'closed',
13
14
  }
14
15
 
15
- export class OutputStream {
16
- checkWrite(): bigint;
17
- write(contents: Uint8Array): void;
18
- blockingWriteAndFlush(contents: Uint8Array): void;
19
- blockingFlush(): void;
20
- }
21
-
22
16
  export class InputStream {
23
17
  read(len: bigint): Uint8Array;
24
18
  blockingRead(len: bigint): Uint8Array;
25
19
  }
26
20
 
27
- export class Error {
21
+ export class OutputStream {
22
+ checkWrite(): bigint;
23
+ write(contents: Uint8Array): void;
24
+ blockingWriteAndFlush(contents: Uint8Array): void;
25
+ blockingFlush(): void;
28
26
  }
@@ -1,9 +1,16 @@
1
1
  export type Files = [string, Uint8Array][];
2
2
  export type Maps = [string, string][];
3
+ export type InstantiationMode = InstantiationModeAsync | InstantiationModeSync;
4
+ export interface InstantiationModeAsync {
5
+ tag: 'async',
6
+ }
7
+ export interface InstantiationModeSync {
8
+ tag: 'sync',
9
+ }
3
10
  export interface GenerateOptions {
4
11
  name: string,
5
12
  noTypescript?: boolean,
6
- instantiation?: boolean,
13
+ instantiation?: InstantiationMode,
7
14
  map?: Maps,
8
15
  compat?: boolean,
9
16
  noNodejsCompat?: boolean,
@@ -11,6 +18,7 @@ export interface GenerateOptions {
11
18
  tlaCompat?: boolean,
12
19
  validLiftingOptimization?: boolean,
13
20
  tracing?: boolean,
21
+ noNamespacedExports?: boolean,
14
22
  }
15
23
  export type Wit = WitSource | WitBinary | WitPath;
16
24
  export interface WitSource {
@@ -29,7 +37,7 @@ export interface TypeGenerationOptions {
29
37
  wit: Wit,
30
38
  world?: string,
31
39
  tlaCompat?: boolean,
32
- instantiation?: boolean,
40
+ instantiation?: InstantiationMode,
33
41
  map?: Maps,
34
42
  }
35
43
  /**
@@ -58,6 +66,7 @@ import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout.js'
58
66
  import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock.js';
59
67
  import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens.js';
60
68
  import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types.js';
69
+ import { WasiIoError } from './interfaces/wasi-io-error.js';
61
70
  import { WasiIoStreams } from './interfaces/wasi-io-streams.js';
62
71
  import { WasiRandomRandom } from './interfaces/wasi-random-random.js';
63
72
  import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp.js';