@gjsify/os 0.4.0 → 0.4.3

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/package.json CHANGED
@@ -1,43 +1,46 @@
1
1
  {
2
- "name": "@gjsify/os",
3
- "version": "0.4.0",
4
- "description": "Node.js os module for Gjs",
5
- "module": "lib/esm/index.js",
6
- "types": "lib/types/index.d.ts",
7
- "type": "module",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "default": "./lib/esm/index.js"
2
+ "name": "@gjsify/os",
3
+ "version": "0.4.3",
4
+ "description": "Node.js os module for Gjs",
5
+ "module": "lib/esm/index.js",
6
+ "types": "lib/types/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/esm/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
19
+ "check": "tsc --noEmit",
20
+ "build": "gjsify run build:gjsify && gjsify run build:types",
21
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
22
+ "build:types": "tsc",
23
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
24
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
25
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
26
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
27
+ "test:gjs": "gjsify run test.gjs.mjs",
28
+ "test:node": "node test.node.mjs"
29
+ },
30
+ "keywords": [
31
+ "gjs",
32
+ "node",
33
+ "os"
34
+ ],
35
+ "dependencies": {
36
+ "@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
37
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
38
+ "@gjsify/utils": "workspace:^"
39
+ },
40
+ "devDependencies": {
41
+ "@gjsify/cli": "workspace:^",
42
+ "@gjsify/unit": "workspace:^",
43
+ "@types/node": "^25.6.2",
44
+ "typescript": "^6.0.3"
12
45
  }
