@gjsify/process 0.52.0 → 0.53.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";import{probeUname as t}from"./uname.js";import{hostPid as n,hostPpid as r}from"@gjsify/utils/core";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(){return!onGjs()&&typeof globalThis.process?.ppid==`number`?globalThis.process.ppid:r()??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(){return!onGjs()&&typeof globalThis.process?.pid==`number`?globalThis.process.pid:n()??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";import{hostPid as n,hostPpid as r}from"@gjsify/utils/core";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(){let e=runtimeProcess();return e&&typeof e.ppid==`number`?e.ppid:r()??0}function runtimeProcess(){let e=globalThis.process;return typeof e?.release?.name==`string`?e:void 0}function onGjs(){try{return e().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){let e=runtimeProcess();if(e)return e.platform;if(onGjs()){let e=t();if(e)return e.platform}return`linux`}function detectArch(){let e=runtimeProcess();if(e)return e.arch;if(onGjs()){let e=t();if(e)return e.arch}return`x64`}function getPid(){let e=runtimeProcess();return e&&typeof e.pid==`number`?e.pid:n()??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{readProcessMemory as t}from"@gjsify/utils/core";function isGjs(){return e().imports?.gi?.GLib!==void 0}function killPid(t,n){try{let r=e().imports?.gi?.GLib;if(r){let e=typeof n==`number`?String(n):n||`SIGTERM`,i=e.startsWith(`SIG`)?`-${e.slice(3)}`:`-${e}`;return r.spawn_command_line_sync(`kill ${i} ${t}`),!0}}catch{}if(!isGjs()){let e=globalThis.process;if(e&&typeof e.kill==`function`)return e.kill(t,n)}throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=t();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}function readUmask(){try{let t=e().imports?.gi?.GLib;if(t){let[e,n]=t.file_get_contents(`/proc/self/status`);if(e){let e=/^Umask:\s*([0-7]+)/m.exec(new TextDecoder().decode(n));if(e)return parseInt(e[1],8)}}}catch{}return 18}export{cpuUsage,killPid,memoryUsage,readUmask};
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{readProcessMemory as t}from"@gjsify/utils/core";function isGjs(){return e().imports?.gi?.GLib!==void 0}function classifyKillFailure(e){if(/No such process/i.test(e))return`ESRCH`;if(/Operation not permitted/i.test(e))return`EPERM`}function killPid(t,n){let r=e().imports?.gi?.GLib;if(r){let e=typeof n==`number`?String(n):n||`SIGTERM`,i=[`kill`,e.startsWith(`SIG`)?`-${e.slice(3)}`:`-${e}`,`--`,String(t)],a=r.environ_setenv(r.get_environ(),`LC_ALL`,`C`,!0),[,,o,s]=r.spawn_sync(null,i,a,4,null),c=!1;try{c=r.spawn_check_wait_status(s)}catch{c=!1}if(c)return!0;let l=o?new TextDecoder().decode(o).trim():``,u=classifyKillFailure(l),d=Error(u?`kill ${u}`:`kill failed${l?`: ${l}`:``}`);throw u&&(d.code=u,d.errno=u===`ESRCH`?-3:-1,d.syscall=`kill`),d}let i=globalThis.process;if(i&&typeof i.kill==`function`)return i.kill(t,n);throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=t();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}function readUmask(){try{let t=e().imports?.gi?.GLib;if(t){let[e,n]=t.file_get_contents(`/proc/self/status`);if(e){let e=/^Umask:\s*([0-7]+)/m.exec(new TextDecoder().decode(n));if(e)return parseInt(e[1],8)}}}catch{}return 18}export{classifyKillFailure,cpuUsage,killPid,memoryUsage,readUmask};
@@ -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,readUmask as g}from"./internal/system.js";import{armSignal as _,disarmSignal as v,isDeliverableSignal as y}from"./internal/signals.js";import{ProcessReadStream as b,ProcessWriteStream as x}from"./streams.js";import{EventEmitter as S}from"@gjsify/events";const C=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 S{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,this.on(`newListener`,e=>{y(e)&&_(e,e=>this.emit(e,e))}),this.on(`removeListener`,e=>{y(e)&&this.listenerCount(e)===0&&v(e)})}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()-C)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new x(1);stderr=new x(2);stdin=new b(0);abort(){this.exit(1)}umask(e){let t=g();return e!==void 0&&!this._umaskWarned&&(this._umaskWarned=!0,this.emitWarning(`process.umask(0${e.toString(8)}) cannot change the file-creation mask under GJS — there is no umask(2) binding, so the mask is UNCHANGED. Pass an explicit \`mode\` to open/mkdir/writeFile instead; the kernel applies it atomically at creation.`,`UnsupportedWarning`)),t}_umaskWarned=!1;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,readUmask as g}from"./internal/system.js";import{armSignal as _,disarmSignal as v,isDeliverableSignal as y}from"./internal/signals.js";import{restoreClaimedRawModes as b}from"./raw-mode.js";import{ProcessReadStream as x,ProcessWriteStream as S}from"./streams.js";import{EventEmitter as C}from"@gjsify/events";const w=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 C{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),this.on(`exit`,()=>{try{b()}catch(e){console.error(`@gjsify/process: raw mode could not be restored:`,e)}}),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,this.on(`newListener`,e=>{y(e)&&_(e,e=>this.emit(e,e))}),this.on(`removeListener`,e=>{y(e)&&this.listenerCount(e)===0&&v(e)})}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()-w)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new S(1);stderr=new S(2);stdin=new x(0);abort(){this.exit(1)}umask(e){let t=g();return e!==void 0&&!this._umaskWarned&&(this._umaskWarned=!0,this.emitWarning(`process.umask(0${e.toString(8)}) cannot change the file-creation mask under GJS — there is no umask(2) binding, so the mask is UNCHANGED. Pass an explicit \`mode\` to open/mkdir/writeFile instead; the kernel applies it atomically at creation.`,`UnsupportedWarning`)),t}_umaskWarned=!1;emitWarning(e,t){console.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return f()};export{Process};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";const e=new Map;function claimRawMode(t,n){e.set(t,n)}function releaseRawMode(t){e.delete(t)}function isRawModeClaimed(t){return e.has(t)}function restoreClaimedRawModes(){let t=[...e.entries()];e.clear();let n=0,r;for(let[,e]of t)try{e(),n+=1}catch(e){r??=e}if(r!==void 0)throw r;return n}export{claimRawMode,isRawModeClaimed,releaseRawMode,restoreClaimedRawModes};
@@ -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/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};
1
+ import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{claimRawMode as n,releaseRawMode as r}from"./raw-mode.js";import{nativeTerminal as i}from"@gjsify/terminal-native";import{EventEmitter as a}from"@gjsify/events";import{ensureMainLoop as o,quitMainLoop as s}from"@gjsify/utils/core";import{StringDecoder as c}from"@gjsify/string_decoder";const l=new TextEncoder;var ProcessWriteStream=class extends a{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`?l.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(i)return i.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(i){let[e,,t]=i.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(i){let[e,t]=i.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 a{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(t){super(),this.fd=t,this._gio=e()}get isTTY(){return i?i.Terminal.is_tty(this.fd):!1}setRawMode(e){return i&&i.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this._noteRawMode(e,()=>{i.Terminal.set_raw_mode(this.fd,!1)}),this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_noteRawMode(e,t){e?n(this.fd,t):r(this.fd)}_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`];new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),this._noteRawMode(e,()=>this._setRawModeViaStty(!1))}catch{}}setEncoding(e){return this._decoder=new c(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||s(),!1)):s()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,o());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,o()),!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,3 +1,13 @@
1
+ /**
2
+ * Map a failed `kill(1)` to the errno Node's `process.kill` would have thrown.
3
+ *
4
+ * Returns `undefined` for a failure it cannot classify: the caller then throws
5
+ * WITHOUT a code, so nobody reads "the process is gone" out of, say, a missing
6
+ * `kill` binary. The two phrases are strerror(3)'s C-locale text, which is why
7
+ * the child runs under `LC_ALL=C` — procps, util-linux, BusyBox and the BSD
8
+ * `/bin/kill` on macOS all print them verbatim there.
9
+ */
10
+ export declare function classifyKillFailure(stderr: string): 'ESRCH' | 'EPERM' | undefined;
1
11
  export declare function killPid(pid: number, signal?: string | number): boolean;
