@gjsify/utils 0.51.1 → 0.53.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/lib/esm/core.js CHANGED
@@ -1 +1 @@
1
- import{makeCallable as e}from"./callable.js";import{deferEmit as t}from"./defer.js";import{initErrorV8Methods as n}from"./error.js";import{GIO_ERROR_TO_NODE as r,GLIB_FILE_ERROR_TO_NODE as i,createGLibFileError as a,createNodeError as o,isNotFoundError as s}from"./gio-errors.js";import{registerGlobal as c}from"./globals.js";import{TARGET_OSES as l,hostOs as u,hostPlatform as d,isDarwin as f,isLinux as p,isTargetOs as m,isWin32 as h}from"./host-os.js";import{notImplemented as g,warnNotImplemented as _}from"./message.js";import{queueMicrotask as v}from"./microtask.js";import{encodePathForFileUrl as y,isWindowsPath as b,lastPathSeparatorIndex as x,pathToFileUrlHref as S,splitPathComponents as C}from"./path-shape.js";import{PROBED_GI_LIBDIRS as w,TYPELIB_SUBDIR as T,giLibraryDirsForTypelibDir as E,splitSearchPath as D,systemGiLibraryDirs as O}from"./system-gi-dirs.js";import{mapMachine as k,mapSysname as A}from"./platform-names.js";import{structuredClone as j}from"./structured-clone.js";import{hasProcfs as M,hostExecPath as N,hostPid as P,hostPpid as F,readProcessMemory as I}from"./host-process.js";import{ensureMainLoop as L,holdMainLoop as R,quitMainLoop as z}from"./main-loop.js";import{__resetBurstStateForTests as B,nextTick as V}from"./next-tick.js";export{r as GIO_ERROR_TO_NODE,i as GLIB_FILE_ERROR_TO_NODE,w as PROBED_GI_LIBDIRS,l as TARGET_OSES,T as TYPELIB_SUBDIR,B as __resetBurstStateForTests,a as createGLibFileError,o as createNodeError,t as deferEmit,y as encodePathForFileUrl,L as ensureMainLoop,E as giLibraryDirsForTypelibDir,M as hasProcfs,R as holdMainLoop,N as hostExecPath,u as hostOs,P as hostPid,d as hostPlatform,F as hostPpid,n as initErrorV8Methods,f as isDarwin,p as isLinux,s as isNotFoundError,m as isTargetOs,h as isWin32,b as isWindowsPath,x as lastPathSeparatorIndex,e as makeCallable,k as mapMachine,A as mapSysname,V as nextTick,g as notImplemented,S as pathToFileUrlHref,v as queueMicrotask,z as quitMainLoop,I as readProcessMemory,c as registerGlobal,C as splitPathComponents,D as splitSearchPath,j as structuredClone,O as systemGiLibraryDirs,_ as warnNotImplemented};
1
+ import{makeCallable as e}from"./callable.js";import{deferEmit as t}from"./defer.js";import{initErrorV8Methods as n}from"./error.js";import{GIO_ERROR_TO_NODE as r,GLIB_FILE_ERROR_TO_NODE as i,createGLibFileError as a,createNodeError as o,isNotFoundError as s}from"./gio-errors.js";import{registerGlobal as c}from"./globals.js";import{TARGET_OSES as l,hostOs as u,hostPlatform as d,isDarwin as f,isLinux as p,isTargetOs as m,isWin32 as h}from"./host-os.js";import{notImplemented as g,warnNotImplemented as _}from"./message.js";import{queueMicrotask as v}from"./microtask.js";import{encodePathForFileUrl as y,isWindowsPath as b,lastPathSeparatorIndex as x,pathToFileUrlHref as S,splitPathComponents as C}from"./path-shape.js";import{PROBED_GI_LIBDIRS as w,TYPELIB_SUBDIR as T,dyldDefaultFallbackDirs as E,giLibraryDirsForTypelibDir as D,splitSearchPath as O,systemGiLibraryDirs as k}from"./system-gi-dirs.js";import{mapMachine as A,mapSysname as j}from"./platform-names.js";import{structuredClone as M}from"./structured-clone.js";import{hasProcfs as N,hostEnv as P,hostExecPath as F,hostPid as I,hostPpid as L,readProcessMemory as R}from"./host-process.js";import{ensureMainLoop as z,holdMainLoop as B,quitMainLoop as V}from"./main-loop.js";import{NativeLibraryLoadError as H,colocateNativeLibrary as U,loadOptionalNativeModule as W,missingLibraryDependency as G,openNativeLibrary as K,probeNativeLibrary as q}from"./native-library.js";import{__resetBurstStateForTests as J,nextTick as Y}from"./next-tick.js";export{r as GIO_ERROR_TO_NODE,i as GLIB_FILE_ERROR_TO_NODE,H as NativeLibraryLoadError,w as PROBED_GI_LIBDIRS,l as TARGET_OSES,T as TYPELIB_SUBDIR,J as __resetBurstStateForTests,U as colocateNativeLibrary,a as createGLibFileError,o as createNodeError,t as deferEmit,E as dyldDefaultFallbackDirs,y as encodePathForFileUrl,z as ensureMainLoop,D as giLibraryDirsForTypelibDir,N as hasProcfs,B as holdMainLoop,P as hostEnv,F as hostExecPath,u as hostOs,I as hostPid,d as hostPlatform,L as hostPpid,n as initErrorV8Methods,f as isDarwin,p as isLinux,s as isNotFoundError,m as isTargetOs,h as isWin32,b as isWindowsPath,x as lastPathSeparatorIndex,W as loadOptionalNativeModule,e as makeCallable,A as mapMachine,j as mapSysname,G as missingLibraryDependency,Y as nextTick,g as notImplemented,K as openNativeLibrary,S as pathToFileUrlHref,q as probeNativeLibrary,v as queueMicrotask,V as quitMainLoop,R as readProcessMemory,c as registerGlobal,C as splitPathComponents,O as splitSearchPath,M as structuredClone,k as systemGiLibraryDirs,_ as warnNotImplemented};
@@ -1,2 +1,2 @@
1
- import"./_virtual/_rolldown/runtime.js";function hostGlib(){try{return globalThis.imports?.gi?.GLib}catch{return}}function readText(e,t){try{let[n,r]=e.file_get_contents(t);return!n||!r?null:new TextDecoder().decode(r)}catch{return null}}function shellOut(e,t){try{let[n,r]=e.spawn_command_line_sync(t);if(!n||!r)return null;let i=new TextDecoder().decode(r).trim();return i.length>0?i:null}catch{return null}}function hasProcfs(){let e=hostGlib();if(!e)return!1;try{return e.file_test(`/proc/self/status`,16)}catch{return!1}}let e=null;function hostPid(){if(e!==null)return e>0?e:void 0;let t=hostGlib();if(!t)return;let n=0,r=hasProcfs()?readText(t,`/proc/self/stat`):null;if(r)n=parseInt(r,10);else{let e=shellOut(t,`sh -c 'echo $PPID'`);e&&(n=parseInt(e,10))}return e=Number.isInteger(n)&&n>0?n:0,e>0?e:void 0}function hostPpid(){let e=hostGlib();if(!e)return;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=/PPid:\s+(\d+)/.exec(t);if(e){let t=parseInt(e[1],10);return Number.isInteger(t)?t:void 0}}let n=hostPid();if(n===void 0)return;let r=shellOut(e,`ps -o ppid= -p ${n}`);if(!r)return;let i=parseInt(r,10);return Number.isInteger(i)?i:void 0}function hostExecPath(){let e=hostGlib();if(e){if(hasProcfs())try{let t=e.file_read_link(`/proc/self/exe`);if(t)return t}catch{}try{let t=e.get_prgname();if(t){let n=e.find_program_in_path(t);if(n)return n}}catch{return}}}function readProcessMemory(){let e=hostGlib();if(!e)return null;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=new Map;for(let n of t.split(`
2
- `)){let t=/^(\w+):\s+(\d+)(\s+kB)?/.exec(n);t&&e.set(t[1],parseInt(t[2],10)*(t[3]?1024:1))}if(e.size>0)return{virtual:e.get(`VmSize`)??0,resident:e.get(`VmRSS`)??0,data:e.get(`VmData`)??0,peak:e.get(`VmPeak`)??0}}let n=shellOut(e,`sh -c 'ps -o rss=,vsz= -p $PPID'`);if(!n)return null;let r=/^(\d+)\s+(\d+)$/.exec(n);return r?{virtual:parseInt(r[2],10)*1024,resident:parseInt(r[1],10)*1024,data:0,peak:0}:null}export{hasProcfs,hostExecPath,hostPid,hostPpid,readProcessMemory};
1
+ import"./_virtual/_rolldown/runtime.js";function hostGlib(){try{return globalThis.imports?.gi?.GLib}catch{return}}function readText(e,t){try{let[n,r]=e.file_get_contents(t);return!n||!r?null:new TextDecoder().decode(r)}catch{return null}}function shellOut(e,t){try{let[n,r]=e.spawn_command_line_sync(t);if(!n||!r)return null;let i=new TextDecoder().decode(r).trim();return i.length>0?i:null}catch{return null}}function hostEnv(e){let t=globalThis.process?.env?.[e];return typeof t==`string`?t:hostGlib()?.getenv(e)??void 0}function hasProcfs(){let e=hostGlib();if(!e)return!1;try{return e.file_test(`/proc/self/status`,16)}catch{return!1}}let e=null;function hostPid(){if(e!==null)return e>0?e:void 0;let t=hostGlib();if(!t)return;let n=0,r=hasProcfs()?readText(t,`/proc/self/stat`):null;if(r)n=parseInt(r,10);else{let e=shellOut(t,`sh -c 'echo $PPID'`);e&&(n=parseInt(e,10))}return e=Number.isInteger(n)&&n>0?n:0,e>0?e:void 0}function hostPpid(){let e=hostGlib();if(!e)return;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=/PPid:\s+(\d+)/.exec(t);if(e){let t=parseInt(e[1],10);return Number.isInteger(t)?t:void 0}}let n=hostPid();if(n===void 0)return;let r=shellOut(e,`ps -o ppid= -p ${n}`);if(!r)return;let i=parseInt(r,10);return Number.isInteger(i)?i:void 0}function hostExecPath(){let e=hostGlib();if(e){if(hasProcfs())try{let t=e.file_read_link(`/proc/self/exe`);if(t)return t}catch{}try{let t=e.get_prgname();if(t){let n=e.find_program_in_path(t);if(n)return n}}catch{return}}}function readProcessMemory(){let e=hostGlib();if(!e)return null;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=new Map;for(let n of t.split(`
2
+ `)){let t=/^(\w+):\s+(\d+)(\s+kB)?/.exec(n);t&&e.set(t[1],parseInt(t[2],10)*(t[3]?1024:1))}if(e.size>0)return{virtual:e.get(`VmSize`)??0,resident:e.get(`VmRSS`)??0,data:e.get(`VmData`)??0,peak:e.get(`VmPeak`)??0}}let n=shellOut(e,`sh -c 'ps -o rss=,vsz= -p $PPID'`);if(!n)return null;let r=/^(\d+)\s+(\d+)$/.exec(n);return r?{virtual:parseInt(r[2],10)*1024,resident:parseInt(r[1],10)*1024,data:0,peak:0}:null}export{hasProcfs,hostEnv,hostExecPath,hostPid,hostPpid,readProcessMemory};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{gbytesToUint8Array as e}from"./byte-array.js";import{makeCallable as t}from"./callable.js";import{cli as n}from"./cli.js";import{deferEmit as r}from"./defer.js";import{initErrorV8Methods as i}from"./error.js";import{GIO_ERROR_TO_NODE as a,GLIB_FILE_ERROR_TO_NODE as o,createGLibFileError as s,createNodeError as c,isNotFoundError as l}from"./gio-errors.js";import{registerGlobal as u}from"./globals.js";import{TARGET_OSES as d,hostOs as f,hostPlatform as p,isDarwin as m,isLinux as h,isTargetOs as g,isWin32 as _}from"./host-os.js";import{notImplemented as v,warnNotImplemented as y}from"./message.js";import{queueMicrotask as b}from"./microtask.js";import{encodePathForFileUrl as x,isWindowsPath as S,lastPathSeparatorIndex as C,pathToFileUrlHref as w,splitPathComponents as T}from"./path-shape.js";import{PROBED_GI_LIBDIRS as E,TYPELIB_SUBDIR as D,giLibraryDirsForTypelibDir as O,splitSearchPath as k,systemGiLibraryDirs as A}from"./system-gi-dirs.js";import{mapMachine as j,mapSysname as M}from"./platform-names.js";import{structuredClone as N}from"./structured-clone.js";import{hasProcfs as P,hostExecPath as F,hostPid as I,hostPpid as L,readProcessMemory as R}from"./host-process.js";import{ensureMainLoop as z,holdMainLoop as B,quitMainLoop as V}from"./main-loop.js";import{__resetBurstStateForTests as H,nextTick as U}from"./next-tick.js";import"./core.js";import{readJSON as W}from"./file.js";import{existsFD as G,existsSync as K}from"./fs.js";import{gioAsync as q,inputStreamAsyncIterator as J,readBytesAsync as Y}from"./gio.js";import{getNodeModulesPath as X,getPathSeparator as Z,getProgramDir as Q,getProgramExe as $,resolve as ee}from"./path.js";export{a as GIO_ERROR_TO_NODE,o as GLIB_FILE_ERROR_TO_NODE,E as PROBED_GI_LIBDIRS,d as TARGET_OSES,D as TYPELIB_SUBDIR,H as __resetBurstStateForTests,n as cli,s as createGLibFileError,c as createNodeError,r as deferEmit,x as encodePathForFileUrl,z as ensureMainLoop,G as existsFD,K as existsSync,e as gbytesToUint8Array,X as getNodeModulesPath,Z as getPathSeparator,Q as getProgramDir,$ as getProgramExe,O as giLibraryDirsForTypelibDir,q as gioAsync,P as hasProcfs,B as holdMainLoop,F as hostExecPath,f as hostOs,I as hostPid,p as hostPlatform,L as hostPpid,i as initErrorV8Methods,J as inputStreamAsyncIterator,m as isDarwin,h as isLinux,l as isNotFoundError,g as isTargetOs,_ as isWin32,S as isWindowsPath,C as lastPathSeparatorIndex,t as makeCallable,j as mapMachine,M as mapSysname,U as nextTick,v as notImplemented,w as pathToFileUrlHref,b as queueMicrotask,V as quitMainLoop,Y as readBytesAsync,W as readJSON,R as readProcessMemory,u as registerGlobal,ee as resolve,T as splitPathComponents,k as splitSearchPath,N as structuredClone,A as systemGiLibraryDirs,y as warnNotImplemented};
1
+ import{gbytesToUint8Array as e}from"./byte-array.js";import{makeCallable as t}from"./callable.js";import{cli as n}from"./cli.js";import{deferEmit as r}from"./defer.js";import{initErrorV8Methods as i}from"./error.js";import{GIO_ERROR_TO_NODE as a,GLIB_FILE_ERROR_TO_NODE as o,createGLibFileError as s,createNodeError as c,isNotFoundError as l}from"./gio-errors.js";import{registerGlobal as u}from"./globals.js";import{TARGET_OSES as d,hostOs as f,hostPlatform as p,isDarwin as m,isLinux as h,isTargetOs as g,isWin32 as _}from"./host-os.js";import{notImplemented as v,warnNotImplemented as y}from"./message.js";import{queueMicrotask as b}from"./microtask.js";import{encodePathForFileUrl as x,isWindowsPath as S,lastPathSeparatorIndex as C,pathToFileUrlHref as w,splitPathComponents as T}from"./path-shape.js";import{PROBED_GI_LIBDIRS as E,TYPELIB_SUBDIR as D,dyldDefaultFallbackDirs as O,giLibraryDirsForTypelibDir as k,splitSearchPath as A,systemGiLibraryDirs as j}from"./system-gi-dirs.js";import{mapMachine as M,mapSysname as N}from"./platform-names.js";import{structuredClone as P}from"./structured-clone.js";import{hasProcfs as F,hostEnv as I,hostExecPath as L,hostPid as R,hostPpid as z,readProcessMemory as B}from"./host-process.js";import{ensureMainLoop as V,holdMainLoop as H,quitMainLoop as U}from"./main-loop.js";import{NativeLibraryLoadError as W,colocateNativeLibrary as G,loadOptionalNativeModule as K,missingLibraryDependency as q,openNativeLibrary as J,probeNativeLibrary as Y}from"./native-library.js";import{__resetBurstStateForTests as X,nextTick as Z}from"./next-tick.js";import"./core.js";import{readJSON as Q}from"./file.js";import{existsFD as $,existsSync as ee}from"./fs.js";import{gioAsync as te,inputStreamAsyncIterator as ne,readBytesAsync as re}from"./gio.js";import{getNodeModulesPath as ie,getPathSeparator as ae,getProgramDir as oe,getProgramExe as se,resolve as ce}from"./path.js";import{closeSocketService as le,releaseListenPort as ue}from"./socket-service.js";export{a as GIO_ERROR_TO_NODE,o as GLIB_FILE_ERROR_TO_NODE,W as NativeLibraryLoadError,E as PROBED_GI_LIBDIRS,d as TARGET_OSES,D as TYPELIB_SUBDIR,X as __resetBurstStateForTests,n as cli,le as closeSocketService,G as colocateNativeLibrary,s as createGLibFileError,c as createNodeError,r as deferEmit,O as dyldDefaultFallbackDirs,x as encodePathForFileUrl,V as ensureMainLoop,$ as existsFD,ee as existsSync,e as gbytesToUint8Array,ie as getNodeModulesPath,ae as getPathSeparator,oe as getProgramDir,se as getProgramExe,k as giLibraryDirsForTypelibDir,te as gioAsync,F as hasProcfs,H as holdMainLoop,I as hostEnv,L as hostExecPath,f as hostOs,R as hostPid,p as hostPlatform,z as hostPpid,i as initErrorV8Methods,ne as inputStreamAsyncIterator,m as isDarwin,h as isLinux,l as isNotFoundError,g as isTargetOs,_ as isWin32,S as isWindowsPath,C as lastPathSeparatorIndex,K as loadOptionalNativeModule,t as makeCallable,M as mapMachine,N as mapSysname,q as missingLibraryDependency,Z as nextTick,v as notImplemented,J as openNativeLibrary,w as pathToFileUrlHref,Y as probeNativeLibrary,b as queueMicrotask,U as quitMainLoop,re as readBytesAsync,Q as readJSON,B as readProcessMemory,u as registerGlobal,ue as releaseListenPort,ce as resolve,T as splitPathComponents,A as splitSearchPath,P as structuredClone,j as systemGiLibraryDirs,y as warnNotImplemented};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";let e=null,t=!1,n=!1;function glib(){return globalThis.imports?.gi?.GLib}function arm(e){n||(n=!0,e.runAsync().catch(()=>{}))}function ensureMainLoop(){let n=glib();if(n)return t?e:(e=new n.MainLoop(null,!1),t=!0,n.main_depth()===0&&arm(e),e)}function holdMainLoop(){let e=ensureMainLoop();return e&&arm(e),e}function quitMainLoop(){e&&=(e.quit(),t=!1,n=!1,null)}export{ensureMainLoop,holdMainLoop,quitMainLoop};
1
+ import"./_virtual/_rolldown/runtime.js";let e=null,t=!1,n=!1;function glib(){let e=globalThis;if(typeof e.process?.versions?.gjs==`string`||e.process===void 0)return e.imports?.gi?.GLib}function arm(e){n||(n=!0,e.runAsync().catch(()=>{}))}function ensureMainLoop(){let n=glib();if(n)return t?e:(e=new n.MainLoop(null,!1),t=!0,n.main_depth()===0&&arm(e),e)}function holdMainLoop(){let e=ensureMainLoop();return e&&arm(e),e}function quitMainLoop(){e&&=(e.quit(),t=!1,n=!1,null)}export{ensureMainLoop,holdMainLoop,quitMainLoop};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function hostGi(){return globalThis.imports?.gi}function directoryOf(e){return/^(.*)[\\/][^\\/]*$/.exec(e)?.[1]}function colocateNativeLibrary(e,t=hostGi()){try{let n=t?.GIRepository?.Repository?.dup_default?.(),r=n?.get_typelib_path(e),i=r?directoryOf(r):void 0;return!n||!i?!1:(n.prepend_library_path(i),!0)}catch{return!1}}function probeNativeLibrary(e,t=hostGi()){try{let n=t?.GIRepository?.Repository?.dup_default?.(),r=n?.get_typelib_path(e);if(!t||!n||!r)return null;let i=firstSymbol(n,e);if(!i||(t.GModule?.module_error(),i.info.get_typelib().symbol(i.name)[0]))return null;let a=directoryOf(r)??`.`,o=r.includes(`\\`)&&!r.includes(`/`)?`\\`:`/`;for(let s of n.get_shared_libraries(e)??[]){let n=`${a}${o}${s}`,c=t.GLib?.file_test(n,t.GLib.FileTest.EXISTS)?n:s,l=loaderError(t,e,r,c,i.name);if(l!==void 0)return{namespace:e,library:c,reason:l,missingDependency:missingLibraryDependency(l,c)}}let s=(n.get_shared_libraries(e)??[]).join(`, `)||`(none named)`;return{namespace:e,library:s,reason:`symbol ${i.name} not found in ${s}, and the loader reported no error`}}catch{return null}}function firstSymbol(e,t){let n=e.get_n_infos(t),r=null;for(let i=0;i<n;i++){let n=e.get_info(t,i),a=n.get_type_init_function_name?.();if(a)return{info:n,name:a};let o=n.get_symbol?.();o&&!r&&(r={info:n,name:o})}return r}function loaderError(e,t,n,r,i){let{GIRepository:a,GLib:o,GModule:s}=e;if(!a?.Repository||!a.Typelib||!o||!s)return;let[,c]=o.file_get_contents(n),l=new TextEncoder().encode(`${r}\0`),u=new Uint8Array(c.length+l.length);u.set(c),u.set(l,c.length);let d=new DataView(u.buffer);d.setUint32(40,u.length,!0),d.setUint32(52,c.length,!0);let f=new a.Repository,p=firstSymbol(f,f.load_typelib(a.Typelib.new_from_bytes(new o.Bytes(u)),0));if(p&&(s.module_error(),!p.info.get_typelib().symbol(i)[0]))return s.module_error()??`${t}: ${r} could not be opened (the loader reported no error)`}function missingLibraryDependency(e,t){let n=/Library not loaded: (\S+)/.exec(e)?.[1]??/Error loading shared library ([^\s:]+): .*\(needed by /.exec(e)?.[1]??/(?:^|\s)([^\s:]+): cannot open shared object file/.exec(e)?.[1];if(!n)return;let r=n.replace(/^.*[\\/]/,``);if(!(t&&r===t.replace(/^.*[\\/]/,``)))return r}var NativeLibraryLoadError=class extends Error{failure;constructor(e,t){let n=e.missingDependency?`It needs ${e.missingDependency}, which the loader could not find: not installed, or not on its search path.`:`The loader could not open it.`;super(`${e.namespace}: the native library ${e.library} could not be loaded. ${n}\nLoader: ${e.reason.trim()}\n`+(t??"`gjsify system-check` lists the system libraries the installed @gjsify packages need, with the install command for this host.")),this.name=`NativeLibraryLoadError`,this.failure=e}};function openNativeLibrary(e,t=hostGi()){colocateNativeLibrary(e,t);let n=probeNativeLibrary(e,t);return n?new NativeLibraryLoadError(n):null}function loadOptionalNativeModule(e,t,n=hostGi()){if(!n)return{module:null,error:Error(`${e}: imports.gi is not available (not running on GJS)`)};try{let r=n[e];if(!r)return{module:null,error:Error(`${e}: typelib not found`)};let i=openNativeLibrary(e,n);if(i)return console.debug(i.message),{module:null,error:i};for(let e of t)r[e];return{module:r,error:null}}catch(e){return{module:null,error:e instanceof Error?e:Error(String(e))}}}export{NativeLibraryLoadError,colocateNativeLibrary,loadOptionalNativeModule,missingLibraryDependency,openNativeLibrary,probeNativeLibrary};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";const t=new Map;function finishClose(e){let n=t.get(e);if(n){t.delete(e);try{e.close()}finally{n.onClosed?.()}}}function closeSocketService(n,r,i){n.stop(),t.set(n,{ports:r,onClosed:i}),e.timeout_add(e.PRIORITY_DEFAULT,0,()=>(finishClose(n),e.SOURCE_REMOVE))}function releaseListenPort(e){if(e)for(let[n,r]of t)r.ports.includes(e)&&finishClose(n)}export{closeSocketService,releaseListenPort};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{isWindowsPath as e,lastPathSeparatorIndex as t,splitPathComponents as n}from"./path-shape.js";const r=`girepository-1.0`,i={darwin:[`/opt/homebrew/lib`,`/usr/local/lib`,`/opt/local/lib`]};function splitSearchPath(e,t=`:`){return(e??``).split(t).filter(Boolean)}function stripTrailingSeparators(t){return t.replace(e(t)?/(?<=.)[\\/]+$/:/(?<=.)\/+$/,``)}function dirname(e){let n=stripTrailingSeparators(e),r=t(n);return r<0?`.`:r===0?n.slice(0,1):n.slice(0,r)}function basename(e){let t=n(e).filter(Boolean);return t.length===0?``:t[t.length-1]}function giLibraryDirsForTypelibDir(e){let t=dirname(e);return basename(e)===`girepository-1.0`?[t]:[e,t]}function systemGiLibraryDirs(e){let t=i[e.platform];if(!t)return[];let n=[],add=e=>{e&&e!==`/`&&!n.includes(e)&&n.push(e)};for(let t of splitSearchPath(e.typelibPath))for(let n of giLibraryDirsForTypelibDir(t))e.existsDir(n)&&add(n);let r=[];for(let t of e.pkgConfigDirs??[])basename(t)===`pkgconfig`&&r.push(dirname(t));r.push(...t);for(let t of r)e.existsDir(`${t}/girepository-1.0`)&&add(t);return n}export{i as PROBED_GI_LIBDIRS,r as TYPELIB_SUBDIR,giLibraryDirsForTypelibDir,splitSearchPath,systemGiLibraryDirs};
1
+ import"./_virtual/_rolldown/runtime.js";import{isWindowsPath as e,lastPathSeparatorIndex as t,splitPathComponents as n}from"./path-shape.js";const r=`girepository-1.0`,i={darwin:[`/opt/homebrew/lib`,`/usr/local/lib`,`/opt/local/lib`]};function splitSearchPath(e,t=`:`){return(e??``).split(t).filter(Boolean)}function stripTrailingSeparators(t){return t.replace(e(t)?/(?<=.)[\\/]+$/:/(?<=.)\/+$/,``)}function dirname(e){let n=stripTrailingSeparators(e),r=t(n);return r<0?`.`:r===0?n.slice(0,1):n.slice(0,r)}function basename(e){let t=n(e).filter(Boolean);return t.length===0?``:t[t.length-1]}function giLibraryDirsForTypelibDir(e){let t=dirname(e);return basename(e)===`girepository-1.0`?[t]:[e,t]}function dyldDefaultFallbackDirs(e={}){let t=e.HOME;return[...t?[`${t}/lib`]:[],`/usr/local/lib`,`/lib`,`/usr/lib`]}function systemGiLibraryDirs(e){let t=i[e.platform];if(!t)return[];let n=[],add=e=>{e&&e!==`/`&&!n.includes(e)&&n.push(e)};for(let t of splitSearchPath(e.typelibPath))for(let n of giLibraryDirsForTypelibDir(t))e.existsDir(n)&&add(n);let r=[];for(let t of e.pkgConfigDirs??[])basename(t)===`pkgconfig`&&r.push(dirname(t));r.push(...t);for(let t of r)e.existsDir(`${t}/girepository-1.0`)&&add(t);return n}export{i as PROBED_GI_LIBDIRS,r as TYPELIB_SUBDIR,dyldDefaultFallbackDirs,giLibraryDirsForTypelibDir,splitSearchPath,systemGiLibraryDirs};
@@ -12,4 +12,5 @@ export * from './platform-names.js';
12
12
  export * from './structured-clone.js';
13
13
  export * from './host-process.js';
14
14
  export * from './main-loop.js';
15
+ export * from './native-library.js';
15
16
  export * from './next-tick.js';
@@ -1,3 +1,13 @@
1
+ /**
2
+ * One environment variable of this process, or `undefined` when it is unset or
3
+ * nothing can answer.
4
+ *
5
+ * `process.env` first — Node, Bun, Deno and a GJS bundle whose `@gjsify/process`
6
+ * is registered all have it — then GLib's `g_getenv()` for a GJS host without that
7
+ * singleton. The two read the same environment block, so the order only decides
8
+ * who answers, never what.
9
+ */
10
+ export declare function hostEnv(name: string): string | undefined;
1
11
  /** Does this host have a readable procfs for the current process? */
2
12
  export declare function hasProcfs(): boolean;
3
13
  /**
@@ -5,3 +5,4 @@ export * from './file.js';
5
5
  export * from './fs.js';
6
6
  export * from './gio.js';
7
7
  export * from './path.js';
8
+ export * from './socket-service.js';
@@ -0,0 +1,141 @@
1
+ /** What {@link probeNativeLibrary} measured about a library that would not load. */
2
+ export interface NativeLibraryFailure {
3
+ /** The GI namespace whose library failed, e.g. `GjsifyRolldown`. */
4
+ namespace: string;
5
+ /** The library file that failed — absolute when it sits beside its typelib, else the typelib's leaf. */
6
+ library: string;
7
+ /** The host loader's own message (dlerror / dyld / LoadLibrary), or a fixed text when none was readable. */
8
+ reason: string;
9
+ /** Leaf name of the dependency the loader could not find, when its message names one. */
10
+ missingDependency?: string;
11
+ }
12
+ interface RegisteredInfoView {
13
+ get_type_init_function_name?(): string | null;
14
+ get_symbol?(): string | null;
15
+ get_typelib(): {
16
+ symbol(name: string): [boolean, unknown];
17
+ };
18
+ }
19
+ interface RepositoryView {
20
+ get_typelib_path(namespace: string): string | null;
21
+ prepend_library_path(directory: string): void;
22
+ get_shared_libraries(namespace: string): string[] | null;
23
+ get_n_infos(namespace: string): number;
24
+ get_info(namespace: string, index: number): RegisteredInfoView;
25
+ load_typelib(typelib: unknown, flags: number): string;
26
+ }
27
+ /** Structural view of `imports.gi` — only the slots this module reads. */
28
+ export interface GiImportsView {
29
+ readonly GIRepository?: {
30
+ Repository?: {
31
+ dup_default?: () => RepositoryView | null;
32
+ new (): RepositoryView;
33
+ };
34
+ Typelib?: {
35
+ new_from_bytes(bytes: unknown): unknown;
36
+ };
37
+ };
38
+ readonly GLib?: {
39
+ file_get_contents(path: string): [boolean, Uint8Array];
40
+ file_test(path: string, test: number): boolean;
41
+ Bytes: new (data: Uint8Array) => unknown;
42
+ FileTest: {
43
+ EXISTS: number;
44
+ };
45
+ };
46
+ readonly GModule?: {
47
+ module_error(): string | null;
48
+ };
49
+ }
50
+ /**
51
+ * Put the directory `namespace`'s typelib was loaded from on girepository's
52
+ * library path.
53
+ *
54
+ * Call it AFTER resolving the namespace (`imports.gi.<Ns>` or a `gi://` import —
55
+ * that loads the typelib only) and BEFORE the first class or function access,
56
+ * which is what opens the library. Prepending a directory that already resolves
57
+ * changes nothing, so no caller has to know whether the environment was intact.
58
+ *
59
+ * Capability-probed rather than assumed: `dup_default()` is GLib >= 2.86, and an
60
+ * older host keeps the environment-only behaviour. Never throws.
61
+ *
62
+ * @param gi the `imports.gi` to use — defaults to the running GJS host's; a
63
+ * parameter so the spec can drive every branch with a stub
64
+ * @returns whether a directory was prepended
65
+ */
66
+ export declare function colocateNativeLibrary(namespace: string, gi?: GiImportsView | undefined): boolean;
67
+ /**
68
+ * Force `namespace`'s shared library to load and, when it cannot, say which file
69
+ * failed and why.
70
+ *
71
+ * Call it after the namespace resolved (`imports.gi.<Ns>` loads the typelib
72
+ * only) and before relying on its classes. On success it has done what the first
73
+ * class access would have done anyway — girepository opens a typelib's library
74
+ * once — so a caller pays nothing extra.
75
+ *
76
+ * Returns `null` when the library loads AND when nothing can be measured (not on
77
+ * GJS, GLib without GIRepository 3, a namespace the repository has not loaded):
78
+ * this answers "did it fail", never "is it present". Never throws: callers run
79
+ * it while deciding how to report another failure.
80
+ *
81
+ * @param gi the `imports.gi` to use — defaults to the running GJS host's; a
82
+ * parameter so the spec can drive the unmeasurable branches with a stub
83
+ */
84
+ export declare function probeNativeLibrary(namespace: string, gi?: GiImportsView | undefined): NativeLibraryFailure | null;
85
+ /**
86
+ * The leaf name of the dependency a loader message says is missing, or
87
+ * `undefined` when it names none (win32's LoadLibrary never does) or names the
88
+ * library itself (then the library is what is missing, not a dependency).
89
+ *
90
+ * Pure — the three message shapes are the loaders' own, captured verbatim in
91
+ * the spec.
92
+ */
93
+ export declare function missingLibraryDependency(reason: string, library?: string): string | undefined;
94
+ /**
95
+ * A native bridge's library could not be loaded. The message names the file, the
96
+ * missing dependency and what to do — the text GJS's own "Unsupported type void"
97
+ * leaves out.
98
+ */
99
+ export declare class NativeLibraryLoadError extends Error {
100
+ readonly failure: NativeLibraryFailure;
101
+ /**
102
+ * @param installHint how to install what is missing, when the caller knows
103
+ * (the CLI derives it from its system-dependency table); otherwise the
104
+ * message points at `gjsify system-check`, which reads that same table
105
+ */
106
+ constructor(failure: NativeLibraryFailure, installHint?: string);
107
+ }
108
+ /**
109
+ * Make `namespace`'s library loadable and load it: {@link colocateNativeLibrary},
110
+ * then {@link probeNativeLibrary}. The call a bridge loader makes between
111
+ * resolving its namespace and its first class access.
112
+ *
113
+ * @returns the error naming the file and its missing dependency, or `null` when
114
+ * the library loaded or nothing could be measured
115
+ */
116
+ export declare function openNativeLibrary(namespace: string, gi?: GiImportsView | undefined): NativeLibraryLoadError | null;
117
+ /** What {@link loadOptionalNativeModule} found: the namespace, or why there is none. */
118
+ export interface OptionalNativeModule<T> {
119
+ /** The loaded namespace, `null` when it is absent or its library cannot be opened. */
120
+ readonly module: T | null;
121
+ /** Why `module` is `null` — a {@link NativeLibraryLoadError} when the library was found and refused. */
122
+ readonly error: Error | null;
123
+ }
124
+ /**
125
+ * Load an OPTIONAL bridge: resolve `namespace` from `imports.gi`, open its
126
+ * library ({@link openNativeLibrary}) and touch `classes`, so a namespace that
127
+ * resolved while its library did not reads as absent rather than failing at
128
+ * first use. Never throws — an optional bridge that cannot load is a fallback
129
+ * path for the caller, not an error.
130
+ *
131
+ * Absent and broken are different diagnoses, so the result keeps the error:
132
+ * a missing typelib is girepository's "not found", a found library that will
133
+ * not open is the {@link NativeLibraryLoadError} naming the dependency. The
134
+ * latter also goes to `console.debug` (GJS: `G_MESSAGES_DEBUG=Gjs-Console`),
135
+ * because a broken install that silently degrades is otherwise invisible.
136
+ *
137
+ * @param classes members to touch after the library opened — the safety net for
138
+ * a host on which the probe measures nothing (GLib < 2.86)
139
+ */
140
+ export declare function loadOptionalNativeModule<T>(namespace: string, classes: readonly string[], gi?: GiImportsView | undefined): OptionalNativeModule<T>;
141
+ export {};
@@ -0,0 +1,16 @@
1
+ import type Gio from '@girs/gio-2.0';
2
+ /**
3
+ * Stop accepting on `service` and close its listening sockets once no Gio source
4
+ * polls them any more. `ports` are the ports it is bound to (see
5
+ * {@link releaseListenPort}); `onClosed` runs right after the descriptors close.
6
+ */
7
+ export declare function closeSocketService(service: Gio.SocketService, ports: readonly number[], onClosed?: () => void): void;
8
+ /**
9
+ * Call before binding `port`. Node's `server.close()` releases the port
10
+ * synchronously (libuv closes the fd in `uv_close`), so `close(); listen(port)`
11
+ * on the same port is legal there. A deferred close still holding `port` is
12
+ * therefore finished NOW: on darwin that may cost the one EBADF warning the
13
+ * deferral exists to avoid, which beats an EADDRINUSE Node would not raise.
14
+ * Port 0 (ephemeral) never collides, so it flushes nothing.
15
+ */
16
+ export declare function releaseListenPort(port: number): void;
@@ -56,4 +56,18 @@ export interface SystemGiLibraryDirsHost {
56
56
  * Sources 2 and 3 are GUESSES at a prefix, so each must show the
57
57
  * `girepository-1.0/` marker before it is believed. Source 1 is not a guess.
58
58
  */
59
+ /**
60
+ * dyld's OWN default fallback list, verbatim from `dyld(1)`. Setting
61
+ * `DYLD_FALLBACK_LIBRARY_PATH` REPLACES it rather than extending it, so any
62
+ * caller that composes a value for that variable must carry this tail or a
63
+ * child launched through it searches LESS than one launched with the
64
+ * variable unset — the regression `packages/infra/cli/src/utils/system-gi.ts`
65
+ * (`composeDyldFallback`) and `packages/node-gi/node-gi/system-gi.js` both
66
+ * exist to avoid. A THIRD caller that only needs the tail, not the rest of
67
+ * that composition (a launcher replacing the environment outright has no
68
+ * "current value of the variable" to fold in), imports this rather than
69
+ * hand-rolling the same four-entry array — see
70
+ * `packages/framework/gtk-host/src/placement.spec.ts`.
71
+ */
72
+ export declare function dyldDefaultFallbackDirs(env?: Record<string, string | undefined>): string[];
59
73
  export declare function systemGiLibraryDirs(host: SystemGiLibraryDirsHost): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/utils",
3
- "version": "0.51.1",
3
+ "version": "0.53.0",
4
4
  "description": "Utils module for gjsify",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -21,6 +21,10 @@
21
21
  "./main-loop": {
22
22
  "types": "./lib/types/main-loop.d.ts",
23
23
  "default": "./lib/esm/main-loop.js"
24
+ },
25
+ "./native-library": {
26
+ "types": "./lib/types/native-library.d.ts",
27
+ "default": "./lib/esm/native-library.js"
24
28
  }
25
29
  },
26
30
  "scripts": {
@@ -40,14 +44,14 @@
40
44
  "fs"
41
45
  ],
42
46
  "devDependencies": {
43
- "@gjsify/cli": "^0.51.1",
47
+ "@gjsify/cli": "^0.53.0",
44
48
  "typescript": "^6.0.3"
45
49
  },
46
50
  "dependencies": {
47
- "@girs/gio-2.0": "5.0.0",
48
- "@girs/giounix-2.0": "5.0.0",
49
- "@girs/gjs": "5.0.0",
50
- "@girs/glib-2.0": "5.0.0"
51
+ "@girs/gio-2.0": "5.4.0",
52
+ "@girs/giounix-2.0": "5.4.0",
53
+ "@girs/gjs": "5.4.0",
54
+ "@girs/glib-2.0": "5.4.0"
51
55
  },
52
56
  "license": "MIT",
53
57
  "repository": {
@@ -79,6 +83,12 @@
79
83
  "node": "polyfill",
80
84
  "browser": "polyfill",
81
85
  "nativescript": "polyfill"
86
+ },
87
+ "./native-library": {
88
+ "gjs": "polyfill",
89
+ "node": "polyfill",
90
+ "browser": "polyfill",
91
+ "nativescript": "polyfill"
82
92
  }
83
93
  },
84
94
  "os": {