@gjsify/process 0.4.44 → 0.5.1

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{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};
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}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||a(),!1)):a()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,i()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this.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};
@@ -26,6 +26,12 @@ export declare class ProcessReadStream extends EventEmitter {
26
26
  setRawMode(mode: boolean): this;
27
27
  private _setRawModeViaStty;
28
28
  setEncoding(_enc: string): this;
29
+ on(type: string | symbol, listener: (...args: unknown[]) => void): this;
30
+ addListener(type: string | symbol, listener: (...args: unknown[]) => void): this;
31
+ once(type: string | symbol, listener: (...args: unknown[]) => void): this;
32
+ removeListener(type: string | symbol, listener: (...args: unknown[]) => void): this;
33
+ off(type: string | symbol, listener: (...args: unknown[]) => void): this;
34
+ removeAllListeners(type?: string | symbol): this;
29
35
  resume(): this;
30
36
  pause(): this;
31
37
  read(): null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/process",
3
- "version": "0.4.44",
3
+ "version": "0.5.1",
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.4.44",
44
- "@gjsify/terminal-native": "^0.4.44",
45
- "@gjsify/utils": "^0.4.44"
43
+ "@gjsify/events": "^0.5.1",
44
+ "@gjsify/terminal-native": "^0.5.1",
45
+ "@gjsify/utils": "^0.5.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@gjsify/cli": "^0.4.44",
49
- "@gjsify/unit": "^0.4.44",
50
- "@types/node": "^25.9.1",
48
+ "@gjsify/cli": "^0.5.1",
49
+ "@gjsify/unit": "^0.5.1",
50
+ "@types/node": "^25.9.2",
51
51
  "typescript": "^6.0.3"
52
52
  },
53
53
  "gjsify": {