@serveryyswys/node.operit 0.0.0-stage → 0.1.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 (123) hide show
  1. package/BUILTINS.json +233 -0
  2. package/DESIGN.md +513 -0
  3. package/LICENSE +674 -0
  4. package/README.md +301 -2
  5. package/dist/assert/strict.d.ts +2 -0
  6. package/dist/assert/strict.js +7 -0
  7. package/dist/assert.d.ts +3 -0
  8. package/dist/assert.js +483 -0
  9. package/dist/buffer.d.ts +60 -0
  10. package/dist/buffer.js +524 -0
  11. package/dist/child_process.d.ts +56 -0
  12. package/dist/child_process.js +371 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/constants.js +19 -0
  15. package/dist/crypto.d.ts +76 -0
  16. package/dist/crypto.js +312 -0
  17. package/dist/dns/promises.d.ts +34 -0
  18. package/dist/dns/promises.js +190 -0
  19. package/dist/dns.d.ts +88 -0
  20. package/dist/dns.js +259 -0
  21. package/dist/events.d.ts +40 -0
  22. package/dist/events.js +237 -0
  23. package/dist/fs/promises.d.ts +159 -0
  24. package/dist/fs/promises.js +129 -0
  25. package/dist/fs.d.ts +221 -0
  26. package/dist/fs.js +944 -0
  27. package/dist/http.d.ts +92 -0
  28. package/dist/http.js +319 -0
  29. package/dist/https.d.ts +296 -0
  30. package/dist/https.js +50 -0
  31. package/dist/index.d.ts +2422 -0
  32. package/dist/index.js +57 -0
  33. package/dist/lib/bridge.d.ts +60 -0
  34. package/dist/lib/bridge.js +205 -0
  35. package/dist/lib/bytes.d.ts +20 -0
  36. package/dist/lib/bytes.js +239 -0
  37. package/dist/lib/child-process-types.d.ts +45 -0
  38. package/dist/lib/child-process-types.js +2 -0
  39. package/dist/lib/cwd.d.ts +2 -0
  40. package/dist/lib/cwd.js +32 -0
  41. package/dist/lib/deep-equal.d.ts +3 -0
  42. package/dist/lib/deep-equal.js +223 -0
  43. package/dist/lib/deflate.d.ts +2 -0
  44. package/dist/lib/deflate.js +234 -0
  45. package/dist/lib/dns-driver.d.ts +14 -0
  46. package/dist/lib/dns-driver.js +85 -0
  47. package/dist/lib/dns-types.d.ts +22 -0
  48. package/dist/lib/dns-types.js +2 -0
  49. package/dist/lib/errors.d.ts +48 -0
  50. package/dist/lib/errors.js +424 -0
  51. package/dist/lib/fs-driver.d.ts +70 -0
  52. package/dist/lib/fs-driver.js +364 -0
  53. package/dist/lib/fs-env.d.ts +30 -0
  54. package/dist/lib/fs-env.js +157 -0
  55. package/dist/lib/fs-types.d.ts +19 -0
  56. package/dist/lib/fs-types.js +2 -0
  57. package/dist/lib/hashes.d.ts +27 -0
  58. package/dist/lib/hashes.js +432 -0
  59. package/dist/lib/http-driver.d.ts +30 -0
  60. package/dist/lib/http-driver.js +72 -0
  61. package/dist/lib/http-types.d.ts +18 -0
  62. package/dist/lib/http-types.js +2 -0
  63. package/dist/lib/inflate.d.ts +6 -0
  64. package/dist/lib/inflate.js +284 -0
  65. package/dist/lib/path-types.d.ts +37 -0
  66. package/dist/lib/path-types.js +2 -0
  67. package/dist/lib/paths.d.ts +8 -0
  68. package/dist/lib/paths.js +106 -0
  69. package/dist/lib/perf-hooks-types.d.ts +18 -0
  70. package/dist/lib/perf-hooks-types.js +2 -0
  71. package/dist/lib/process-driver.d.ts +31 -0
  72. package/dist/lib/process-driver.js +102 -0
  73. package/dist/lib/punycode.d.ts +8 -0
  74. package/dist/lib/punycode.js +179 -0
  75. package/dist/lib/stream-types.d.ts +29 -0
  76. package/dist/lib/stream-types.js +2 -0
  77. package/dist/lib/timers-types.d.ts +18 -0
  78. package/dist/lib/timers-types.js +2 -0
  79. package/dist/lib/url-search-params.d.ts +26 -0
  80. package/dist/lib/url-search-params.js +281 -0
  81. package/dist/lib/url-types.d.ts +44 -0
  82. package/dist/lib/url-types.js +2 -0
  83. package/dist/lib/url-whatwg.d.ts +78 -0
  84. package/dist/lib/url-whatwg.js +857 -0
  85. package/dist/lib/zlib-types.d.ts +12 -0
  86. package/dist/lib/zlib-types.js +2 -0
  87. package/dist/module.d.ts +8 -0
  88. package/dist/module.js +72 -0
  89. package/dist/os.d.ts +80 -0
  90. package/dist/os.js +247 -0
  91. package/dist/path/posix.d.ts +2 -0
  92. package/dist/path/posix.js +7 -0
  93. package/dist/path/win32.d.ts +2 -0
  94. package/dist/path/win32.js +10 -0
  95. package/dist/path.d.ts +3 -0
  96. package/dist/path.js +1222 -0
  97. package/dist/perf_hooks.d.ts +36 -0
  98. package/dist/perf_hooks.js +144 -0
  99. package/dist/process.d.ts +69 -0
  100. package/dist/process.js +230 -0
  101. package/dist/querystring.d.ts +15 -0
  102. package/dist/querystring.js +209 -0
  103. package/dist/stream/promises.d.ts +5 -0
  104. package/dist/stream/promises.js +10 -0
  105. package/dist/stream.d.ts +84 -0
  106. package/dist/stream.js +875 -0
  107. package/dist/string_decoder.d.ts +15 -0
  108. package/dist/string_decoder.js +237 -0
  109. package/dist/timers/promises.d.ts +19 -0
  110. package/dist/timers/promises.js +74 -0
  111. package/dist/timers.d.ts +21 -0
  112. package/dist/timers.js +41 -0
  113. package/dist/tty.d.ts +9 -0
  114. package/dist/tty.js +25 -0
  115. package/dist/unsupported.d.ts +12 -0
  116. package/dist/unsupported.js +17 -0
  117. package/dist/url.d.ts +28 -0
  118. package/dist/url.js +486 -0
  119. package/dist/util.d.ts +74 -0
  120. package/dist/util.js +515 -0
  121. package/dist/zlib.d.ts +88 -0
  122. package/dist/zlib.js +371 -0
  123. package/package.json +29 -4
