@bytecodealliance/jco 0.13.0 → 0.13.2

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 (35) hide show
  1. package/obj/interfaces/wasi-cli-stderr.d.ts +1 -1
  2. package/obj/interfaces/wasi-cli-stdin.d.ts +1 -1
  3. package/obj/interfaces/wasi-cli-stdout.d.ts +1 -1
  4. package/obj/interfaces/wasi-cli-terminal-input.d.ts +4 -2
  5. package/obj/interfaces/wasi-cli-terminal-output.d.ts +4 -2
  6. package/obj/interfaces/wasi-cli-terminal-stderr.d.ts +1 -1
  7. package/obj/interfaces/wasi-cli-terminal-stdin.d.ts +1 -1
  8. package/obj/interfaces/wasi-cli-terminal-stdout.d.ts +1 -1
  9. package/obj/interfaces/wasi-filesystem-preopens.d.ts +1 -1
  10. package/obj/interfaces/wasi-filesystem-types.d.ts +24 -17
  11. package/obj/interfaces/wasi-io-streams.d.ts +26 -26
  12. package/obj/interfaces/wasi-sockets-tcp.d.ts +4 -0
  13. package/obj/js-component-bindgen-component.component.wasm +0 -0
  14. package/obj/js-component-bindgen-component.core.wasm +0 -0
  15. package/obj/js-component-bindgen-component.d.ts +16 -16
  16. package/obj/wasm-tools.d.ts +16 -16
  17. package/package.json +4 -4
  18. package/src/cmd/run.js +21 -27
  19. package/src/jco.js +1 -1
  20. package/obj/interfaces/wasi-cli-environment-0.2.0-rc-2023-11-05.d.ts +0 -3
  21. package/obj/interfaces/wasi-cli-exit-0.2.0-rc-2023-11-05.d.ts +0 -4
  22. package/obj/interfaces/wasi-cli-stderr-0.2.0-rc-2023-11-05.d.ts +0 -5
  23. package/obj/interfaces/wasi-cli-stdin-0.2.0-rc-2023-11-05.d.ts +0 -5
  24. package/obj/interfaces/wasi-cli-stdout-0.2.0-rc-2023-11-05.d.ts +0 -5
  25. package/obj/interfaces/wasi-cli-terminal-input-0.2.0-rc-2023-11-05.d.ts +0 -2
  26. package/obj/interfaces/wasi-cli-terminal-output-0.2.0-rc-2023-11-05.d.ts +0 -2
  27. package/obj/interfaces/wasi-cli-terminal-stderr-0.2.0-rc-2023-11-05.d.ts +0 -5
  28. package/obj/interfaces/wasi-cli-terminal-stdin-0.2.0-rc-2023-11-05.d.ts +0 -5
  29. package/obj/interfaces/wasi-cli-terminal-stdout-0.2.0-rc-2023-11-05.d.ts +0 -5
  30. package/obj/interfaces/wasi-clocks-wall-clock-0.2.0-rc-2023-11-05.d.ts +0 -6
  31. package/obj/interfaces/wasi-filesystem-preopens-0.2.0-rc-2023-11-05.d.ts +0 -5
  32. package/obj/interfaces/wasi-filesystem-types-0.2.0-rc-2023-11-05.d.ts +0 -156
  33. package/obj/interfaces/wasi-io-streams-0.2.0-rc-2023-11-05.d.ts +0 -24
  34. package/obj/interfaces/wasi-random-random-0.2.0-rc-2023-11-05.d.ts +0 -3
  35. package/obj/interfaces/wasi-sockets-tcp-0.2.0-rc-2023-11-05.d.ts +0 -2
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliStderr {
2
2
  export function getStderr(): OutputStream;
3
3
  }
4
- import type { OutputStream } from '../interfaces/wasi-io-streams';
4
+ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
5
5
  export { OutputStream };
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliStdin {
2
2
  export function getStdin(): InputStream;
3
3
  }
4
- import type { InputStream } from '../interfaces/wasi-io-streams';
4
+ import type { InputStream } from '../interfaces/wasi-io-streams.js';
5
5
  export { InputStream };
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliStdout {
2
2
  export function getStdout(): OutputStream;
3
3
  }
4
- import type { OutputStream } from '../interfaces/wasi-io-streams';
4
+ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
5
5
  export { OutputStream };
