@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,36 @@
1
+ /**
2
+ * perf_hooks 模块(部分)。
3
+ *
4
+ * 宿主提供 `performance.now()`,但只有这一个方法;mark / measure / getEntries 这些
5
+ * 由本模块自己维护一张表实现,与 Node 的语义对齐(含 measure 的两种调用形式)。
6
+ *
7
+ * 未实现:PerformanceObserver、PerformanceEntry 等类、monitorEventLoopDelay、
8
+ * createHistogram。这些要么依赖 V8/Node 的观测能力,要么在沙箱里没有意义;
9
+ * 保持 undefined 而不是给空壳。
10
+ */
11
+ import type { MeasureOptions, PerformanceEntryLike } from './lib/perf-hooks-types';
12
+ declare function now(): number;
13
+ declare function mark(name: unknown, options?: {
14
+ detail?: unknown;
15
+ }): PerformanceEntryLike;
16
+ declare function measure(name: unknown, startOrOptions?: string | number | MeasureOptions, endMark?: string | number): PerformanceEntryLike;
17
+ declare function getEntries(): PerformanceEntryLike[];
18
+ declare function getEntriesByName(name: unknown, type?: unknown): PerformanceEntryLike[];
19
+ declare function getEntriesByType(type: unknown): PerformanceEntryLike[];
20
+ declare function clearMarks(name?: unknown): void;
21
+ declare function clearMeasures(name?: unknown): void;
22
+ declare const api: {
23
+ performance: {
24
+ now: typeof now;
25
+ timeOrigin: number;
26
+ mark: typeof mark;
27
+ measure: typeof measure;
28
+ getEntries: typeof getEntries;
29
+ getEntriesByName: typeof getEntriesByName;
30
+ getEntriesByType: typeof getEntriesByType;
31
+ clearMarks: typeof clearMarks;
32
+ clearMeasures: typeof clearMeasures;
33
+ };
34
+ constants: Record<string, number>;
35
+ };
36
+ export = api;
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+ const entries = [];
3
+ const markTimes = new Map();
4
+ const timeOrigin = Date.now() - performance.now();
5
+ function now() {
6
+ return performance.now();
7
+ }
8
+ function makeEntry(name, entryType, startTime, duration, detail) {
9
+ const entry = {
10
+ name: name,
11
+ entryType: entryType,
12
+ startTime: startTime,
13
+ duration: duration
14
+ };
15
+ if (detail !== undefined) {
16
+ entry.detail = detail;
17
+ }
18
+ return entry;
19
+ }
20
+ /** options 形式:start/end 既可以是 mark 名字,也可以是时间戳。 */
21
+ function resolveOptionTime(value, fallback) {
22
+ if (value === undefined) {
23
+ return fallback;
24
+ }
25
+ if (typeof value === 'number') {
26
+ return value;
27
+ }
28
+ const marked = markTimes.get(value);
29
+ return marked === undefined ? fallback : marked;
30
+ }
31
+ /**
32
+ * 位置参数形式:startMark / endMark **只当 mark 名字**,不认数字。
33
+ * 这是实测 Node 的行为 —— measure('x', 10, 30) 在 Node 里是"找名叫 10 和 30 的 mark",
34
+ * 找不到就是 start=0、end=now(),而不是把 10/30 当时间戳。
35
+ */
36
+ function resolveMarkName(value, fallback) {
37
+ if (value === undefined) {
38
+ return fallback;
39
+ }
40
+ const marked = markTimes.get(String(value));
41
+ return marked === undefined ? fallback : marked;
42
+ }
43
+ function mark(name, options) {
44
+ const label = String(name);
45
+ const startTime = now();
46
+ markTimes.set(label, startTime);
47
+ const entry = makeEntry(label, 'mark', startTime, 0, options === undefined ? undefined : options.detail);
48
+ entries.push(entry);
49
+ return entry;
50
+ }
51
+ function measure(name, startOrOptions, endMark) {
52
+ const label = String(name);
53
+ let start = 0;
54
+ let end = now();
55
+ let detail;
56
+ if (startOrOptions !== undefined && typeof startOrOptions === 'object') {
57
+ start = resolveOptionTime(startOrOptions.start, 0);
58
+ end = resolveOptionTime(startOrOptions.end, now());
59
+ detail = startOrOptions.detail;
60
+ }
61
+ else {
62
+ start = resolveMarkName(startOrOptions, 0);
63
+ end = resolveMarkName(endMark, now());
64
+ }
65
+ const entry = makeEntry(label, 'measure', start, end - start, detail);
66
+ entries.push(entry);
67
+ return entry;
68
+ }
69
+ function getEntries() {
70
+ return entries.slice();
71
+ }
72
+ function getEntriesByName(name, type) {
73
+ const label = String(name);
74
+ return entries.filter(function (entry) {
75
+ if (entry.name !== label) {
76
+ return false;
77
+ }
78
+ return type === undefined || entry.entryType === String(type);
79
+ });
80
+ }
81
+ function getEntriesByType(type) {
82
+ const wanted = String(type);
83
+ return entries.filter(function (entry) {
84
+ return entry.entryType === wanted;
85
+ });
86
+ }
87
+ function clearMarks(name) {
88
+ const label = name === undefined ? undefined : String(name);
89
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
90
+ if (entries[i].entryType !== 'mark') {
91
+ continue;
92
+ }
93
+ if (label === undefined || entries[i].name === label) {
94
+ entries.splice(i, 1);
95
+ }
96
+ }
97
+ if (label === undefined) {
98
+ markTimes.clear();
99
+ }
100
+ else {
101
+ markTimes.delete(label);
102
+ }
103
+ }
104
+ function clearMeasures(name) {
105
+ const label = name === undefined ? undefined : String(name);
106
+ for (let i = entries.length - 1; i >= 0; i -= 1) {
107
+ if (entries[i].entryType !== 'measure') {
108
+ continue;
109
+ }
110
+ if (label === undefined || entries[i].name === label) {
111
+ entries.splice(i, 1);
112
+ }
113
+ }
114
+ }
115
+ const performanceApi = {
116
+ now: now,
117
+ timeOrigin: timeOrigin,
118
+ mark: mark,
119
+ measure: measure,
120
+ getEntries: getEntries,
121
+ getEntriesByName: getEntriesByName,
122
+ getEntriesByType: getEntriesByType,
123
+ clearMarks: clearMarks,
124
+ clearMeasures: clearMeasures
125
+ };
126
+ /** 与 Node 的 perf_hooks.constants 一致。 */
127
+ const constants = {
128
+ NODE_PERFORMANCE_GC_MAJOR: 4,
129
+ NODE_PERFORMANCE_GC_MINOR: 1,
130
+ NODE_PERFORMANCE_GC_INCREMENTAL: 8,
131
+ NODE_PERFORMANCE_GC_WEAKCB: 16,
132
+ NODE_PERFORMANCE_GC_FLAGS_NO: 0,
133
+ NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: 2,
134
+ NODE_PERFORMANCE_GC_FLAGS_FORCED: 4,
135
+ NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: 8,
136
+ NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: 16,
137
+ NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: 32,
138
+ NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: 64
139
+ };
140
+ const api = {
141
+ performance: performanceApi,
142
+ constants: constants
143
+ };
144
+ module.exports = api;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Node process 模块的移植。
3
+ *
4
+ * 这是 `require('process')` 返回的对象。注意 Operit 运行时**没有** `process` 全局,
5
+ * 所以直接引用裸 `process` 的代码需要由 OperitPackageManager 在重写时注入(见 README)。
6
+ *
7
+ * 已知差异:
8
+ * - process.env 是 Proxy,读走 Operit 的 getEnv;getEnv 对不存在的变量返回空串,
9
+ * 因此空串与未设置都表现为 undefined;且无法枚举(Object.keys(env) 恒为 [])
10
+ * - process.exit() 会终止整个 Operit 运行时,这里显式抛错而不是静默继续
11
+ * - versions.node 是"声明的兼容目标",不是真实运行时版本
12
+ */
13
+ import EventEmitter = require('./events');
14
+ declare function nextTick(fn: (...args: unknown[]) => void, ...args: unknown[]): void;
15
+ declare class Process extends EventEmitter {
16
+ exitCode: number | undefined;
17
+ title: string;
18
+ get platform(): string;
19
+ get arch(): string;
20
+ get version(): string;
21
+ readonly versions: {
22
+ node: string;
23
+ operit: string;
24
+ quickjs: string;
25
+ };
26
+ readonly argv: string[];
27
+ readonly execArgv: string[];
28
+ readonly execPath = "operit";
29
+ readonly env: Record<string, string | undefined>;
30
+ readonly stdout: {
31
+ isTTY: boolean;
32
+ columns: number;
33
+ rows: number;
34
+ write(chunk: string | Uint8Array): boolean;
35
+ };
36
+ readonly stderr: {
37
+ isTTY: boolean;
38
+ columns: number;
39
+ rows: number;
40
+ write(chunk: string | Uint8Array): boolean;
41
+ };
42
+ readonly stdin: {
43
+ isTTY: boolean;
44
+ read: () => null;
45
+ on: () => unknown;
46
+ resume: () => void;
47
+ };
48
+ readonly nextTick: typeof nextTick;
49
+ readonly hrtime: ((previous?: number[]) => number[]) & {
50
+ bigint(): bigint;
51
+ };
52
+ get pid(): number;
53
+ cwd(): string;
54
+ chdir(directory: string): void;
55
+ uptime(): number;
56
+ memoryUsage(): {
57
+ rss: number;
58
+ heapTotal: number;
59
+ heapUsed: number;
60
+ external: number;
61
+ arrayBuffers: number;
62
+ };
63
+ emitWarning(warning: unknown): void;
64
+ exit(code?: number): never;
65
+ abort(): never;
66
+ umask(): number;
67
+ }
68
+ declare const processObject: Process;
69
+ export = processObject;
@@ -0,0 +1,230 @@
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
+ /**
36
+ * Node process 模块的移植。
37
+ *
38
+ * 这是 `require('process')` 返回的对象。注意 Operit 运行时**没有** `process` 全局,
39
+ * 所以直接引用裸 `process` 的代码需要由 OperitPackageManager 在重写时注入(见 README)。
40
+ *
41
+ * 已知差异:
42
+ * - process.env 是 Proxy,读走 Operit 的 getEnv;getEnv 对不存在的变量返回空串,
43
+ * 因此空串与未设置都表现为 undefined;且无法枚举(Object.keys(env) 恒为 [])
44
+ * - process.exit() 会终止整个 Operit 运行时,这里显式抛错而不是静默继续
45
+ * - versions.node 是"声明的兼容目标",不是真实运行时版本
46
+ */
47
+ const EventEmitter = require("./events");
48
+ const fsModule = require("./fs");
49
+ const pathModule = require("./path");
50
+ const os = __importStar(require("./os"));
51
+ const cwd = __importStar(require("./lib/cwd"));
52
+ const bridge = __importStar(require("./lib/bridge"));
53
+ const bytesCodec = __importStar(require("./lib/bytes"));
54
+ const errors_1 = require("./lib/errors");
55
+ const pending = [];
56
+ let drainScheduled = false;
57
+ function drainQueue() {
58
+ drainScheduled = false;
59
+ const batch = pending.splice(0, pending.length);
60
+ for (let i = 0; i < batch.length; i += 1) {
61
+ batch[i].fn.apply(null, batch[i].args);
62
+ }
63
+ }
64
+ function nextTick(fn, ...args) {
65
+ if (typeof fn !== 'function') {
66
+ throw new TypeError('The "callback" argument must be of type function.');
67
+ }
68
+ pending.push({ fn: fn, args: args });
69
+ if (!drainScheduled) {
70
+ drainScheduled = true;
71
+ queueMicrotask(drainQueue);
72
+ }
73
+ }
74
+ function hrtime(previous) {
75
+ const nowMs = performance.now();
76
+ let seconds = Math.floor(nowMs / 1000);
77
+ let nanoseconds = Math.floor((nowMs % 1000) * 1e6);
78
+ if (previous !== undefined) {
79
+ seconds -= previous[0];
80
+ nanoseconds -= previous[1];
81
+ if (nanoseconds < 0) {
82
+ seconds -= 1;
83
+ nanoseconds += 1e9;
84
+ }
85
+ }
86
+ return [seconds, nanoseconds];
87
+ }
88
+ const hrtimeFunction = hrtime;
89
+ hrtimeFunction.bigint = function () {
90
+ return BigInt(Math.floor(performance.now() * 1e6));
91
+ };
92
+ function readEnvVariable(key) {
93
+ if (typeof getEnv !== 'function') {
94
+ return undefined;
95
+ }
96
+ const value = getEnv(key);
97
+ // Operit 的 getEnv 对不存在的变量返回空串,无法与"设为空串"区分
98
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
99
+ }
100
+ const env = new Proxy({}, {
101
+ get: function (_target, key) {
102
+ return typeof key === 'string' ? readEnvVariable(key) : undefined;
103
+ },
104
+ set: function (_target, key, value) {
105
+ bridge.setEnv(String(key), value === undefined || value === null ? null : String(value));
106
+ return true;
107
+ },
108
+ has: function (_target, key) {
109
+ return typeof key === 'string' && readEnvVariable(key) !== undefined;
110
+ },
111
+ deleteProperty: function (_target, key) {
112
+ bridge.setEnv(String(key), null);
113
+ return true;
114
+ },
115
+ ownKeys: function () {
116
+ // Operit 没有枚举环境变量的接口,因此这里只能为空
117
+ return [];
118
+ }
119
+ });
120
+ function createWritable(level) {
121
+ return {
122
+ isTTY: false,
123
+ columns: 0,
124
+ rows: 0,
125
+ write: function (chunk) {
126
+ const text = typeof chunk === 'string' ? chunk : bytesCodec.utf8Decode(chunk);
127
+ const line = text.charAt(text.length - 1) === '\n' ? text.slice(0, text.length - 1) : text;
128
+ if (level === 'log') {
129
+ console.log(line);
130
+ }
131
+ else {
132
+ console.warn(line);
133
+ }
134
+ return true;
135
+ }
136
+ };
137
+ }
138
+ class Process extends EventEmitter {
139
+ constructor() {
140
+ // 注意:Process 只以实例形式导出(export =),所以所有成员必须是 public,
141
+ // 否则 declaration 生成会报 TS4094。
142
+ super(...arguments);
143
+ this.exitCode = undefined;
144
+ this.title = 'operit';
145
+ this.versions = {
146
+ // 声明的兼容目标,不是真实运行时版本;见 README「已知偏差」
147
+ node: '18.0.0',
148
+ operit: 'node.operit/0.1.0',
149
+ quickjs: 'unknown'
150
+ };
151
+ this.argv = ['operit'];
152
+ this.execArgv = [];
153
+ this.execPath = 'operit';
154
+ this.env = env;
155
+ this.stdout = createWritable('log');
156
+ this.stderr = createWritable('warn');
157
+ this.stdin = {
158
+ isTTY: false,
159
+ read: function () {
160
+ return null;
161
+ },
162
+ on: function () {
163
+ return this;
164
+ },
165
+ resume: function () {
166
+ // 沙箱里没有真实 stdin
167
+ }
168
+ };
169
+ this.nextTick = nextTick;
170
+ this.hrtime = hrtimeFunction;
171
+ }
172
+ // 这三个改成 getter:读的时候才碰宿主,模块加载本身不调用 bridge
173
+ get platform() {
174
+ return os.platform();
175
+ }
176
+ get arch() {
177
+ return os.arch();
178
+ }
179
+ get version() {
180
+ return os.version();
181
+ }
182
+ get pid() {
183
+ return Number(bridge.callStatic('android.os.Process', 'myPid', [])) || 0;
184
+ }
185
+ cwd() {
186
+ return cwd.get();
187
+ }
188
+ chdir(directory) {
189
+ if (typeof directory !== 'string') {
190
+ throw new TypeError('The "directory" argument must be of type string.');
191
+ }
192
+ const stats = fsModule.statSync(directory);
193
+ if (stats === undefined || !stats.isDirectory()) {
194
+ throw (0, errors_1.createError)('ENOTDIR', 'chdir', directory);
195
+ }
196
+ // Node 把 cwd 存成解析后的绝对路径,不是原始参数
197
+ cwd.set(pathModule.resolve(directory));
198
+ }
199
+ uptime() {
200
+ return os.uptime();
201
+ }
202
+ memoryUsage() {
203
+ const heapTotal = os.totalmem();
204
+ const free = os.freemem();
205
+ return {
206
+ rss: heapTotal,
207
+ heapTotal: heapTotal,
208
+ heapUsed: heapTotal - free,
209
+ external: 0,
210
+ arrayBuffers: 0
211
+ };
212
+ }
213
+ emitWarning(warning) {
214
+ const value = warning instanceof Error ? warning : new Error(String(warning));
215
+ this.emit('warning', value);
216
+ console.warn('Warning: ' + value.message);
217
+ }
218
+ exit(code) {
219
+ void code;
220
+ throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'process.exit() 会终止整个 Operit 运行时,node.operit 不提供。');
221
+ }
222
+ abort() {
223
+ throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'process.abort() 会终止整个 Operit 运行时,node.operit 不提供。');
224
+ }
225
+ umask() {
226
+ return 0o022;
227
+ }
228
+ }
229
+ const processObject = new Process();
230
+ module.exports = processObject;
@@ -0,0 +1,15 @@
1
+ /** 与 Node 一致:querystring.escape 就是 encodeURIComponent(不额外转义 ! ' ( ) *)。 */
2
+ export declare function escape(value: unknown): string;
3
+ export declare function unescape(value: unknown): string;
4
+ interface StringifyOptions {
5
+ encodeURIComponent?: (value: string) => string;
6
+ }
7
+ export declare function stringify(value: unknown, separator?: string, equals?: string, options?: StringifyOptions): string;
8
+ interface ParseOptions {
9
+ maxKeys?: number;
10
+ decodeURIComponent?: (value: string) => string;
11
+ }
12
+ export declare function parse(text: unknown, separator?: string, equals?: string, options?: ParseOptions): Record<string, string | string[]>;
13
+ export declare const encode: typeof stringify;
14
+ export declare const decode: typeof parse;
15
+ export {};