@gjsify/process 0.53.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.
- package/lib/esm/process-class.js +1 -1
- package/lib/esm/streams.js +1 -1
- package/lib/types/streams.d.ts +3 -8
- package/package.json +7 -7
- package/lib/esm/raw-mode.js +0 -1
- package/lib/types/raw-mode.d.ts +0 -26
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{
|
|
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};
|
package/lib/types/streams.d.ts
CHANGED
|
@@ -24,14 +24,9 @@ export declare class ProcessReadStream extends EventEmitter {
|
|
|
24
24
|
constructor(fd: number);
|
|
25
25
|
get isTTY(): boolean;
|
|
26
26
|
setRawMode(mode: boolean): this;
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
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;
|
|
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. */
|
|
35
30
|
private _setRawModeViaStty;
|
|
36
31
|
setEncoding(enc: string): this;
|
|
37
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
|
},
|
package/lib/esm/raw-mode.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/lib/types/raw-mode.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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;
|