@gjsify/process 0.30.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{probeUname as t}from"./uname.js";function detectGjsVersion(){try{let t=e().imports?.system;if(t?.version!==void 0){let e=Number(t.version);return`${Math.floor(e/1e4)}.${Math.floor(e%1e4/100)}.${e%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){if(typeof globalThis.process?.ppid==`number`)return globalThis.process.ppid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/status`);if(e){let t=new TextDecoder().decode(e).match(/PPid:\s+(\d+)/);if(t)return parseInt(t[1],10)}}}catch{}return 0}function onGjs(){try{return e().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){if(onGjs()){let e=t();return e?e.platform:`linux`}let e=globalThis.process;return typeof e?.platform==`string`?e.platform:`linux`}function detectArch(){if(onGjs()){let e=t();return e?e.arch:`x64`}let e=globalThis.process;return typeof e?.arch==`string`?e.arch:`x64`}function getPid(){if(typeof globalThis.process?.pid==`number`)return globalThis.process.pid;try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/stat`);if(e){let t=new TextDecoder().decode(e),n=parseInt(t,10);if(!isNaN(n))return n}}}catch{}return 0}export{detectArch,detectGjsVersion,detectNodeVersion,detectPlatform,detectPpid,detectVersionInfo,getPid};
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{probeUname as t}from"./uname.js";import{hostPid as n,hostPpid as r}from"@gjsify/utils/core";function detectGjsVersion(){try{let t=e().imports?.system;if(t?.version!==void 0){let e=Number(t.version);return`${Math.floor(e/1e4)}.${Math.floor(e%1e4/100)}.${e%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){return!onGjs()&&typeof globalThis.process?.ppid==`number`?globalThis.process.ppid:r()??0}function onGjs(){try{return e().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){if(onGjs()){let e=t();return e?e.platform:`linux`}let e=globalThis.process;return typeof e?.platform==`string`?e.platform:`linux`}function detectArch(){if(onGjs()){let e=t();return e?e.arch:`x64`}let e=globalThis.process;return typeof e?.arch==`string`?e.arch:`x64`}function getPid(){return!onGjs()&&typeof globalThis.process?.pid==`number`?globalThis.process.pid:n()??0}export{detectArch,detectGjsVersion,detectNodeVersion,detectPlatform,detectPpid,detectVersionInfo,getPid};
@@ -1 +1 @@
1
- import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let t=e().imports?.gi?.GLib;if(t)return new Proxy({},{get(e,n){if(typeof n==`string`)return t.getenv(n)??void 0},set(e,n,r){return typeof n==`string`?(t.setenv(n,String(r),!0),!0):!1},deleteProperty(e,n){return typeof n==`string`?(t.unsetenv(n),!0):!1},has(e,n){return typeof n==`string`?t.getenv(n)!==null:!1},ownKeys(e){return t.listenv()},getOwnPropertyDescriptor(e,n){if(typeof n!=`string`)return;let r=t.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let t=e().imports?.system;if(t?.programArgs)return[`gjs`,t.programInvocationName||``,...t.programArgs]}catch{}return[`gjs`]}function getExecPath(){if(typeof globalThis.process?.execPath==`string`)return globalThis.process.execPath;try{let t=e().imports?.system;if(t?.programInvocationName)return t.programInvocationName}catch{}return`/usr/bin/gjs`}function getCwd(){try{let t=e().imports?.gi?.GLib;if(t?.get_current_dir)return t.get_current_dir()}catch{}return`/`}function chdir(t){let n=e().imports?.gi?.GLib;try{if(n?.chdir){if(!n.file_test(t,16)){let e=Error(`ENOENT: no such file or directory, chdir '${t}'`);throw e.code=`ENOENT`,e.syscall=`chdir`,e.path=t,e}n.chdir(t);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}if(!n){let e=globalThis.process;if(e&&typeof e.chdir==`function`){e.chdir(t);return}}throw Error(`process.chdir() is not supported in this environment`)}export{chdir,getArgv,getCwd,getEnvProxy,getExecPath};
1
+ import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";import{hostExecPath as t}from"@gjsify/utils/core";function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let t=e().imports?.gi?.GLib;if(t)return new Proxy({},{get(e,n){if(typeof n==`string`)return t.getenv(n)??void 0},set(e,n,r){return typeof n==`string`?(t.setenv(n,String(r),!0),!0):!1},deleteProperty(e,n){return typeof n==`string`?(t.unsetenv(n),!0):!1},has(e,n){return typeof n==`string`?t.getenv(n)!==null:!1},ownKeys(e){return t.listenv()},getOwnPropertyDescriptor(e,n){if(typeof n!=`string`)return;let r=t.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let t=e().imports?.system;if(t?.programArgs)return[`gjs`,t.programInvocationName||``,...t.programArgs]}catch{}return[`gjs`]}function getExecPath(){let e=globalThis.process;return!isGjsHost()&&typeof e?.execPath==`string`?e.execPath:t()??`/usr/bin/gjs`}function isGjsHost(){try{return e().imports?.gi!==void 0}catch{return!1}}function getCwd(){try{let t=e().imports?.gi?.GLib;if(t?.get_current_dir)return t.get_current_dir()}catch{}return`/`}function chdir(t){let n=e().imports?.gi?.GLib;try{if(n?.chdir){if(!n.file_test(t,16)){let e=Error(`ENOENT: no such file or directory, chdir '${t}'`);throw e.code=`ENOENT`,e.syscall=`chdir`,e.path=t,e}n.chdir(t);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}if(!n){let e=globalThis.process;if(e&&typeof e.chdir==`function`){e.chdir(t);return}}throw Error(`process.chdir() is not supported in this environment`)}export{chdir,getArgv,getCwd,getEnvProxy,getExecPath};
@@ -1 +1 @@
1
- import"../_virtual/_rolldown/runtime.js";import{getGjsGlobal as e}from"./gjs.js";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(){try{let t=e().imports?.gi?.GLib;if(t){let[,e]=t.file_get_contents(`/proc/self/status`);if(e){let t=new TextDecoder().decode(e).match(/VmRSS:\s+(\d+)/),n=t?parseInt(t[1],10)*1024:0;return{rss:n,heapTotal:n,heapUsed:n,external:0,arrayBuffers:0}}}}catch{}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};
@@ -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 g,ProcessWriteStream as _}from"./streams.js";import{EventEmitter as v}from"@gjsify/events";const y=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 v{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()-y)/1e3}memoryUsage(){return h()}cpuUsage(e){return p(e)}stdout=new _(1);stderr=new _(2);stdin=new g(0);abort(){this.exit(1)}umask(e){return 18}emitWarning(e,t){console.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return f()};export{Process};
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};
@@ -1,5 +1,24 @@
1
1
  export declare function getEnvProxy(): Record<string, string | undefined>;
2
2
  export declare function getArgv(): string[];
3
+ /**
4
+ * Node's `process.execPath` — the absolute path of the INTERPRETER, not of the
5
+ * script it is running.
6
+ *
7
+ * This used to return `imports.system.programInvocationName`, which is the
8
+ * ENTRY MODULE (the same value `getArgv()` above puts in `argv[1]`, and says so).
9
+ * The two are different questions and the wrong answer is load-bearing:
10
+ * `spawn(process.execPath, […])` is the documented portable way to start a
11
+ * second copy of the current runtime, and against a bundle path it fails
12
+ * `ENOENT` — or, because `g_spawn` retries a non-executable text file through
13
+ * `/bin/sh`, hands a megabyte of JavaScript to the shell.
14
+ *
15
+ * Nor is `/usr/bin/gjs` a defensible fallback: no macOS host has that path
16
+ * (Homebrew installs to `/usr/local/bin` or `/opt/homebrew/bin`), so the
17
+ * "default" was a Linux literal wearing a default's clothes. `hostExecPath()`
18
+ * resolves the real one; the literal remains only as the last resort for a host
19
+ * that answers nothing at all, where any string is equally wrong and Node's
20
+ * type says it must be a string.
21
+ */
3
22
  export declare function getExecPath(): string;
4
23
  export declare function getCwd(): string;
5
24
  export declare function chdir(directory: string): void;
@@ -6,9 +6,35 @@ export interface MemoryUsage {
6
6
  external: number;
7
7
  arrayBuffers: number;
8
8
  }
9
+ /**
10
+ * Node-shaped `process.memoryUsage()`.
11
+ *
12
+ * SpiderMonkey exposes no per-heap accounting to JS, so `heapTotal`/`heapUsed`
13
+ * are approximated from the OS's view of the whole process — the same
14
+ * approximation `@gjsify/v8`'s `getHeapStatistics()` makes, from the same
15
+ * reader, which is why the reader lives in `@gjsify/utils/core` and not here.
16
+ * Before that lift this function read `/proc/self/status` inline and therefore
17
+ * reported `rss: 0` on every macOS host.
18
+ */
9
19
  export declare function memoryUsage(): MemoryUsage;
10
20
  export interface CpuUsage {
11
21
  user: number;
12
22
  system: number;
13
23
  }
14
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
- umask(_mask?: number): number;
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.30.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.30.0",
44
- "@gjsify/string_decoder": "^0.30.0",
45
- "@gjsify/terminal-native": "^0.30.0",
46
- "@gjsify/utils": "^0.30.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.30.0",
50
- "@gjsify/unit": "^0.30.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
  },
@@ -58,7 +58,15 @@
58
58
  "browser": "polyfill",
59
59
  "nativescript": "polyfill"
60
60
  },
61
- "tier": 1
61
+ "tier": 1,
62
+ "os": {
63
+ "linux": "supported",
64
+ "darwin": "supported",
65
+ "win32": "partial"
66
+ },
67
+ "osNotes": {
68
+ "win32": "Under Node the platform comes from the host itself and is authoritative. Under GJS it comes from a `uname` probe, which is POSIX-only — `mapSysname` maps a MINGW/MSYS sysname to `win32`, but no GJS host exists on Windows to produce one, so that path is unexercised. Measured on the win11-gjsify VM: 6 of 167 specs fail, all POSIX assumptions in the SPECS."
69
+ }
62
70
  },
63
71
  "license": "MIT",
64
72
  "repository": {