@bytecodealliance/preview2-shim 0.18.1 → 0.20.0

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 (82) hide show
  1. package/README.md +15 -15
  2. package/dist/browser/cli.d.ts +16 -0
  3. package/dist/browser/cli.js +109 -0
  4. package/dist/browser/clocks.d.ts +3 -0
  5. package/dist/browser/clocks.js +36 -0
  6. package/dist/browser/config.d.ts +2 -0
  7. package/{lib → dist}/browser/config.js +2 -4
  8. package/dist/browser/environment.d.ts +5 -0
  9. package/dist/browser/environment.js +24 -0
  10. package/dist/browser/filesystem.d.ts +132 -0
  11. package/dist/browser/filesystem.js +488 -0
  12. package/dist/browser/http.d.ts +4 -0
  13. package/dist/browser/http.js +643 -0
  14. package/dist/browser/index.d.ts +7 -0
  15. package/dist/browser/index.js +7 -0
  16. package/dist/browser/io.d.ts +58 -0
  17. package/dist/browser/io.js +205 -0
  18. package/dist/browser/random.d.ts +4 -0
  19. package/dist/browser/random.js +49 -0
  20. package/dist/browser/sockets.d.ts +8 -0
  21. package/dist/browser/sockets.js +66 -0
  22. package/dist/common/instantiation.d.ts +97 -0
  23. package/dist/common/instantiation.js +228 -0
  24. package/dist/io/calls.d.ts +91 -0
  25. package/{lib → dist}/io/calls.js +4 -19
  26. package/dist/io/worker-http.d.ts +17 -0
  27. package/dist/io/worker-http.js +192 -0
  28. package/dist/io/worker-io.d.ts +84 -0
  29. package/dist/io/worker-io.js +381 -0
  30. package/dist/io/worker-socket-tcp.d.ts +34 -0
  31. package/dist/io/worker-socket-tcp.js +251 -0
  32. package/dist/io/worker-socket-udp.d.ts +54 -0
  33. package/dist/io/worker-socket-udp.js +493 -0
  34. package/dist/io/worker-sockets.d.ts +32 -0
  35. package/dist/io/worker-sockets.js +265 -0
  36. package/dist/io/worker-thread.d.ts +73 -0
  37. package/dist/io/worker-thread.js +794 -0
  38. package/dist/nodejs/cli.d.ts +30 -0
  39. package/dist/nodejs/cli.js +86 -0
  40. package/dist/nodejs/clocks.d.ts +3 -0
  41. package/dist/nodejs/clocks.js +61 -0
  42. package/dist/nodejs/filesystem.d.ts +113 -0
  43. package/dist/nodejs/filesystem.js +761 -0
  44. package/dist/nodejs/http.d.ts +82 -0
  45. package/dist/nodejs/http.js +674 -0
  46. package/dist/nodejs/index.d.ts +7 -0
  47. package/dist/nodejs/index.js +7 -0
  48. package/dist/nodejs/io.d.ts +1 -0
  49. package/dist/nodejs/io.js +1 -0
  50. package/dist/nodejs/random.d.ts +4 -0
  51. package/dist/nodejs/random.js +42 -0
  52. package/dist/nodejs/sockets.d.ts +21 -0
  53. package/dist/nodejs/sockets.js +482 -0
  54. package/dist/synckit/index.d.ts +2 -0
  55. package/dist/synckit/index.js +117 -0
  56. package/package.json +28 -15
  57. package/types/instantiation.d.ts +7 -7
  58. package/lib/browser/cli.js +0 -135
  59. package/lib/browser/clocks.js +0 -39
  60. package/lib/browser/environment.js +0 -29
  61. package/lib/browser/filesystem.js +0 -503
  62. package/lib/browser/http.js +0 -707
  63. package/lib/browser/index.js +0 -9
  64. package/lib/browser/io.js +0 -262
  65. package/lib/browser/random.js +0 -56
  66. package/lib/browser/sockets.js +0 -88
  67. package/lib/common/instantiation.js +0 -253
  68. package/lib/io/worker-http.js +0 -206
  69. package/lib/io/worker-io.js +0 -468
  70. package/lib/io/worker-socket-tcp.js +0 -331
  71. package/lib/io/worker-socket-udp.js +0 -587
  72. package/lib/io/worker-sockets.js +0 -364
  73. package/lib/io/worker-thread.js +0 -1051
  74. package/lib/nodejs/cli.js +0 -109
  75. package/lib/nodejs/clocks.js +0 -67
  76. package/lib/nodejs/filesystem.js +0 -829
  77. package/lib/nodejs/http.js +0 -764
  78. package/lib/nodejs/index.js +0 -9
  79. package/lib/nodejs/io.js +0 -1
  80. package/lib/nodejs/random.js +0 -49
  81. package/lib/nodejs/sockets.js +0 -565
  82. package/lib/synckit/index.js +0 -127
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.18.1",
3
+ "version": "0.20.0",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "homepage": "https://github.com/bytecodealliance/jco#readme",
6
6
  "bugs": {
@@ -27,34 +27,47 @@
27
27
  },
