@bytecodealliance/preview2-shim 0.17.3 → 0.17.5
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 +47 -0
- package/lib/browser/cli.js +3 -27
- package/lib/browser/config.js +10 -0
- package/lib/browser/environment.js +29 -0
- package/lib/browser/filesystem.js +5 -8
- package/lib/common/instantiation.js +41 -34
- package/lib/io/calls.js +1 -0
- package/lib/io/worker-http.js +40 -36
- package/lib/io/worker-io.js +36 -36
- package/lib/io/worker-sockets.js +79 -79
- package/lib/io/worker-thread.js +545 -541
- package/lib/nodejs/filesystem.js +92 -92
- package/lib/nodejs/http.js +10 -6
- package/package.json +35 -14
- package/types/instantiation.d.ts +27 -3
package/lib/nodejs/filesystem.js
CHANGED
|
@@ -220,12 +220,12 @@ class Descriptor {
|
|
|
220
220
|
|
|
221
221
|
#getNewTimestamp(newTimestamp, maybeNow) {
|
|
222
222
|
switch (newTimestamp.tag) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
case 'no-change':
|
|
224
|
+
return timestampToMs(maybeNow);
|
|
225
|
+
case 'now':
|
|
226
|
+
return Math.floor(Date.now() / 1e3);
|
|
227
|
+
case 'timestamp':
|
|
228
|
+
return timestampToMs(newTimestamp.val);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -561,8 +561,8 @@ class Descriptor {
|
|
|
561
561
|
? isWindows
|
|
562
562
|
? 'access'
|
|
563
563
|
: isMac
|
|
564
|
-
|
|
565
|
-
|
|
564
|
+
? 'not-permitted'
|
|
565
|
+
: 'is-directory'
|
|
566
566
|
: 'not-directory';
|
|
567
567
|
}
|
|
568
568
|
unlinkSync(fullPath);
|
|
@@ -668,8 +668,8 @@ class Descriptor {
|
|
|
668
668
|
(descriptor.#hostPreopen.endsWith('/')
|
|
669
669
|
? ''
|
|
670
670
|
: subpath.length > 0
|
|
671
|
-
|
|
672
|
-
|
|
671
|
+
? '/'
|
|
672
|
+
: '') +
|
|
673
673
|
subpath
|
|
674
674
|
);
|
|
675
675
|
}
|
|
@@ -752,95 +752,95 @@ export function _addPreopen(virtualPath, hostPreopen) {
|
|
|
752
752
|
|
|
753
753
|
function convertFsError(e) {
|
|
754
754
|
switch (e.code) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
755
|
+
case 'EACCES':
|
|
756
|
+
return 'access';
|
|
757
|
+
case 'EAGAIN':
|
|
758
|
+
case 'EWOULDBLOCK':
|
|
759
|
+
return 'would-block';
|
|
760
|
+
case 'EALREADY':
|
|
761
|
+
return 'already';
|
|
762
|
+
case 'EBADF':
|
|
763
|
+
return 'bad-descriptor';
|
|
764
|
+
case 'EBUSY':
|
|
765
|
+
return 'busy';
|
|
766
|
+
case 'EDEADLK':
|
|
767
|
+
return 'deadlock';
|
|
768
|
+
case 'EDQUOT':
|
|
769
|
+
return 'quota';
|
|
770
|
+
case 'EEXIST':
|
|
771
|
+
return 'exist';
|
|
772
|
+
case 'EFBIG':
|
|
773
|
+
return 'file-too-large';
|
|
774
|
+
case 'EILSEQ':
|
|
775
|
+
return 'illegal-byte-sequence';
|
|
776
|
+
case 'EINPROGRESS':
|
|
777
|
+
return 'in-progress';
|
|
778
|
+
case 'EINTR':
|
|
779
|
+
return 'interrupted';
|
|
780
|
+
case 'EINVAL':
|
|
781
|
+
return 'invalid';
|
|
782
|
+
case 'EIO':
|
|
783
|
+
return 'io';
|
|
784
|
+
case 'EISDIR':
|
|
785
|
+
return 'is-directory';
|
|
786
|
+
case 'ELOOP':
|
|
787
|
+
return 'loop';
|
|
788
|
+
case 'EMLINK':
|
|
789
|
+
return 'too-many-links';
|
|
790
|
+
case 'EMSGSIZE':
|
|
791
|
+
return 'message-size';
|
|
792
|
+
case 'ENAMETOOLONG':
|
|
793
|
+
return 'name-too-long';
|
|
794
|
+
case 'ENODEV':
|
|
795
|
+
return 'no-device';
|
|
796
|
+
case 'ENOENT':
|
|
797
|
+
return 'no-entry';
|
|
798
|
+
case 'ENOLCK':
|
|
799
|
+
return 'no-lock';
|
|
800
|
+
case 'ENOMEM':
|
|
801
|
+
return 'insufficient-memory';
|
|
802
|
+
case 'ENOSPC':
|
|
803
|
+
return 'insufficient-space';
|
|
804
|
+
case 'ENOTDIR':
|
|
805
|
+
case 'ERR_FS_EISDIR':
|
|
806
|
+
return 'not-directory';
|
|
807
|
+
case 'ENOTEMPTY':
|
|
808
|
+
return 'not-empty';
|
|
809
|
+
case 'ENOTRECOVERABLE':
|
|
810
|
+
return 'not-recoverable';
|
|
811
|
+
case 'ENOTSUP':
|
|
812
|
+
return 'unsupported';
|
|
813
|
+
case 'ENOTTY':
|
|
814
|
+
return 'no-tty';
|
|
815
815
|
// windows gives this error for badly structured `//` reads
|
|
816
816
|
// this seems like a slightly better error than unknown given
|
|
817
817
|
// that it's a common footgun
|
|
818
|
+
case -4094:
|
|
819
|
+
case 'ENXIO':
|
|
820
|
+
return 'no-such-device';
|
|
821
|
+
case 'EOVERFLOW':
|
|
822
|
+
return 'overflow';
|
|
823
|
+
case 'EPERM':
|
|
824
|
+
return 'not-permitted';
|
|
825
|
+
case 'EPIPE':
|
|
826
|
+
return 'pipe';
|
|
827
|
+
case 'EROFS':
|
|
828
|
+
return 'read-only';
|
|
829
|
+
case 'ESPIPE':
|
|
830
|
+
return 'invalid-seek';
|
|
831
|
+
case 'ETXTBSY':
|
|
832
|
+
return 'text-file-busy';
|
|
833
|
+
case 'EXDEV':
|
|
834
|
+
return 'cross-device';
|
|
835
|
+
case 'UNKNOWN':
|
|
836
|
+
switch (e.errno) {
|
|
818
837
|
case -4094:
|
|
819
|
-
case 'ENXIO':
|
|
820
838
|
return 'no-such-device';
|
|
821
|
-
case 'EOVERFLOW':
|
|
822
|
-
return 'overflow';
|
|
823
|
-
case 'EPERM':
|
|
824
|
-
return 'not-permitted';
|
|
825
|
-
case 'EPIPE':
|
|
826
|
-
return 'pipe';
|
|
827
|
-
case 'EROFS':
|
|
828
|
-
return 'read-only';
|
|
829
|
-
case 'ESPIPE':
|
|
830
|
-
return 'invalid-seek';
|
|
831
|
-
case 'ETXTBSY':
|
|
832
|
-
return 'text-file-busy';
|
|
833
|
-
case 'EXDEV':
|
|
834
|
-
return 'cross-device';
|
|
835
|
-
case 'UNKNOWN':
|
|
836
|
-
switch (e.errno) {
|
|
837
|
-
case -4094:
|
|
838
|
-
return 'no-such-device';
|
|
839
|
-
default:
|
|
840
|
-
throw e;
|
|
841
|
-
}
|
|
842
839
|
default:
|
|
843
840
|
throw e;
|
|
841
|
+
}
|
|
842
|
+
default:
|
|
843
|
+
throw e;
|
|
844
844
|
}
|
|
845
845
|
}
|
|
846
846
|
|
package/lib/nodejs/http.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
HTTP_SERVER_SET_OUTGOING_RESPONSE,
|
|
10
10
|
HTTP_SERVER_START,
|
|
11
11
|
HTTP_SERVER_STOP,
|
|
12
|
+
HTTP_SERVER_GET_ADDRESS,
|
|
12
13
|
OUTPUT_STREAM_CREATE,
|
|
13
14
|
OUTPUT_STREAM_DISPOSE,
|
|
14
15
|
} from '../io/calls.js';
|
|
@@ -673,12 +674,12 @@ function schemeString(scheme) {
|
|
|
673
674
|
return 'https:';
|
|
674
675
|
}
|
|
675
676
|
switch (scheme.tag) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
677
|
+
case 'HTTP':
|
|
678
|
+
return 'http:';
|
|
679
|
+
case 'HTTPS':
|
|
680
|
+
return 'https:';
|
|
681
|
+
case 'other':
|
|
682
|
+
return scheme.val.toLowerCase() + ':';
|
|
682
683
|
}
|
|
683
684
|
}
|
|
684
685
|
|
|
@@ -776,6 +777,9 @@ export class HTTPServer {
|
|
|
776
777
|
this.#liveEventLoopInterval = setInterval(() => {}, 10_000);
|
|
777
778
|
ioCall(HTTP_SERVER_START, this.#id, { port, host });
|
|
778
779
|
}
|
|
780
|
+
address() {
|
|
781
|
+
return ioCall(HTTP_SERVER_GET_ADDRESS, this.#id);
|
|
782
|
+
}
|
|
779
783
|
stop() {
|
|
780
784
|
if (this.#stopped) {
|
|
781
785
|
return;
|
package/package.json
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/preview2-shim",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.5",
|
|
4
4
|
"description": "WASI Preview2 shim for JS environments",
|
|
5
5
|
"author": "Guy Bedford, Eduardo Rodrigues<16357187+eduardomourar@users.noreply.github.com>",
|
|
6
|
+
"contributors": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Guy Bedford"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "Eduardo Rodrigues",
|
|
12
|
+
"email": "16357187+eduardomourar@users.noreply.github.com"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "Victor Adossi",
|
|
16
|
+
"email": "vadossi@cosmonic.com"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/bytecodealliance/jco.git"
|
|
22
|
+
},
|
|
23
|
+
"license": "(Apache-2.0 WITH LLVM-exception)",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/bytecodealliance/jco/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/bytecodealliance/jco#readme",
|
|
6
28
|
"type": "module",
|
|
7
29
|
"types": "./types/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"types",
|
|
32
|
+
"lib"
|
|
33
|
+
],
|
|
8
34
|
"exports": {
|
|
9
35
|
".": {
|
|
10
36
|
"types": "./types/index.d.ts",
|
|
@@ -23,21 +49,16 @@
|
|
|
23
49
|
}
|
|
24
50
|
},
|
|
25
51
|
"scripts": {
|
|
52
|
+
"types:check": "tsc --noEmit",
|
|
53
|
+
"fmt": "npm run lint:fix",
|
|
26
54
|
"lint": "eslint -c ../../eslint.config.mjs ./lib/**/*.js",
|
|
27
55
|
"lint:fix": "npm run lint -- --fix",
|
|
28
56
|
"test": "vitest run -c test/vitest.ts"
|
|
29
57
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"url": "git+https://github.com/bytecodealliance/jco.git"
|
|
37
|
-
},
|
|
38
|
-
"license": "(Apache-2.0 WITH LLVM-exception)",
|
|
39
|
-
"bugs": {
|
|
40
|
-
"url": "https://github.com/bytecodealliance/jco/issues"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/bytecodealliance/jco#readme"
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@bytecodealliance/componentize-js": "0.19.3",
|
|
60
|
+
"@bytecodealliance/jco": "1.15.2",
|
|
61
|
+
"mime": "^4.0.7",
|
|
62
|
+
"puppeteer": "^24.16.2"
|
|
63
|
+
}
|
|
43
64
|
}
|
package/types/instantiation.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* While the feature can be disabled when building with `jco componentize` or `componentize-js`,
|
|
9
9
|
* by default it is enabled, and as such included here (practically, the implementations can be no-ops).
|
|
10
10
|
*/
|
|
11
|
-
type
|
|
11
|
+
type _WASIImportObject = {
|
|
12
12
|
'wasi:cli/environment': typeof import('./interfaces/wasi-cli-environment.d.ts');
|
|
13
13
|
'wasi:cli/exit': typeof import('./interfaces/wasi-cli-exit.d.ts');
|
|
14
14
|
'wasi:cli/stderr': typeof import('./interfaces/wasi-cli-stderr.d.ts');
|
|
@@ -40,13 +40,30 @@ type WASIImportObject = {
|
|
|
40
40
|
'wasi:random/insecure-seed': typeof import('./interfaces/wasi-random-insecure-seed.d.ts');
|
|
41
41
|
|
|
42
42
|
'wasi:clocks/monotonic-clock': typeof import('./interfaces/wasi-clocks-monotonic-clock.d.ts');
|
|
43
|
-
'wasi:clocks/timezone': typeof import('./interfaces/wasi-clocks-timezone.d.ts');
|
|
44
43
|
'wasi:clocks/wall-clock': typeof import('./interfaces/wasi-clocks-wall-clock.d.ts');
|
|
45
44
|
|
|
46
45
|
'wasi:http/types': typeof import('./interfaces/wasi-http-types.d.ts');
|
|
47
46
|
'wasi:http/outgoing-handler': typeof import('./interfaces/wasi-http-outgoing-handler.d.ts');
|
|
48
47
|
};
|
|
49
48
|
|
|
49
|
+
type WASIImportObject = VersionedWASIImportObject<''>;
|
|
50
|
+
|
|
51
|
+
type VersionedWASIImportObject<V extends string> = {
|
|
52
|
+
[K in keyof _WASIImportObject as AppendVersion<K, V>]: _WASIImportObject[K];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Used to append versions to generated WASI import objects */
|
|
56
|
+
type AppendVersion<
|
|
57
|
+
Key extends string | number | symbol,
|
|
58
|
+
Version extends string,
|
|
59
|
+
> = Version extends `${infer V}`
|
|
60
|
+
? Key extends `${infer K}`
|
|
61
|
+
? Key extends ''
|
|
62
|
+
? `${K}`
|
|
63
|
+
: `${K}@${V}`
|
|
64
|
+
: never
|
|
65
|
+
: never;
|
|
66
|
+
|
|
50
67
|
/**
|
|
51
68
|
* (EXPERIMENTAL) A class that holds WASI shims and can be used to configure
|
|
52
69
|
* an instantiation of a WebAssembly component transpiled with jco
|
|
@@ -106,7 +123,14 @@ export class WASIShim {
|
|
|
106
123
|
* functions like `instantiate` that are exposed from a transpiled
|
|
107
124
|
* WebAssembly component.
|
|
108
125
|
*
|
|
126
|
+
* @param {options} [opt]
|
|
109
127
|
* @returns {object}
|
|
110
128
|
*/
|
|
111
|
-
getImportObject(
|
|
129
|
+
getImportObject<V extends string = ''>(
|
|
130
|
+
opts?: GetImportObjectArgs
|
|
131
|
+
): VersionedWASIImportObject<V>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface GetImportObjectArgs {
|
|
135
|
+
asVersion?: string;
|
|
112
136
|
}
|