@@ -0,0 +1,15 @@
1
+ export declare class StringDecoder {
2
+ static StringDecoder: typeof StringDecoder;
3
+ readonly encoding: string;
4
+ private pending;
5
+ constructor(encoding?: string);
6
+ get lastNeed(): number;
7
+ get lastTotal(): number;
8
+ get lastChar(): Uint8Array;
9
+ write(buffer: Uint8Array): string;
10
+ end(buffer?: Uint8Array): string;
11
+ private combine;
12
+ private writeUtf8;
13
+ private writeUtf16;
14
+ private writeBase64;
15
+ }
@@ -0,0 +1,237 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.StringDecoder = void 0;
37
+ /**
38
+ * Node string_decoder 模块的移植。
39
+ *
40
+ * 三种编码的缓冲语义(照 Node 实测行为):
41
+ * utf8 末尾不完整的字符缓起来;end() 只吐**一个** U+FFFD,不按字节数吐
42
+ * utf16le 末尾悬空的单字节缓起来;end() 直接丢弃(不吐替换字符)
43
+ * base64 缓冲的是**输入字节**:每 3 字节输出 4 个 base64 字符,end() 用带 padding 的形式收尾
44
+ * hex/ascii/latin1 无缓冲
45
+ */
46
+ const bytesCodec = __importStar(require("./lib/bytes"));
47
+ function normalizeEncoding(encoding) {
48
+ const value = typeof encoding === 'string' ? encoding.toLowerCase() : 'utf8';
49
+ if (value === 'utf-8') {
50
+ return 'utf8';
51
+ }
52
+ if (value === 'binary') {
53
+ return 'latin1';
54
+ }
55
+ if (value === 'ucs2' || value === 'ucs-2' || value === 'utf-16le') {
56
+ return 'utf16le';
57
+ }
58
+ if (value === 'utf8' || value === 'utf16le' || value === 'latin1' || value === 'ascii' || value === 'base64' || value === 'hex') {
59
+ return value;
60
+ }
61
+ throw new TypeError('Unknown encoding: ' + String(encoding));
62
+ }
63
+ /** UTF-8 序列首字节应有的总长度;非法首字节按 1 处理(交给解码器吐替换字符)。 */
64
+ function utf8SequenceLength(byte) {
65
+ if (byte < 0x80) {
66
+ return 1;
67
+ }
68
+ if (byte >= 0xc2 && byte <= 0xdf) {
69
+ return 2;
70
+ }
71
+ if (byte >= 0xe0 && byte <= 0xef) {
72
+ return 3;
73
+ }
74
+ if (byte >= 0xf0 && byte <= 0xf4) {
75
+ return 4;
76
+ }
77
+ return 1;
78
+ }
79
+ /** 返回 bytes 中最长的、以完整字符结尾的前缀长度。 */
80
+ function completePrefixLength(bytes) {
81
+ let index = bytes.length;
82
+ let lookback = 0;
83
+ while (index > 0 && lookback < 4) {
84
+ index -= 1;
85
+ lookback += 1;
86
+ const byte = bytes[index];
87
+ if (byte < 0x80) {
88
+ return bytes.length;
89
+ }
90
+ if (byte >= 0xc0) {
91
+ return index + utf8SequenceLength(byte) > bytes.length ? index : bytes.length;
92
+ }
93
+ }
94
+ return bytes.length;
95
+ }
96
+ class StringDecoder {
97
+ constructor(encoding) {
98
+ this.encoding = normalizeEncoding(encoding);
99
+ this.pending = new Uint8Array(0);
100
+ }
101
+ get lastNeed() {
102
+ if (this.pending.length === 0) {
103
+ return 0;
104
+ }
105
+ if (this.encoding === 'utf8') {
106
+ return utf8SequenceLength(this.pending[0]) - this.pending.length;
107
+ }
108
+ if (this.encoding === 'utf16le') {
109
+ return 1;
110
+ }
111
+ if (this.encoding === 'base64') {
112
+ return 3 - this.pending.length;
113
+ }
114
+ return 0;
115
+ }
116
+ get lastTotal() {
117
+ if (this.pending.length === 0) {
118
+ return 0;
119
+ }
120
+ if (this.encoding === 'utf8') {
121
+ return utf8SequenceLength(this.pending[0]);
122
+ }
123
+ if (this.encoding === 'utf16le') {
124
+ return 2;
125
+ }
126
+ if (this.encoding === 'base64') {
127
+ return 3;
128
+ }
129
+ return 0;
130
+ }
131
+ get lastChar() {
132
+ return this.pending;
133
+ }
134
+ write(buffer) {
135
+ if (!(buffer instanceof Uint8Array)) {
136
+ throw new TypeError('The "buf" argument must be an instance of Buffer or Uint8Array.');
137
+ }
138
+ if (this.encoding === 'utf8') {
139
+ return this.writeUtf8(buffer);
140
+ }
141
+ if (this.encoding === 'utf16le') {
142
+ return this.writeUtf16(buffer);
143
+ }
144
+ if (this.encoding === 'base64') {
145
+ return this.writeBase64(buffer);
146
+ }
147
+ if (this.encoding === 'hex') {
148
+ return hexOf(buffer);
149
+ }
150
+ if (this.encoding === 'ascii') {
151
+ return asciiOf(buffer);
152
+ }
153
+ return bytesCodec.bytesToLatin1(buffer);
154
+ }
155
+ end(buffer) {
156
+ let text = '';
157
+ if (buffer !== undefined && buffer.length > 0) {
158
+ text = this.write(buffer);
159
+ }
160
+ if (this.pending.length === 0) {
161
+ return text;
162
+ }
163
+ const pending = this.pending;
164
+ this.pending = new Uint8Array(0);
165
+ if (this.encoding === 'utf8') {
166
+ return text + '�';
167
+ }
168
+ if (this.encoding === 'base64') {
169
+ return text + bytesCodec.encodeBase64(pending);
170
+ }
171
+ // utf16le 的悬空半字符与 hex/ascii/latin1 一样没有残留,直接结束
172
+ return text;
173
+ }
174
+ combine(buffer) {
175
+ if (this.pending.length === 0) {
176
+ return buffer;
177
+ }
178
+ const merged = new Uint8Array(this.pending.length + buffer.length);
179
+ merged.set(this.pending);
180
+ merged.set(buffer, this.pending.length);
181
+ this.pending = new Uint8Array(0);
182
+ return merged;
183
+ }
184
+ writeUtf8(buffer) {
185
+ const merged = this.combine(buffer);
186
+ const complete = completePrefixLength(merged);
187
+ if (complete < merged.length) {
188
+ const rest = merged.subarray(complete);
189
+ this.pending = new Uint8Array(rest.length);
190
+ this.pending.set(rest);
191
+ }
192
+ return bytesCodec.utf8Decode(merged.subarray(0, complete));
193
+ }
194
+ writeUtf16(buffer) {
195
+ const merged = this.combine(buffer);
196
+ let usable = merged.length;
197
+ if (usable % 2 === 1) {
198
+ usable -= 1;
199
+ this.pending = new Uint8Array([merged[merged.length - 1]]);
200
+ }
201
+ return decodeUtf16Pairs(merged.subarray(0, usable));
202
+ }
203
+ writeBase64(buffer) {
204
+ const merged = this.combine(buffer);
205
+ const usable = merged.length - (merged.length % 3);
206
+ if (usable < merged.length) {
207
+ const rest = merged.subarray(usable);
208
+ this.pending = new Uint8Array(rest.length);
209
+ this.pending.set(rest);
210
+ }
211
+ return bytesCodec.encodeBase64(merged.subarray(0, usable));
212
+ }
213
+ }
214
+ exports.StringDecoder = StringDecoder;
215
+ StringDecoder.StringDecoder = StringDecoder;
216
+ function hexOf(buffer) {
217
+ const digits = '0123456789abcdef';
218
+ let out = '';
219
+ for (let i = 0; i < buffer.length; i += 1) {
220
+ out += digits.charAt(buffer[i] >> 4) + digits.charAt(buffer[i] & 15);
221
+ }
222
+ return out;
223
+ }
224
+ function decodeUtf16Pairs(buffer) {
225
+ let out = '';
226
+ for (let i = 0; i + 1 < buffer.length; i += 2) {
227
+ out += String.fromCharCode(buffer[i] | (buffer[i + 1] << 8));
228
+ }
229
+ return out;
230
+ }
231
+ function asciiOf(buffer) {
232
+ let out = '';
233
+ for (let i = 0; i < buffer.length; i += 1) {
234
+ out += String.fromCharCode(buffer[i] & 0x7f);
235
+ }
236
+ return out;
237
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * timers/promises 子路径入口。
3
+ *
4
+ * 与 Node 的差异(都写进了 BUILTINS.json):
5
+ * - setInterval 用「每次 await 一个 setTimeout」实现,而不是原生 interval,
6
+ * 所以延迟会随迭代次数累积漂移;好处是取消语义直白、与 Node 的可迭代行为一致。
7
+ * - signal 只按结构检查(aborted / addEventListener),因为没有 AbortController。
8
+ */
9
+ import type { TimerOptions } from '../lib/timers-types';
10
+ declare const api: {
11
+ setTimeout: (delayMs?: number, value?: unknown, options?: TimerOptions) => Promise<unknown>;
12
+ setImmediate: (value?: unknown, options?: TimerOptions) => Promise<unknown>;
13
+ setInterval: (delayMs: number, value?: unknown, options?: TimerOptions) => AsyncGenerator<unknown>;
14
+ scheduler: {
15
+ wait: (delayMs?: number, options?: TimerOptions) => Promise<void>;
16
+ yield: () => Promise<void>;
17
+ };
18
+ };
19
+ export = api;
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+ function abortFailure() {
3
+ const error = new Error('The operation was aborted');
4
+ error.name = 'AbortError';
5
+ error.code = 'ABORT_ERR';
6
+ return error;
7
+ }
8
+ function alreadyAborted(signal) {
9
+ return signal !== undefined && signal.aborted === true;
10
+ }
11
+ /** 到点后用 value 决议;signal 中止则用 AbortError 拒绝。 */
12
+ function waitFor(delayMs, value, options) {
13
+ return new Promise(function (resolve, reject) {
14
+ const signal = options === undefined ? undefined : options.signal;
15
+ if (alreadyAborted(signal)) {
16
+ reject(abortFailure());
17
+ return;
18
+ }
19
+ let settled = false;
20
+ const handle = setTimeout(function () {
21
+ settled = true;
22
+ detach();
23
+ resolve(value);
24
+ }, delayMs);
25
+ const onAbort = function () {
26
+ if (settled) {
27
+ return;
28
+ }
29
+ settled = true;
30
+ detach();
31
+ clearTimeout(handle);
32
+ reject(abortFailure());
33
+ };
34
+ function detach() {
35
+ if (signal !== undefined && typeof signal.removeEventListener === 'function') {
36
+ signal.removeEventListener('abort', onAbort);
37
+ }
38
+ }
39
+ if (signal !== undefined && typeof signal.addEventListener === 'function') {
40
+ signal.addEventListener('abort', onAbort);
41
+ }
42
+ });
43
+ }
44
+ async function* interval(delayMs, value, options) {
45
+ for (;;) {
46
+ await waitFor(delayMs, undefined, options);
47
+ yield value;
48
+ }
49
+ }
50
+ const scheduler = {
51
+ wait: function (delayMs, options) {
52
+ return waitFor(delayMs === undefined ? 1 : delayMs, undefined, options);
53
+ },
54
+ yield: function () {
55
+ return new Promise(function (resolve) {
56
+ queueMicrotask(function () {
57
+ resolve();
58
+ });
59
+ });
60
+ }
61
+ };
62
+ const api = {
63
+ setTimeout: function (delayMs, value, options) {
64
+ return waitFor(delayMs === undefined ? 1 : delayMs, value, options);
65
+ },
66
+ setImmediate: function (value, options) {
67
+ return waitFor(0, value, options);
68
+ },
69
+ setInterval: function (delayMs, value, options) {
70
+ return interval(delayMs, value, options);
71
+ },
72
+ scheduler: scheduler
73
+ };
74
+ module.exports = api;
@@ -0,0 +1,21 @@
1
+ import type { TimerOptions } from './lib/timers-types';
2
+ declare function setImmediate(handler: (...args: unknown[]) => void, ...args: unknown[]): unknown;
3
+ declare function clearImmediate(handle: unknown): void;
4
+ declare const api: {
5
+ setTimeout: typeof setTimeout;
6
+ clearTimeout: typeof clearTimeout;
7
+ setInterval: typeof setInterval;
8
+ clearInterval: typeof clearInterval;
9
+ setImmediate: typeof setImmediate;
10
+ clearImmediate: typeof clearImmediate;
11
+ promises: {
12
+ setTimeout: (delayMs?: number, value?: unknown, options?: TimerOptions) => Promise<unknown>;
13
+ setImmediate: (value?: unknown, options?: TimerOptions) => Promise<unknown>;
14
+ setInterval: (delayMs: number, value?: unknown, options?: TimerOptions) => AsyncGenerator<unknown>;
15
+ scheduler: {
16
+ wait: (delayMs?: number, options?: TimerOptions) => Promise<void>;
17
+ yield: () => Promise<void>;
18
+ };
19
+ };
20
+ };
21
+ export = api;
package/dist/timers.js ADDED
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+ /**
3
+ * timers 模块。
4
+ *
5
+ * 宿主(Operit)提供 setTimeout / clearTimeout / setInterval / clearInterval 全局,
6
+ * 所以这几个直接就是全局函数本身(Node 的 timers.setTimeout === 全局 setTimeout 也是这样)。
7
+ *
8
+ * setImmediate / clearImmediate 宿主没有,这里落在 setTimeout(…, 0) 上。
9
+ * 与 Node 的差别:Node 的 setImmediate 在 check 阶段、先于定时器;这里两者同一个队列,
10
+ * 因此 setImmediate(fn) 与 setTimeout(fn, 0) 是同一件事。已在 BUILTINS.json 写明。
11
+ */
12
+ const timersPromises = require("./timers/promises");
13
+ const promisifyCustom = Symbol.for('nodejs.util.promisify.custom');
14
+ function setImmediate(handler, ...args) {
15
+ return setTimeout(handler, 0, ...args);
16
+ }
17
+ function clearImmediate(handle) {
18
+ clearTimeout(handle);
19
+ }
20
+ // promisify(setTimeout) 是很常见的写法,靠的就是 setTimeout 上的这个符号。
21
+ // 宿主已经有就不动它(Node 上它是只读 getter,赋值会直接抛),没有才补上。
22
+ if (Object.getOwnPropertyDescriptor(setTimeout, promisifyCustom) === undefined) {
23
+ Object.defineProperty(setTimeout, promisifyCustom, {
24
+ value: function (delayMs, value, options) {
25
+ return timersPromises.setTimeout(delayMs, value, options);
26
+ },
27
+ writable: true,
28
+ enumerable: false,
29
+ configurable: true
30
+ });
31
+ }
32
+ const api = {
33
+ setTimeout: setTimeout,
34
+ clearTimeout: clearTimeout,
35
+ setInterval: setInterval,
36
+ clearInterval: clearInterval,
37
+ setImmediate: setImmediate,
38
+ clearImmediate: clearImmediate,
39
+ promises: timersPromises
40
+ };
41
+ module.exports = api;
package/dist/tty.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare function isatty(): boolean;
2
+ declare function ReadStream(): never;
3
+ declare function WriteStream(): never;
4
+ declare const api: {
5
+ isatty: typeof isatty;
6
+ ReadStream: typeof ReadStream;
7
+ WriteStream: typeof WriteStream;
8
+ };
9
+ export = api;
package/dist/tty.js ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ /**
3
+ * tty 模块。
4
+ *
5
+ * Operit 沙箱里没有终端,所以:
6
+ * - isatty() 一律 false(这正是 supports-color / debug 这类包需要知道的答案);
7
+ * - ReadStream / WriteStream 需要真实终端,构造时显式抛 ONJ_UNSUPPORTED,
8
+ * 不放一个"能 new 但不能用"的空壳。
9
+ */
10
+ const errors_1 = require("./lib/errors");
11
+ function isatty() {
12
+ return false;
13
+ }
14
+ function ReadStream() {
15
+ throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'tty.ReadStream 需要真实终端,Operit 沙箱里没有终端。');
16
+ }
17
+ function WriteStream() {
18
+ throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'tty.WriteStream 需要真实终端,Operit 沙箱里没有终端。');
19
+ }
20
+ const api = {
21
+ isatty: isatty,
22
+ ReadStream: ReadStream,
23
+ WriteStream: WriteStream
24
+ };
25
+ module.exports = api;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * node.operit 对"在 Operit 运行时不成立的 Node 内置模块"的统一表达。
3
+ *
4
+ * 首选策略是构建期拒绝:OperitPackageManager 读到 BUILTINS.json 中 status 为 unsupported 的条目时,
5
+ * 应当直接报构建错误,不要把问题带到运行时。
6
+ *
7
+ * 若选择在运行时表达,重写器应产出调用形式:
8
+ * require('<rel>/node_modules/@serveryyswys/node.operit/unsupported.js')('vm')
9
+ * 这样错误信息里能带上原始模块名。直接 require 本模块只会得到下面的通用错误。
10
+ */
11
+ declare function unsupportedNodeBuiltin(name?: string): never;
12
+ export = unsupportedNodeBuiltin;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ /**
3
+ * node.operit 对"在 Operit 运行时不成立的 Node 内置模块"的统一表达。
4
+ *
5
+ * 首选策略是构建期拒绝:OperitPackageManager 读到 BUILTINS.json 中 status 为 unsupported 的条目时,
6
+ * 应当直接报构建错误,不要把问题带到运行时。
7
+ *
8
+ * 若选择在运行时表达,重写器应产出调用形式:
9
+ * require('<rel>/node_modules/@serveryyswys/node.operit/unsupported.js')('vm')
10
+ * 这样错误信息里能带上原始模块名。直接 require 本模块只会得到下面的通用错误。
11
+ */
12
+ function unsupportedNodeBuiltin(name) {
13
+ const target = typeof name === 'string' && name.length > 0 ? name : '<未知模块>';
14
+ throw new Error('node.operit 不提供 Node 内置模块 "' + target + '":它在 Operit 的 QuickJS 运行时不成立。' +
15
+ '请查阅 node.operit/BUILTINS.json 的 builtins 条目。');
16
+ }
17
+ module.exports = unsupportedNodeBuiltin;
package/dist/url.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { URLSearchParams as SearchParams } from './lib/url-search-params';
2
+ import { URL as WhatwgUrl } from './lib/url-whatwg';
3
+ import type { ParsedUrl } from './lib/url-types';
4
+ declare function parseUrl(input: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): ParsedUrl;
5
+ declare function formatUrl(source?: unknown): string;
6
+ declare function resolveUrl(from: unknown, to: unknown): string;
7
+ declare function pathToFileURL(filepath: unknown): WhatwgUrl;
8
+ /**
9
+ * 把 URL 实例转成 http.request 的选项对象。
10
+ * 语义照 Node:IPv6 主机去掉方括号、path 是 pathname + search、auth 从 username/password 还原。
11
+ */
12
+ declare function urlToHttpOptions(url: unknown): Record<string, unknown>;
13
+ declare function fileURLToPath(path: unknown): string;
14
+ declare function domainToASCII(domain: unknown): string;
15
+ declare function domainToUnicode(domain: unknown): string;
16
+ declare const urlModule: {
17
+ URLSearchParams: typeof SearchParams;
18
+ parse: typeof parseUrl;
19
+ format: typeof formatUrl;
20
+ resolve: typeof resolveUrl;
21
+ pathToFileURL: typeof pathToFileURL;
22
+ fileURLToPath: typeof fileURLToPath;
23
+ domainToASCII: typeof domainToASCII;
24
+ domainToUnicode: typeof domainToUnicode;
25
+ URL: typeof WhatwgUrl;
26
+ urlToHttpOptions: typeof urlToHttpOptions;
27
+ };
28
+ export = urlModule;