@gjsify/process 0.41.0 → 0.42.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/README.md +16 -0
- package/lib/esm/internal/signals.js +1 -0
- package/lib/esm/process-class.js +1 -1
- package/lib/types/internal/signals.d.ts +15 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -24,6 +24,22 @@ console.log(process.env.HOME);
|
|
|
24
24
|
console.log(process.platform);
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
## Signals
|
|
28
|
+
|
|
29
|
+
`process.on('SIGINT' | 'SIGTERM' | 'SIGHUP', …)` is delivered under GJS through
|
|
30
|
+
`GLibUnix.signal_add()`, so the handler runs on the JS thread and — as in Node —
|
|
31
|
+
registering one replaces the kernel's default disposition. The source is armed on the
|
|
32
|
+
first listener and removed with the last, so a process that never asks keeps the
|
|
33
|
+
default behaviour.
|
|
34
|
+
|
|
35
|
+
Delivery needs something driving the default main context, which is the same condition
|
|
36
|
+
every other async source in a GJS process lives under: a program that must react while
|
|
37
|
+
otherwise idle holds a loop (`holdMainLoop()` from `@gjsify/utils/main-loop`).
|
|
38
|
+
|
|
39
|
+
The other signals are deliberately absent. `g_unix_signal_add()` also accepts
|
|
40
|
+
`SIGUSR1`/`SIGUSR2`/`SIGWINCH`, but those are renumbered on some architectures, and a
|
|
41
|
+
hardcoded table would arm the WRONG signal there rather than fail.
|
|
42
|
+
|
|
27
43
|
## Inspirations and credits
|
|
28
44
|
|
|
29
45
|
- https://github.com/cgjs/cgjs/tree/master/packages/process
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";const t={SIGHUP:1,SIGINT:2,SIGTERM:15},n=new Map;function resolveSignalAdd(){let t=e().imports?.gi;if(!t)return null;for(let[e,n]of[[`GLibUnix`,`signal_add`],[`GLib`,`unix_signal_add`]])try{let r=t[e]?.[n];if(typeof r==`function`)return r}catch{}return null}function isDeliverableSignal(e){return typeof e==`string`&&e in t}function armSignal(r,i){if(n.has(r))return;let a=t[r],o=resolveSignalAdd(),s=e().imports?.gi?.GLib;if(a===void 0||o===null||!s)return;let c=s.PRIORITY_DEFAULT,l=o(c,a,()=>(i(r),!0));n.set(r,l)}function disarmSignal(t){let r=n.get(t);if(r===void 0)return;n.delete(t);let i=e().imports?.gi?.GLib;i&&typeof i.source_remove==`function`&&i.source_remove(r)}export{armSignal,disarmSignal,isDeliverableSignal};
|
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{
|
|
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{EventEmitter as S}from"@gjsify/events";const C=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 S{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),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()-C)/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};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Whether `name` is a signal this module can deliver. */
|
|
2
|
+
export declare function isDeliverableSignal(name: string | symbol): name is string;
|
|
3
|
+
/**
|
|
4
|
+
* Start delivering `signal` to `emit`. Idempotent, and a no-op off GJS — where
|
|
5
|
+
* the host runtime already delivers signals to `globalThis.process`.
|
|
6
|
+
*
|
|
7
|
+
* The GLib source is attached to the DEFAULT main context, so nothing arrives
|
|
8
|
+
* until something drives it. That is the same condition every other async
|
|
9
|
+
* source in a GJS process lives under; a program that wants a handler to run
|
|
10
|
+
* while it is otherwise idle has to hold a main loop
|
|
11
|
+
* (`@gjsify/utils`'s `holdMainLoop()`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function armSignal(signal: string, emit: (signal: string) => void): void;
|
|
14
|
+
/** Stop delivering `signal`, restoring the default disposition. Idempotent. */
|
|
15
|
+
export declare function disarmSignal(signal: string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.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.42.0",
|
|
44
|
+
"@gjsify/string_decoder": "^0.42.0",
|
|
45
|
+
"@gjsify/terminal-native": "^0.42.0",
|
|
46
|
+
"@gjsify/utils": "^0.42.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@gjsify/cli": "^0.
|
|
50
|
-
"@gjsify/unit": "^0.
|
|
49
|
+
"@gjsify/cli": "^0.42.0",
|
|
50
|
+
"@gjsify/unit": "^0.42.0",
|
|
51
51
|
"@types/node": "^25.9.2",
|
|
52
52
|
"typescript": "^6.0.3"
|
|
53
53
|
},
|