28
28
  "files": [
29
29
  "types",
30
- "lib"
30
+ "dist"
31
31
  ],
32
32
  "type": "module",
33
- "types": "./types/index.d.ts",
34
33
  "exports": {
35
34
  ".": {
36
- "types": "./types/index.d.ts",
37
- "node": "./lib/nodejs/index.js",
38
- "default": "./lib/browser/index.js"
35
+ "types": "./dist/browser/index.d.ts",
36
+ "node": {
37
+ "types": "./dist/nodejs/index.d.ts",
38
+ "default": "./dist/nodejs/index.js"
39
+ },
40
+ "default": "./dist/browser/index.js"
39
41
  },
40
42
  "./*": {
41
- "types": "./types/*.d.ts",
42
- "node": "./lib/nodejs/*.js",
43
- "default": "./lib/browser/*.js"
43
+ "types": "./dist/browser/*.d.ts",
44
+ "node": {
45
+ "types": "./dist/nodejs/*.d.ts",
46
+ "default": "./dist/nodejs/*.js"
47
+ },
48
+ "default": "./dist/browser/*.js"
44
49
  },
45
50
  "./instantiation": {
46
- "types": "./types/instantiation.d.ts",
47
- "node": "./lib/common/instantiation.js",
48
- "default": "./lib/common/instantiation.js"
51
+ "types": "./dist/common/*.d.ts",
52
+ "node": "./dist/common/instantiation.js",
53
+ "default": "./dist/common/instantiation.js"
54
+ },
55
+ "./interfaces/*": {
56
+ "types": "./types/interfaces/*.d.ts"
49
57
  }
50
58
  },
51
59
  "devDependencies": {
52
- "@bytecodealliance/componentize-js": "0.21.0",
53
- "@bytecodealliance/jco": "1.15.2",
60
+ "@bytecodealliance/componentize-js": "0.22.0",
61
+ "@bytecodealliance/jco": "1.25.2",
62
+ "@types/node": "^24.12.4",
54
63
  "mime": "^4.0.7",
55
- "puppeteer": "^25.1.0"
64
+ "puppeteer": "^25.1.0",
65
+ "typescript": "^6.0.3",
66
+ "vitest": "^4.0.8"
56
67
  },
