@gjsify/process 0.4.21 → 0.4.22
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/index.js +1 -1
- package/lib/esm/internal/detect.js +1 -0
- package/lib/esm/internal/env.js +1 -0
- package/lib/esm/internal/exit.js +1 -0
- package/lib/esm/internal/gjs.js +1 -0
- package/lib/esm/internal/hrtime.js +1 -0
- package/lib/esm/internal/system.js +1 -0
- package/lib/esm/process-class.js +1 -0
- package/lib/esm/streams.js +1 -0
- package/lib/types/index.d.ts +4 -82
- package/lib/types/internal/detect.d.ts +15 -0
- package/lib/types/internal/env.d.ts +5 -0
- package/lib/types/internal/exit.d.ts +7 -0
- package/lib/types/internal/gjs.d.ts +27 -0
- package/lib/types/internal/hrtime.d.ts +4 -0
- package/lib/types/internal/system.d.ts +14 -0
- package/lib/types/process-class.d.ts +38 -0
- package/lib/types/streams.d.ts +33 -0
- package/package.json +7 -7
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{EventEmitter as e}from"@gjsify/events";import{ensureMainLoop as t,quitMainLoop as n}from"@gjsify/utils";import{nativeTerminal as r}from"@gjsify/terminal-native";const i=new TextEncoder;function getGjsGlobal(){return globalThis}function detectGjsVersion(){try{let e=getGjsGlobal().imports?.system;if(e?.version!==void 0){let t=Number(e.version);return`${Math.floor(t/1e4)}.${Math.floor(t%1e4/100)}.${t%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 e=getGjsGlobal().imports?.gi?.GLib;if(e){let[,t]=e.file_get_contents(`/proc/self/status`);if(t){let e=new TextDecoder().decode(t).match(/PPid:\s+(\d+)/);if(e)return parseInt(e[1],10)}}}catch{}return 0}function detectPlatform(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e&&e.get_os_info(`ID`))return`linux`}catch{}return getGjsGlobal().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 getCwd(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_current_dir)return e.get_current_dir()}catch{}return`/`}function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return new Proxy({},{get(t,n){if(typeof n==`string`)return e.getenv(n)??void 0},set(t,n,r){return typeof n==`string`?(e.setenv(n,String(r),!0),!0):!1},deleteProperty(t,n){return typeof n==`string`?(e.unsetenv(n),!0):!1},has(t,n){return typeof n==`string`?e.getenv(n)!==null:!1},ownKeys(t){return e.listenv()},getOwnPropertyDescriptor(t,n){if(typeof n!=`string`)return;let r=e.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let e=getGjsGlobal().imports?.system;if(e?.programArgs)return[`gjs`,e.programInvocationName||``,...e.programArgs]}catch{}return[`gjs`]}function getExecPath(){if(typeof globalThis.process?.execPath==`string`)return globalThis.process.execPath;try{let e=getGjsGlobal().imports?.system;if(e?.programInvocationName)return e.programInvocationName}catch{}return`/usr/bin/gjs`}function getPid(){if(typeof globalThis.process?.pid==`number`)return globalThis.process.pid;try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let[,t]=e.file_get_contents(`/proc/self/stat`);if(t){let e=new TextDecoder().decode(t),n=parseInt(e,10);if(!isNaN(n))return n}}}catch{}return 0}const a=Date.now();function getGioNamespace(){let e=globalThis.imports?.gi;if(!e)return null;let t=null;try{t=e.GioUnix}catch{}if(!t)try{t=e.Gio}catch{}return t}var ProcessWriteStream=class extends e{fd;writable=!0;_outGio=null;constructor(e){super(),this.fd=e;let t=getGioNamespace();if(t){let e=t.UnixOutputStream??t.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?i.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(r)return r.Terminal.is_tty(this.fd);try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(r){let[e,,t]=r.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().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(r){let[e,t]=r.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends e{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;constructor(e){super(),this.fd=e,this._gio=getGioNamespace()}get isTTY(){return r?r.Terminal.is_tty(this.fd):!1}setRawMode(e){return r&&r.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`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`];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}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||n(),!1)):n()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,t());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,t()),!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.emit(`data`,Buffer.from(n));else if(n!==null&&n.byteLength===0){this._reading=!1,this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};function getMonotonicTime(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_monotonic_time)return BigInt(e.get_monotonic_time())*1000n}catch{}return typeof performance?.now==`function`?BigInt(Math.round(performance.now()*1e6)):BigInt(Date.now())*1000000n}const o=getMonotonicTime();var Process=class extends e{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),this.platform=detectPlatform(),this.arch=detectArch(),this.env=getEnvProxy(),this.argv=getArgv(),this.argv0=this.argv[0]||`gjs`,this.execPath=getExecPath(),this.execArgv=globalThis.process?.execArgv??[],this.config=globalThis.process?.config??{target_defaults:{},variables:{}},this.pid=getPid(),this.ppid=detectPpid();let e=detectVersionInfo();this.version=e.version,this.versions=e.versions,this.title=e.title}cwd(){return getCwd()}chdir(e){try{let t=getGjsGlobal().imports?.gi?.GLib;if(t?.chdir){if(!t.file_test(e,16)){let t=Error(`ENOENT: no such file or directory, chdir '${e}'`);throw t.code=`ENOENT`,t.syscall=`chdir`,t.path=e,t}t.chdir(e);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}let t=globalThis.process;if(t&&t!==this&&typeof t.chdir==`function`){t.chdir(e);return}throw Error(`process.chdir() is not supported in this environment`)}kill(e,t){let n=globalThis.process;if(n&&n!==this&&typeof n.kill==`function`)return n.kill(e,t);try{let n=getGjsGlobal().imports?.gi?.GLib;if(n){let r=typeof t==`number`?String(t):t||`SIGTERM`,i=r.startsWith(`SIG`)?`-${r.slice(3)}`:`-${r}`;return n.spawn_command_line_sync(`kill ${i} ${e}`),!0}}catch{}throw Error(`process.kill() is not supported in this environment`)}exit(e){this.exitCode=e??this.exitCode??0,this.emit(`exit`,this.exitCode);let r=getGjsGlobal().imports,i=r?.gi?.GLib,a=r?.system,o=i?.idle_add,s=i?.SOURCE_REMOVE,c=i?.PRIORITY_DEFAULT;if(a?.exit&&o&&typeof c==`number`&&typeof s==`boolean`){let e=this.exitCode;return t(),o(c,()=>(n(),a.exit(e),s)),new Promise(()=>{})}try{a?.exit&&a.exit(this.exitCode)}catch{}let l=globalThis.process;throw l&&l!==this&&typeof l.exit==`function`&&l.exit(this.exitCode),Error(`process.exit(${this.exitCode})`)}nextTick(e,...t){typeof queueMicrotask==`function`?queueMicrotask(()=>e(...t)):Promise.resolve().then(()=>e(...t))}hrtime(e){let t=getMonotonicTime()-o,n=Number(t/1000000000n),r=Number(t%1000000000n);if(e){let t=n-e[0],i=r-e[1];return i<0&&(t--,i+=1e9),[t,i]}return[n,r]}uptime(){return(Date.now()-a)/1e3}memoryUsage(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let[,t]=e.file_get_contents(`/proc/self/status`);if(t){let e=new TextDecoder().decode(t).match(/VmRSS:\s+(\d+)/),n=e?parseInt(e[1],10)*1024:0;return{rss:n,heapTotal:n,heapUsed:n,external:0,arrayBuffers:0}}}}catch{}let e=globalThis.process;return e&&e!==this&&typeof e.memoryUsage==`function`?e.memoryUsage():{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}cpuUsage(e){let t=globalThis.process;return t&&t!==this&&typeof t.cpuUsage==`function`?t.cpuUsage(e):{user:0,system:0}}stdout=new ProcessWriteStream(1);stderr=new ProcessWriteStream(2);stdin=new ProcessReadStream(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 getMonotonicTime()-o};const s=new Process;if(r)try{let e=new r.ResizeWatcher;e.connect(`resized`,(e,t,n)=>{s.stdout.emit(`resize`),s.stderr.emit(`resize`)}),e.start()}catch{}const c=s.platform,l=s.arch,u=s.env,d=s.argv,f=s.argv0,p=s.execPath,m=s.pid,h=s.ppid,g=s.version,_=s.versions,v=s.cwd.bind(s),y=s.chdir.bind(s),b=s.exit.bind(s),x=s.nextTick.bind(s),S=Object.assign(s.hrtime.bind(s),{bigint:s.hrtime.bigint.bind(s)}),C=s.uptime.bind(s),w=s.memoryUsage.bind(s),T=s.cpuUsage.bind(s),E=s.kill.bind(s),D=s.abort.bind(s),O=s.umask.bind(s),k=s.emitWarning.bind(s),A=s.execArgv,j=s.config,M=s.stdout,N=s.stderr,P=s.stdin;export{D as abort,l as arch,d as argv,f as argv0,y as chdir,j as config,T as cpuUsage,v as cwd,s as default,k as emitWarning,u as env,A as execArgv,p as execPath,b as exit,S as hrtime,E as kill,w as memoryUsage,x as nextTick,m as pid,c as platform,h as ppid,N as stderr,P as stdin,M as stdout,O as umask,C as uptime,g as version,_ as versions};
|
|
1
|
+
import{hrtimeBigint as e}from"./internal/hrtime.js";import{Process as t}from"./process-class.js";import{nativeTerminal as n}from"@gjsify/terminal-native";const r=new t;if(n)try{let e=new n.ResizeWatcher;e.connect(`resized`,(e,t,n)=>{r.stdout.emit(`resize`),r.stderr.emit(`resize`)}),e.start()}catch{}const i=r.platform,a=r.arch,o=r.env,s=r.argv,c=r.argv0,l=r.execPath,u=r.pid,d=r.ppid,f=r.version,p=r.versions,m=r.cwd.bind(r),h=r.chdir.bind(r),g=r.exit.bind(r),_=r.nextTick.bind(r),v=Object.assign(r.hrtime.bind(r),{bigint:e}),y=r.uptime.bind(r),b=r.memoryUsage.bind(r),x=r.cpuUsage.bind(r),S=r.kill.bind(r),C=r.abort.bind(r),w=r.umask.bind(r),T=r.emitWarning.bind(r),E=r.execArgv,D=r.config,O=r.stdout,k=r.stderr,A=r.stdin;export{C as abort,a as arch,s as argv,c as argv0,h as chdir,D as config,x as cpuUsage,m as cwd,r as default,T as emitWarning,o as env,E as execArgv,l as execPath,g as exit,v as hrtime,S as kill,b as memoryUsage,_ as nextTick,u as pid,i as platform,d as ppid,k as stderr,A as stdin,O as stdout,w as umask,y as uptime,f as version,p as versions};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let t=e().imports?.gi?.GLib;if(t)return new Proxy({},{get(e,n){if(typeof n==`string`)return t.getenv(n)??void 0},set(e,n,r){return typeof n==`string`?(t.setenv(n,String(r),!0),!0):!1},deleteProperty(e,n){return typeof n==`string`?(t.unsetenv(n),!0):!1},has(e,n){return typeof n==`string`?t.getenv(n)!==null:!1},ownKeys(e){return t.listenv()},getOwnPropertyDescriptor(e,n){if(typeof n!=`string`)return;let r=t.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let t=e().imports?.system;if(t?.programArgs)return[`gjs`,t.programInvocationName||``,...t.programArgs]}catch{}return[`gjs`]}function getExecPath(){if(typeof globalThis.process?.execPath==`string`)return globalThis.process.execPath;try{let t=e().imports?.system;if(t?.programInvocationName)return t.programInvocationName}catch{}return`/usr/bin/gjs`}function getCwd(){try{let t=e().imports?.gi?.GLib;if(t?.get_current_dir)return t.get_current_dir()}catch{}return`/`}function chdir(t){let n=e().imports?.gi?.GLib;try{if(n?.chdir){if(!n.file_test(t,16)){let e=Error(`ENOENT: no such file or directory, chdir '${t}'`);throw e.code=`ENOENT`,e.syscall=`chdir`,e.path=t,e}n.chdir(t);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}if(!n){let e=globalThis.process;if(e&&typeof e.chdir==`function`){e.chdir(t);return}}throw Error(`process.chdir() is not supported in this environment`)}export{chdir,getArgv,getCwd,getEnvProxy,getExecPath};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";function getGjsGlobal(){return globalThis}function getGioNamespace(){let e=globalThis.imports?.gi;if(!e)return null;let t=null;try{t=e.GioUnix}catch{}if(!t)try{t=e.Gio}catch{}return t}export{getGioNamespace,getGjsGlobal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";function getMonotonicTime(){try{let t=e().imports?.gi?.GLib;if(t?.get_monotonic_time)return BigInt(t.get_monotonic_time())*1000n}catch{}return typeof performance?.now==`function`?BigInt(Math.round(performance.now()*1e6)):BigInt(Date.now())*1000000n}const t=getMonotonicTime();function hrtime(e){let n=getMonotonicTime()-t,r=Number(n/1000000000n),i=Number(n%1000000000n);if(e){let t=r-e[0],n=i-e[1];return n<0&&(t--,n+=1e9),[t,n]}return[r,i]}function hrtimeBigint(){return getMonotonicTime()-t}export{getMonotonicTime,hrtime,t as hrtimeBase,hrtimeBigint};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";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(){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(/VmRSS:\s+(\d+)/),n=t?parseInt(t[1],10)*1024:0;return{rss:n,heapTotal:n,heapUsed:n,external:0,arrayBuffers:0}}}}catch{}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}}export{cpuUsage,killPid,memoryUsage};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +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";const o=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`?o.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;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`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`];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}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.emit(`data`,Buffer.from(n));else if(n!==null&&n.byteLength===0){this._reading=!1,this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};export{ProcessReadStream,ProcessWriteStream};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,82 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ProcessPlatform = NodeJS.Platform;
|
|
3
|
-
type ProcessArch = NodeJS.Architecture;
|
|
4
|
-
declare class ProcessWriteStream extends EventEmitter {
|
|
5
|
-
readonly fd: number;
|
|
6
|
-
writable: boolean;
|
|
7
|
-
private _outGio;
|
|
8
|
-
constructor(fd: number);
|
|
9
|
-
write(data: string | Uint8Array): boolean;
|
|
10
|
-
get isTTY(): boolean;
|
|
11
|
-
get columns(): number;
|
|
12
|
-
end(): void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
get rows(): number;
|
|
15
|
-
}
|
|
16
|
-
declare class ProcessReadStream extends EventEmitter {
|
|
17
|
-
readonly fd: number;
|
|
18
|
-
isRaw: boolean;
|
|
19
|
-
private _gio;
|
|
20
|
-
private _stdinGio;
|
|
21
|
-
private _reading;
|
|
22
|
-
private _flowing;
|
|
23
|
-
private _sttyCleanupRegistered;
|
|
24
|
-
private _mainLoopHeld;
|
|
25
|
-
private _pendingRead;
|
|
26
|
-
constructor(fd: number);
|
|
27
|
-
get isTTY(): boolean;
|
|
28
|
-
setRawMode(mode: boolean): this;
|
|
29
|
-
private _setRawModeViaStty;
|
|
30
|
-
setEncoding(_enc: string): this;
|
|
31
|
-
resume(): this;
|
|
32
|
-
pause(): this;
|
|
33
|
-
read(): null;
|
|
34
|
-
private _startReading;
|
|
35
|
-
}
|
|
36
|
-
declare class Process extends EventEmitter {
|
|
37
|
-
readonly platform: ProcessPlatform;
|
|
38
|
-
readonly arch: ProcessArch;
|
|
39
|
-
readonly env: Record<string, string | undefined>;
|
|
40
|
-
readonly argv: string[];
|
|
41
|
-
readonly argv0: string;
|
|
42
|
-
readonly execPath: string;
|
|
43
|
-
readonly pid: number;
|
|
44
|
-
readonly ppid: number;
|
|
45
|
-
readonly version: string;
|
|
46
|
-
readonly versions: Record<string, string>;
|
|
47
|
-
title: string;
|
|
48
|
-
readonly execArgv: string[];
|
|
49
|
-
readonly config: Record<string, unknown>;
|
|
50
|
-
exitCode: number | undefined;
|
|
51
|
-
constructor();
|
|
52
|
-
cwd(): string;
|
|
53
|
-
chdir(directory: string): void;
|
|
54
|
-
kill(pid: number, signal?: string | number): boolean;
|
|
55
|
-
exit(code?: number): never;
|
|
56
|
-
nextTick(callback: Function, ...args: unknown[]): void;
|
|
57
|
-
hrtime(time?: [number, number]): [number, number];
|
|
58
|
-
uptime(): number;
|
|
59
|
-
memoryUsage(): {
|
|
60
|
-
rss: number;
|
|
61
|
-
heapTotal: number;
|
|
62
|
-
heapUsed: number;
|
|
63
|
-
external: number;
|
|
64
|
-
arrayBuffers: number;
|
|
65
|
-
};
|
|
66
|
-
cpuUsage(previousValue?: {
|
|
67
|
-
user: number;
|
|
68
|
-
system: number;
|
|
69
|
-
}): {
|
|
70
|
-
user: number;
|
|
71
|
-
system: number;
|
|
72
|
-
};
|
|
73
|
-
readonly stdout: ProcessWriteStream;
|
|
74
|
-
readonly stderr: ProcessWriteStream;
|
|
75
|
-
readonly stdin: ProcessReadStream;
|
|
76
|
-
abort(): void;
|
|
77
|
-
umask(mask?: number): number;
|
|
78
|
-
emitWarning(warning: string | Error, name?: string): void;
|
|
79
|
-
}
|
|
1
|
+
import { Process } from './process-class.js';
|
|
80
2
|
declare const process: Process;
|
|
81
3
|
export declare const platform: NodeJS.Platform;
|
|
82
4
|
export declare const arch: NodeJS.Architecture;
|
|
@@ -102,7 +24,7 @@ export declare const umask: any;
|
|
|
102
24
|
export declare const emitWarning: any;
|
|
103
25
|
export declare const execArgv: string[];
|
|
104
26
|
export declare const config: Record<string, unknown>;
|
|
105
|
-
export declare const stdout: ProcessWriteStream;
|
|
106
|
-
export declare const stderr: ProcessWriteStream;
|
|
107
|
-
export declare const stdin: ProcessReadStream;
|
|
27
|
+
export declare const stdout: import("./streams.js").ProcessWriteStream;
|
|
28
|
+
export declare const stderr: import("./streams.js").ProcessWriteStream;
|
|
29
|
+
export declare const stdin: import("./streams.js").ProcessReadStream;
|
|
108
30
|
export default process;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ProcessPlatform = NodeJS.Platform;
|
|
2
|
+
type ProcessArch = NodeJS.Architecture;
|
|
3
|
+
export declare function detectGjsVersion(): string | undefined;
|
|
4
|
+
export declare function detectNodeVersion(): string | undefined;
|
|
5
|
+
export interface VersionInfo {
|
|
6
|
+
version: string;
|
|
7
|
+
versions: Record<string, string>;
|
|
8
|
+
title: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function detectVersionInfo(): VersionInfo;
|
|
11
|
+
export declare function detectPpid(): number;
|
|
12
|
+
export declare function detectPlatform(): ProcessPlatform;
|
|
13
|
+
export declare function detectArch(): ProcessArch;
|
|
14
|
+
export declare function getPid(): number;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getEnvProxy(): Record<string, string | undefined>;
|
|
2
|
+
export declare function getArgv(): string[];
|
|
3
|
+
export declare function getExecPath(): string;
|
|
4
|
+
export declare function getCwd(): string;
|
|
5
|
+
export declare function chdir(directory: string): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger process termination with the given exit code. Returns `never` —
|
|
3
|
+
* the function does not return to its caller under any path. If the GJS
|
|
4
|
+
* idle-scheduled path is taken, this returns a forever-pending Promise so
|
|
5
|
+
* the caller's synchronous control flow stalls until the syscall fires.
|
|
6
|
+
*/
|
|
7
|
+
export declare function exitProcess(code: number): never;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Subset of globalThis we touch on GJS — typed loosely because we have to
|
|
2
|
+
* cohabit with Node's typed globals when this code is bundled cross-platform. */
|
|
3
|
+
export interface GjsGlobalThis {
|
|
4
|
+
imports?: {
|
|
5
|
+
gi?: {
|
|
6
|
+
GLib?: Record<string, Function>;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
system?: {
|
|
10
|
+
programArgs?: string[];
|
|
11
|
+
programInvocationName?: string;
|
|
12
|
+
exit?: (code: number) => never;
|
|
13
|
+
version?: number;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Cast the global view to our loose shape — kept in one place. */
|
|
20
|
+
export declare function getGjsGlobal(): GjsGlobalThis;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the right Gio-flavoured namespace. GJS ≥ 1.88 supersedes
|
|
23
|
+
* `Gio.UnixInputStream` etc. with `GioUnix.InputStream`; we try the new
|
|
24
|
+
* namespace first and fall back to the legacy one. Returns `null` when
|
|
25
|
+
* neither is available (e.g. under Node).
|
|
26
|
+
*/
|
|
27
|
+
export declare function getGioNamespace(): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function killPid(pid: number, signal?: string | number): boolean;
|
|
2
|
+
export interface MemoryUsage {
|
|
3
|
+
rss: number;
|
|
4
|
+
heapTotal: number;
|
|
5
|
+
heapUsed: number;
|
|
6
|
+
external: number;
|
|
7
|
+
arrayBuffers: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function memoryUsage(): MemoryUsage;
|
|
10
|
+
export interface CpuUsage {
|
|
11
|
+
user: number;
|
|
12
|
+
system: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function cpuUsage(previousValue?: CpuUsage): CpuUsage;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventEmitter } from '@gjsify/events';
|
|
2
|
+
import { type CpuUsage, type MemoryUsage } from './internal/system.js';
|
|
3
|
+
import { ProcessReadStream, ProcessWriteStream } from './streams.js';
|
|
4
|
+
type ProcessPlatform = NodeJS.Platform;
|
|
5
|
+
type ProcessArch = NodeJS.Architecture;
|
|
6
|
+
export declare class Process extends EventEmitter {
|
|
7
|
+
readonly platform: ProcessPlatform;
|
|
8
|
+
readonly arch: ProcessArch;
|
|
9
|
+
readonly env: Record<string, string | undefined>;
|
|
10
|
+
readonly argv: string[];
|
|
11
|
+
readonly argv0: string;
|
|
12
|
+
readonly execPath: string;
|
|
13
|
+
readonly pid: number;
|
|
14
|
+
readonly ppid: number;
|
|
15
|
+
readonly version: string;
|
|
16
|
+
readonly versions: Record<string, string>;
|
|
17
|
+
title: string;
|
|
18
|
+
readonly execArgv: string[];
|
|
19
|
+
readonly config: Record<string, unknown>;
|
|
20
|
+
exitCode: number | undefined;
|
|
21
|
+
constructor();
|
|
22
|
+
cwd(): string;
|
|
23
|
+
chdir(directory: string): void;
|
|
24
|
+
kill(pid: number, signal?: string | number): boolean;
|
|
25
|
+
exit(code?: number): never;
|
|
26
|
+
nextTick(callback: Function, ...args: unknown[]): void;
|
|
27
|
+
hrtime(time?: [number, number]): [number, number];
|
|
28
|
+
uptime(): number;
|
|
29
|
+
memoryUsage(): MemoryUsage;
|
|
30
|
+
cpuUsage(previousValue?: CpuUsage): CpuUsage;
|
|
31
|
+
readonly stdout: ProcessWriteStream;
|
|
32
|
+
readonly stderr: ProcessWriteStream;
|
|
33
|
+
readonly stdin: ProcessReadStream;
|
|
34
|
+
abort(): void;
|
|
35
|
+
umask(_mask?: number): number;
|
|
36
|
+
emitWarning(warning: string | Error, name?: string): void;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventEmitter } from '@gjsify/events';
|
|
2
|
+
export declare class ProcessWriteStream extends EventEmitter {
|
|
3
|
+
readonly fd: number;
|
|
4
|
+
writable: boolean;
|
|
5
|
+
private _outGio;
|
|
6
|
+
constructor(fd: number);
|
|
7
|
+
write(data: string | Uint8Array): boolean;
|
|
8
|
+
get isTTY(): boolean;
|
|
9
|
+
get columns(): number;
|
|
10
|
+
end(): void;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
get rows(): number;
|
|
13
|
+
}
|
|
14
|
+
export declare class ProcessReadStream extends EventEmitter {
|
|
15
|
+
readonly fd: number;
|
|
16
|
+
isRaw: boolean;
|
|
17
|
+
private _gio;
|
|
18
|
+
private _stdinGio;
|
|
19
|
+
private _reading;
|
|
20
|
+
private _flowing;
|
|
21
|
+
private _sttyCleanupRegistered;
|
|
22
|
+
private _mainLoopHeld;
|
|
23
|
+
private _pendingRead;
|
|
24
|
+
constructor(fd: number);
|
|
25
|
+
get isTTY(): boolean;
|
|
26
|
+
setRawMode(mode: boolean): this;
|
|
27
|
+
private _setRawModeViaStty;
|
|
28
|
+
setEncoding(_enc: string): this;
|
|
29
|
+
resume(): this;
|
|
30
|
+
pause(): this;
|
|
31
|
+
read(): null;
|
|
32
|
+
private _startReading;
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/process",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.22",
|
|
4
4
|
"description": "Node.js process module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"process"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@gjsify/events": "^0.4.
|
|
37
|
-
"@gjsify/terminal-native": "^0.4.
|
|
38
|
-
"@gjsify/utils": "^0.4.
|
|
36
|
+
"@gjsify/events": "^0.4.22",
|
|
37
|
+
"@gjsify/terminal-native": "^0.4.22",
|
|
38
|
+
"@gjsify/utils": "^0.4.22"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@gjsify/cli": "^0.4.
|
|
42
|
-
"@gjsify/unit": "^0.4.
|
|
43
|
-
"@types/node": "^25.
|
|
41
|
+
"@gjsify/cli": "^0.4.22",
|
|
42
|
+
"@gjsify/unit": "^0.4.22",
|
|
43
|
+
"@types/node": "^25.9.1",
|
|
44
44
|
"typescript": "^6.0.3"
|
|
45
45
|
}
|
|
46
46
|
}
|