@gjsify/os 0.0.4 → 0.1.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.
- package/README.md +26 -1
- package/lib/esm/constants.js +15 -0
- package/lib/esm/darwin.js +50 -14
- package/lib/esm/index.js +167 -25
- package/lib/esm/linux.js +106 -21
- package/lib/types/constants.d.ts +135 -0
- package/lib/types/createSubnet.d.ts +5 -0
- package/lib/types/darwin.d.ts +16 -0
- package/lib/types/index.d.ts +204 -0
- package/lib/types/linux.d.ts +17 -0
- package/lib/types/win32.d.ts +0 -0
- package/package.json +16 -17
- package/src/constants.ts +17 -1
- package/src/createSubnet.ts +3 -0
- package/src/darwin.ts +83 -23
- package/src/index.spec.ts +388 -4
- package/src/index.ts +170 -15
- package/src/linux.ts +136 -26
- package/src/win32.ts +3 -0
- package/tsconfig.json +23 -10
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/constants.js +0 -122
- package/lib/cjs/createSubnet.js +0 -17
- package/lib/cjs/darwin.js +0 -115
- package/lib/cjs/index.js +0 -92
- package/lib/cjs/linux.js +0 -92
- package/lib/cjs/win32.js +0 -1
- package/test.gjs.mjs +0 -34685
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.mjs +0 -307
- package/tsconfig.types.json +0 -8
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
UV_UDP_REUSEADDR: number;
|
|
3
|
+
errno: {
|
|
4
|
+
E2BIG: number;
|
|
5
|
+
EACCES: number;
|
|
6
|
+
EADDRINUSE: number;
|
|
7
|
+
EADDRNOTAVAIL: number;
|
|
8
|
+
EAFNOSUPPORT: number;
|
|
9
|
+
EAGAIN: number;
|
|
10
|
+
EALREADY: number;
|
|
11
|
+
EBADF: number;
|
|
12
|
+
EBADMSG: number;
|
|
13
|
+
EBUSY: number;
|
|
14
|
+
ECANCELED: number;
|
|
15
|
+
ECHILD: number;
|
|
16
|
+
ECONNABORTED: number;
|
|
17
|
+
ECONNREFUSED: number;
|
|
18
|
+
ECONNRESET: number;
|
|
19
|
+
EDEADLK: number;
|
|
20
|
+
EDESTADDRREQ: number;
|
|
21
|
+
EDOM: number;
|
|
22
|
+
EDQUOT: number;
|
|
23
|
+
EEXIST: number;
|
|
24
|
+
EFAULT: number;
|
|
25
|
+
EFBIG: number;
|
|
26
|
+
EHOSTUNREACH: number;
|
|
27
|
+
EIDRM: number;
|
|
28
|
+
EILSEQ: number;
|
|
29
|
+
EINPROGRESS: number;
|
|
30
|
+
EINTR: number;
|
|
31
|
+
EINVAL: number;
|
|
32
|
+
EIO: number;
|
|
33
|
+
EISCONN: number;
|
|
34
|
+
EISDIR: number;
|
|
35
|
+
ELOOP: number;
|
|
36
|
+
EMFILE: number;
|
|
37
|
+
EMLINK: number;
|
|
38
|
+
EMSGSIZE: number;
|
|
39
|
+
EMULTIHOP: number;
|
|
40
|
+
ENAMETOOLONG: number;
|
|
41
|
+
ENETDOWN: number;
|
|
42
|
+
ENETRESET: number;
|
|
43
|
+
ENETUNREACH: number;
|
|
44
|
+
ENFILE: number;
|
|
45
|
+
ENOBUFS: number;
|
|
46
|
+
ENODATA: number;
|
|
47
|
+
ENODEV: number;
|
|
48
|
+
ENOENT: number;
|
|
49
|
+
ENOEXEC: number;
|
|
50
|
+
ENOLCK: number;
|
|
51
|
+
ENOLINK: number;
|
|
52
|
+
ENOMEM: number;
|
|
53
|
+
ENOMSG: number;
|
|
54
|
+
ENOPROTOOPT: number;
|
|
55
|
+
ENOSPC: number;
|
|
56
|
+
ENOSR: number;
|
|
57
|
+
ENOSTR: number;
|
|
58
|
+
ENOSYS: number;
|
|
59
|
+
ENOTCONN: number;
|
|
60
|
+
ENOTDIR: number;
|
|
61
|
+
ENOTEMPTY: number;
|
|
62
|
+
ENOTSOCK: number;
|
|
63
|
+
ENOTSUP: number;
|
|
64
|
+
ENOTTY: number;
|
|
65
|
+
ENXIO: number;
|
|
66
|
+
EOPNOTSUPP: number;
|
|
67
|
+
EOVERFLOW: number;
|
|
68
|
+
EPERM: number;
|
|
69
|
+
EPIPE: number;
|
|
70
|
+
EPROTO: number;
|
|
71
|
+
EPROTONOSUPPORT: number;
|
|
72
|
+
EPROTOTYPE: number;
|
|
73
|
+
ERANGE: number;
|
|
74
|
+
EROFS: number;
|
|
75
|
+
ESPIPE: number;
|
|
76
|
+
ESRCH: number;
|
|
77
|
+
ESTALE: number;
|
|
78
|
+
ETIME: number;
|
|
79
|
+
ETIMEDOUT: number;
|
|
80
|
+
ETXTBSY: number;
|
|
81
|
+
EWOULDBLOCK: number;
|
|
82
|
+
EXDEV: number;
|
|
83
|
+
};
|
|
84
|
+
signals: {
|
|
85
|
+
SIGHUP: number;
|
|
86
|
+
SIGINT: number;
|
|
87
|
+
SIGQUIT: number;
|
|
88
|
+
SIGILL: number;
|
|
89
|
+
SIGTRAP: number;
|
|
90
|
+
SIGABRT: number;
|
|
91
|
+
SIGIOT: number;
|
|
92
|
+
SIGBUS: number;
|
|
93
|
+
SIGFPE: number;
|
|
94
|
+
SIGKILL: number;
|
|
95
|
+
SIGUSR1: number;
|
|
96
|
+
SIGSEGV: number;
|
|
97
|
+
SIGUSR2: number;
|
|
98
|
+
SIGPIPE: number;
|
|
99
|
+
SIGALRM: number;
|
|
100
|
+
SIGTERM: number;
|
|
101
|
+
SIGCHLD: number;
|
|
102
|
+
SIGSTKFLT: number;
|
|
103
|
+
SIGCONT: number;
|
|
104
|
+
SIGSTOP: number;
|
|
105
|
+
SIGTSTP: number;
|
|
106
|
+
SIGTTIN: number;
|
|
107
|
+
SIGTTOU: number;
|
|
108
|
+
SIGURG: number;
|
|
109
|
+
SIGXCPU: number;
|
|
110
|
+
SIGXFSZ: number;
|
|
111
|
+
SIGVTALRM: number;
|
|
112
|
+
SIGPROF: number;
|
|
113
|
+
SIGWINCH: number;
|
|
114
|
+
SIGIO: number;
|
|
115
|
+
SIGPOLL: number;
|
|
116
|
+
SIGPWR: number;
|
|
117
|
+
SIGSYS: number;
|
|
118
|
+
};
|
|
119
|
+
priority: {
|
|
120
|
+
PRIORITY_LOW: number;
|
|
121
|
+
PRIORITY_BELOW_NORMAL: number;
|
|
122
|
+
PRIORITY_NORMAL: number;
|
|
123
|
+
PRIORITY_ABOVE_NORMAL: number;
|
|
124
|
+
PRIORITY_HIGH: number;
|
|
125
|
+
PRIORITY_HIGHEST: number;
|
|
126
|
+
};
|
|
127
|
+
dlopen: {
|
|
128
|
+
RTLD_LAZY: number;
|
|
129
|
+
RTLD_NOW: number;
|
|
130
|
+
RTLD_GLOBAL: number;
|
|
131
|
+
RTLD_LOCAL: number;
|
|
132
|
+
RTLD_DEEPBIND: number;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const cpus: () => any[];
|
|
2
|
+
export declare const endianness: () => string;
|
|
3
|
+
/**
|
|
4
|
+
* Get free memory on macOS using vm_stat.
|
|
5
|
+
* vm_stat reports memory pages; multiply by page size to get bytes.
|
|
6
|
+
* "free" pages + "speculative" pages approximate available memory.
|
|
7
|
+
* Falls back to (hw.memsize - hw.physmem) if vm_stat is unavailable.
|
|
8
|
+
*/
|
|
9
|
+
export declare const freemem: () => number;
|
|
10
|
+
export declare const loadavg: () => number[];
|
|
11
|
+
export declare const networkInterfaces: () => {};
|
|
12
|
+
/**
|
|
13
|
+
* Get total memory on macOS using sysctl hw.memsize.
|
|
14
|
+
*/
|
|
15
|
+
export declare const totalmem: () => number;
|
|
16
|
+
export declare const uptime: () => number;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
export { constants };
|
|
2
|
+
import constants from './constants.js';
|
|
3
|
+
export declare const EOL: string;
|
|
4
|
+
export declare const devNull: string;
|
|
5
|
+
export declare const homedir: () => string;
|
|
6
|
+
export declare const hostname: () => string;
|
|
7
|
+
export declare const release: () => string;
|
|
8
|
+
export declare const tmpdir: () => string;
|
|
9
|
+
export declare const type: () => string;
|
|
10
|
+
export declare const platform: () => NodeJS.Platform;
|
|
11
|
+
export declare const arch: () => string;
|
|
12
|
+
export declare const machine: () => string;
|
|
13
|
+
export declare const version: () => string;
|
|
14
|
+
export declare const uptime: () => number;
|
|
15
|
+
export declare const totalmem: () => number;
|
|
16
|
+
export declare const availableParallelism: () => number;
|
|
17
|
+
export declare const userInfo: () => {
|
|
18
|
+
uid: number;
|
|
19
|
+
gid: number;
|
|
20
|
+
username: string;
|
|
21
|
+
homedir: string;
|
|
22
|
+
shell: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const cpus: () => any[];
|
|
25
|
+
export declare const endianness: () => string;
|
|
26
|
+
export declare const freemem: () => number;
|
|
27
|
+
export declare const loadavg: () => number[];
|
|
28
|
+
export declare const networkInterfaces: () => {};
|
|
29
|
+
/**
|
|
30
|
+
* Get process scheduling priority.
|
|
31
|
+
* Uses `ps -o ni=` to read the nice value for a given process.
|
|
32
|
+
* pid 0 (or omitted) means the current process.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getPriority: (pid?: number) => number;
|
|
35
|
+
/**
|
|
36
|
+
* Set process scheduling priority.
|
|
37
|
+
* Uses `renice` command. Requires appropriate permissions for other processes.
|
|
38
|
+
*/
|
|
39
|
+
export declare const setPriority: (pidOrPriority: number, priority?: number) => void;
|
|
40
|
+
declare const _default: {
|
|
41
|
+
EOL: string;
|
|
42
|
+
arch: () => string;
|
|
43
|
+
availableParallelism: () => number;
|
|
44
|
+
constants: {
|
|
45
|
+
UV_UDP_REUSEADDR: number;
|
|
46
|
+
errno: {
|
|
47
|
+
E2BIG: number;
|
|
48
|
+
EACCES: number;
|
|
49
|
+
EADDRINUSE: number;
|
|
50
|
+
EADDRNOTAVAIL: number;
|
|
51
|
+
EAFNOSUPPORT: number;
|
|
52
|
+
EAGAIN: number;
|
|
53
|
+
EALREADY: number;
|
|
54
|
+
EBADF: number;
|
|
55
|
+
EBADMSG: number;
|
|
56
|
+
EBUSY: number;
|
|
57
|
+
ECANCELED: number;
|
|
58
|
+
ECHILD: number;
|
|
59
|
+
ECONNABORTED: number;
|
|
60
|
+
ECONNREFUSED: number;
|
|
61
|
+
ECONNRESET: number;
|
|
62
|
+
EDEADLK: number;
|
|
63
|
+
EDESTADDRREQ: number;
|
|
64
|
+
EDOM: number;
|
|
65
|
+
EDQUOT: number;
|
|
66
|
+
EEXIST: number;
|
|
67
|
+
EFAULT: number;
|
|
68
|
+
EFBIG: number;
|
|
69
|
+
EHOSTUNREACH: number;
|
|
70
|
+
EIDRM: number;
|
|
71
|
+
EILSEQ: number;
|
|
72
|
+
EINPROGRESS: number;
|
|
73
|
+
EINTR: number;
|
|
74
|
+
EINVAL: number;
|
|
75
|
+
EIO: number;
|
|
76
|
+
EISCONN: number;
|
|
77
|
+
EISDIR: number;
|
|
78
|
+
ELOOP: number;
|
|
79
|
+
EMFILE: number;
|
|
80
|
+
EMLINK: number;
|
|
81
|
+
EMSGSIZE: number;
|
|
82
|
+
EMULTIHOP: number;
|
|
83
|
+
ENAMETOOLONG: number;
|
|
84
|
+
ENETDOWN: number;
|
|
85
|
+
ENETRESET: number;
|
|
86
|
+
ENETUNREACH: number;
|
|
87
|
+
ENFILE: number;
|
|
88
|
+
ENOBUFS: number;
|
|
89
|
+
ENODATA: number;
|
|
90
|
+
ENODEV: number;
|
|
91
|
+
ENOENT: number;
|
|
92
|
+
ENOEXEC: number;
|
|
93
|
+
ENOLCK: number;
|
|
94
|
+
ENOLINK: number;
|
|
95
|
+
ENOMEM: number;
|
|
96
|
+
ENOMSG: number;
|
|
97
|
+
ENOPROTOOPT: number;
|
|
98
|
+
ENOSPC: number;
|
|
99
|
+
ENOSR: number;
|
|
100
|
+
ENOSTR: number;
|
|
101
|
+
ENOSYS: number;
|
|
102
|
+
ENOTCONN: number;
|
|
103
|
+
ENOTDIR: number;
|
|
104
|
+
ENOTEMPTY: number;
|
|
105
|
+
ENOTSOCK: number;
|
|
106
|
+
ENOTSUP: number;
|
|
107
|
+
ENOTTY: number;
|
|
108
|
+
ENXIO: number;
|
|
109
|
+
EOPNOTSUPP: number;
|
|
110
|
+
EOVERFLOW: number;
|
|
111
|
+
EPERM: number;
|
|
112
|
+
EPIPE: number;
|
|
113
|
+
EPROTO: number;
|
|
114
|
+
EPROTONOSUPPORT: number;
|
|
115
|
+
EPROTOTYPE: number;
|
|
116
|
+
ERANGE: number;
|
|
117
|
+
EROFS: number;
|
|
118
|
+
ESPIPE: number;
|
|
119
|
+
ESRCH: number;
|
|
120
|
+
ESTALE: number;
|
|
121
|
+
ETIME: number;
|
|
122
|
+
ETIMEDOUT: number;
|
|
123
|
+
ETXTBSY: number;
|
|
124
|
+
EWOULDBLOCK: number;
|
|
125
|
+
EXDEV: number;
|
|
126
|
+
};
|
|
127
|
+
signals: {
|
|
128
|
+
SIGHUP: number;
|
|
129
|
+
SIGINT: number;
|
|
130
|
+
SIGQUIT: number;
|
|
131
|
+
SIGILL: number;
|
|
132
|
+
SIGTRAP: number;
|
|
133
|
+
SIGABRT: number;
|
|
134
|
+
SIGIOT: number;
|
|
135
|
+
SIGBUS: number;
|
|
136
|
+
SIGFPE: number;
|
|
137
|
+
SIGKILL: number;
|
|
138
|
+
SIGUSR1: number;
|
|
139
|
+
SIGSEGV: number;
|
|
140
|
+
SIGUSR2: number;
|
|
141
|
+
SIGPIPE: number;
|
|
142
|
+
SIGALRM: number;
|
|
143
|
+
SIGTERM: number;
|
|
144
|
+
SIGCHLD: number;
|
|
145
|
+
SIGSTKFLT: number;
|
|
146
|
+
SIGCONT: number;
|
|
147
|
+
SIGSTOP: number;
|
|
148
|
+
SIGTSTP: number;
|
|
149
|
+
SIGTTIN: number;
|
|
150
|
+
SIGTTOU: number;
|
|
151
|
+
SIGURG: number;
|
|
152
|
+
SIGXCPU: number;
|
|
153
|
+
SIGXFSZ: number;
|
|
154
|
+
SIGVTALRM: number;
|
|
155
|
+
SIGPROF: number;
|
|
156
|
+
SIGWINCH: number;
|
|
157
|
+
SIGIO: number;
|
|
158
|
+
SIGPOLL: number;
|
|
159
|
+
SIGPWR: number;
|
|
160
|
+
SIGSYS: number;
|
|
161
|
+
};
|
|
162
|
+
priority: {
|
|
163
|
+
PRIORITY_LOW: number;
|
|
164
|
+
PRIORITY_BELOW_NORMAL: number;
|
|
165
|
+
PRIORITY_NORMAL: number;
|
|
166
|
+
PRIORITY_ABOVE_NORMAL: number;
|
|
167
|
+
PRIORITY_HIGH: number;
|
|
168
|
+
PRIORITY_HIGHEST: number;
|
|
169
|
+
};
|
|
170
|
+
dlopen: {
|
|
171
|
+
RTLD_LAZY: number;
|
|
172
|
+
RTLD_NOW: number;
|
|
173
|
+
RTLD_GLOBAL: number;
|
|
174
|
+
RTLD_LOCAL: number;
|
|
175
|
+
RTLD_DEEPBIND: number;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
cpus: () => any[];
|
|
179
|
+
devNull: string;
|
|
180
|
+
endianness: () => string;
|
|
181
|
+
freemem: () => number;
|
|
182
|
+
getPriority: (pid?: number) => number;
|
|
183
|
+
homedir: () => string;
|
|
184
|
+
hostname: () => string;
|
|
185
|
+
loadavg: () => number[];
|
|
186
|
+
machine: () => string;
|
|
187
|
+
networkInterfaces: () => {};
|
|
188
|
+
platform: () => NodeJS.Platform;
|
|
189
|
+
release: () => string;
|
|
190
|
+
setPriority: (pidOrPriority: number, priority?: number) => void;
|
|
191
|
+
tmpdir: () => string;
|
|
192
|
+
totalmem: () => number;
|
|
193
|
+
type: () => string;
|
|
194
|
+
uptime: () => number;
|
|
195
|
+
userInfo: () => {
|
|
196
|
+
uid: number;
|
|
197
|
+
gid: number;
|
|
198
|
+
username: string;
|
|
199
|
+
homedir: string;
|
|
200
|
+
shell: string;
|
|
201
|
+
};
|
|
202
|
+
version: () => string;
|
|
203
|
+
};
|
|
204
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const cpus: () => {
|
|
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 declare const endianness: () => string;
|
|
13
|
+
export declare const freemem: () => number;
|
|
14
|
+
export declare const loadavg: () => number[];
|
|
15
|
+
export declare const networkInterfaces: () => {};
|
|
16
|
+
export declare const totalmem: () => number;
|
|
17
|
+
export declare const uptime: () => number;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/os",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Node.js os module for Gjs",
|
|
5
|
-
"main": "lib/cjs/index.js",
|
|
6
5
|
"module": "lib/esm/index.js",
|
|
6
|
+
"types": "lib/types/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"default": "./lib/esm/index.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "./lib/types/index.d.ts",
|
|
16
|
-
"default": "./lib/cjs/index.js"
|
|
17
|
-
}
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"default": "./lib/esm/index.js"
|
|
18
12
|
}
|
|
19
13
|
},
|
|
20
14
|
"scripts": {
|
|
21
|
-
"clear": "rm -rf lib tsconfig.tsbuildinfo test.gjs.mjs test.node.mjs",
|
|
22
|
-
"
|
|
23
|
-
"build": "yarn
|
|
15
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
|
|
16
|
+
"check": "tsc --noEmit",
|
|
17
|
+
"build": "yarn build:gjsify && yarn build:types",
|
|
24
18
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
19
|
+
"build:types": "tsc",
|
|
25
20
|
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
26
21
|
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
27
22
|
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
28
|
-
"test": "yarn
|
|
23
|
+
"test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
|
|
29
24
|
"test:gjs": "gjs -m test.gjs.mjs",
|
|
30
25
|
"test:node": "node test.node.mjs"
|
|
31
26
|
},
|
|
@@ -35,10 +30,14 @@
|
|
|
35
30
|
"os"
|
|
36
31
|
],
|
|
37
32
|
"dependencies": {
|
|
38
|
-
"@girs/
|
|
39
|
-
"@
|
|
33
|
+
"@girs/gio-2.0": "^2.88.0-4.0.0-beta.42",
|
|
34
|
+
"@girs/glib-2.0": "^2.88.0-4.0.0-beta.42",
|
|
35
|
+
"@gjsify/utils": "^0.1.0"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.0
|
|
38
|
+
"@gjsify/cli": "^0.1.0",
|
|
39
|
+
"@gjsify/unit": "^0.1.0",
|
|
40
|
+
"@types/node": "^25.5.0",
|
|
41
|
+
"typescript": "^6.0.2"
|
|
43
42
|
}
|
|
44
43
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Reference: Node.js lib/os.js — OS constants (errno, signals, priority)
|
|
2
|
+
// Copied from Node.js
|
|
2
3
|
export default {
|
|
3
4
|
"UV_UDP_REUSEADDR": 4,
|
|
4
5
|
"errno": {
|
|
@@ -116,5 +117,20 @@ export default {
|
|
|
116
117
|
"SIGPOLL": 29,
|
|
117
118
|
"SIGPWR": 30,
|
|
118
119
|
"SIGSYS": 31
|
|
120
|
+
},
|
|
121
|
+
"priority": {
|
|
122
|
+
"PRIORITY_LOW": 19,
|
|
123
|
+
"PRIORITY_BELOW_NORMAL": 10,
|
|
124
|
+
"PRIORITY_NORMAL": 0,
|
|
125
|
+
"PRIORITY_ABOVE_NORMAL": -7,
|
|
126
|
+
"PRIORITY_HIGH": -14,
|
|
127
|
+
"PRIORITY_HIGHEST": -20
|
|
128
|
+
},
|
|
129
|
+
"dlopen": {
|
|
130
|
+
"RTLD_LAZY": 1,
|
|
131
|
+
"RTLD_NOW": 2,
|
|
132
|
+
"RTLD_GLOBAL": 256,
|
|
133
|
+
"RTLD_LOCAL": 0,
|
|
134
|
+
"RTLD_DEEPBIND": 8
|
|
119
135
|
}
|
|
120
136
|
};
|
package/src/createSubnet.ts
CHANGED
package/src/darwin.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
// Reference: Node.js lib/os.js — macOS-specific os module helpers
|
|
2
|
+
// Reimplemented for GJS using GLib
|
|
3
|
+
|
|
1
4
|
import { createSubnet } from './createSubnet.js';
|
|
2
5
|
import { cli } from '@gjsify/utils';
|
|
3
6
|
|
|
4
|
-
const EOL = /\r\n|\n/;
|
|
5
7
|
const NOMAC = '00:00:00:00:00:00';
|
|
6
8
|
|
|
7
9
|
const getIPv6Subnet = createSubnet(128, 16, 16, ':');
|
|
@@ -66,11 +68,48 @@ export const cpus = () => {
|
|
|
66
68
|
|
|
67
69
|
export const endianness = () => 'LE';
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Get free memory on macOS using vm_stat.
|
|
73
|
+
* vm_stat reports memory pages; multiply by page size to get bytes.
|
|
74
|
+
* "free" pages + "speculative" pages approximate available memory.
|
|
75
|
+
* Falls back to (hw.memsize - hw.physmem) if vm_stat is unavailable.
|
|
76
|
+
*/
|
|
77
|
+
export const freemem = () => {
|
|
78
|
+
try {
|
|
79
|
+
const vmstat = cli('vm_stat');
|
|
80
|
+
// Parse page size from first line: "Mach Virtual Memory Statistics: (page size of 16384 bytes)"
|
|
81
|
+
const pageSizeMatch = /page size of (\d+) bytes/.exec(vmstat);
|
|
82
|
+
const pageSize = pageSizeMatch ? parseInt(pageSizeMatch[1], 10) : 16384;
|
|
83
|
+
|
|
84
|
+
// Parse "Pages free" and "Pages speculative" (inactive can be reclaimed too)
|
|
85
|
+
let freePages = 0;
|
|
86
|
+
const freeMatch = /Pages free:\s+(\d+)/.exec(vmstat);
|
|
87
|
+
if (freeMatch) freePages += parseInt(freeMatch[1], 10);
|
|
88
|
+
|
|
89
|
+
// "Pages speculative" are also considered free/available
|
|
90
|
+
const specMatch = /Pages speculative:\s+(\d+)/.exec(vmstat);
|
|
91
|
+
if (specMatch) freePages += parseInt(specMatch[1], 10);
|
|
92
|
+
|
|
93
|
+
// Include purgeable pages as available (can be reclaimed)
|
|
94
|
+
const purgeMatch = /Pages purgeable:\s+(\d+)/.exec(vmstat);
|
|
95
|
+
if (purgeMatch) freePages += parseInt(purgeMatch[1], 10);
|
|
96
|
+
|
|
97
|
+
if (freePages > 0) return freePages * pageSize;
|
|
98
|
+
} catch {
|
|
99
|
+
// vm_stat not available, fall back
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Fallback: difference between hw.memsize and hw.physmem
|
|
103
|
+
// (not accurate but better than 0)
|
|
104
|
+
try {
|
|
105
|
+
return parseFloat(cli('sysctl -n hw.memsize')) -
|
|
106
|
+
parseFloat(cli('sysctl -n hw.physmem'));
|
|
107
|
+
} catch {
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
72
111
|
|
|
73
|
-
// PORTED TO deno runtime
|
|
112
|
+
// PORTED TO deno runtime
|
|
74
113
|
export const loadavg = () => /load\s+averages:\s+(\d+(?:\.\d+))\s+(\d+(?:\.\d+))\s+(\d+(?:\.\d+))/.test(
|
|
75
114
|
cli('uptime')
|
|
76
115
|
) && [
|
|
@@ -82,7 +121,7 @@ export const loadavg = () => /load\s+averages:\s+(\d+(?:\.\d+))\s+(\d+(?:\.\d+))
|
|
|
82
121
|
export const networkInterfaces = () => {
|
|
83
122
|
const ifaces = {};
|
|
84
123
|
const groups = [];
|
|
85
|
-
const lines = cli('ifconfig').split(
|
|
124
|
+
const lines = cli('ifconfig').split(/\r\n|\n/);
|
|
86
125
|
const length = lines.length;
|
|
87
126
|
for (let
|
|
88
127
|
group = [],
|
|
@@ -97,35 +136,56 @@ export const networkInterfaces = () => {
|
|
|
97
136
|
}
|
|
98
137
|
--i;
|
|
99
138
|
}
|
|
100
|
-
groups.push(group.join(
|
|
139
|
+
groups.push(group.join('\n'));
|
|
101
140
|
}
|
|
102
141
|
groups.forEach(parseInterfaces, ifaces);
|
|
103
142
|
return ifaces;
|
|
104
143
|
};
|
|
105
144
|
|
|
106
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Get total memory on macOS using sysctl hw.memsize.
|
|
147
|
+
*/
|
|
107
148
|
export const totalmem = () => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
149
|
+
try {
|
|
150
|
+
return parseFloat(cli('sysctl -n hw.memsize'));
|
|
151
|
+
} catch {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
111
154
|
};
|
|
112
155
|
|
|
113
156
|
// PORTED TO deno runtime
|
|
114
157
|
export const uptime = () => {
|
|
115
|
-
|
|
116
|
-
|
|
158
|
+
// Try sysctl kern.boottime first (most reliable)
|
|
159
|
+
try {
|
|
160
|
+
const boottime = cli('sysctl -n kern.boottime');
|
|
161
|
+
// Format: "{ sec = 1711234567, usec = 123456 } Mon Mar 25 ..."
|
|
162
|
+
const secMatch = /sec\s*=\s*(\d+)/.exec(boottime);
|
|
163
|
+
if (secMatch) {
|
|
164
|
+
const bootSec = parseInt(secMatch[1], 10);
|
|
165
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
166
|
+
return nowSec - bootSec;
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
// fall through
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Fallback: parse uptime command output
|
|
173
|
+
const output = cli('uptime');
|
|
174
|
+
const up = /up\s+([^,]+)?,/.test(output) && RegExp.$1;
|
|
117
175
|
switch (true) {
|
|
118
|
-
case /^(\d+):(\d+)$/.test(up):
|
|
176
|
+
case /^(\d+):(\d+)$/.test(up as string):
|
|
119
177
|
return ((parseInt(RegExp.$1, 10) * 60) + parseInt(RegExp.$2, 10)) * 60;
|
|
120
|
-
case /^(\d+)\s+mins?$/.test(up):
|
|
178
|
+
case /^(\d+)\s+mins?$/.test(up as string):
|
|
121
179
|
return parseInt(RegExp.$1, 10) * 60;
|
|
122
|
-
case /^(\d+)\s+days?$/.test(up):
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
|
|
180
|
+
case /^(\d+)\s+days?$/.test(up as string): {
|
|
181
|
+
const days = parseInt(RegExp.$1, 10) * 86400;
|
|
182
|
+
// Check for "N days, HH:MM" format
|
|
183
|
+
const timeMatch = /days?,\s+(\d+):(\d+)/.exec(output);
|
|
184
|
+
if (timeMatch) {
|
|
185
|
+
return days + ((parseInt(timeMatch[1], 10) * 60) + parseInt(timeMatch[2], 10)) * 60;
|
|
186
|
+
}
|
|
187
|
+
return days;
|
|
188
|
+
}
|
|
129
189
|
}
|
|
130
|
-
return
|
|
190
|
+
return 0;
|
|
131
191
|
};
|