57
68
  "scripts": {
69
+ "build": "tsc --project tsconfig.build.json",
70
+ "build:watch": "tsc --watch",
58
71
  "types:check": "tsc --noEmit",
59
72
  "fmt": "oxfmt",
60
73
  "fmt:check": "oxfmt --check",
@@ -56,13 +56,13 @@ type VersionedWASIImportObject<V extends string> = {
56
56
  type AppendVersion<
57
57
  Key extends string | number | symbol,
58
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;
59
+ > = Version extends ''
60
+ ? Key
61
+ : Version extends `${infer V}`
62
+ ? Key extends `${infer K}`
63
+ ? `${K}@${V}`
64
+ : never
65
+ : never;
66
66
 
67
67
  /**
68
68
  * Sandbox configuration options for WASIShim
@@ -1,135 +0,0 @@
1
- import { streams } from "./io.js";
2
- const { InputStream, OutputStream } = streams;
3
-
4
- export { _setEnv, _setArgs, environment } from "./environment.js";
5
- export { _setCwd } from "./config.js";
6
-
7
- const symbolDispose = Symbol.dispose ?? Symbol.for("dispose");
8
-
9
- class ComponentExit extends Error {
10
- constructor(code) {
11
- super(`Component exited ${code === 0 ? "successfully" : "with error"}`);
12
- this.exitError = true;
13
- this.code = code;
14
- }
15
- }
16
-
17
- export const exit = {
18
- exit(status) {
19
- throw new ComponentExit(status.tag === "err" ? 1 : 0);
20
- },
21
- exitWithCode(code) {
22
- throw new ComponentExit(code);
23
- },
24
- };
25
-
26
- /**
27
- * @param {import('../common/io.js').InputStreamHandler} handler
28
- */
29
- export function _setStdin(handler) {
30
- stdinStream.handler = handler;
31
- }
32
- /**
33
- * @param {import('../common/io.js').OutputStreamHandler} handler
34
- */
35
- export function _setStderr(handler) {
36
- stderrStream.handler = handler;
37
- }
38
- /**
39
- * @param {import('../common/io.js').OutputStreamHandler} handler
40
- */
41
- export function _setStdout(handler) {
42
- stdoutStream.handler = handler;
43
- }
44
-
45
- const stdinStream = new InputStream({
46
- blockingRead(_len) {
47
- // TODO
48
- },
49
- subscribe() {
50
- // TODO
51
- },
52
- [symbolDispose]() {
53
- // TODO
54
- },
55
- });
56
- let textDecoder = new TextDecoder();
57
- const stdoutStream = new OutputStream({
58
- write(contents) {
59
- if (contents[contents.length - 1] == 10) {
60
- // console.log already appends a new line
61
- contents = contents.subarray(0, contents.length - 1);
62
- }
63
- console.log(textDecoder.decode(contents));
64
- },
65
- blockingFlush() {},
66
- [symbolDispose]() {},
67
- });
68
- const stderrStream = new OutputStream({
69
- write(contents) {
70
- if (contents[contents.length - 1] == 10) {
71
- // console.error already appends a new line
72
- contents = contents.subarray(0, contents.length - 1);
73
- }
74
- console.error(textDecoder.decode(contents));
75
- },
76
- blockingFlush() {},
77
- [symbolDispose]() {},
78
- });
79
-
80
- export const stdin = {
81
- InputStream,
82
- getStdin() {
83
- return stdinStream;
84
- },
85
- };
86
-
87
- export const stdout = {
88
- OutputStream,
89
- getStdout() {
90
- return stdoutStream;
91
- },
92
- };
93
-
94
- export const stderr = {
95
- OutputStream,
96
- getStderr() {
97
- return stderrStream;
98
- },
99
- };
100
-
101
- class TerminalInput {}
102
- class TerminalOutput {}
103
-
104
- const terminalStdoutInstance = new TerminalOutput();
105
- const terminalStderrInstance = new TerminalOutput();
106
- const terminalStdinInstance = new TerminalInput();
107
-
108
- export const terminalInput = {
109
- TerminalInput,
110
- };
111
-
112
- export const terminalOutput = {
113
- TerminalOutput,
114
- };
115
-
116
- export const terminalStderr = {
117
- TerminalOutput,
118
- getTerminalStderr() {
119
- return terminalStderrInstance;
120
- },
121
- };
122
-
123
- export const terminalStdin = {
124
- TerminalInput,
125
- getTerminalStdin() {
126
- return terminalStdinInstance;
127
- },
128
- };
129
-
130
- export const terminalStdout = {
131
- TerminalOutput,
132
- getTerminalStdout() {
133
- return terminalStdoutInstance;
134
- },
135
- };
@@ -1,39 +0,0 @@
1
- import { poll } from "./io.js";
2
- const { Pollable } = poll;
3
-
4
- export const monotonicClock = {
5
- resolution() {
6
- // usually we dont get sub-millisecond accuracy in the browser
7
- // Note: is there a better way to determine this?
8
- return 1e6;
9
- },
10
- now() {
11
- // performance.now() is in milliseconds, but we want nanoseconds
12
- return BigInt(Math.floor(performance.now() * 1e6));
13
- },
14
- subscribeInstant(instant) {
15
- instant = BigInt(instant);
16
- const now = monotonicClock.now();
17
- if (instant <= now) {
18
- return new Pollable(new Promise((resolve) => setTimeout(resolve, 0)));
19
- }
20
- return monotonicClock.subscribeDuration(instant - now);
21
- },
22
- subscribeDuration(duration) {
23
- duration = BigInt(duration);
24
- const ms = duration <= 0n ? 0 : Number(duration / 1_000_000n);
25
- return new Pollable(new Promise((resolve) => setTimeout(resolve, ms)));
26
- },
27
- };
28
-
29
- export const wallClock = {
30
- now() {
31
- let now = Date.now(); // in milliseconds
32
- const seconds = BigInt(Math.floor(now / 1e3));
33
- const nanoseconds = (now % 1e3) * 1e6;
34
- return { seconds, nanoseconds };
35
- },
36
- resolution() {
37
- return { seconds: 0n, nanoseconds: 1e6 };
38
- },
39
- };
@@ -1,29 +0,0 @@
1
- import { _setCwd as fsSetCwd } from "./config.js";
2
-
3
- let _env = [],
4
- _args = [],
5
- _cwd = "/";
6
-
7
- export function _setEnv(envObj) {
8
- _env = Object.entries(envObj);
9
- }
10
-
11
- export function _setArgs(args) {
12
- _args = args;
13
- }
14
-
15
- export function _setCwd(cwd) {
16
- fsSetCwd((_cwd = cwd));
17
- }
18
-
19
- export const environment = {
20
- getEnvironment() {
21
- return _env;
22
- },
23
- getArguments() {
24
- return _args;
25
- },
26
- initialCwd() {
27
- return _cwd;
28
- },
29
- };