@gjsify/child_process 0.3.19 → 0.3.21
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/package.json +6 -6
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@girs/gio-2.0";import t from"@girs/glib-2.0";import{EventEmitter as n}from"node:events";import{Buffer as r}from"node:buffer";import{Readable as i}from"node:stream";import{deferEmit as a,ensureMainLoop as o,gbytesToUint8Array as s}from"@gjsify/utils";var
|
|
1
|
+
import e from"@girs/gio-2.0";import t from"@girs/glib-2.0";import{EventEmitter as n}from"node:events";import{Buffer as r}from"node:buffer";import{Readable as i}from"node:stream";import{deferEmit as a,ensureMainLoop as o,gbytesToUint8Array as s}from"@gjsify/utils";var GioInputStreamReadable=class extends i{_stream;_cancellable=new e.Cancellable;constructor(e){super(),this._stream=e}_read(e){this._stream.read_bytes_async(Math.max(e,4096),t.PRIORITY_DEFAULT,this._cancellable,(e,t)=>{try{let e=this._stream.read_bytes_finish(t).get_data();!e||e.length===0?this.push(null):this.push(r.from(e))}catch(e){this._cancellable.is_cancelled()||this.destroy(e)}})}_destroy(e,t){this._cancellable.cancel(),t(e)}};const c=new Set;var ChildProcess=class extends n{pid;exitCode=null;signalCode=null;killed=!1;connected=!1;stdin=null;stdout=null;stderr=null;_subprocess=null;_setSubprocess(e){this._subprocess=e;let t=e.get_identifier();t&&(this.pid=parseInt(t,10))}kill(e){if(!this._subprocess)return!1;try{return e===`SIGKILL`||e===9?this._subprocess.force_exit():this._subprocess.send_signal(typeof e==`number`?e:15),this.killed=!0,!0}catch{return!1}}ref(){return this}unref(){return this}};function _spawnSubprocess(t,n,r){let i=new e.SubprocessLauncher({flags:n});if(r?.cwd&&i.set_cwd(r.cwd),r?.env)for(let[e,t]of Object.entries(r.env))i.setenv(e,t,!0);return i.spawnv(t)}function execSync(n,i){let a=i?.encoding,o=i?.input,c=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE|(o?e.SubprocessFlags.STDIN_PIPE:e.SubprocessFlags.NONE),l=_spawnSubprocess([typeof i?.shell==`string`?i.shell:`/bin/sh`,`-c`,n],c,i),u=o?new t.Bytes(typeof o==`string`?new TextEncoder().encode(o):o):null,[,d,f]=l.communicate(u,null),p=l.get_exit_status();if(p!==0){let e=f?new TextDecoder().decode(s(f)):``,t=Error(`Command failed: ${n}\n${e}`);throw t.status=p,t.stderr=e,t.stdout=d?new TextDecoder().decode(s(d)):``,t}if(!d)return a&&a!==`buffer`?``:r.alloc(0);let m=s(d);return a&&a!==`buffer`?new TextDecoder().decode(m):r.from(m)}function _exec(t,n,r){typeof n==`function`&&(r=n,n={});let i=n||{},a=new ChildProcess,s=typeof i.shell==`string`?i.shell:`/bin/sh`,c=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE;try{let e=_spawnSubprocess([s,`-c`,t],c,i);a._setSubprocess(e),o(),e.communicate_utf8_async(null,null,(n,i)=>{try{let[,n,o]=e.communicate_utf8_finish(i),s=e.get_exit_status();if(a.exitCode=s,s!==0){let e=Error(`Command failed: ${t}`);e.code=s,e.killed=a.killed,e.stdout=n||``,e.stderr=o||``,r&&r(e,n||``,o||``)}else r&&r(null,n||``,o||``);a.emit(`close`,s,null),a.emit(`exit`,s,null)}catch(e){let t=e instanceof Error?e:Error(String(e));r&&r(t,``,``),a.emit(`error`,t)}})}catch(e){let t=e instanceof Error?e:Error(String(e));setTimeout(()=>{r&&r(t,``,``),a.emit(`error`,t)},0)}return a}function execFile(t,n,r,i){let a=[],s={},c;typeof n==`function`?c=n:Array.isArray(n)&&(a=n,typeof r==`function`?c=r:(s=r||{},c=i));let l=new ChildProcess,u=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE;try{let e=_spawnSubprocess([t,...a],u,s);l._setSubprocess(e),o(),e.communicate_utf8_async(null,null,(n,r)=>{try{let[,n,i]=e.communicate_utf8_finish(r),a=e.get_exit_status();if(l.exitCode=a,a!==0){let e=Error(`Command failed: ${t}`);e.code=a,e.stdout=n||``,e.stderr=i||``,c&&c(e,n||``,i||``)}else c&&c(null,n||``,i||``);l.emit(`close`,a,null),l.emit(`exit`,a,null)}catch(e){let t=e instanceof Error?e:Error(String(e));c&&c(t,``,``),l.emit(`error`,t)}})}catch(e){let t=e instanceof Error?e:Error(String(e));setTimeout(()=>{c&&c(t,``,``),l.emit(`error`,t)},0)}return l}function execFileSync(n,i,a){let o=i||[],c=a?.encoding,l=a?.input,u=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE|(l?e.SubprocessFlags.STDIN_PIPE:e.SubprocessFlags.NONE),d=_spawnSubprocess([n,...o],u,a),f=l?new t.Bytes(typeof l==`string`?new TextEncoder().encode(l):l):null,[,p,m]=d.communicate(f,null),h=d.get_exit_status();if(h!==0){let e=m?new TextDecoder().decode(s(m)):``,t=Error(`Command failed: ${n} ${o.join(` `)}`);throw t.status=h,t.stderr=e,t}if(!p)return c&&c!==`buffer`?``:r.alloc(0);let g=s(p);return c&&c!==`buffer`?new TextDecoder().decode(g):r.from(g)}function spawn(t,n,r){let i=n||[],s=new ChildProcess,l=r?.shell,u;u=l?[typeof l==`string`?l:`/bin/sh`,`-c`,[t,...i].join(` `)]:[t,...i];let d=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE|e.SubprocessFlags.STDIN_PIPE;try{let e=_spawnSubprocess(u,d,r);s._setSubprocess(e),c.add(s);let t=e.get_stdout_pipe();t&&(s.stdout=new GioInputStreamReadable(t));let n=e.get_stderr_pipe();n&&(s.stderr=new GioInputStreamReadable(n)),o(),e.wait_async(null,(t,n)=>{try{e.wait_finish(n);let t=e.get_if_exited()?e.get_exit_status():null,r=e.get_if_signaled()?`SIGTERM`:null;s.exitCode=t,s.signalCode=r,s.emit(`exit`,t,r),s.emit(`close`,t,r)}catch(e){s.emit(`error`,e instanceof Error?e:Error(String(e)))}c.delete(s)}),a(s,`spawn`)}catch(e){a(s,`error`,e instanceof Error?e:Error(String(e)))}return s}function spawnSync(n,i,a){let o=i||[],c=a?.shell,l=a?.input,u;u=c?[typeof c==`string`?c:`/bin/sh`,`-c`,[n,...o].join(` `)]:[n,...o];let d=e.SubprocessFlags.STDOUT_PIPE|e.SubprocessFlags.STDERR_PIPE|(l?e.SubprocessFlags.STDIN_PIPE:e.SubprocessFlags.NONE);try{let e=_spawnSubprocess(u,d,a),n=e.get_identifier(),i=l?new t.Bytes(typeof l==`string`?new TextEncoder().encode(l):l):null,[,o,c]=e.communicate(i,null),f=o?r.from(s(o)):r.alloc(0),p=c?r.from(s(c)):r.alloc(0),m=a?.encoding,h=m&&m!==`buffer`?new TextDecoder().decode(f):f,g=m&&m!==`buffer`?new TextDecoder().decode(p):p,_=e.get_if_exited()?e.get_exit_status():null,v=e.get_if_signaled()?`SIGTERM`:null;return{pid:n?parseInt(n,10):0,output:[null,h,g],stdout:h,stderr:g,status:_,signal:v}}catch(e){let t=a?.encoding&&a.encoding!==`buffer`?``:r.alloc(0);return{pid:0,output:[null,t,t],stdout:t,stderr:t,status:null,signal:null,error:e instanceof Error?e:Error(String(e))}}}var l={ChildProcess,exec:_exec,execSync,execFile,execFileSync,spawn,spawnSync};export{ChildProcess,l as default,_exec as exec,execFile,execFileSync,execSync,spawn,spawnSync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/child_process",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "Node.js child_process module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
"child_process"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@gjsify/cli": "^0.3.
|
|
34
|
-
"@gjsify/unit": "^0.3.
|
|
33
|
+
"@gjsify/cli": "^0.3.21",
|
|
34
|
+
"@gjsify/unit": "^0.3.21",
|
|
35
35
|
"@types/node": "^25.6.2",
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@girs/gio-2.0": "2.88.0-4.0.0-rc.14",
|
|
40
40
|
"@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
|
|
41
|
-
"@gjsify/buffer": "^0.3.
|
|
42
|
-
"@gjsify/events": "^0.3.
|
|
43
|
-
"@gjsify/utils": "^0.3.
|
|
41
|
+
"@gjsify/buffer": "^0.3.21",
|
|
42
|
+
"@gjsify/events": "^0.3.21",
|
|
43
|
+
"@gjsify/utils": "^0.3.21"
|
|
44
44
|
}
|
|
45
45
|
}
|