@gjsify/process 0.22.0 → 0.23.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.
@@ -1 +1 @@
1
- import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";function detectGjsVersion(){try{let t=e().imports?.system;if(t?.version!==void 0){let e=Number(t.version);return`${Math.floor(e/1e4)}.${Math.floor(e%1e4/100)}.${e%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){if(typeof globalThis.process?.ppid==`number`)return globalThis.process.ppid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/status`);if(e){let t=new TextDecoder().decode(e).match(/PPid:\s+(\d+)/);if(t)return parseInt(t[1],10)}}}catch{}return 0}function detectPlatform(){try{let t=e().imports?.gi?.GLib;if(t&&t.get_os_info(`ID`))return`linux`}catch{}return e().imports?.system===void 0&&typeof globalThis.process?.platform==`string`?globalThis.process.platform:`linux`}function detectArch(){return typeof globalThis.process?.arch==`string`?globalThis.process.arch:`x64`}function getPid(){if(typeof globalThis.process?.pid==`number`)return globalThis.process.pid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/stat`);if(e){let t=new TextDecoder().decode(e),n=parseInt(t,10);if(!isNaN(n))return n}}}catch{}return 0}export{detectArch,detectGjsVersion,detectNodeVersion,detectPlatform,detectPpid,detectVersionInfo,getPid};
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{probeUname as t}from"./uname.js";function detectGjsVersion(){try{let t=e().imports?.system;if(t?.version!==void 0){let e=Number(t.version);return`${Math.floor(e/1e4)}.${Math.floor(e%1e4/100)}.${e%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){if(typeof globalThis.process?.ppid==`number`)return globalThis.process.ppid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/status`);if(e){let t=new TextDecoder().decode(e).match(/PPid:\s+(\d+)/);if(t)return parseInt(t[1],10)}}}catch{}return 0}function onGjs(){try{return e().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){if(onGjs()){let e=t();return e?e.platform:`linux`}let e=globalThis.process;return typeof e?.platform==`string`?e.platform:`linux`}function detectArch(){if(onGjs()){let e=t();return e?e.arch:`x64`}let e=globalThis.process;return typeof e?.arch==`string`?e.arch:`x64`}function getPid(){if(typeof globalThis.process?.pid==`number`)return globalThis.process.pid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/stat`);if(e){let t=new TextDecoder().decode(e),n=parseInt(t,10);if(!isNaN(n))return n}}}catch{}return 0}export{detectArch,detectGjsVersion,detectNodeVersion,detectPlatform,detectPpid,detectVersionInfo,getPid};
@@ -1 +1 @@
1
- import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{ensureMainLoop as t,quitMainLoop as n}from"@gjsify/utils";function exitProcess(r){let i=e().imports,a=i?.gi?.GLib,o=i?.system,s=a?.idle_add,c=a?.SOURCE_REMOVE,l=a?.PRIORITY_DEFAULT;if(o?.exit&&s&&typeof l==`number`&&typeof c==`boolean`)return t(),s(l,()=>(n(),o.exit(r),c)),new Promise(()=>{});try{o?.exit&&o.exit(r)}catch{}let u=globalThis.process;throw u&&typeof u.exit==`function`&&u.exit(r),Error(`process.exit(${r})`)}export{exitProcess};
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{ensureMainLoop as t,quitMainLoop as n}from"@gjsify/utils/core";function exitProcess(r){let i=e().imports,a=i?.gi?.GLib,o=i?.system,s=a?.idle_add,c=a?.SOURCE_REMOVE,l=a?.PRIORITY_DEFAULT;if(o?.exit&&s&&typeof l==`number`&&typeof c==`boolean`)return t(),s(l,()=>(n(),o.exit(r),c)),new Promise(()=>{});try{o?.exit&&o.exit(r)}catch{}let u=globalThis.process;throw u&&typeof u.exit==`function`&&u.exit(r),Error(`process.exit(${r})`)}export{exitProcess};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{mapMachine as t,mapSysname as n}from"@gjsify/utils/core";let r;function probeUname(){if(r!==void 0)return r;r=null;try{let i=e().imports?.gi?.GLib;if(!i)return r;let a=i.spawn_sync,o=i.SpawnFlags?.SEARCH_PATH;if(!a||o===void 0)return r;let[s,c]=a(null,[`uname`,`-sm`],null,o,null);if(!s||!c)return r;let l=new TextDecoder().decode(c).trim().split(/\s+/);if(l.length<2)return r;let u=n(l[0]),d=t(l[l.length-1]);if(!u||!d)return r;r={platform:u,arch:d}}catch{}return r}function resetUnameCache(){r=void 0}export{probeUname,resetUnameCache};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{detectArch as e,detectPlatform as t,detectPpid as n,detectVersionInfo as r,getPid as i}from"./internal/detect.js";import{chdir as a,getArgv as o,getCwd as s,getEnvProxy as c,getExecPath as l}from"./internal/env.js";import{exitProcess as u}from"./internal/exit.js";import{hrtime as d,hrtimeBigint as f}from"./internal/hrtime.js";import{cpuUsage as p,killPid as m,memoryUsage as h}from"./internal/system.js";import{ProcessReadStream as g,ProcessWriteStream as _}from"./streams.js";import{EventEmitter as v}from"@gjsify/events";const y=Date.now();var Process=class extends v{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),this.platform=t(),this.arch=e(),this.env=c(),this.argv=o(),this.argv0=this.argv[0]||`gjs`,this.execPath=l(),this.execArgv=globalThis.process?.execArgv??[],this.config=globalThis.process?.config??{target_defaults:{},variables:{}},this.pid=i(),this.ppid=n();let a=r();this.version=a.version,this.versions=a.versions,this.title=a.title}cwd(){return s()}chdir(e){a(e)}kill(e,t){return m(e,t)}exit(e){return this.exitCode=e??this.exitCode??0,this.emit(`exit`,this.exitCode),u(this.exitCode)}nextTick(e,...t){typeof queueMicrotask==`function`?queueMicrotask(()=>e(...t)):Promise.resolve().then(()=>e(...t))}hrtime(e){return d(e)}uptime(){return(Date.now()-y)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new _(1);stderr=new _(2);stdin=new g(0);abort(){this.exit(1)}umask(e){return 18}emitWarning(e,t){console.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return f()};export{Process};
1
+ import"./_virtual/_rolldown/runtime.js";import{detectArch as e,detectPlatform as t,detectPpid as n,detectVersionInfo as r,getPid as i}from"./internal/detect.js";import{chdir as a,getArgv as o,getCwd as s,getEnvProxy as c,getExecPath as l}from"./internal/env.js";import{exitProcess as u}from"./internal/exit.js";import{hrtime as d,hrtimeBigint as f}from"./internal/hrtime.js";import{cpuUsage as p,killPid as m,memoryUsage as h}from"./internal/system.js";import{ProcessReadStream as g,ProcessWriteStream as _}from"./streams.js";import{EventEmitter as v}from"@gjsify/events";const y=Date.now();function defineLazy(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let r=n();return Object.defineProperty(e,t,{value:r,configurable:!0,enumerable:!0,writable:!1}),r}})}var Process=class extends v{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),defineLazy(this,`platform`,t),defineLazy(this,`arch`,e),this.env=c(),this.argv=o(),this.argv0=this.argv[0]||`gjs`,this.execPath=l(),this.execArgv=globalThis.process?.execArgv??[],this.config=globalThis.process?.config??{target_defaults:{},variables:{}},this.pid=i(),this.ppid=n();let a=r();this.version=a.version,this.versions=a.versions,this.title=a.title}cwd(){return s()}chdir(e){a(e)}kill(e,t){return m(e,t)}exit(e){return this.exitCode=e??this.exitCode??0,this.emit(`exit`,this.exitCode),u(this.exitCode)}nextTick(e,...t){typeof queueMicrotask==`function`?queueMicrotask(()=>e(...t)):Promise.resolve().then(()=>e(...t))}hrtime(e){return d(e)}uptime(){return(Date.now()-y)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new _(1);stderr=new _(2);stdin=new g(0);abort(){this.exit(1)}umask(e){return 18}emitWarning(e,t){console.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return f()};export{Process};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{nativeTerminal as n}from"@gjsify/terminal-native";import{EventEmitter as r}from"@gjsify/events";import{ensureMainLoop as i,quitMainLoop as a}from"@gjsify/utils";import{StringDecoder as o}from"@gjsify/string_decoder";const s=new TextEncoder;var ProcessWriteStream=class extends r{fd;writable=!0;_outGio=null;constructor(t){super(),this.fd=t;let n=e();if(n){let e=n.UnixOutputStream??n.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?s.encode(e):e;return this._outGio.write_all(t,null),!0}catch{}return this.fd===2?console.error(e):console.log(e),!0}get isTTY(){if(n)return n.Terminal.is_tty(this.fd);try{let e=t().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(n){let[e,,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`COLUMNS`)??`0`,10);if(t>0)return t}}catch{}return 80}end(){}destroy(){}get rows(){if(n){let[e,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends r{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(t){super(),this.fd=t,this._gio=e()}get isTTY(){return n?n.Terminal.is_tty(this.fd):!1}setRawMode(e){return n&&n.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`-isig`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`,`isig`];if(new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),e&&!this._sttyCleanupRegistered){this._sttyCleanupRegistered=!0;let e=globalThis.process;e?.once&&typeof e.once==`function`&&e.once(`exit`,()=>this._setRawModeViaStty(!1))}}catch{}}setEncoding(e){return this._decoder=new o(e),this}_pushData(e){if(this._decoder){let t=this._decoder.write(e);t.length>0&&this.emit(`data`,t)}else this.emit(`data`,e)}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||a(),!1)):a()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this._pushData(Buffer.from(n));else if(n!==null&&n.byteLength===0){if(this._reading=!1,this._decoder){let e=this._decoder.end();e.length>0&&this.emit(`data`,e)}this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};export{ProcessReadStream,ProcessWriteStream};
1
+ import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{nativeTerminal as n}from"@gjsify/terminal-native";import{EventEmitter as r}from"@gjsify/events";import{ensureMainLoop as i,quitMainLoop as a}from"@gjsify/utils/core";import{StringDecoder as o}from"@gjsify/string_decoder";const s=new TextEncoder;var ProcessWriteStream=class extends r{fd;writable=!0;_outGio=null;constructor(t){super(),this.fd=t;let n=e();if(n){let e=n.UnixOutputStream??n.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?s.encode(e):e;return this._outGio.write_all(t,null),!0}catch{}return this.fd===2?console.error(e):console.log(e),!0}get isTTY(){if(n)return n.Terminal.is_tty(this.fd);try{let e=t().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(n){let[e,,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`COLUMNS`)??`0`,10);if(t>0)return t}}catch{}return 80}end(){}destroy(){}get rows(){if(n){let[e,t]=n.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=t().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends r{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(t){super(),this.fd=t,this._gio=e()}get isTTY(){return n?n.Terminal.is_tty(this.fd):!1}setRawMode(e){return n&&n.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`-isig`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`,`isig`];if(new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),e&&!this._sttyCleanupRegistered){this._sttyCleanupRegistered=!0;let e=globalThis.process;e?.once&&typeof e.once==`function`&&e.once(`exit`,()=>this._setRawModeViaStty(!1))}}catch{}}setEncoding(e){return this._decoder=new o(e),this}_pushData(e){if(this._decoder){let t=this._decoder.write(e);t.length>0&&this.emit(`data`,t)}else this.emit(`data`,e)}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||a(),!1)):a()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this._pushData(Buffer.from(n));else if(n!==null&&n.byteLength===0){if(this._reading=!1,this._decoder){let e=this._decoder.end();e.length>0&&this.emit(`data`,e)}this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};export{ProcessReadStream,ProcessWriteStream};
@@ -0,0 +1,15 @@
1
+ type ProcessPlatform = NodeJS.Platform;
2
+ type ProcessArch = NodeJS.Architecture;
3
+ export interface UnameInfo {
4
+ platform: ProcessPlatform;
5
+ arch: ProcessArch;
6
+ }
7
+ /**
8
+ * Run `uname -sm` once and map both fields. Returns `null` when the probe is
9
+ * unavailable (no GLib, spawn refused, unrecognised output) so callers can
10
+ * fall back rather than assert a guess.
11
+ */
12
+ export declare function probeUname(): UnameInfo | null;
13
+ /** Test seam: drop the cached probe result. */
14
+ export declare function resetUnameCache(): void;
15
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/process",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Node.js process module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -40,14 +40,14 @@
40
40
  "process"
41
41
  ],
42
42
  "dependencies": {
43
- "@gjsify/events": "^0.22.0",
44
- "@gjsify/string_decoder": "^0.22.0",
45
- "@gjsify/terminal-native": "^0.22.0",
46
- "@gjsify/utils": "^0.22.0"
43
+ "@gjsify/events": "^0.23.0",
44
+ "@gjsify/string_decoder": "^0.23.0",
45
+ "@gjsify/terminal-native": "^0.23.0",
46
+ "@gjsify/utils": "^0.23.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@gjsify/cli": "^0.22.0",
50
- "@gjsify/unit": "^0.22.0",
49
+ "@gjsify/cli": "^0.23.0",
50
+ "@gjsify/unit": "^0.23.0",
51
51
  "@types/node": "^25.9.2",
52
52
  "typescript": "^6.0.3"
53
53
  },