@gjsify/process 0.52.0 → 0.54.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(){
|
|
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){
|
|
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};
|
package/lib/esm/process-class.js
CHANGED
|
@@ -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{
|
|
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{restoreClaimedRawModes as S}from"@gjsify/terminal-native";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{S()}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 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};
|
package/lib/esm/streams.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{getGioNamespace as e,getGjsGlobal as t}from"./internal/gjs.js";import{nativeIsTty as n,nativeSetRawMode as r,nativeTerminalSize as i,noteRawMode as a}from"@gjsify/terminal-native";import{EventEmitter as o}from"@gjsify/events";import{ensureMainLoop as s,quitMainLoop as c}from"@gjsify/utils/core";import{StringDecoder as l}from"@gjsify/string_decoder";const u=new TextEncoder;var ProcessWriteStream=class extends o{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`?u.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(){let e=n(this.fd);if(e!==null)return e;try{let e=t().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){let e=i(this.fd);if(e)return e.columns;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(){let e=i(this.fd);if(e)return e.rows;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 o{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 n(this.fd)??!1}setRawMode(e){return a(this.fd,e,e=>r(this.fd,e)===!0)?(this.isRaw=e,this):(a(this.fd,e,e=>this._setRawModeViaStty(e)),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return!1;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`-isig`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`,`isig`],a=new n.SubprocessLauncher({flags:r}).spawnv(i);return a.wait(null),a.get_successful()}catch{return!1}}setEncoding(e){return this._decoder=new l(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||c(),!1)):c()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,s());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,s()),!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;
|
package/lib/types/streams.d.ts
CHANGED
|
@@ -18,13 +18,15 @@ 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
|
+
/** Whether the spawn left the terminal in the state asked for, which is what
|
|
28
|
+
* makes a claim on it honest: `stty` exits non-zero without touching a
|
|
29
|
+
* descriptor that is not a TTY, and that must claim nothing. */
|
|
28
30
|
private _setRawModeViaStty;
|
|
29
31
|
setEncoding(enc: string): this;
|
|
30
32
|
protected _pushData(buf: Buffer): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.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.
|
|
44
|
-
"@gjsify/string_decoder": "^0.
|
|
45
|
-
"@gjsify/terminal-native": "^0.
|
|
46
|
-
"@gjsify/utils": "^0.
|
|
43
|
+
"@gjsify/events": "^0.54.0",
|
|
44
|
+
"@gjsify/string_decoder": "^0.54.0",
|
|
45
|
+
"@gjsify/terminal-native": "^0.54.0",
|
|
46
|
+
"@gjsify/utils": "^0.54.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@gjsify/cli": "^0.
|
|
50
|
-
"@gjsify/unit": "^0.
|
|
49
|
+
"@gjsify/cli": "^0.54.0",
|
|
50
|
+
"@gjsify/unit": "^0.54.0",
|
|
51
51
|
"@types/node": "^25.9.2",
|
|
52
52
|
"typescript": "^6.0.3"
|
|
53
53
|
},
|