2
12
  export interface MemoryUsage {
3
13
  rss: number;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Record that this process put `fd` into raw mode, and how to undo it.
3
+ *
4
+ * Called by whoever performs the transition, on EVERY path — a path that forgets
5
+ * to claim is a terminal nobody will restore, which is the bug this exists for.
6
+ */
7
+ export declare function claimRawMode(fd: number, restore: () => void): void;
8
+ /**
9
+ * Record that the owner turned `fd` back itself, in the normal close() path.
10
+ *
11
+ * A paid debt: nothing is owed at exit, so the exit hook must not run a restore
12
+ * that could fight whoever claimed the descriptor afterwards.
13
+ */
14
+ export declare function releaseRawMode(fd: number): void;
15
+ /** Whether this process still owes `fd` a restore. */
16
+ export declare function isRawModeClaimed(fd: number): boolean;
17
+ /**
18
+ * Pay every outstanding debt, and report how many were paid.
19
+ *
20
+ * The map is emptied BEFORE anything runs, so a restore that claims again — or
21
+ * throws — cannot be undone by this same pass. One descriptor failing does not
22
+ * strand the others: every restore is attempted, and the first failure is
23
+ * rethrown afterwards so the caller can see it. A silently empty restore is the
24
+ * exact failure this module exists to remove, so the error is never swallowed.
25
+ */
26
+ export declare function restoreClaimedRawModes(): number;
@@ -18,13 +18,20 @@ export declare class ProcessReadStream extends EventEmitter {
18
18
  private _stdinGio;
19
19
  private _reading;
20
20
  private _flowing;
21
- private _sttyCleanupRegistered;
22
21
  private _mainLoopHeld;
23
22
  private _pendingRead;
24
23
  private _decoder;
25
24
  constructor(fd: number);
26
25
  get isTTY(): boolean;
27
26
  setRawMode(mode: boolean): this;
27
+ /**
28
+ * Record what this stream owes the terminal, or clear the debt.
29
+ *
30
+ * `releaseRawMode` matters as much as the claim: the owner turning raw mode
31
+ * off in the normal `close()` path has PAID, and an exit hook that ran the
32
+ * stale undo afterwards could fight a later owner that wanted raw mode.
33
+ */
34
+ private _noteRawMode;
28
35
  private _setRawModeViaStty;
29
36
  setEncoding(enc: string): this;
30
37
  protected _pushData(buf: Buffer): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/process",
3
- "version": "0.52.0",
3
+ "version": "0.53.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.52.0",
44
- "@gjsify/string_decoder": "^0.52.0",
45
- "@gjsify/terminal-native": "^0.52.0",
46
- "@gjsify/utils": "^0.52.0"
43
+ "@gjsify/events": "^0.53.0",
44
+ "@gjsify/string_decoder": "^0.53.0",
45
+ "@gjsify/terminal-native": "^0.53.0",
46
+ "@gjsify/utils": "^0.53.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@gjsify/cli": "^0.52.0",
50
- "@gjsify/unit": "^0.52.0",
49
+ "@gjsify/cli": "^0.53.0",
50
+ "@gjsify/unit": "^0.53.0",
51
51
  "@types/node": "^25.9.2",
52
52
  "typescript": "^6.0.3"
53
53
  },