13
- },
14
- "scripts": {
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",
18
- "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
19
- "build:types": "tsc",
20
- "build:test": "yarn build:test:gjs && yarn build:test:node",
21
- "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
22
- "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
23
- "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
24
- "test:gjs": "gjsify run test.gjs.mjs",
25
- "test:node": "node test.node.mjs"
26
- },
27
- "keywords": [
28
- "gjs",
29
- "node",
30
- "os"
31
- ],
32
- "dependencies": {
33
- "@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
34
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
35
- "@gjsify/utils": "^0.4.0"
36
- },
37
- "devDependencies": {
38
- "@gjsify/cli": "^0.4.0",
39
- "@gjsify/unit": "^0.4.0",
40
- "@types/node": "^25.6.2",
41
- "typescript": "^6.0.3"
42
- }
43
- }
46
+ }
package/src/constants.ts DELETED
@@ -1,136 +0,0 @@
1
- // Reference: Node.js lib/os.js — OS constants (errno, signals, priority)
2
- // Copied from Node.js
3
- export default {
4
- "UV_UDP_REUSEADDR": 4,
5
- "errno": {
6
- "E2BIG": 7,
7
- "EACCES": 13,
8
- "EADDRINUSE": 98,
9
- "EADDRNOTAVAIL": 99,
10
- "EAFNOSUPPORT": 97,
11
- "EAGAIN": 11,
12
- "EALREADY": 114,
13
- "EBADF": 9,
14
- "EBADMSG": 74,
15
- "EBUSY": 16,
16
- "ECANCELED": 125,
17
- "ECHILD": 10,
18
- "ECONNABORTED": 103,
19
- "ECONNREFUSED": 111,
20
- "ECONNRESET": 104,
21
- "EDEADLK": 35,
22
- "EDESTADDRREQ": 89,
23
- "EDOM": 33,
24
- "EDQUOT": 122,
25
- "EEXIST": 17,
26
- "EFAULT": 14,
27
- "EFBIG": 27,
28
- "EHOSTUNREACH": 113,
29
- "EIDRM": 43,
30
- "EILSEQ": 84,
31
- "EINPROGRESS": 115,
32
- "EINTR": 4,
33
- "EINVAL": 22,
34
- "EIO": 5,
35
- "EISCONN": 106,
36
- "EISDIR": 21,
37
- "ELOOP": 40,
38
- "EMFILE": 24,
39
- "EMLINK": 31,
40
- "EMSGSIZE": 90,
41
- "EMULTIHOP": 72,
42
- "ENAMETOOLONG": 36,
43
- "ENETDOWN": 100,
44
- "ENETRESET": 102,
45
- "ENETUNREACH": 101,
46
- "ENFILE": 23,
47
- "ENOBUFS": 105,
48
- "ENODATA": 61,
49
- "ENODEV": 19,
50
- "ENOENT": 2,
51
- "ENOEXEC": 8,
52
- "ENOLCK": 37,
53
- "ENOLINK": 67,
54
- "ENOMEM": 12,
55
- "ENOMSG": 42,
56
- "ENOPROTOOPT": 92,
57
- "ENOSPC": 28,
58
- "ENOSR": 63,
59
- "ENOSTR": 60,
60
- "ENOSYS": 38,
61
- "ENOTCONN": 107,
62
- "ENOTDIR": 20,
63
- "ENOTEMPTY": 39,
64
- "ENOTSOCK": 88,
65
- "ENOTSUP": 95,
66
- "ENOTTY": 25,
67
- "ENXIO": 6,
68
- "EOPNOTSUPP": 95,
69
- "EOVERFLOW": 75,
70
- "EPERM": 1,
71
- "EPIPE": 32,
72
- "EPROTO": 71,
73
- "EPROTONOSUPPORT": 93,
74
- "EPROTOTYPE": 91,
75
- "ERANGE": 34,
76
- "EROFS": 30,
77
- "ESPIPE": 29,
78
- "ESRCH": 3,
79
- "ESTALE": 116,
80
- "ETIME": 62,
81
- "ETIMEDOUT": 110,
82
- "ETXTBSY": 26,
83
- "EWOULDBLOCK": 11,
84
- "EXDEV": 18
85
- },
86
- "signals": {
87
- "SIGHUP": 1,
88
- "SIGINT": 2,
89
- "SIGQUIT": 3,
90
- "SIGILL": 4,
91
- "SIGTRAP": 5,
92
- "SIGABRT": 6,
93
- "SIGIOT": 6,
94
- "SIGBUS": 7,
95
- "SIGFPE": 8,
96
- "SIGKILL": 9,
97
- "SIGUSR1": 10,
98
- "SIGSEGV": 11,
99
- "SIGUSR2": 12,
100
- "SIGPIPE": 13,
101
- "SIGALRM": 14,
102
- "SIGTERM": 15,
103
- "SIGCHLD": 17,
104
- "SIGSTKFLT": 16,
105
- "SIGCONT": 18,
106
- "SIGSTOP": 19,
107
- "SIGTSTP": 20,
108
- "SIGTTIN": 21,
109
- "SIGTTOU": 22,
110
- "SIGURG": 23,
111
- "SIGXCPU": 24,
112
- "SIGXFSZ": 25,
113
- "SIGVTALRM": 26,
114
- "SIGPROF": 27,
115
- "SIGWINCH": 28,
116
- "SIGIO": 29,
117
- "SIGPOLL": 29,
118
- "SIGPWR": 30,
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
135
- }
136
- };
@@ -1,16 +0,0 @@
1
- // Reference: Node.js lib/os.js — subnet mask helper
2
- // Reimplemented for GJS
3
-
4
- export function createSubnet(size, segment, base, sep) {
5
- const empty = '0'.repeat(size);
6
- return mask => {
7
- const str = ('1'.repeat(parseInt(mask, 10)) + empty).slice(0, size);
8
- const out = [];
9
- for (let i = 0; i < size; i += segment) {
10
- out.push(parseInt(str.substr(i, segment), 2).toString(base));
11
- }
12
- return out.join(sep);
13
- };
14
- };
15
-
16
- export default { createSubnet }
package/src/darwin.ts DELETED
@@ -1,191 +0,0 @@
1
- // Reference: Node.js lib/os.js — macOS-specific os module helpers
2
- // Reimplemented for GJS using GLib
3
-
4
- import { createSubnet } from './createSubnet.js';
5
- import { cli } from '@gjsify/utils';
6
-
7
- const NOMAC = '00:00:00:00:00:00';
8
-
9
- const getIPv6Subnet = createSubnet(128, 16, 16, ':');
10
-
11
- const parseInterfaces = function(info) {
12
- info = info.trim();
13
- if (info.length < 1 || !/\binet\b/.test(info)) return;
14
- const lines = info.split('\n');
15
- const iface = [];
16
- const length = lines.length;
17
- let mac = NOMAC;
18
- for (let line, i = 0; i < length; i++) {
19
- line = lines[i];
20
- switch (true) {
21
- case /ether\s+((?:\S{2}:)+\S{2})/.test(line):
22
- mac = RegExp.$1;
23
- break;
24
- case /inet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+0x(.{2})(.{2})(.{2})(.{2})/.test(line):
25
- iface.push({
26
- address: RegExp.$1,
27
- netmask: [
28
- parseInt(RegExp.$2, 16),
29
- parseInt(RegExp.$3, 16),
30
- parseInt(RegExp.$4, 16),
31
- parseInt(RegExp.$5, 16)
32
- ].join('.'),
33
- family: 'IPv4',
34
- mac: mac,
35
- internal: RegExp.$1 === '127.0.0.1'
36
- });
37
- break;
38
- case /inet6\s+((?:\S{0,4}:)+\S{1,4}).+?prefixlen\s+(\d+)/.test(line):
39
- iface.push({
40
- address: RegExp.$1,
41
- netmask: getIPv6Subnet(RegExp.$2),
42
- family: 'IPv6',
43
- mac: mac,
44
- internal: mac !== NOMAC
45
- });
46
- break;
47
- }
48
- }
49
- this[info.slice(0, info.indexOf(':'))] = iface;
50
- };
51
-
52
- // PORTED TO deno runtime
53
- export const cpus = () => {
54
- let cores = parseFloat(cli('sysctl -n hw.ncpu'));
55
- const cpus = [];
56
- while (cores--) {
57
- cpus.push({
58
- model: cli('sysctl -n machdep.cpu.brand_string').replace(/\s+/g, ' '),
59
- speed: parseFloat(cli('sysctl -n hw.cpufrequency')) / 1000 / 1000,
60
- get times() {
61
- console.warn('cpus.times is not supported');
62
- return {};
63
- }
64
- });
65
- }
66
- return cpus;
67
- };
68
-
69
- export const endianness = () => 'LE';
70
-
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
- };
111
-
112
- // PORTED TO deno runtime
113
- export const loadavg = () => /load\s+averages:\s+(\d+(?:\.\d+))\s+(\d+(?:\.\d+))\s+(\d+(?:\.\d+))/.test(
114
- cli('uptime')
115
- ) && [
116
- parseFloat(RegExp.$1),
117
- parseFloat(RegExp.$2),
118
- parseFloat(RegExp.$3)
119
- ];
120
-
121
- export const networkInterfaces = () => {
122
- const ifaces = {};
123
- const groups = [];
124
- const lines = cli('ifconfig').split(/\r\n|\n/);
125
- const length = lines.length;
126
- for (let
127
- group = [],
128
- re = /^\S+?:/,
129
- i = 0;
130
- i < length; i++
131
- ) {
132
- if (re.test(lines[i])) {
133
- group = [lines[i]];
134
- while (++i < length && !re.test(lines[i])) {
135
- group.push(lines[i]);
136
- }
137
- --i;
138
- }
139
- groups.push(group.join('\n'));
140
- }
141
- groups.forEach(parseInterfaces, ifaces);
142
- return ifaces;
143
- };
144
-
145
- /**
146
- * Get total memory on macOS using sysctl hw.memsize.
147
- */
148
- export const totalmem = () => {
149
- try {
150
- return parseFloat(cli('sysctl -n hw.memsize'));
151
- } catch {
152
- return 0;
153
- }
154
- };
155
-
156
- // PORTED TO deno runtime
157
- export const uptime = () => {
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;
175
- switch (true) {
176
- case /^(\d+):(\d+)$/.test(up as string):
177
- return ((parseInt(RegExp.$1, 10) * 60) + parseInt(RegExp.$2, 10)) * 60;
178
- case /^(\d+)\s+mins?$/.test(up as string):
179
- return parseInt(RegExp.$1, 10) * 60;
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
- }
189
- }
190
- return 0;
191
- };