@gjsify/process 0.3.21 → 0.4.3

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.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- 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=s.hrtime.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"./_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=s.hrtime.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};
package/package.json CHANGED
@@ -1,43 +1,46 @@
1
1
  {
2
- "name": "@gjsify/process",
3
- "version": "0.3.21",
4
- "description": "Node.js process module for Gjs",
5
- "module": "lib/esm/index.js",
6
- "types": "lib/types/index.d.ts",
7
- "type": "module",
8
- "exports": {
9
- ".": {
10
- "types": "./lib/types/index.d.ts",
11
- "default": "./lib/esm/index.js"
2
+ "name": "@gjsify/process",
3
+ "version": "0.4.3",
4
+ "description": "Node.js process module for Gjs",
5
+ "module": "lib/esm/index.js",
6
+ "types": "lib/types/index.d.ts",
7
+ "files": [
8
+ "lib"
9
+ ],
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/esm/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
19
+ "check": "tsc --noEmit",
20
+ "build": "gjsify run build:gjsify && gjsify run build:types",
21
+ "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
22
+ "build:types": "tsc",
23
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node",
24
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
25
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
26
+ "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
27
+ "test:gjs": "gjsify run test.gjs.mjs",
28
+ "test:node": "node test.node.mjs"
29
+ },
30
+ "keywords": [
31
+ "gjs",
32
+ "node",
33
+ "process"
34
+ ],
35
+ "dependencies": {
36
+ "@gjsify/events": "workspace:^",
37
+ "@gjsify/terminal-native": "workspace:^",
38
+ "@gjsify/utils": "workspace:^"
39
+ },
40
+ "devDependencies": {
41
+ "@gjsify/cli": "workspace:^",
42
+ "@gjsify/unit": "workspace:^",
43
+ "@types/node": "^25.6.2",
44
+ "typescript": "^6.0.3"
12
45
  }
13
- },
14
- "scripts": {
15
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
16
- "check": "tsc --noEmit",
17
- "build": "yarn build:gjsify && yarn build:types",
18
- "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
19
- "build:types": "tsc",
20
- "build:test": "yarn build:test:gjs && yarn build:test:node",
21
- "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
22
- "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
23
- "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
24
- "test:gjs": "gjsify run test.gjs.mjs",
25
- "test:node": "node test.node.mjs"
26
- },
27
- "keywords": [
28
- "gjs",
29
- "node",
30
- "process"
31
- ],
32
- "dependencies": {
33
- "@gjsify/events": "^0.3.21",
34
- "@gjsify/terminal-native": "^0.3.21",
35
- "@gjsify/utils": "^0.3.21"
36
- },
37
- "devDependencies": {
38
- "@gjsify/cli": "^0.3.21",
39
- "@gjsify/unit": "^0.3.21",
40
- "@types/node": "^25.6.2",
41
- "typescript": "^6.0.3"
42
- }
43
- }
46
+ }
@@ -1,214 +0,0 @@
1
- // Ported from refs/node-test/parallel/test-process-*.js
2
- // Original: MIT license, Node.js contributors
3
-
4
- import { describe, it, expect } from '@gjsify/unit';
5
- import process from 'node:process';
6
-
7
- export default async () => {
8
-
9
- // ===================== Signal handling =====================
10
- await describe('process signal handling', async () => {
11
- await it('should support registering SIGTERM handler', async () => {
12
- let handlerCalled = false;
13
- const handler = () => { handlerCalled = true; };
14
- process.on('SIGTERM', handler);
15
- expect(process.listenerCount('SIGTERM')).toBeGreaterThan(0);
16
- process.removeListener('SIGTERM', handler);
17
- });
18
-
19
- await it('should support registering SIGINT handler', async () => {
20
- const handler = () => {};
21
- process.on('SIGINT', handler);
22
- expect(process.listenerCount('SIGINT')).toBeGreaterThan(0);
23
- process.removeListener('SIGINT', handler);
24
- });
25
- });
26
-
27
- // ===================== process.stdout/stderr =====================
28
- await describe('process.stdout and process.stderr', async () => {
29
- await it('process.stdout should exist', async () => {
30
- expect(process.stdout).toBeDefined();
31
- });
32
-
33
- await it('process.stderr should exist', async () => {
34
- expect(process.stderr).toBeDefined();
35
- });
36
-
37
- await it('process.stdout should have write method', async () => {
38
- expect(typeof process.stdout.write).toBe('function');
39
- });
40
-
41
- await it('process.stderr should have write method', async () => {
42
- expect(typeof process.stderr.write).toBe('function');
43
- });
44
- });
45
-
46
- // ===================== process.stdin =====================
47
- await describe('process.stdin', async () => {
48
- await it('should exist', async () => {
49
- expect(process.stdin).toBeDefined();
50
- });
51
- });
52
-
53
- // ===================== process.nextTick ordering =====================
54
- await describe('process.nextTick ordering', async () => {
55
- await it('should execute callbacks in FIFO order', async () => {
56
- const order: number[] = [];
57
- await new Promise<void>((resolve) => {
58
- process.nextTick(() => { order.push(1); });
59
- process.nextTick(() => { order.push(2); });
60
- process.nextTick(() => {
61
- order.push(3);
62
- resolve();
63
- });
64
- });
65
- expect(order[0]).toBe(1);
66
- expect(order[1]).toBe(2);
67
- expect(order[2]).toBe(3);
68
- });
69
-
70
- await it('should pass arguments to callback', async () => {
71
- const result = await new Promise<string>((resolve) => {
72
- process.nextTick((a: string, b: string) => {
73
- resolve(a + b);
74
- }, 'hello', ' world');
75
- });
76
- expect(result).toBe('hello world');
77
- });
78
- });
79
-
80
- // ===================== process.env deep =====================
81
- await describe('process.env deep', async () => {
82
- await it('should support setting and deleting env vars', async () => {
83
- process.env.TEST_GJSIFY_VAR = 'test_value';
84
- expect(process.env.TEST_GJSIFY_VAR).toBe('test_value');
85
- delete process.env.TEST_GJSIFY_VAR;
86
- expect(process.env.TEST_GJSIFY_VAR).toBeUndefined();
87
- });
88
-
89
- await it('should coerce non-string values to strings', async () => {
90
- (process.env as any).TEST_NUM = 42;
91
- expect(typeof process.env.TEST_NUM).toBe('string');
92
- expect(process.env.TEST_NUM).toBe('42');
93
- delete process.env.TEST_NUM;
94
- });
95
-
96
- await it('should enumerate env vars with Object.keys', async () => {
97
- const keys = Object.keys(process.env);
98
- expect(keys.length).toBeGreaterThan(0);
99
- // PATH or HOME should be present
100
- const hasCommon = keys.includes('PATH') || keys.includes('HOME') || keys.includes('USER');
101
- expect(hasCommon).toBe(true);
102
- });
103
- });
104
-
105
- // ===================== process.hrtime =====================
106
- await describe('process.hrtime deep', async () => {
107
- await it('hrtime should return [seconds, nanoseconds]', async () => {
108
- const hr = process.hrtime();
109
- expect(Array.isArray(hr)).toBe(true);
110
- expect(hr.length).toBe(2);
111
- expect(typeof hr[0]).toBe('number');
112
- expect(typeof hr[1]).toBe('number');
113
- expect(hr[0]).toBeGreaterThan(-1);
114
- expect(hr[1]).toBeGreaterThan(-1);
115
- });
116
-
117
- await it('hrtime diff should measure elapsed time', async () => {
118
- const start = process.hrtime();
119
- // Small busy wait
120
- let sum = 0;
121
- for (let i = 0; i < 100000; i++) sum += i;
122
- const diff = process.hrtime(start);
123
- expect(diff[0]).toBeGreaterThan(-1);
124
- // Total nanoseconds should be positive
125
- const totalNs = diff[0] * 1e9 + diff[1];
126
- expect(totalNs).toBeGreaterThan(0);
127
- });
128
-
129
- await it('hrtime.bigint should return bigint', async () => {
130
- const t = process.hrtime.bigint();
131
- expect(typeof t).toBe('bigint');
132
- expect(t > 0n).toBe(true);
133
- });
134
-
135
- await it('hrtime.bigint should be monotonic', async () => {
136
- const a = process.hrtime.bigint();
137
- const b = process.hrtime.bigint();
138
- expect(b >= a).toBe(true);
139
- });
140
- });
141
-
142
- // ===================== process.memoryUsage =====================
143
- await describe('process.memoryUsage deep', async () => {
144
- await it('should return object with expected fields', async () => {
145
- const mem = process.memoryUsage();
146
- expect(typeof mem).toBe('object');
147
- expect(typeof mem.rss).toBe('number');
148
- expect(typeof mem.heapTotal).toBe('number');
149
- expect(typeof mem.heapUsed).toBe('number');
150
- expect(typeof mem.external).toBe('number');
151
- });
152
-
153
- await it('rss should be positive', async () => {
154
- const mem = process.memoryUsage();
155
- expect(mem.rss).toBeGreaterThan(0);
156
- });
157
-
158
- await it('heapUsed should be less than or equal to heapTotal', async () => {
159
- const mem = process.memoryUsage();
160
- expect(mem.heapUsed <= mem.heapTotal).toBe(true);
161
- });
162
- });
163
-
164
- // ===================== process.cpuUsage =====================
165
- await describe('process.cpuUsage deep', async () => {
166
- await it('should return user and system times', async () => {
167
- const usage = process.cpuUsage();
168
- expect(typeof usage.user).toBe('number');
169
- expect(typeof usage.system).toBe('number');
170
- });
171
-
172
- await it('should accept previous value for delta', async () => {
173
- const prev = process.cpuUsage();
174
- // Do some work
175
- let sum = 0;
176
- for (let i = 0; i < 100000; i++) sum += i;
177
- const delta = process.cpuUsage(prev);
178
- expect(typeof delta.user).toBe('number');
179
- expect(typeof delta.system).toBe('number');
180
- // Delta user time should be non-negative
181
- expect(delta.user >= 0).toBe(true);
182
- });
183
- });
184
-
185
- // ===================== process.emitWarning =====================
186
- await describe('process.emitWarning', async () => {
187
- await it('should be a function', async () => {
188
- expect(typeof process.emitWarning).toBe('function');
189
- });
190
- });
191
-
192
- // ===================== process.versions =====================
193
- await describe('process.versions deep', async () => {
194
- await it('should have versions object', async () => {
195
- expect(typeof process.versions).toBe('object');
196
- expect(process.versions !== null).toBe(true);
197
- });
198
-
199
- await it('should have v8 or gjs version', async () => {
200
- // On Node.js: v8 exists. On GJS: may have gjs or modules
201
- const hasEngine = process.versions.v8 !== undefined ||
202
- (process.versions as any).gjs !== undefined ||
203
- process.versions.modules !== undefined;
204
- expect(hasEngine).toBe(true);
205
- });
206
- });
207
-
208
- // ===================== process.config =====================
209
- await describe('process.config', async () => {
210
- await it('should be an object', async () => {
211
- expect(typeof process.config).toBe('object');
212
- });
213
- });
214
- };