@gjsify/utils 0.52.0 → 0.54.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 +1 -1
- package/lib/esm/font-map.js +1 -0
- package/lib/esm/host-process.js +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/main-loop.js +1 -1
- package/lib/esm/native-library.js +1 -0
- package/lib/esm/socket-service.js +1 -0
- package/lib/esm/system-gi-dirs.js +1 -1
- package/lib/types/core.d.ts +1 -0
- package/lib/types/font-map.d.ts +164 -0
- package/lib/types/host-process.d.ts +10 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/native-library.d.ts +141 -0
- package/lib/types/socket-service.d.ts +16 -0
- package/lib/types/system-gi-dirs.d.ts +14 -0
- package/package.json +26 -3
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,
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"gi://GLib?version=2.0";import t from"gi://Gio?version=2.0";import n from"gi://PangoCairo?version=1.0";import r from"gi://Pango?version=1.0";const i=1;function fontMapNamespace(){let e=n.FontMap;if(e!=null&&typeof e.get_default==`function`&&typeof e.new_for_font_type==`function`)return e}function isUnsupportedByFontMap(n){let r=e.Error,i=t.io_error_quark,a=t.IOErrorEnum?.NOT_SUPPORTED;return typeof r!=`function`||typeof i!=`function`||a===void 0||!(n instanceof r)?!1:n.matches(i(),a)}function fontErrorMessage(t){let n=e.Error;return typeof n==`function`&&t instanceof n?t.message??String(t):t instanceof Error?t.message:String(t)}function fontMapFamilies(e){return e.list_families().map(e=>e.get_name())}function fontMapHasFamily(e,t){return e.get_family(t)!==null}function layoutSize(e,t){let n=new r.FontDescription;n.set_family(t),n.set_size(40*r.SCALE);let i=r.Layout.new(e.create_context());return i.set_font_description(n),i.set_text(`Wg`,-1),i.get_pixel_size().join(`x`)}function fontMapServesFamily(e,t,n=layoutSize){return n(e,t)!==n(e,`ZzzGjsifySubstitutionControlQx`)}const a={map:null,before:[],failed:new Map,adopted:!1};function probeFontconfigMap(t,n,r,i=[]){if(r.length===0||e.getenv(`PANGOCAIRO_BACKEND`)!==null)return a;let o=t.new_for_font_type(1);if(o==null)return a;let s=fontMapFamilies(o);if(s.length===0)return a;let c=new Map;for(let e of r)try{o.add_font_file(e)}catch(t){c.set(e,fontErrorMessage(t))}let l=fontMapFamilies(o).filter(e=>!s.includes(e));if(l.length===0)return{map:o,before:s,failed:c,adopted:!1};let alreadyReached=e=>!i.includes(e)&&n.get_family(e)!==null;if(l.every(alreadyReached))return{map:o,before:s,failed:c,adopted:!1};let u=o.set_default;return typeof u==`function`?(u.call(o),{map:o,before:s,failed:c,adopted:!0}):{map:o,before:s,failed:c,adopted:!1}}function noRegistration(){return{available:!1,map:void 0,before:[],registered:[],declined:[],unreachable:[],failed:[],fontconfigFallback:!1}}function registerFontFaces(e,t){let n=fontMapNamespace();if(n===void 0)return noRegistration();let r=t??n.get_default();if(e.length===0)return{...noRegistration(),available:!0,map:r,before:fontMapFamilies(r)};let i=fontMapFamilies(r),a=[],o=[],s=[],c=[];for(let t of e)try{r.add_font_file(t),a.push(t)}catch(e){if(isUnsupportedByFontMap(e)){o.push(t);continue}c.push({path:t,message:fontErrorMessage(e)})}let l=[];a.length>0&&(l=fontMapFamilies(r).filter(e=>!i.includes(e)).filter(e=>!fontMapServesFamily(r,e)),l.length>0&&s.push(...a));let u=[...o,...s];if(u.length>0){let e=probeFontconfigMap(n,r,u,l),t=[];for(let n of o){let r=e.failed.get(n);r===void 0?e.adopted?a.push(n):t.push(n):c.push({path:n,message:r})}if(o.length=0,o.push(...t),e.adopted)s.length=0;else{let t=s.filter(t=>!e.failed.has(t));for(let t of s){let n=e.failed.get(t);n!==void 0&&c.push({path:t,message:n})}s.length=0,s.push(...t)}if(e.adopted&&e.map!==null)return{available:!0,map:e.map,before:e.before,registered:a,declined:o,unreachable:s,failed:c,fontconfigFallback:!0}}return{available:!0,map:r,before:i,registered:a,declined:o,unreachable:s,failed:c,fontconfigFallback:!1}}export{i as CAIRO_FONT_TYPE_FT,fontErrorMessage,fontMapFamilies,fontMapHasFamily,fontMapServesFamily,isUnsupportedByFontMap,registerFontFaces};
|
package/lib/esm/host-process.js
CHANGED
|
@@ -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,
|
|
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};
|
package/lib/esm/main-loop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";let e=null,t=!1,n=!1;function glib(){
|
|
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};
|
package/lib/types/core.d.ts
CHANGED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import Pango from 'gi://Pango?version=1.0';
|
|
2
|
+
/**
|
|
3
|
+
* `CAIRO_FONT_TYPE_FT` from `cairo.h` — the value `pango_cairo_font_map_new_for_font_type()` maps to
|
|
4
|
+
* its fontconfig backend.
|
|
5
|
+
*
|
|
6
|
+
* A literal rather than `gi://cairo`'s `FontType.FT`: the enum is part of cairo's ABI, so importing a
|
|
7
|
+
* fourth namespace to spell one stable integer would add a load-time dependency for nothing.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CAIRO_FONT_TYPE_FT = 1;
|
|
10
|
+
/** A face the font map would not take, and why. */
|
|
11
|
+
export interface FontFaceFailure {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly message: string;
|
|
14
|
+
}
|
|
15
|
+
/** What one {@link registerFontFaces} call did. */
|
|
16
|
+
export interface FontFaceRegistration {
|
|
17
|
+
/**
|
|
18
|
+
* `false` where there is no Pango font map to register anything on at all — a `--app browser`
|
|
19
|
+
* bundle empties `gi://` (`plugins/gjs-imports-empty.ts`), and there a browser's OWN font
|
|
20
|
+
* machinery is what resolves a `FontFace`.
|
|
21
|
+
*
|
|
22
|
+
* Reported rather than left to be inferred from an empty outcome, because the two must not be
|
|
23
|
+
* reported alike: nothing was DECLINED on a browser, and a caller warning about a decline there
|
|
24
|
+
* would print a font warning per face in every web app.
|
|
25
|
+
*/
|
|
26
|
+
readonly available: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The map in force afterwards — the adopted fontconfig one where the fallback ran, the `map` that
|
|
29
|
+
* was passed in otherwise. `undefined` when {@link available} is `false`.
|
|
30
|
+
*
|
|
31
|
+
* A caller registering more than one batch MUST thread this forward: after a swap the process
|
|
32
|
+
* default is the fontconfig map, and only this value knows.
|
|
33
|
+
*/
|
|
34
|
+
readonly map: Pango.FontMap | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The family names the registering map held before any face was added — the BEFORE of a family
|
|
37
|
+
* diff. On the fallback path this is the CANDIDATE's list, because the diff has to be taken on
|
|
38
|
+
* the map that ends up in force or every family the two backends merely SPELL differently would
|
|
39
|
+
* be credited to this call.
|
|
40
|
+
*/
|
|
41
|
+
readonly before: readonly string[];
|
|
42
|
+
/** Faces now on the map. */
|
|
43
|
+
readonly registered: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* Faces no map here would take — see {@link isUnsupportedByFontMap}. A face in a shipped `.app`
|
|
46
|
+
* lands here and is CORRECT: the OS activated the directory before the process started.
|
|
47
|
+
*/
|
|
48
|
+
readonly declined: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Faces this call put on the map that no layout can be served by — registered, `get_family`
|
|
51
|
+
* answers the family, and text asking for it still measures the fallback. A SUBSET of
|
|
52
|
+
* {@link registered}, and disjoint from {@link declined}.
|
|
53
|
+
*
|
|
54
|
+
* ITS OWN FIELD rather than a third bucket beside the two above, and the difference is what
|
|
55
|
+
* happened to the map. `declined` is a map that would not TAKE the face, which for a shipped
|
|
56
|
+
* `.app` is the correct outcome; a face here was TAKEN and then could not SERVE it. A caller
|
|
57
|
+
* reading `declined` tells its user that no font map would take this file and points at
|
|
58
|
+
* `ATSApplicationFontsPath` and `initFonts()` — advice that is wrong here, because the face is
|
|
59
|
+
* already on the map and re-running a registration cannot help. That is why the distinction is
|
|
60
|
+
* data rather than a comment: one is silent and correct, the other is loud and necessary, and
|
|
61
|
+
* a caller cannot tell them apart without laying text out itself.
|
|
62
|
+
*
|
|
63
|
+
* EMPTY where the fontconfig fallback took over, which is the whole point of it: then the faces
|
|
64
|
+
* render and there is nothing left to report.
|
|
65
|
+
*/
|
|
66
|
+
readonly unreachable: readonly string[];
|
|
67
|
+
/** Faces that failed for any other reason, plus any the fontconfig map could not open either. */
|
|
68
|
+
readonly failed: readonly FontFaceFailure[];
|
|
69
|
+
/**
|
|
70
|
+
* `true` when this call REPLACED the process's default font map with a fontconfig-backed one.
|
|
71
|
+
*
|
|
72
|
+
* A whole-application consequence of one call — every widget created afterwards renders through
|
|
73
|
+
* FreeType instead of the platform rasteriser — so it is reported rather than inferred, and
|
|
74
|
+
* `PANGOCAIRO_BACKEND=coretext` gives the platform map back (ADR 0038 § Amendment 5).
|
|
75
|
+
*/
|
|
76
|
+
readonly fontconfigFallback: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Did the font map decline runtime registration outright?
|
|
80
|
+
*
|
|
81
|
+
* `pango_font_map_add_font_file()` is a vfunc, and the CoreText map implements none — so on macOS the
|
|
82
|
+
* call falls through to Pango's base implementation, which answers `G_IO_ERROR_NOT_SUPPORTED`. That is
|
|
83
|
+
* not a failure to report: a shipped `.app` is already correct declaratively, because
|
|
84
|
+
* `ATSApplicationFontsPath` had the OS activate the staged directory before the process started, and
|
|
85
|
+
* the ordering makes the runtime call the wrong tool there rather than merely a redundant one —
|
|
86
|
+
* `pango_core_text_font_map_changed()` only bumps a serial, there is no
|
|
87
|
+
* `kCTFontManagerRegisteredFontsChangedNotification` observer and no re-scan path in
|
|
88
|
+
* `pangocoretext-fontmap.c`, so a face registered after the map initialises could not be recovered by
|
|
89
|
+
* poking it anyway.
|
|
90
|
+
*
|
|
91
|
+
* KEYED ON THE ERROR rather than on `process.platform`, which is the difference between a capability
|
|
92
|
+
* test and a guess about who is asking. It costs no `gjsify.os` declaration, and it stays right for any
|
|
93
|
+
* other map that declines — which stopped being hypothetical: the backend is whichever is selected
|
|
94
|
+
* rather than one per platform, and `@gjsify/node-gi`'s loader selects `PANGOCAIRO_BACKEND=fc` on the
|
|
95
|
+
* bundled windowing runtime (ADR 0038 § Amendment 3), so a darwin process on it reaches this arm's
|
|
96
|
+
* other side and REGISTERS the faces. A `process.platform` branch would have had to be found and
|
|
97
|
+
* reversed instead.
|
|
98
|
+
*/
|
|
99
|
+
export declare function isUnsupportedByFontMap(error: unknown): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The reported reason as a GError's `message`, never a stringified GError.
|
|
102
|
+
*
|
|
103
|
+
* `GLib.Error` is NOT `instanceof Error` under GJS — measured on gjs 1.88.1, where
|
|
104
|
+
* `GLib.Error.new_literal(…) instanceof Error` is `false`. A plain `instanceof Error` narrowing
|
|
105
|
+
* therefore misses EXACTLY the errors this module sees, and every diagnostic printed over them would
|
|
106
|
+
* silently degrade to `String(error)` — which is not obviously broken, only domain-prefixed.
|
|
107
|
+
*/
|
|
108
|
+
export declare function fontErrorMessage(error: unknown): string;
|
|
109
|
+
/**
|
|
110
|
+
* The family names a font map currently holds.
|
|
111
|
+
*
|
|
112
|
+
* Typed `Pango.FontMap` and not `PangoCairo.FontMap`, which is what the call sites have:
|
|
113
|
+
* `pango_cairo_font_map_get_default()` is declared to RETURN the base type.
|
|
114
|
+
*/
|
|
115
|
+
export declare function fontMapFamilies(fontMap: Pango.FontMap): string[];
|
|
116
|
+
/** Is `family` one this map can resolve? Pango's own answer, asked directly rather than inferred. */
|
|
117
|
+
export declare function fontMapHasFamily(fontMap: Pango.FontMap, family: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* How {@link fontMapServesFamily} takes its reading: a value that is EQUAL for a family the map
|
|
120
|
+
* serves and for one it substitutes.
|
|
121
|
+
*
|
|
122
|
+
* A seam, so the decision can be held from a host that cannot produce the condition — the same
|
|
123
|
+
* discipline {@link isUnsupportedByFontMap} exists for, and the reason `font-map.spec.ts` can assert
|
|
124
|
+
* the decision on every leg instead of only where a poisoned map can be built.
|
|
125
|
+
*/
|
|
126
|
+
export type FontFamilyProbe = (fontMap: Pango.FontMap, family: string) => string;
|
|
127
|
+
/**
|
|
128
|
+
* Does this map actually SERVE `family`, or does asking for it get the fallback?
|
|
129
|
+
*
|
|
130
|
+
* A LAYOUT, because that is the only reading that does not lie, and the readings that look cheaper
|
|
131
|
+
* were measured first (pango 1.58.2 / gjs 1.88.1, on the fc map Fedora has, reached here with
|
|
132
|
+
* `PANGOCAIRO_BACKEND=fontconfig`) on a map that had resolved the family to the fallback and then
|
|
133
|
+
* had the face registered on it:
|
|
134
|
+
*
|
|
135
|
+
* `get_family(name)` answers it
|
|
136
|
+
* `list_families()` contains it
|
|
137
|
+
* `load_font(desc).describe()` the requested family — from a FRESH context
|
|
138
|
+
* `get_serial()` 1, exactly as on an unpoisoned map
|
|
139
|
+
* `Pango.Layout` pixel size THE FALLBACK — 86x66, identical to an invented family
|
|
140
|
+
*
|
|
141
|
+
* So the map holds the face, hands the right font to a caller that asks for it by name, reports the
|
|
142
|
+
* same serial as a healthy map, and lays every glyph out in Verdana: a per-map-instance cache of the
|
|
143
|
+
* negative resolution, which `add_font_file` does not invalidate and which nothing in JS reaches.
|
|
144
|
+
* Warming a context with `load_font` first does not help (measured — still 86x66), and neither does a
|
|
145
|
+
* context created after the registration; only a map that never saw the question serves it, which is
|
|
146
|
+
* the fresh map {@link probeFontconfigMap} builds.
|
|
147
|
+
*
|
|
148
|
+
* Which is also why the equality is against a control family rather than against a fixed number: the
|
|
149
|
+
* fallback's metrics are the host's business (Verdana 86x66 here, 87x63 on the Fedora 44 leg), and a
|
|
150
|
+
* number pinned to one host's default sans would red everywhere else while proving nothing extra.
|
|
151
|
+
*/
|
|
152
|
+
export declare function fontMapServesFamily(fontMap: Pango.FontMap, family: string, probe?: FontFamilyProbe): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Register faces on a font map, falling back to a fontconfig-backed one when that map DECLINES.
|
|
155
|
+
*
|
|
156
|
+
* `map` defaults to the process default and exists so a caller can keep a batch on the map a previous
|
|
157
|
+
* batch adopted — see {@link FontFaceRegistration.map}.
|
|
158
|
+
*
|
|
159
|
+
* Total: a face that will not open, or that no map here will take, is reported and never thrown.
|
|
160
|
+
* Taking an application down over a decorative face would be worse than rendering it in a fallback —
|
|
161
|
+
* but doing so SILENTLY is the defect this exists against (ADR 0038), so both are reported and the
|
|
162
|
+
* caller decides what to say about them.
|
|
163
|
+
*/
|
|
164
|
+
export declare function registerFontFaces(faces: readonly string[], map?: Pango.FontMap): FontFaceRegistration;
|
|
@@ -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
|
/**
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Utils module for gjsify",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -18,9 +18,17 @@
|
|
|
18
18
|
"types": "./lib/types/core.d.ts",
|
|
19
19
|
"default": "./lib/esm/core.js"
|
|
20
20
|
},
|
|
21
|
+
"./font-map": {
|
|
22
|
+
"types": "./lib/types/font-map.d.ts",
|
|
23
|
+
"default": "./lib/esm/font-map.js"
|
|
24
|
+
},
|
|
21
25
|
"./main-loop": {
|
|
22
26
|
"types": "./lib/types/main-loop.d.ts",
|
|
23
27
|
"default": "./lib/esm/main-loop.js"
|
|
28
|
+
},
|
|
29
|
+
"./native-library": {
|
|
30
|
+
"types": "./lib/types/native-library.d.ts",
|
|
31
|
+
"default": "./lib/esm/native-library.js"
|
|
24
32
|
}
|
|
25
33
|
},
|
|
26
34
|
"scripts": {
|
|
@@ -28,6 +36,7 @@
|
|
|
28
36
|
"check": "gjsify tsc --noEmit",
|
|
29
37
|
"build": "gjsify run build:gjsify && gjsify run build:types",
|
|
30
38
|
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
39
|
+
"build:esm": "gjsify tsc -p tsconfig.build.json",
|
|
31
40
|
"build:types": "gjsify tsc",
|
|
32
41
|
"build:test": "gjsify run build:test:gjs",
|
|
33
42
|
"build:test:gjs": "gjsify build src/test.ts --app gjs --outfile test.gjs.js",
|
|
@@ -40,14 +49,16 @@
|
|
|
40
49
|
"fs"
|
|
41
50
|
],
|
|
42
51
|
"devDependencies": {
|
|
43
|
-
"@gjsify/cli": "^0.
|
|
52
|
+
"@gjsify/cli": "^0.54.0",
|
|
44
53
|
"typescript": "^6.0.3"
|
|
45
54
|
},
|
|
46
55
|
"dependencies": {
|
|
47
56
|
"@girs/gio-2.0": "5.4.0",
|
|
48
57
|
"@girs/giounix-2.0": "5.4.0",
|
|
49
58
|
"@girs/gjs": "5.4.0",
|
|
50
|
-
"@girs/glib-2.0": "5.4.0"
|
|
59
|
+
"@girs/glib-2.0": "5.4.0",
|
|
60
|
+
"@girs/pango-1.0": "5.4.0",
|
|
61
|
+
"@girs/pangocairo-1.0": "5.4.0"
|
|
51
62
|
},
|
|
52
63
|
"license": "MIT",
|
|
53
64
|
"repository": {
|
|
@@ -74,11 +85,23 @@
|
|
|
74
85
|
"browser": "polyfill",
|
|
75
86
|
"nativescript": "polyfill"
|
|
76
87
|
},
|
|
88
|
+
"./font-map": {
|
|
89
|
+
"gjs": "polyfill",
|
|
90
|
+
"node": "polyfill",
|
|
91
|
+
"browser": "polyfill",
|
|
92
|
+
"nativescript": "polyfill"
|
|
93
|
+
},
|
|
77
94
|
"./main-loop": {
|
|
78
95
|
"gjs": "polyfill",
|
|
79
96
|
"node": "polyfill",
|
|
80
97
|
"browser": "polyfill",
|
|
81
98
|
"nativescript": "polyfill"
|
|
99
|
+
},
|
|
100
|
+
"./native-library": {
|
|
101
|
+
"gjs": "polyfill",
|
|
102
|
+
"node": "polyfill",
|
|
103
|
+
"browser": "polyfill",
|
|
104
|
+
"nativescript": "polyfill"
|
|
82
105
|
}
|
|
83
106
|
},
|
|
84
107
|
"os": {
|