@bytecodealliance/preview2-shim 0.0.16 → 0.0.18

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/lib/nodejs/cli.js CHANGED
@@ -1,19 +1,11 @@
1
- let _env, _args = [], _cwd = null;
2
- export function _setEnv (envObj) {
3
- _env = Object.entries(envObj);
4
- }
1
+ import { argv, env, cwd } from 'node:process';
2
+ import { streams } from '../common/io.js';
3
+ const { InputStream, OutputStream } = streams;
5
4
 
6
- export function _setArgs (args) {
7
- _args = args;
8
- }
9
-
10
- export function _setCwd (cwd) {
11
- _cwd = cwd;
12
- }
5
+ let _env = Object.entries(env), _args = argv, _cwd = cwd();
13
6
 
14
7
  export const environment = {
15
8
  getEnvironment () {
16
- if (!_env) _setEnv(process.env);
17
9
  return _env;
18
10
  },
19
11
  getArguments () {
@@ -30,46 +22,93 @@ export const exit = {
30
22
  }
31
23
  };
32
24
 
25
+ const stdinStream = new InputStream({
26
+ blockingRead (_len) {
27
+ // TODO
28
+ },
29
+ subscribe () {
30
+ // TODO
31
+ },
32
+ drop () {
33
+ // TODO
34
+ }
35
+ });
36
+ const stdoutStream = new OutputStream({
37
+ write (contents) {
38
+ process.stdout.write(contents);
39
+ },
40
+ blockingFlush () {
41
+ },
42
+ drop () {
43
+ }
44
+ });
45
+ const stderrStream = new OutputStream({
46
+ write (contents) {
47
+ process.stderr.write(contents);
48
+ },
49
+ blockingFlush () {
50
+
51
+ },
52
+ drop () {
53
+
54
+ }
55
+ });
56
+
33
57
  export const stdin = {
58
+ InputStream,
34
59
  getStdin () {
35
- return 0;
60
+ return stdinStream;
36
61
  }
37
62
  };
38
63
 
39
64
  export const stdout = {
65
+ OutputStream,
40
66
  getStdout () {
41
- return 1;
67
+ return stdoutStream;
42
68
  }
43
69
  };
44
70
 
45
71
  export const stderr = {
72
+ OutputStream,
46
73
  getStderr () {
47
- return 2;
74
+ return stderrStream;
48
75
  }
49
76
  };
50
77
 
78
+ class TerminalInput {}
79
+ class TerminalOutput {}
80
+
81
+ const terminalStdoutInstance = new TerminalOutput();
82
+ const terminalStderrInstance = new TerminalOutput();
83
+ const terminalStdinInstance = new TerminalInput();
84
+
51
85
  export const terminalInput = {
86
+ TerminalInput,
52
87
  dropTerminalInput () {}
53
88
  };
54
89
 
55
90
  export const terminalOutput = {
91
+ TerminalOutput,
56
92
  dropTerminalOutput () {}
57
93
  };
58
94
 
59
95
  export const terminalStderr = {
96
+ TerminalOutput,
60
97
  getTerminalStderr () {
61
- return 0;
98
+ return terminalStderrInstance;
62
99
  }
63
100
  };
64
101
 
65
102
  export const terminalStdin = {
103
+ TerminalInput,
66
104
  getTerminalStdin () {
67
- return 1;
105
+ return terminalStdinInstance;
68
106
  }
69
107
  };
70
108
 
71
109
  export const terminalStdout = {
110
+ TerminalOutput,
72
111
  getTerminalStdout () {
73
- return 2;
112
+ return terminalStdoutInstance;
74
113
  }
75
114
  };