@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.
- package/BUILTINS.json +233 -0
- package/DESIGN.md +513 -0
- package/LICENSE +674 -0
- package/README.md +301 -2
- package/dist/assert/strict.d.ts +2 -0
- package/dist/assert/strict.js +7 -0
- package/dist/assert.d.ts +3 -0
- package/dist/assert.js +483 -0
- package/dist/buffer.d.ts +60 -0
- package/dist/buffer.js +524 -0
- package/dist/child_process.d.ts +56 -0
- package/dist/child_process.js +371 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +19 -0
- package/dist/crypto.d.ts +76 -0
- package/dist/crypto.js +312 -0
- package/dist/dns/promises.d.ts +34 -0
- package/dist/dns/promises.js +190 -0
- package/dist/dns.d.ts +88 -0
- package/dist/dns.js +259 -0
- package/dist/events.d.ts +40 -0
- package/dist/events.js +237 -0
- package/dist/fs/promises.d.ts +159 -0
- package/dist/fs/promises.js +129 -0
- package/dist/fs.d.ts +221 -0
- package/dist/fs.js +944 -0
- package/dist/http.d.ts +92 -0
- package/dist/http.js +319 -0
- package/dist/https.d.ts +296 -0
- package/dist/https.js +50 -0
- package/dist/index.d.ts +2422 -0
- package/dist/index.js +57 -0
- package/dist/lib/bridge.d.ts +60 -0
- package/dist/lib/bridge.js +205 -0
- package/dist/lib/bytes.d.ts +20 -0
- package/dist/lib/bytes.js +239 -0
- package/dist/lib/child-process-types.d.ts +45 -0
- package/dist/lib/child-process-types.js +2 -0
- package/dist/lib/cwd.d.ts +2 -0
- package/dist/lib/cwd.js +32 -0
- package/dist/lib/deep-equal.d.ts +3 -0
- package/dist/lib/deep-equal.js +223 -0
- package/dist/lib/deflate.d.ts +2 -0
- package/dist/lib/deflate.js +234 -0
- package/dist/lib/dns-driver.d.ts +14 -0
- package/dist/lib/dns-driver.js +85 -0
- package/dist/lib/dns-types.d.ts +22 -0
- package/dist/lib/dns-types.js +2 -0
- package/dist/lib/errors.d.ts +48 -0
- package/dist/lib/errors.js +424 -0
- package/dist/lib/fs-driver.d.ts +70 -0
- package/dist/lib/fs-driver.js +364 -0
- package/dist/lib/fs-env.d.ts +30 -0
- package/dist/lib/fs-env.js +157 -0
- package/dist/lib/fs-types.d.ts +19 -0
- package/dist/lib/fs-types.js +2 -0
- package/dist/lib/hashes.d.ts +27 -0
- package/dist/lib/hashes.js +432 -0
- package/dist/lib/http-driver.d.ts +30 -0
- package/dist/lib/http-driver.js +72 -0
- package/dist/lib/http-types.d.ts +18 -0
- package/dist/lib/http-types.js +2 -0
- package/dist/lib/inflate.d.ts +6 -0
- package/dist/lib/inflate.js +284 -0
- package/dist/lib/path-types.d.ts +37 -0
- package/dist/lib/path-types.js +2 -0
- package/dist/lib/paths.d.ts +8 -0
- package/dist/lib/paths.js +106 -0
- package/dist/lib/perf-hooks-types.d.ts +18 -0
- package/dist/lib/perf-hooks-types.js +2 -0
- package/dist/lib/process-driver.d.ts +31 -0
- package/dist/lib/process-driver.js +102 -0
- package/dist/lib/punycode.d.ts +8 -0
- package/dist/lib/punycode.js +179 -0
- package/dist/lib/stream-types.d.ts +29 -0
- package/dist/lib/stream-types.js +2 -0
- package/dist/lib/timers-types.d.ts +18 -0
- package/dist/lib/timers-types.js +2 -0
- package/dist/lib/url-search-params.d.ts +26 -0
- package/dist/lib/url-search-params.js +281 -0
- package/dist/lib/url-types.d.ts +44 -0
- package/dist/lib/url-types.js +2 -0
- package/dist/lib/url-whatwg.d.ts +78 -0
- package/dist/lib/url-whatwg.js +857 -0
- package/dist/lib/zlib-types.d.ts +12 -0
- package/dist/lib/zlib-types.js +2 -0
- package/dist/module.d.ts +8 -0
- package/dist/module.js +72 -0
- package/dist/os.d.ts +80 -0
- package/dist/os.js +247 -0
- package/dist/path/posix.d.ts +2 -0
- package/dist/path/posix.js +7 -0
- package/dist/path/win32.d.ts +2 -0
- package/dist/path/win32.js +10 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +1222 -0
- package/dist/perf_hooks.d.ts +36 -0
- package/dist/perf_hooks.js +144 -0
- package/dist/process.d.ts +69 -0
- package/dist/process.js +230 -0
- package/dist/querystring.d.ts +15 -0
- package/dist/querystring.js +209 -0
- package/dist/stream/promises.d.ts +5 -0
- package/dist/stream/promises.js +10 -0
- package/dist/stream.d.ts +84 -0
- package/dist/stream.js +875 -0
- package/dist/string_decoder.d.ts +15 -0
- package/dist/string_decoder.js +237 -0
- package/dist/timers/promises.d.ts +19 -0
- package/dist/timers/promises.js +74 -0
- package/dist/timers.d.ts +21 -0
- package/dist/timers.js +41 -0
- package/dist/tty.d.ts +9 -0
- package/dist/tty.js +25 -0
- package/dist/unsupported.d.ts +12 -0
- package/dist/unsupported.js +17 -0
- package/dist/url.d.ts +28 -0
- package/dist/url.js +486 -0
- package/dist/util.d.ts +74 -0
- package/dist/util.js +515 -0
- package/dist/zlib.d.ts +88 -0
- package/dist/zlib.js +371 -0
- package/package.json +29 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zlib 的公开类型。
|
|
3
|
+
*
|
|
4
|
+
* 独立成文件的原因与 path-types 相同:zlib.ts 用 `export =` 导出模块本体,
|
|
5
|
+
* 无法再导出类型,而 index.ts 聚合时需要这些名字是"可命名"的。
|
|
6
|
+
*/
|
|
7
|
+
export interface DeflateOptions {
|
|
8
|
+
/** 0 = 不压缩(stored);1..9 越大越慢,未实现动态 Huffman,压缩率低于 zlib。 */
|
|
9
|
+
level?: number;
|
|
10
|
+
/** 仅用于与 Node 的签名兼容;本实现总是按 32K 窗口处理。 */
|
|
11
|
+
windowBits?: number;
|
|
12
|
+
}
|
package/dist/module.d.ts
ADDED
package/dist/module.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* module 模块(只取在 Operit 里说得通的部分)。
|
|
4
|
+
*
|
|
5
|
+
* 提供:
|
|
6
|
+
* - builtinModules:**与 BUILTINS.json 的键逐字一致**(包含尚未实现的那些,
|
|
7
|
+
* 因为 isBuiltin 回答的是"这是不是一个 Node 内建名",不是"我们实现了没有")。
|
|
8
|
+
* 测试里会断言两者同步,防止改契约表时漏改这里;
|
|
9
|
+
* - isBuiltin():认 'node:' 前缀;
|
|
10
|
+
* - createRequire():显式抛 ONJ_UNSUPPORTED。
|
|
11
|
+
*
|
|
12
|
+
* createRequire 为什么不做:它依赖 node_modules 逐级查找与 main/exports 解析,
|
|
13
|
+
* 而 Operit 的 require 两样都没有(见 BUILTINS.json 的 packing 段)。
|
|
14
|
+
* 与其给一个"看起来像但解析不出东西"的 require,不如明确拒绝。
|
|
15
|
+
*
|
|
16
|
+
* Module 类、_resolveFilename 等内部接口不提供。
|
|
17
|
+
*/
|
|
18
|
+
const errors_1 = require("./lib/errors");
|
|
19
|
+
const builtinModules = [
|
|
20
|
+
'assert',
|
|
21
|
+
'assert/strict',
|
|
22
|
+
'async_hooks',
|
|
23
|
+
'buffer',
|
|
24
|
+
'child_process',
|
|
25
|
+
'cluster',
|
|
26
|
+
'constants',
|
|
27
|
+
'crypto',
|
|
28
|
+
'dns',
|
|
29
|
+
'events',
|
|
30
|
+
'fs',
|
|
31
|
+
'fs/promises',
|
|
32
|
+
'http',
|
|
33
|
+
'https',
|
|
34
|
+
'inspector',
|
|
35
|
+
'module',
|
|
36
|
+
'net',
|
|
37
|
+
'os',
|
|
38
|
+
'path',
|
|
39
|
+
'path/posix',
|
|
40
|
+
'path/win32',
|
|
41
|
+
'perf_hooks',
|
|
42
|
+
'process',
|
|
43
|
+
'querystring',
|
|
44
|
+
'readline',
|
|
45
|
+
'repl',
|
|
46
|
+
'stream',
|
|
47
|
+
'stream/promises',
|
|
48
|
+
'string_decoder',
|
|
49
|
+
'timers',
|
|
50
|
+
'timers/promises',
|
|
51
|
+
'tty',
|
|
52
|
+
'url',
|
|
53
|
+
'util',
|
|
54
|
+
'vm',
|
|
55
|
+
'worker_threads',
|
|
56
|
+
'zlib'
|
|
57
|
+
];
|
|
58
|
+
function isBuiltin(name) {
|
|
59
|
+
const text = String(name);
|
|
60
|
+
const bare = text.indexOf('node:') === 0 ? text.slice(5) : text;
|
|
61
|
+
return builtinModules.indexOf(bare) >= 0;
|
|
62
|
+
}
|
|
63
|
+
function createRequire() {
|
|
64
|
+
throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'module.createRequire() 依赖 node_modules 逐级查找与 main/exports 解析,Operit 的 require 两者都没有;' +
|
|
65
|
+
'打包期由 OperitPackageManager 把裸名重写成相对路径。');
|
|
66
|
+
}
|
|
67
|
+
const api = {
|
|
68
|
+
builtinModules: builtinModules,
|
|
69
|
+
isBuiltin: isBuiltin,
|
|
70
|
+
createRequire: createRequire
|
|
71
|
+
};
|
|
72
|
+
module.exports = api;
|
package/dist/os.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface CpuInfo {
|
|
2
|
+
model: string;
|
|
3
|
+
speed: number;
|
|
4
|
+
times: {
|
|
5
|
+
user: number;
|
|
6
|
+
nice: number;
|
|
7
|
+
sys: number;
|
|
8
|
+
idle: number;
|
|
9
|
+
irq: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface NetworkInterfaceInfo {
|
|
13
|
+
address: string;
|
|
14
|
+
family: string;
|
|
15
|
+
internal: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const EOL = "\n";
|
|
18
|
+
export declare function platform(): string;
|
|
19
|
+
export declare function arch(): string;
|
|
20
|
+
export declare function machine(): string;
|
|
21
|
+
export declare function type(): string;
|
|
22
|
+
export declare function release(): string;
|
|
23
|
+
export declare function version(): string;
|
|
24
|
+
export declare function endianness(): string;
|
|
25
|
+
export declare function hostname(): string;
|
|
26
|
+
export declare function tmpdir(): string;
|
|
27
|
+
/** Android 没有用户 home;按已安装包都可见的公共目录取 /sdcard。 */
|
|
28
|
+
export declare function homedir(): string;
|
|
29
|
+
export declare function availableParallelism(): number;
|
|
30
|
+
export declare function cpus(): CpuInfo[];
|
|
31
|
+
/** JVM 堆上限,不是物理内存总量。 */
|
|
32
|
+
export declare function totalmem(): number;
|
|
33
|
+
/** JVM 堆空闲量,不是系统可用内存。 */
|
|
34
|
+
export declare function freemem(): number;
|
|
35
|
+
export declare function loadavg(): number[];
|
|
36
|
+
export declare function uptime(): number;
|
|
37
|
+
export interface UserInfo {
|
|
38
|
+
uid: number;
|
|
39
|
+
gid: number;
|
|
40
|
+
username: string;
|
|
41
|
+
homedir: string;
|
|
42
|
+
shell: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function userInfo(): UserInfo;
|
|
45
|
+
/** 通过 NetworkInterface 的 Enumeration 逐个展开;Java 侧没有直接可用的集合视图。 */
|
|
46
|
+
export declare function networkInterfaces(): Record<string, NetworkInterfaceInfo[]>;
|
|
47
|
+
/** Node 的 os.devNull 是字符串属性,不是函数。 */
|
|
48
|
+
export declare const devNull = "/dev/null";
|
|
49
|
+
/** 进程优先级在 Android 上由调度器策略决定,Node 的 niceness 语义不成立。 */
|
|
50
|
+
export declare function getPriority(): number;
|
|
51
|
+
export declare function setPriority(): void;
|
|
52
|
+
export declare const constants: {
|
|
53
|
+
signals: {
|
|
54
|
+
SIGHUP: number;
|
|
55
|
+
SIGINT: number;
|
|
56
|
+
SIGQUIT: number;
|
|
57
|
+
SIGILL: number;
|
|
58
|
+
SIGTRAP: number;
|
|
59
|
+
SIGABRT: number;
|
|
60
|
+
SIGBUS: number;
|
|
61
|
+
SIGFPE: number;
|
|
62
|
+
SIGKILL: number;
|
|
63
|
+
SIGUSR1: number;
|
|
64
|
+
SIGSEGV: number;
|
|
65
|
+
SIGUSR2: number;
|
|
66
|
+
SIGPIPE: number;
|
|
67
|
+
SIGALRM: number;
|
|
68
|
+
SIGTERM: number;
|
|
69
|
+
SIGWINCH: number;
|
|
70
|
+
};
|
|
71
|
+
errno: Record<string, number>;
|
|
72
|
+
priority: {
|
|
73
|
+
PRIORITY_LOW: number;
|
|
74
|
+
PRIORITY_BELOW_NORMAL: number;
|
|
75
|
+
PRIORITY_NORMAL: number;
|
|
76
|
+
PRIORITY_ABOVE_NORMAL: number;
|
|
77
|
+
PRIORITY_HIGH: number;
|
|
78
|
+
PRIORITY_HIGHEST: number;
|
|
79
|
+
};
|
|
80
|
+
};
|
package/dist/os.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
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.constants = exports.devNull = exports.EOL = void 0;
|
|
37
|
+
exports.platform = platform;
|
|
38
|
+
exports.arch = arch;
|
|
39
|
+
exports.machine = machine;
|
|
40
|
+
exports.type = type;
|
|
41
|
+
exports.release = release;
|
|
42
|
+
exports.version = version;
|
|
43
|
+
exports.endianness = endianness;
|
|
44
|
+
exports.hostname = hostname;
|
|
45
|
+
exports.tmpdir = tmpdir;
|
|
46
|
+
exports.homedir = homedir;
|
|
47
|
+
exports.availableParallelism = availableParallelism;
|
|
48
|
+
exports.cpus = cpus;
|
|
49
|
+
exports.totalmem = totalmem;
|
|
50
|
+
exports.freemem = freemem;
|
|
51
|
+
exports.loadavg = loadavg;
|
|
52
|
+
exports.uptime = uptime;
|
|
53
|
+
exports.userInfo = userInfo;
|
|
54
|
+
exports.networkInterfaces = networkInterfaces;
|
|
55
|
+
exports.getPriority = getPriority;
|
|
56
|
+
exports.setPriority = setPriority;
|
|
57
|
+
/**
|
|
58
|
+
* Node os 模块的移植。
|
|
59
|
+
*
|
|
60
|
+
* 取值全部来自 Android / Java 侧,因此与桌面 Node 的数值必然不同;
|
|
61
|
+
* 这里保证的是**形状与语义**(类型、单位、字段名)与 Node 一致,
|
|
62
|
+
* 以及每个近似值都在 README / BUILTINS.json 里写清楚。
|
|
63
|
+
*
|
|
64
|
+
* 已知近似:
|
|
65
|
+
* - totalmem / freemem 取的是 JVM 堆上限与空闲量,不是物理内存
|
|
66
|
+
* - cpus() 的 model 是 os.arch,speed 为 0,times 全 0
|
|
67
|
+
* - homedir() 返回 /sdcard(Android 没有用户 home 概念)
|
|
68
|
+
* - loadavg() 恒为 [0,0,0]
|
|
69
|
+
*/
|
|
70
|
+
const bridge = __importStar(require("./lib/bridge"));
|
|
71
|
+
const paths = __importStar(require("./lib/paths"));
|
|
72
|
+
const errors_1 = require("./lib/errors");
|
|
73
|
+
function runtime() {
|
|
74
|
+
return bridge.callStatic('java.lang.Runtime', 'getRuntime', []);
|
|
75
|
+
}
|
|
76
|
+
function readProperty(name) {
|
|
77
|
+
const value = bridge.callStatic('java.lang.System', 'getProperty', [name]);
|
|
78
|
+
return typeof value === 'string' ? value : '';
|
|
79
|
+
}
|
|
80
|
+
/** Node 的 arch 命名与 Java 的 os.arch 不同,这里显式映射。 */
|
|
81
|
+
function mapArch(javaArch) {
|
|
82
|
+
switch (javaArch) {
|
|
83
|
+
case 'aarch64':
|
|
84
|
+
case 'arm64':
|
|
85
|
+
return 'arm64';
|
|
86
|
+
case 'x86_64':
|
|
87
|
+
case 'amd64':
|
|
88
|
+
return 'x64';
|
|
89
|
+
case 'i386':
|
|
90
|
+
case 'i686':
|
|
91
|
+
case 'x86':
|
|
92
|
+
return 'ia32';
|
|
93
|
+
case 'arm':
|
|
94
|
+
return 'arm';
|
|
95
|
+
default:
|
|
96
|
+
return javaArch;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.EOL = '\n';
|
|
100
|
+
function platform() {
|
|
101
|
+
return 'android';
|
|
102
|
+
}
|
|
103
|
+
function arch() {
|
|
104
|
+
return mapArch(readProperty('os.arch'));
|
|
105
|
+
}
|
|
106
|
+
function machine() {
|
|
107
|
+
return arch();
|
|
108
|
+
}
|
|
109
|
+
function type() {
|
|
110
|
+
return 'Linux';
|
|
111
|
+
}
|
|
112
|
+
function release() {
|
|
113
|
+
const value = bridge.getStaticField('android.os.Build$VERSION', 'RELEASE');
|
|
114
|
+
return typeof value === 'string' ? value : '';
|
|
115
|
+
}
|
|
116
|
+
function version() {
|
|
117
|
+
return readProperty('os.version');
|
|
118
|
+
}
|
|
119
|
+
function endianness() {
|
|
120
|
+
return 'LE';
|
|
121
|
+
}
|
|
122
|
+
function hostname() {
|
|
123
|
+
const local = bridge.callStatic('java.net.InetAddress', 'getLocalHost', []);
|
|
124
|
+
const name = bridge.callInstance(local, 'getHostName', []);
|
|
125
|
+
return typeof name === 'string' ? name : '';
|
|
126
|
+
}
|
|
127
|
+
function tmpdir() {
|
|
128
|
+
return paths.cacheDir();
|
|
129
|
+
}
|
|
130
|
+
/** Android 没有用户 home;按已安装包都可见的公共目录取 /sdcard。 */
|
|
131
|
+
function homedir() {
|
|
132
|
+
return '/sdcard';
|
|
133
|
+
}
|
|
134
|
+
function availableParallelism() {
|
|
135
|
+
const value = bridge.callInstance(runtime(), 'availableProcessors', []);
|
|
136
|
+
const count = Number(value);
|
|
137
|
+
return isFinite(count) && count > 0 ? count : 1;
|
|
138
|
+
}
|
|
139
|
+
function cpus() {
|
|
140
|
+
const count = availableParallelism();
|
|
141
|
+
const model = readProperty('os.arch');
|
|
142
|
+
const out = [];
|
|
143
|
+
for (let i = 0; i < count; i += 1) {
|
|
144
|
+
out.push({
|
|
145
|
+
model: model,
|
|
146
|
+
speed: 0,
|
|
147
|
+
times: { user: 0, nice: 0, sys: 0, idle: 0, irq: 0 }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
/** JVM 堆上限,不是物理内存总量。 */
|
|
153
|
+
function totalmem() {
|
|
154
|
+
return Number(bridge.callInstance(runtime(), 'maxMemory', [])) || 0;
|
|
155
|
+
}
|
|
156
|
+
/** JVM 堆空闲量,不是系统可用内存。 */
|
|
157
|
+
function freemem() {
|
|
158
|
+
return Number(bridge.callInstance(runtime(), 'freeMemory', [])) || 0;
|
|
159
|
+
}
|
|
160
|
+
function loadavg() {
|
|
161
|
+
return [0, 0, 0];
|
|
162
|
+
}
|
|
163
|
+
function uptime() {
|
|
164
|
+
const elapsed = Number(bridge.callStatic('android.os.SystemClock', 'elapsedRealtime', [])) || 0;
|
|
165
|
+
return Math.floor(elapsed / 1000);
|
|
166
|
+
}
|
|
167
|
+
function userInfo() {
|
|
168
|
+
return {
|
|
169
|
+
uid: -1,
|
|
170
|
+
gid: -1,
|
|
171
|
+
username: readProperty('user.name'),
|
|
172
|
+
homedir: homedir(),
|
|
173
|
+
shell: '/system/sh'
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/** 通过 NetworkInterface 的 Enumeration 逐个展开;Java 侧没有直接可用的集合视图。 */
|
|
177
|
+
function networkInterfaces() {
|
|
178
|
+
const out = {};
|
|
179
|
+
const interfaces = bridge.callStatic('java.net.NetworkInterface', 'getNetworkInterfaces', []);
|
|
180
|
+
if (interfaces === null || typeof interfaces !== 'object') {
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
while (bridge.normalizeBoolean(bridge.callInstance(interfaces, 'hasMoreElements', []))) {
|
|
184
|
+
const current = bridge.callInstance(interfaces, 'nextElement', []);
|
|
185
|
+
const name = String(bridge.callInstance(current, 'getName', []));
|
|
186
|
+
const addresses = [];
|
|
187
|
+
const enumeration = bridge.callInstance(current, 'getInetAddresses', []);
|
|
188
|
+
while (bridge.normalizeBoolean(bridge.callInstance(enumeration, 'hasMoreElements', []))) {
|
|
189
|
+
const address = bridge.callInstance(enumeration, 'nextElement', []);
|
|
190
|
+
const text = String(bridge.callInstance(address, 'getHostAddress', []));
|
|
191
|
+
addresses.push({
|
|
192
|
+
address: text,
|
|
193
|
+
family: text.indexOf(':') >= 0 ? 'IPv6' : 'IPv4',
|
|
194
|
+
internal: bridge.normalizeBoolean(bridge.callInstance(address, 'isLoopbackAddress', []))
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
out[name] = addresses;
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
/** Node 的 os.devNull 是字符串属性,不是函数。 */
|
|
202
|
+
exports.devNull = '/dev/null';
|
|
203
|
+
/** 进程优先级在 Android 上由调度器策略决定,Node 的 niceness 语义不成立。 */
|
|
204
|
+
function getPriority() {
|
|
205
|
+
throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'os.getPriority() 依赖 POSIX niceness,Android 上不成立。');
|
|
206
|
+
}
|
|
207
|
+
function setPriority() {
|
|
208
|
+
throw (0, errors_1.onjError)('ONJ_UNSUPPORTED', 'os.setPriority() 依赖 POSIX niceness,Android 上不成立。');
|
|
209
|
+
}
|
|
210
|
+
function buildPositiveErrno() {
|
|
211
|
+
const out = {};
|
|
212
|
+
const names = Object.keys(errors_1.ERRNO);
|
|
213
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
214
|
+
out[names[i]] = Math.abs(errors_1.ERRNO[names[i]]);
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
exports.constants = {
|
|
219
|
+
signals: {
|
|
220
|
+
SIGHUP: 1,
|
|
221
|
+
SIGINT: 2,
|
|
222
|
+
SIGQUIT: 3,
|
|
223
|
+
SIGILL: 4,
|
|
224
|
+
SIGTRAP: 5,
|
|
225
|
+
SIGABRT: 6,
|
|
226
|
+
SIGBUS: 7,
|
|
227
|
+
SIGFPE: 8,
|
|
228
|
+
SIGKILL: 9,
|
|
229
|
+
SIGUSR1: 10,
|
|
230
|
+
SIGSEGV: 11,
|
|
231
|
+
SIGUSR2: 12,
|
|
232
|
+
SIGPIPE: 13,
|
|
233
|
+
SIGALRM: 14,
|
|
234
|
+
SIGTERM: 15,
|
|
235
|
+
SIGWINCH: 28
|
|
236
|
+
},
|
|
237
|
+
// Node 的 os.constants.errno 是正的,而 lib/errors 的 ERRNO 取负(对应 error.errno)
|
|
238
|
+
errno: buildPositiveErrno(),
|
|
239
|
+
priority: {
|
|
240
|
+
PRIORITY_LOW: 19,
|
|
241
|
+
PRIORITY_BELOW_NORMAL: 10,
|
|
242
|
+
PRIORITY_NORMAL: 0,
|
|
243
|
+
PRIORITY_ABOVE_NORMAL: -7,
|
|
244
|
+
PRIORITY_HIGH: -14,
|
|
245
|
+
PRIORITY_HIGHEST: -20
|
|
246
|
+
}
|
|
247
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* `path/win32` 子路径入口(Node 亦提供 `require('path/win32')`)。
|
|
4
|
+
*
|
|
5
|
+
* 注意:BUILTINS.json 把本模块标为 partial —— 冒号歧义与 UNC 根这两类边缘
|
|
6
|
+
* 与 Node 存在已知偏差,详见 README「已知偏差」。Operit 平台是 android/linux,
|
|
7
|
+
* 该模块主要服务于解析 Windows 路径的三方库(如打包/归档类)。
|
|
8
|
+
*/
|
|
9
|
+
const pathModule = require("../path");
|
|
10
|
+
module.exports = pathModule.win32;
|
package/dist/path.d.ts
ADDED