@@ -1,4 +1,6 @@
1
1
  export namespace WasiCliTerminalInput {
2
- export function dropTerminalInput(this_: TerminalInput): void;
2
+ export { TerminalInput };
3
+ }
4
+
5
+ export class TerminalInput {
3
6
  }
4
- export type TerminalInput = number;
@@ -1,4 +1,6 @@
1
1
  export namespace WasiCliTerminalOutput {
2
- export function dropTerminalOutput(this_: TerminalOutput): void;
2
+ export { TerminalOutput };
3
+ }
4
+
5
+ export class TerminalOutput {
3
6
  }
4
- export type TerminalOutput = number;
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliTerminalStderr {
2
2
  export function getTerminalStderr(): TerminalOutput | undefined;
3
3
  }
4
- import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output';
4
+ import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output.js';
5
5
  export { TerminalOutput };
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliTerminalStdin {
2
2
  export function getTerminalStdin(): TerminalInput | undefined;
3
3
  }
4
- import type { TerminalInput } from '../interfaces/wasi-cli-terminal-input';
4
+ import type { TerminalInput } from '../interfaces/wasi-cli-terminal-input.js';
5
5
  export { TerminalInput };
@@ -1,5 +1,5 @@
1
1
  export namespace WasiCliTerminalStdout {
2
2
  export function getTerminalStdout(): TerminalOutput | undefined;
3
3
  }
4
- import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output';
4
+ import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output.js';
5
5
  export { TerminalOutput };
@@ -1,5 +1,5 @@
1
1
  export namespace WasiFilesystemPreopens {
2
2
  export function getDirectories(): [Descriptor, string][];
3
3
  }
4
- import type { Descriptor } from '../interfaces/wasi-filesystem-types';
4
+ import type { Descriptor } from '../interfaces/wasi-filesystem-types.js';
5
5
  export { Descriptor };
