@gjsify/os 0.26.1 → 0.27.1
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/lib/esm/darwin.js +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/types/darwin.d.ts +6 -0
- package/lib/types/index.d.ts +12 -0
- package/package.json +5 -5
package/lib/esm/darwin.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{createSubnet as e}from"./createSubnet.js";import{cli as t}from"@gjsify/utils";const n
|
|
2
|
-
`),
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{createSubnet as e}from"./createSubnet.js";import{cli as t}from"@gjsify/utils";const n=e(128,16,16,`:`),parseInterfaces=function(e){if(e=e.trim(),e.length<1||!/\binet6?\b/.test(e))return;let t=e.split(`
|
|
2
|
+
`),r=[],i=t.length,a=`00:00:00:00:00:00`,o=/<[^>]*\bLOOPBACK\b[^>]*>/.test(t[0]??``);for(let e,s=0;s<i;s++)switch(e=t[s],!0){case/ether\s+((?:\S{2}:)+\S{2})/.test(e):a=RegExp.$1;break;case/inet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+0x(.{2})(.{2})(.{2})(.{2})/.test(e):r.push({address:RegExp.$1,netmask:[parseInt(RegExp.$2,16),parseInt(RegExp.$3,16),parseInt(RegExp.$4,16),parseInt(RegExp.$5,16)].join(`.`),family:`IPv4`,mac:a,internal:o});break;case/inet6\s+([^\s%]+)(?:%\S+)?\s+prefixlen\s+(\d+)/.test(e):r.push({address:RegExp.$1,netmask:n(RegExp.$2),family:`IPv6`,mac:a,internal:o});break}this[e.slice(0,e.indexOf(`:`))]=r},sysctl=e=>{try{let n=t(`sysctl -n ${e}`).trim();return n.length>0?n:null}catch{return null}},cpus=()=>{let e=parseFloat(t(`sysctl -n hw.ncpu`)),n=sysctl(`machdep.cpu.brand_string`)?.replace(/\s+/g,` `)??`unknown`,r=sysctl(`hw.cpufrequency`),i=r?parseFloat(r)/1e3/1e3:0,a=[];for(let t=0;t<e;t++)a.push({model:n,speed:i,get times(){return console.warn(`cpus.times is not supported`),{}}});return a},endianness=()=>`LE`,freemem=()=>{try{let e=t(`vm_stat`),n=/page size of (\d+) bytes/.exec(e),r=n?parseInt(n[1],10):16384,i=0,a=/Pages free:\s+(\d+)/.exec(e);a&&(i+=parseInt(a[1],10));let o=/Pages speculative:\s+(\d+)/.exec(e);o&&(i+=parseInt(o[1],10));let s=/Pages purgeable:\s+(\d+)/.exec(e);if(s&&(i+=parseInt(s[1],10)),i>0)return i*r}catch{}try{return parseFloat(t(`sysctl -n hw.memsize`))-parseFloat(t(`sysctl -n hw.physmem`))}catch{return 0}},loadavg=()=>/load\s+averages:\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)/.test(t(`uptime`))?[parseFloat(RegExp.$1),parseFloat(RegExp.$2),parseFloat(RegExp.$3)]:[0,0,0],networkInterfaces=()=>{let e={},n=[],r=t(`ifconfig`).split(/\r\n|\n/),i=r.length;for(let e=[],t=/^\S+?:/,a=0;a<i;a++){if(t.test(r[a])){for(e=[r[a]];++a<i&&!t.test(r[a]);)e.push(r[a]);--a}n.push(e.join(`
|
|
3
3
|
`))}return n.forEach(parseInterfaces,e),e},totalmem=()=>{try{return parseFloat(t(`sysctl -n hw.memsize`))}catch{return 0}},uptime=()=>{try{let e=t(`sysctl -n kern.boottime`),n=/sec\s*=\s*(\d+)/.exec(e);if(n){let e=parseInt(n[1],10);return Math.floor(Date.now()/1e3)-e}}catch{}let e=t(`uptime`),n=/up\s+([^,]+)?,/.test(e)&&RegExp.$1;switch(!0){case/^(\d+):(\d+)$/.test(n):return(parseInt(RegExp.$1,10)*60+parseInt(RegExp.$2,10))*60;case/^(\d+)\s+mins?$/.test(n):return parseInt(RegExp.$1,10)*60;case/^(\d+)\s+days?$/.test(n):{let t=parseInt(RegExp.$1,10)*86400,n=/days?,\s+(\d+):(\d+)/.exec(e);return n?t+(parseInt(n[1],10)*60+parseInt(n[2],10))*60:t}}return 0};export{cpus,endianness,freemem,loadavg,networkInterfaces,totalmem,uptime};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import"./_virtual/_rolldown/runtime.js";import e from"./constants.js";import{cpus as t,endianness as n,freemem as r,loadavg as i,networkInterfaces as a,totalmem as o,uptime as s}from"./darwin.js";import{cpus as c,endianness as l,freemem as u,loadavg as d,networkInterfaces as f,totalmem as p,uptime as m}from"./linux.js";import{cli as h,getPathSeparator as g}from"@gjsify/utils";import{mapMachine as _,mapSysname as v}from"@gjsify/utils/core";import y from"@girs/gio-2.0";import b from"@girs/glib-2.0";let x=``;const getOs=()=>x||(x=v(h(`uname -s`))??`linux`,x);let S=0;const getPid=()=>(S||=new y.Credentials().get_unix_pid(),S),C=g()===`/`?`
|
|
2
2
|
`:`\r
|
|
3
|
-
`,w=g()===`/`?`/dev/null`:`\\\\.\\nul`,homedir=()=>b.get_home_dir(),hostname=()=>b.get_host_name(),release=()=>h(`uname -r`).trim(),tmpdir=()=>b.get_tmp_dir(),type=()=>h(`uname`).trim(),platform=()=>getOs(),arch=()=>_(h(`uname -m`))??`x64`,machine=()=>h(`uname -m`).trim(),version=()=>h(`uname -v`).trim(),uptime=()=>{switch(getOs()){case`darwin`:return s();case`linux`:return m();default:return 0}},totalmem=()=>{switch(getOs()){case`darwin`:return o();case`linux`:return p();default:return 0}},availableParallelism=()=>{let e=cpus();return e?e.length:1},userInfo=()=>{let e=1e3,t=100,n=``;try{e=parseInt(h(`id -u`),10),t=parseInt(h(`id -g`),10),n=b.getenv(`SHELL`)||``}catch{}return{uid:e,gid:t,username:b.get_user_name(),homedir:b.get_home_dir(),shell:n}},cpus=()=>{let e=getOs();switch(e){case`darwin`:return t();case`linux`:return c();default:console.warn(`${e} is not supported!`);break}},endianness=()=>{let e=getOs();switch(e){case`darwin`:return n();case`linux`:return l();default:console.warn(`${e} is not supported!`);break}},freemem=()=>{let e=getOs();switch(e){case`darwin`:return r();case`linux`:return u();default:console.warn(`${e} is not supported!`);break}},loadavg=()=>{let e=getOs();switch(e){case`darwin`:return i();case`linux`:return d();default:console.warn(`${e} is not supported!`);break}},networkInterfaces=()=>{let e=getOs();switch(e){case`darwin`:return a();case`linux`:return f();default:console.warn(`${e} is not supported!`);break}},getPriority=e=>{let t=e===void 0||e===0?getPid():e;try{let e=h(`ps -o ni= -p ${t}`).trim(),n=parseInt(e,10);if(!isNaN(n))return n}catch{}return 0},setPriority=(e,t)=>{let n,r;if(t===void 0?(r=e,n=0):(n=e,r=t),typeof n!=`number`||!Number.isInteger(n))throw TypeError(`The "pid" argument must be an integer`);if(typeof r!=`number`||!Number.isInteger(r)||r<-20||r>19)throw RangeError(`The "priority" argument must be an integer between -20 and 19`);try{let e=n===0?getPid():n;h(`renice -n ${r} -p ${e}`)}catch{let e=Error(`A system error occurred: priority could not be set`);throw e.code=`ERR_SYSTEM_ERROR`,e}};var T={EOL:C,arch,availableParallelism,constants:e,cpus,devNull:w,endianness,freemem,getPriority,homedir,hostname,loadavg,machine,networkInterfaces,platform,release,setPriority,tmpdir,totalmem,type,uptime,userInfo,version};export{C as EOL,arch,availableParallelism,e as constants,cpus,T as default,w as devNull,endianness,freemem,getPriority,homedir,hostname,loadavg,machine,networkInterfaces,platform,release,setPriority,tmpdir,totalmem,type,uptime,userInfo,version};
|
|
3
|
+
`,w=g()===`/`?`/dev/null`:`\\\\.\\nul`,homedir=()=>b.get_home_dir(),hostname=()=>b.get_host_name(),release=()=>h(`uname -r`).trim(),tmpdir=()=>{let e=b.get_tmp_dir(),t=g();return e.length>1&&e.endsWith(t)?e.slice(0,-1):e},type=()=>h(`uname`).trim(),platform=()=>getOs(),arch=()=>_(h(`uname -m`))??`x64`,machine=()=>h(`uname -m`).trim(),version=()=>h(`uname -v`).trim(),uptime=()=>{switch(getOs()){case`darwin`:return s();case`linux`:return m();default:return 0}},totalmem=()=>{switch(getOs()){case`darwin`:return o();case`linux`:return p();default:return 0}},availableParallelism=()=>{let e=cpus();return e?e.length:1},userInfo=()=>{let e=1e3,t=100,n=``;try{e=parseInt(h(`id -u`),10),t=parseInt(h(`id -g`),10),n=b.getenv(`SHELL`)||``}catch{}return{uid:e,gid:t,username:b.get_user_name(),homedir:b.get_home_dir(),shell:n}},cpus=()=>{let e=getOs();switch(e){case`darwin`:return t();case`linux`:return c();default:console.warn(`${e} is not supported!`);break}},endianness=()=>{let e=getOs();switch(e){case`darwin`:return n();case`linux`:return l();default:console.warn(`${e} is not supported!`);break}},freemem=()=>{let e=getOs();switch(e){case`darwin`:return r();case`linux`:return u();default:console.warn(`${e} is not supported!`);break}},loadavg=()=>{let e=getOs();switch(e){case`darwin`:return i();case`linux`:return d();default:console.warn(`${e} is not supported!`);break}},networkInterfaces=()=>{let e=getOs();switch(e){case`darwin`:return a();case`linux`:return f();default:console.warn(`${e} is not supported!`);break}},getPriority=e=>{let t=e===void 0||e===0?getPid():e;try{let e=h(`ps -o ni= -p ${t}`).trim(),n=parseInt(e,10);if(!isNaN(n))return n}catch{}return 0},setPriority=(e,t)=>{let n,r;if(t===void 0?(r=e,n=0):(n=e,r=t),typeof n!=`number`||!Number.isInteger(n))throw TypeError(`The "pid" argument must be an integer`);if(typeof r!=`number`||!Number.isInteger(r)||r<-20||r>19)throw RangeError(`The "priority" argument must be an integer between -20 and 19`);try{let e=n===0?getPid():n;h(`renice -n ${r} -p ${e}`)}catch{let e=Error(`A system error occurred: priority could not be set`);throw e.code=`ERR_SYSTEM_ERROR`,e}};var T={EOL:C,arch,availableParallelism,constants:e,cpus,devNull:w,endianness,freemem,getPriority,homedir,hostname,loadavg,machine,networkInterfaces,platform,release,setPriority,tmpdir,totalmem,type,uptime,userInfo,version};export{C as EOL,arch,availableParallelism,e as constants,cpus,T as default,w as devNull,endianness,freemem,getPriority,homedir,hostname,loadavg,machine,networkInterfaces,platform,release,setPriority,tmpdir,totalmem,type,uptime,userInfo,version};
|
package/lib/types/darwin.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export declare const endianness: () => string;
|
|
|
7
7
|
* Falls back to (hw.memsize - hw.physmem) if vm_stat is unavailable.
|
|
8
8
|
*/
|
|
9
9
|
export declare const freemem: () => number;
|
|
10
|
+
/**
|
|
11
|
+
* Node's `os.loadavg()` is typed `number[]` and documented to always yield the
|
|
12
|
+
* 1/5/15-minute triple. The `&&` form returned the BOOLEAN `false` whenever the
|
|
13
|
+
* `uptime` output did not match, so a caller doing `loadavg()[0]` crashed
|
|
14
|
+
* instead of reading a zero.
|
|
15
|
+
*/
|
|
10
16
|
export declare const loadavg: () => number[];
|
|
11
17
|
export declare const networkInterfaces: () => {};
|
|
12
18
|
/**
|
package/lib/types/index.d.ts
CHANGED
|
@@ -5,6 +5,18 @@ export declare const devNull: string;
|
|
|
5
5
|
export declare const homedir: () => string;
|
|
6
6
|
export declare const hostname: () => string;
|
|
7
7
|
export declare const release: () => string;
|
|
8
|
+
/**
|
|
9
|
+
* Node strips a trailing separator from the temp dir (`lib/os.js`: drop a
|
|
10
|
+
* trailing `/` whenever the path is longer than one character, so `/` itself
|
|
11
|
+
* survives). `g_get_tmp_dir()` returns `$TMPDIR` verbatim, and on macOS that
|
|
12
|
+
* value ALWAYS ends in a slash — a per-user
|
|
13
|
+
* `/var/folders/<…>/T/` — so this divergence is invisible on Linux, where
|
|
14
|
+
* `$TMPDIR` is usually unset and GLib falls back to a bare `/tmp`.
|
|
15
|
+
*
|
|
16
|
+
* The consequence is not cosmetic: `path.join(os.tmpdir(), name)` yields a
|
|
17
|
+
* doubled separator, and any code comparing a normalised path against
|
|
18
|
+
* `os.tmpdir()` stops matching.
|
|
19
|
+
*/
|
|
8
20
|
export declare const tmpdir: () => string;
|
|
9
21
|
export declare const type: () => string;
|
|
10
22
|
export declare const platform: () => NodeJS.Platform;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/os",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.1",
|
|
4
4
|
"description": "Node.js os module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"clear": "
|
|
22
|
+
"clear": "gjsify clear lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs",
|
|
23
23
|
"check": "gjsify tsc --noEmit",
|
|
24
24
|
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
25
25
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@girs/gio-2.0": "^4.1.0",
|
|
42
42
|
"@girs/glib-2.0": "^4.1.0",
|
|
43
|
-
"@gjsify/utils": "^0.
|
|
43
|
+
"@gjsify/utils": "^0.27.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gjsify/cli": "^0.
|
|
47
|
-
"@gjsify/unit": "^0.
|
|
46
|
+
"@gjsify/cli": "^0.27.1",
|
|
47
|
+
"@gjsify/unit": "^0.27.1",
|
|
48
48
|
"@types/node": "^25.9.2",
|
|
49
49
|
"typescript": "^6.0.3"
|
|
50
50
|
},
|