@gjsify/process 0.31.0 → 0.32.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{readProcessMemory as t}from"@gjsify/utils/core";function isGjs(){return e().imports?.gi?.GLib!==void 0}function killPid(t,n){try{let r=e().imports?.gi?.GLib;if(r){let e=typeof n==`number`?String(n):n||`SIGTERM`,i=e.startsWith(`SIG`)?`-${e.slice(3)}`:`-${e}`;return r.spawn_command_line_sync(`kill ${i} ${t}`),!0}}catch{}if(!isGjs()){let e=globalThis.process;if(e&&typeof e.kill==`function`)return e.kill(t,n)}throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=t();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}export{cpuUsage,killPid,memoryUsage};
|
|
1
|
+
import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{readProcessMemory as t}from"@gjsify/utils/core";function isGjs(){return e().imports?.gi?.GLib!==void 0}function killPid(t,n){try{let r=e().imports?.gi?.GLib;if(r){let e=typeof n==`number`?String(n):n||`SIGTERM`,i=e.startsWith(`SIG`)?`-${e.slice(3)}`:`-${e}`;return r.spawn_command_line_sync(`kill ${i} ${t}`),!0}}catch{}if(!isGjs()){let e=globalThis.process;if(e&&typeof e.kill==`function`)return e.kill(t,n)}throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=t();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}function readUmask(){try{let t=e().imports?.gi?.GLib;if(t){let[e,n]=t.file_get_contents(`/proc/self/status`);if(e){let e=/^Umask:\s*([0-7]+)/m.exec(new TextDecoder().decode(n));if(e)return parseInt(e[1],8)}}}catch{}return 18}export{cpuUsage,killPid,memoryUsage,readUmask};
|
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}from"./internal/system.js";import{ProcessReadStream as
|
|
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{ProcessReadStream as _,ProcessWriteStream as v}from"./streams.js";import{EventEmitter as y}from"@gjsify/events";const b=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 y{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}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()-b)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new v(1);stderr=new v(2);stdin=new _(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};
|
|
@@ -22,3 +22,19 @@ export interface CpuUsage {
|
|
|
22
22
|
system: number;
|
|
23
23
|
}
|
|
24
24
|
export declare function cpuUsage(previousValue?: CpuUsage): CpuUsage;
|
|
25
|
+
/**
|
|
26
|
+
* The process's REAL file-creation mask.
|
|
27
|
+
*
|
|
28
|
+
* `process.umask()` returned a hardcoded `0o22`, which is right only on a
|
|
29
|
+
* 022 machine and silently wrong in the PERMISSIVE direction everywhere else:
|
|
30
|
+
* on a 002 host a consumer computing `0o666 & ~process.umask()` believes it
|
|
31
|
+
* produced 0644 while the file is actually 0664, i.e. group-writable.
|
|
32
|
+
*
|
|
33
|
+
* Linux publishes the truth race-free in `/proc/self/status`, so the getter can
|
|
34
|
+
* simply read it — there is no `umask(2)` binding to call, and the usual trick
|
|
35
|
+
* of "set it and set it back" would be a data race against every other thread
|
|
36
|
+
* creating a file. Off Linux there is no such file and the old constant is all
|
|
37
|
+
* that is left; it is returned as a documented last resort rather than as an
|
|
38
|
+
* answer.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readUmask(): number;
|
|
@@ -32,7 +32,28 @@ export declare class Process extends EventEmitter {
|
|
|
32
32
|
readonly stderr: ProcessWriteStream;
|
|
33
33
|
readonly stdin: ProcessReadStream;
|
|
34
34
|
abort(): void;
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The file-creation mask. READING it is real; SETTING it is not possible.
|
|
37
|
+
*
|
|
38
|
+
* The getter used to return a hardcoded `0o22` — right only on a 022
|
|
39
|
+
* machine and wrong in the PERMISSIVE direction everywhere else: on a 002
|
|
40
|
+
* host a caller computing `0o666 & ~process.umask()` believes it produced
|
|
41
|
+
* 0644 while the file is group-writable 0664. Linux publishes the live
|
|
42
|
+
* value in `/proc/self/status`, race-free, so it is read rather than
|
|
43
|
+
* guessed.
|
|
44
|
+
*
|
|
45
|
+
* The setter cannot be implemented: GJS has no `umask(2)` binding, and the
|
|
46
|
+
* mask is per-process kernel state that a library cannot emulate. It stays
|
|
47
|
+
* a no-op for that reason — but not a SILENT one. `process.umask(0o077)`
|
|
48
|
+
* before writing a secret is a standard idiom, and here it changes nothing;
|
|
49
|
+
* a caller who believes it tightened the mask is precisely the
|
|
50
|
+
* "more permissive than requested" failure this package's fs work exists to
|
|
51
|
+
* remove, so the attempt warns once instead of being swallowed. It does not
|
|
52
|
+
* throw: that would break the equally common read-modify-restore pattern,
|
|
53
|
+
* and the real fix for a caller is an explicit `mode`, which now works.
|
|
54
|
+
*/
|
|
55
|
+
umask(mask?: number): number;
|
|
56
|
+
private _umaskWarned;
|
|
36
57
|
emitWarning(warning: string | Error, name?: string): void;
|
|
37
58
|
}
|
|
38
59
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.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.32.0",
|
|
44
|
+
"@gjsify/string_decoder": "^0.32.0",
|
|
45
|
+
"@gjsify/terminal-native": "^0.32.0",
|
|
46
|
+
"@gjsify/utils": "^0.32.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@gjsify/cli": "^0.
|
|
50
|
-
"@gjsify/unit": "^0.
|
|
49
|
+
"@gjsify/cli": "^0.32.0",
|
|
50
|
+
"@gjsify/unit": "^0.32.0",
|
|
51
51
|
"@types/node": "^25.9.2",
|
|
52
52
|
"typescript": "^6.0.3"
|
|
53
53
|
},
|