@@ -1,17 +1,10 @@
1
1
  export namespace WasiFilesystemTypes {
2
- export function readViaStream(this_: Descriptor, offset: Filesize): InputStream;
3
- export function writeViaStream(this_: Descriptor, offset: Filesize): OutputStream;
4
- export function appendViaStream(this_: Descriptor): OutputStream;
5
- export function getType(this_: Descriptor): DescriptorType;
6
- export function stat(this_: Descriptor): DescriptorStat;
7
- export function openAt(this_: Descriptor, pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
8
- export function dropDescriptor(this_: Descriptor): void;
9
- export function dropDirectoryEntryStream(this_: DirectoryEntryStream): void;
10
- export function metadataHash(this_: Descriptor): MetadataHashValue;
2
+ export { Descriptor };
3
+ export function filesystemErrorCode(err: Error): ErrorCode | undefined;
4
+ export { DirectoryEntryStream };
11
5
  }
12
- export type Descriptor = number;
13
6
  export type Filesize = bigint;
14
- import type { InputStream } from '../interfaces/wasi-io-streams';
7
+ import type { InputStream } from '../interfaces/wasi-io-streams.js';
15
8
  export { InputStream };
16
9
  /**
17
10
  * # Variants
@@ -91,7 +84,7 @@ export { InputStream };
91
84
  * ## `"cross-device"`
92
85
  */
93
86
  export type ErrorCode = 'access' | 'would-block' | 'already' | 'bad-descriptor' | 'busy' | 'deadlock' | 'quota' | 'exist' | 'file-too-large' | 'illegal-byte-sequence' | 'in-progress' | 'interrupted' | 'invalid' | 'io' | 'is-directory' | 'loop' | 'too-many-links' | 'message-size' | 'name-too-long' | 'no-device' | 'no-entry' | 'no-lock' | 'insufficient-memory' | 'insufficient-space' | 'not-directory' | 'not-empty' | 'not-recoverable' | 'unsupported' | 'no-tty' | 'no-such-device' | 'overflow' | 'not-permitted' | 'pipe' | 'read-only' | 'invalid-seek' | 'text-file-busy' | 'cross-device';
94
- import type { OutputStream } from '../interfaces/wasi-io-streams';
87
+ import type { OutputStream } from '../interfaces/wasi-io-streams.js';
95
88
  export { OutputStream };
96
89
  /**
97
90
  * # Variants
@@ -114,15 +107,15 @@ export { OutputStream };
114
107
  */
115
108
  export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
116
109
  export type LinkCount = bigint;
117
- import type { Datetime } from '../interfaces/wasi-clocks-wall-clock';
110
+ import type { Datetime } from '../interfaces/wasi-clocks-wall-clock.js';
118
111
  export { Datetime };
119
112
  export interface DescriptorStat {
120
113
  type: DescriptorType,
121
114
  linkCount: LinkCount,
122
115
  size: Filesize,
123
- dataAccessTimestamp: Datetime,
124
- dataModificationTimestamp: Datetime,
125
- statusChangeTimestamp: Datetime,
116
+ dataAccessTimestamp?: Datetime,
117
+ dataModificationTimestamp?: Datetime,
118
+ statusChangeTimestamp?: Datetime,
126
119
  }
127
120
  export interface PathFlags {
128
121
  symlinkFollow?: boolean,
@@ -146,8 +139,22 @@ export interface Modes {
146
139
  writable?: boolean,
147
140
  executable?: boolean,
148
141
  }
149
- export type DirectoryEntryStream = number;
150
142
  export interface MetadataHashValue {
151
143
  lower: bigint,
152
144
  upper: bigint,
153
145
  }
146
+ import type { Error } from '../interfaces/wasi-io-streams.js';
147
+ export { Error };
148
+
149
+ export class Descriptor {
150
+ readViaStream(offset: Filesize): InputStream;
151
+ writeViaStream(offset: Filesize): OutputStream;
152
+ appendViaStream(): OutputStream;
153
+ getType(): DescriptorType;
154
+ stat(): DescriptorStat;
155
+ openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
156
+ metadataHash(): MetadataHashValue;
157
+ }
158
+
159
+ export class DirectoryEntryStream {
160
+ }
@@ -1,28 +1,28 @@
1
1
  export namespace WasiIoStreams {
2
- export function read(this_: InputStream, len: bigint): [Uint8Array, StreamStatus];
3
- export function blockingRead(this_: InputStream, len: bigint): [Uint8Array, StreamStatus];
4
- export function dropInputStream(this_: InputStream): void;
5
- export function checkWrite(this_: OutputStream): bigint;
6
- export function write(this_: OutputStream, contents: Uint8Array): void;
7
- export function blockingWriteAndFlush(this_: OutputStream, contents: Uint8Array): void;
8
- export function blockingFlush(this_: OutputStream): void;
9
- export function dropOutputStream(this_: OutputStream): void;
2
+ export { InputStream };
3
+ export { OutputStream };
4
+ export { Error };
5
+ }
6
+ export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
7
+ export interface StreamErrorLastOperationFailed {
8
+ tag: 'last-operation-failed',
9
+ val: Error,
10
+ }
11
+ export interface StreamErrorClosed {
12
+ tag: 'closed',
13
+ }
14
+
15
+ export class Error {
16
+ }
17
+
18
+ export class InputStream {
19
+ read(len: bigint): Uint8Array;
20
+ blockingRead(len: bigint): Uint8Array;
21
+ }
22
+
23
+ export class OutputStream {
24
+ checkWrite(): bigint;
25
+ write(contents: Uint8Array): void;
26
+ blockingWriteAndFlush(contents: Uint8Array): void;
27
+ blockingFlush(): void;
10
28
  }
11
- export type InputStream = number;
12
- /**
13
- * # Variants
14
- *
15
- * ## `"open"`
16
- *
17
- * ## `"ended"`
18
- */
19
- export type StreamStatus = 'open' | 'ended';
20
- export type OutputStream = number;
21
- /**
22
- * # Variants
23
- *
24
- * ## `"last-operation-failed"`
25
- *
26
- * ## `"closed"`
27
- */
28
- export type WriteError = 'last-operation-failed' | 'closed';
@@ -1,2 +1,6 @@
1
1
  export namespace WasiSocketsTcp {
2
+ export { TcpSocket };
3
+ }
4
+
5
+ export class TcpSocket {
2
6
  }
@@ -45,22 +45,22 @@ export interface Transpiled {
45
45
  imports: string[],
46
46
  exports: [string, ExportType][],
47
47
  }
48
- import { WasiCliEnvironment020rc20231105 } from './interfaces/wasi-cli-environment-0.2.0-rc-2023-11-05';
49
- import { WasiCliExit020rc20231105 } from './interfaces/wasi-cli-exit-0.2.0-rc-2023-11-05';
50
- import { WasiCliStderr020rc20231105 } from './interfaces/wasi-cli-stderr-0.2.0-rc-2023-11-05';
51
- import { WasiCliStdin020rc20231105 } from './interfaces/wasi-cli-stdin-0.2.0-rc-2023-11-05';
52
- import { WasiCliStdout020rc20231105 } from './interfaces/wasi-cli-stdout-0.2.0-rc-2023-11-05';
53
- import { WasiCliTerminalInput020rc20231105 } from './interfaces/wasi-cli-terminal-input-0.2.0-rc-2023-11-05';
54
- import { WasiCliTerminalOutput020rc20231105 } from './interfaces/wasi-cli-terminal-output-0.2.0-rc-2023-11-05';
55
- import { WasiCliTerminalStderr020rc20231105 } from './interfaces/wasi-cli-terminal-stderr-0.2.0-rc-2023-11-05';
56
- import { WasiCliTerminalStdin020rc20231105 } from './interfaces/wasi-cli-terminal-stdin-0.2.0-rc-2023-11-05';
57
- import { WasiCliTerminalStdout020rc20231105 } from './interfaces/wasi-cli-terminal-stdout-0.2.0-rc-2023-11-05';
58
- import { WasiClocksWallClock020rc20231105 } from './interfaces/wasi-clocks-wall-clock-0.2.0-rc-2023-11-05';
59
- import { WasiFilesystemPreopens020rc20231105 } from './interfaces/wasi-filesystem-preopens-0.2.0-rc-2023-11-05';
60
- import { WasiFilesystemTypes020rc20231105 } from './interfaces/wasi-filesystem-types-0.2.0-rc-2023-11-05';
61
- import { WasiIoStreams020rc20231105 } from './interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
62
- import { WasiRandomRandom020rc20231105 } from './interfaces/wasi-random-random-0.2.0-rc-2023-11-05';
63
- import { WasiSocketsTcp020rc20231105 } from './interfaces/wasi-sockets-tcp-0.2.0-rc-2023-11-05';
48
+ import { WasiCliEnvironment } from './interfaces/wasi-cli-environment';
49
+ import { WasiCliExit } from './interfaces/wasi-cli-exit';
50
+ import { WasiCliStderr } from './interfaces/wasi-cli-stderr';
51
+ import { WasiCliStdin } from './interfaces/wasi-cli-stdin';
52
+ import { WasiCliStdout } from './interfaces/wasi-cli-stdout';
53
+ import { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input';
54
+ import { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output';
55
+ import { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr';
56
+ import { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin';
57
+ import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout';
58
+ import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock';
59
+ import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens';
60
+ import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types';
61
+ import { WasiIoStreams } from './interfaces/wasi-io-streams';
62
+ import { WasiRandomRandom } from './interfaces/wasi-random-random';
63
+ import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp';
64
64
  export function generate(component: Uint8Array, options: GenerateOptions): Transpiled;
65
65
  export function generateTypes(name: string, options: TypeGenerationOptions): Files;
66
66
 
@@ -1,19 +1,19 @@
1
- import { WasiCliEnvironment020rc20231105 } from './interfaces/wasi-cli-environment-0.2.0-rc-2023-11-05';
2
- import { WasiCliExit020rc20231105 } from './interfaces/wasi-cli-exit-0.2.0-rc-2023-11-05';
3
- import { WasiCliStderr020rc20231105 } from './interfaces/wasi-cli-stderr-0.2.0-rc-2023-11-05';
4
- import { WasiCliStdin020rc20231105 } from './interfaces/wasi-cli-stdin-0.2.0-rc-2023-11-05';
5
- import { WasiCliStdout020rc20231105 } from './interfaces/wasi-cli-stdout-0.2.0-rc-2023-11-05';
6
- import { WasiCliTerminalInput020rc20231105 } from './interfaces/wasi-cli-terminal-input-0.2.0-rc-2023-11-05';
7
- import { WasiCliTerminalOutput020rc20231105 } from './interfaces/wasi-cli-terminal-output-0.2.0-rc-2023-11-05';
8
- import { WasiCliTerminalStderr020rc20231105 } from './interfaces/wasi-cli-terminal-stderr-0.2.0-rc-2023-11-05';
9
- import { WasiCliTerminalStdin020rc20231105 } from './interfaces/wasi-cli-terminal-stdin-0.2.0-rc-2023-11-05';
10
- import { WasiCliTerminalStdout020rc20231105 } from './interfaces/wasi-cli-terminal-stdout-0.2.0-rc-2023-11-05';
11
- import { WasiClocksWallClock020rc20231105 } from './interfaces/wasi-clocks-wall-clock-0.2.0-rc-2023-11-05';
12
- import { WasiFilesystemPreopens020rc20231105 } from './interfaces/wasi-filesystem-preopens-0.2.0-rc-2023-11-05';
13
- import { WasiFilesystemTypes020rc20231105 } from './interfaces/wasi-filesystem-types-0.2.0-rc-2023-11-05';
14
- import { WasiIoStreams020rc20231105 } from './interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
15
- import { WasiRandomRandom020rc20231105 } from './interfaces/wasi-random-random-0.2.0-rc-2023-11-05';
16
- import { WasiSocketsTcp020rc20231105 } from './interfaces/wasi-sockets-tcp-0.2.0-rc-2023-11-05';
1
+ import { WasiCliEnvironment } from './interfaces/wasi-cli-environment';
2
+ import { WasiCliExit } from './interfaces/wasi-cli-exit';
3
+ import { WasiCliStderr } from './interfaces/wasi-cli-stderr';
4
+ import { WasiCliStdin } from './interfaces/wasi-cli-stdin';
5
+ import { WasiCliStdout } from './interfaces/wasi-cli-stdout';
6
+ import { WasiCliTerminalInput } from './interfaces/wasi-cli-terminal-input';
7
+ import { WasiCliTerminalOutput } from './interfaces/wasi-cli-terminal-output';
8
+ import { WasiCliTerminalStderr } from './interfaces/wasi-cli-terminal-stderr';
9
+ import { WasiCliTerminalStdin } from './interfaces/wasi-cli-terminal-stdin';
10
+ import { WasiCliTerminalStdout } from './interfaces/wasi-cli-terminal-stdout';
11
+ import { WasiClocksWallClock } from './interfaces/wasi-clocks-wall-clock';
12
+ import { WasiFilesystemPreopens } from './interfaces/wasi-filesystem-preopens';
13
+ import { WasiFilesystemTypes } from './interfaces/wasi-filesystem-types';
14
+ import { WasiIoStreams } from './interfaces/wasi-io-streams';
15
+ import { WasiRandomRandom } from './interfaces/wasi-random-random';
16
+ import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp';
17
17
  import { LocalWasmToolsTools } from './interfaces/local-wasm-tools-tools';
18
18
  export const tools: typeof LocalWasmToolsTools;
19
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/jco",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "JavaScript tooling for working with WebAssembly Components",
5
5
  "author": "Guy Bedford",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "type": "module",
20
20
  "dependencies": {
21
- "@bytecodealliance/preview2-shim": "0.0.19",
21
+ "@bytecodealliance/preview2-shim": "0.0.20",
22
22
  "binaryen": "^111.0.0",
23
23
  "chalk-template": "^0.4.0",
24
24
  "commander": "^9.4.1",
@@ -27,7 +27,7 @@
27
27
  "terser": "^5.16.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@bytecodealliance/componentize-js": "^0.3.0",
30
+ "@bytecodealliance/componentize-js": "^0.4.0",
31
31
  "@types/node": "^18.11.17",
32
32
  "@typescript-eslint/eslint-plugin": "^5.41.0",
33
33
  "@typescript-eslint/parser": "^5.41.0",
@@ -52,7 +52,7 @@
52
52
  "homepage": "https://github.com/bytecodealliance/jco#readme",
53
53
  "scripts": {
54
54
  "build": "cargo xtask build workspace",
55
- "build:types:preview2-shim": "cargo xtask build shims",
55
+ "build:types:preview2-shim": "cargo xtask generate wasi-types",
56
56
  "lint": "eslint -c eslintrc.cjs lib/**/*.js packages/*/lib/**/*.js",
57
57
  "test": "mocha -u tdd test/test.js --timeout 120000"
58
58
  },
package/src/cmd/run.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { getTmpDir } from '../common.js';
2
2
  import { transpile } from './transpile.js';
3
- import { rm, stat, mkdir, writeFile, symlink, chmod } from 'node:fs/promises';
3
+ import { rm, stat, mkdir, writeFile, symlink } from 'node:fs/promises';
4
4
  import { basename, resolve, extname } from 'node:path';
5
- import { spawn } from 'node:child_process';
6
- import { argv0, exit } from 'node:process';
5
+ import { fork } from 'node:child_process';
6
+ import process from 'node:process';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import c from 'chalk-template';
9
9
 
10
10
  export async function run (componentPath, args) {
11
+ // Ensure that `args` is an array
12
+ args = [...args];
13
+
11
14
  const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity));
12
15
  const outDir = await getTmpDir();
13
- let cp;
14
16
  try {
15
17
  try {
16
18
  await transpile(componentPath, {
@@ -22,11 +24,9 @@ export async function run (componentPath, args) {
22
24
  });
23
25
  }
24
26
  catch (e) {
25
- console.error(c`{red ERR}: Unable to transpile command for execution`);
26
- throw e;
27
+ throw new Error('Unable to transpile command for execution', { cause: e });
27
28
  }
28
29
 
29
- await mkdir(resolve(outDir, 'node_modules', '@bytecodealliance'), { recursive: true });
30
30
  await writeFile(resolve(outDir, 'package.json'), JSON.stringify({ type: 'module' }));
31
31
 
32
32
  let preview2ShimPath = fileURLToPath(new URL('../../node_modules/@bytecodealliance/preview2-shim', import.meta.url));
@@ -38,14 +38,15 @@ export async function run (componentPath, args) {
38
38
  }
39
39
  catch {}
40
40
  let len = preview2ShimPath.length;
41
- preview2ShimPath = resolve(preview2ShimPath, '../../../node_modules/@bytecodealliance/preview2-shim');
41
+ preview2ShimPath = resolve(preview2ShimPath, '..', '..', '..', 'node_modules', '@bytecodealliance', 'preview2-shim');
42
42
  if (preview2ShimPath.length === len) {
43
- console.error(c`{red ERR}: Unable to locate the {bold @bytecodealliance/preview2-shim} package, make sure it is installed.`);
44
- return;
43
+ throw c`Unable to locate the {bold @bytecodealliance/preview2-shim} package, make sure it is installed.`;
45
44
  }
46
45
  }
47
46
 
48
- await symlink(preview2ShimPath, resolve(outDir, 'node_modules/@bytecodealliance/preview2-shim'), 'dir');
47
+ const modulesDir = resolve(outDir, 'node_modules', '@bytecodealliance');
48
+ await mkdir(modulesDir, { recursive: true });
49
+ await symlink(preview2ShimPath, resolve(modulesDir, 'preview2-shim'), 'dir');
49
50
 
50
51
  const runPath = resolve(outDir, '_run.js');
51
52
  await writeFile(runPath, `
@@ -71,24 +72,17 @@ export async function run (componentPath, args) {
71
72
  throw e;
72
73
  }
73
74
  `);
74
- await chmod(runPath, 0o777);
75
75
 
76
- cp = spawn(argv0, [runPath, ...args], { stdio: 'inherit' });
76
+ process.exitCode = await new Promise((resolve, reject) => {
77
+ const cp = fork(runPath, args, { stdio: 'inherit' });
78
+
79
+ cp.on('error', reject);
80
+ cp.on('exit', resolve);
81
+ });
77
82
  }
78
83
  finally {
79
- if (!cp) {
80
- try {
81
- await rm(outDir, { recursive: true });
82
- } catch {}
83
- }
84
+ try {
85
+ await rm(outDir, { recursive: true });
86
+ } catch {}
84
87
  }
85
-
86
- const exitCode = await new Promise((resolve, reject) => {
87
- cp.on('error', reject);
88
- cp.on('exit', resolve);
89
- });
90
- try {
91
- await rm(outDir, { recursive: true });
92
- } catch {}
93
- exit(exitCode);
94
88
  }
package/src/jco.js CHANGED
@@ -11,7 +11,7 @@ program
11
11
  .name('jco')
12
12
  .description(c`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
13
13
  .usage('<command> [options]')
14
- .version('0.13.0');
14
+ .version('0.13.2');
15
15
 
16
16
  function myParseInt(value) {
17
17
  return parseInt(value, 10);
@@ -1,3 +0,0 @@
1
- export namespace WasiCliEnvironment020rc20231105 {
2
- export function getEnvironment(): [string, string][];
3
- }
@@ -1,4 +0,0 @@
1
- export namespace WasiCliExit020rc20231105 {
2
- export function exit(status: Result<void, void>): void;
3
- }
4
- export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliStderr020rc20231105 {
2
- export function getStderr(): OutputStream;
3
- }
4
- import type { OutputStream } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
5
- export { OutputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliStdin020rc20231105 {
2
- export function getStdin(): InputStream;
3
- }
4
- import type { InputStream } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
5
- export { InputStream };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliStdout020rc20231105 {
2
- export function getStdout(): OutputStream;
3
- }
4
- import type { OutputStream } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
5
- export { OutputStream };
@@ -1,2 +0,0 @@
1
- export namespace WasiCliTerminalInput020rc20231105 {
2
- }
@@ -1,2 +0,0 @@
1
- export namespace WasiCliTerminalOutput020rc20231105 {
2
- }
@@ -1,5 +0,0 @@
1
- export namespace WasiCliTerminalStderr020rc20231105 {
2
- export function getTerminalStderr(): TerminalOutput | undefined;
3
- }
4
- import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output-0.2.0-rc-2023-11-05';
5
- export { TerminalOutput };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliTerminalStdin020rc20231105 {
2
- export function getTerminalStdin(): TerminalInput | undefined;
3
- }
4
- import type { TerminalInput } from '../interfaces/wasi-cli-terminal-input-0.2.0-rc-2023-11-05';
5
- export { TerminalInput };
@@ -1,5 +0,0 @@
1
- export namespace WasiCliTerminalStdout020rc20231105 {
2
- export function getTerminalStdout(): TerminalOutput | undefined;
3
- }
4
- import type { TerminalOutput } from '../interfaces/wasi-cli-terminal-output-0.2.0-rc-2023-11-05';
5
- export { TerminalOutput };
@@ -1,6 +0,0 @@
1
- export namespace WasiClocksWallClock020rc20231105 {
2
- }
3
- export interface Datetime {
4
- seconds: bigint,
5
- nanoseconds: number,
6
- }
@@ -1,5 +0,0 @@
1
- export namespace WasiFilesystemPreopens020rc20231105 {
2
- export function getDirectories(): [Descriptor, string][];
3
- }
4
- import type { Descriptor } from '../interfaces/wasi-filesystem-types-0.2.0-rc-2023-11-05';
5
- export { Descriptor };
@@ -1,156 +0,0 @@
1
- export namespace WasiFilesystemTypes020rc20231105 {
2
- export { Descriptor };
3
- export function filesystemErrorCode(err: Error): ErrorCode | undefined;
4
- }
5
- export type Filesize = bigint;
6
- import type { InputStream } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
7
- export { InputStream };
8
- /**
9
- * # Variants
10
- *
11
- * ## `"access"`
12
- *
13
- * ## `"would-block"`
14
- *
15
- * ## `"already"`
16
- *
17
- * ## `"bad-descriptor"`
18
- *
19
- * ## `"busy"`
20
- *
21
- * ## `"deadlock"`
22
- *
23
- * ## `"quota"`
24
- *
25
- * ## `"exist"`
26
- *
27
- * ## `"file-too-large"`
28
- *
29
- * ## `"illegal-byte-sequence"`
30
- *
31
- * ## `"in-progress"`
32
- *
33
- * ## `"interrupted"`
34
- *
35
- * ## `"invalid"`
36
- *
37
- * ## `"io"`
38
- *
39
- * ## `"is-directory"`
40
- *
41
- * ## `"loop"`
42
- *
43
- * ## `"too-many-links"`
44
- *
45
- * ## `"message-size"`
46
- *
47
- * ## `"name-too-long"`
48
- *
49
- * ## `"no-device"`
50
- *
51
- * ## `"no-entry"`
52
- *
53
- * ## `"no-lock"`
54
- *
55
- * ## `"insufficient-memory"`
56
- *
57
- * ## `"insufficient-space"`
58
- *
59
- * ## `"not-directory"`
60
- *
61
- * ## `"not-empty"`
62
- *
63
- * ## `"not-recoverable"`
64
- *
65
- * ## `"unsupported"`
66
- *
67
- * ## `"no-tty"`
68
- *
69
- * ## `"no-such-device"`
70
- *
71
- * ## `"overflow"`
72
- *
73
- * ## `"not-permitted"`
74
- *
75
- * ## `"pipe"`
76
- *
77
- * ## `"read-only"`
78
- *
79
- * ## `"invalid-seek"`
80
- *
81
- * ## `"text-file-busy"`
82
- *
83
- * ## `"cross-device"`
84
- */
85
- export type ErrorCode = 'access' | 'would-block' | 'already' | 'bad-descriptor' | 'busy' | 'deadlock' | 'quota' | 'exist' | 'file-too-large' | 'illegal-byte-sequence' | 'in-progress' | 'interrupted' | 'invalid' | 'io' | 'is-directory' | 'loop' | 'too-many-links' | 'message-size' | 'name-too-long' | 'no-device' | 'no-entry' | 'no-lock' | 'insufficient-memory' | 'insufficient-space' | 'not-directory' | 'not-empty' | 'not-recoverable' | 'unsupported' | 'no-tty' | 'no-such-device' | 'overflow' | 'not-permitted' | 'pipe' | 'read-only' | 'invalid-seek' | 'text-file-busy' | 'cross-device';
86
- import type { OutputStream } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
87
- export { OutputStream };
88
- /**
89
- * # Variants
90
- *
91
- * ## `"unknown"`
92
- *
93
- * ## `"block-device"`
94
- *
95
- * ## `"character-device"`
96
- *
97
- * ## `"directory"`
98
- *
99
- * ## `"fifo"`
100
- *
101
- * ## `"symbolic-link"`
102
- *
103
- * ## `"regular-file"`
104
- *
105
- * ## `"socket"`
106
- */
107
- export type DescriptorType = 'unknown' | 'block-device' | 'character-device' | 'directory' | 'fifo' | 'symbolic-link' | 'regular-file' | 'socket';
108
- export type LinkCount = bigint;
109
- import type { Datetime } from '../interfaces/wasi-clocks-wall-clock-0.2.0-rc-2023-11-05';
110
- export { Datetime };
111
- export interface DescriptorStat {
112
- type: DescriptorType,
113
- linkCount: LinkCount,
114
- size: Filesize,
115
- dataAccessTimestamp?: Datetime,
116
- dataModificationTimestamp?: Datetime,
117
- statusChangeTimestamp?: Datetime,
118
- }
119
- export interface PathFlags {
120
- symlinkFollow?: boolean,
121
- }
122
- export interface OpenFlags {
123
- create?: boolean,
124
- directory?: boolean,
125
- exclusive?: boolean,
126
- truncate?: boolean,
127
- }
128
- export interface DescriptorFlags {
129
- read?: boolean,
130
- write?: boolean,
131
- fileIntegritySync?: boolean,
132
- dataIntegritySync?: boolean,
133
- requestedWriteSync?: boolean,
134
- mutateDirectory?: boolean,
135
- }
136
- export interface Modes {
137
- readable?: boolean,
138
- writable?: boolean,
139
- executable?: boolean,
140
- }
141
- export interface MetadataHashValue {
142
- lower: bigint,
143
- upper: bigint,
144
- }
145
- import type { Error } from '../interfaces/wasi-io-streams-0.2.0-rc-2023-11-05';
146
- export { Error };
147
-
148
- export class Descriptor {
149
- readViaStream(offset: Filesize): InputStream;
150
- writeViaStream(offset: Filesize): OutputStream;
151
- appendViaStream(): OutputStream;
152
- getType(): DescriptorType;
153
- stat(): DescriptorStat;
154
- openAt(pathFlags: PathFlags, path: string, openFlags: OpenFlags, flags: DescriptorFlags, modes: Modes): Descriptor;
155
- metadataHash(): MetadataHashValue;
156
- }
@@ -1,24 +0,0 @@
1
- export namespace WasiIoStreams020rc20231105 {
2
- export { InputStream };
3
- export { OutputStream };
4
- }
5
- export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
6
- export interface StreamErrorLastOperationFailed {
7
- tag: 'last-operation-failed',
8
- val: Error,
9
- }
10
- export interface StreamErrorClosed {
11
- tag: 'closed',
12
- }
13
-
14
- export class InputStream {
15
- read(len: bigint): Uint8Array;
16
- blockingRead(len: bigint): Uint8Array;
17
- }
18
-
19
- export class OutputStream {
20
- checkWrite(): bigint;
21
- write(contents: Uint8Array): void;
22
- blockingWriteAndFlush(contents: Uint8Array): void;
23
- blockingFlush(): void;
24
- }
@@ -1,3 +0,0 @@
1
- export namespace WasiRandomRandom020rc20231105 {
2
- export function getRandomBytes(len: bigint): Uint8Array;
3
- }
@@ -1,2 +0,0 @@
1
- export namespace WasiSocketsTcp020rc20231105 {
2
- }