@gjsify/utils 0.38.0 → 0.39.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/index.js +1 -1
- package/lib/esm/path-shape.js +1 -0
- package/lib/esm/system-gi-dirs.js +1 -0
- package/lib/types/core.d.ts +2 -0
- package/lib/types/path-shape.d.ts +57 -0
- package/lib/types/system-gi-dirs.d.ts +44 -0
- package/package.json +2 -2
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{
|
|
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,splitSearchPath as E,systemGiLibraryDirs as D}from"./system-gi-dirs.js";import{mapMachine as O,mapSysname as k}from"./platform-names.js";import{structuredClone as A}from"./structured-clone.js";import{hasProcfs as j,hostExecPath as M,hostPid as N,hostPpid as P,readProcessMemory as F}from"./host-process.js";import{ensureMainLoop as I,quitMainLoop as L}from"./main-loop.js";import{__resetBurstStateForTests as R,nextTick as z}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,R as __resetBurstStateForTests,a as createGLibFileError,o as createNodeError,t as deferEmit,y as encodePathForFileUrl,I as ensureMainLoop,j as hasProcfs,M as hostExecPath,u as hostOs,N as hostPid,d as hostPlatform,P 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,O as mapMachine,k as mapSysname,z as nextTick,g as notImplemented,S as pathToFileUrlHref,v as queueMicrotask,L as quitMainLoop,F as readProcessMemory,c as registerGlobal,C as splitPathComponents,E as splitSearchPath,A as structuredClone,D as systemGiLibraryDirs,_ as warnNotImplemented};
|
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{
|
|
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,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,hostExecPath as P,hostPid as F,hostPpid as I,readProcessMemory as L}from"./host-process.js";import{ensureMainLoop as R,quitMainLoop as z}from"./main-loop.js";import{__resetBurstStateForTests as B,nextTick as V}from"./next-tick.js";import"./core.js";import{readJSON as H}from"./file.js";import{existsFD as U,existsSync as W}from"./fs.js";import{gioAsync as G,inputStreamAsyncIterator as K,readBytesAsync as q}from"./gio.js";import{getNodeModulesPath as J,getPathSeparator as Y,getProgramDir as X,getProgramExe as Z,resolve as Q}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,B as __resetBurstStateForTests,n as cli,s as createGLibFileError,c as createNodeError,r as deferEmit,x as encodePathForFileUrl,R as ensureMainLoop,U as existsFD,W as existsSync,e as gbytesToUint8Array,J as getNodeModulesPath,Y as getPathSeparator,X as getProgramDir,Z as getProgramExe,G as gioAsync,N as hasProcfs,P as hostExecPath,f as hostOs,F as hostPid,p as hostPlatform,I as hostPpid,i as initErrorV8Methods,K 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,A as mapMachine,j as mapSysname,V as nextTick,v as notImplemented,w as pathToFileUrlHref,b as queueMicrotask,z as quitMainLoop,q as readBytesAsync,H as readJSON,L as readProcessMemory,u as registerGlobal,Q as resolve,T as splitPathComponents,O as splitSearchPath,M as structuredClone,k as systemGiLibraryDirs,y as warnNotImplemented};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function isWindowsPath(e){return/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`\\\\`)}function lastPathSeparatorIndex(e){let t=e.lastIndexOf(`/`);return isWindowsPath(e)?Math.max(t,e.lastIndexOf(`\\`)):t}function splitPathComponents(e){return isWindowsPath(e)?e.split(/[\\/]/):e.split(`/`)}function pathToFileUrlHref(e,t){let n=t?.windows??isWindowsPath(e),r=n?e.replace(/\\/g,`/`):e;if(n&&r.startsWith(`//`)){let e=r.indexOf(`/`,2);return`file://${e===-1?r.slice(2):r.slice(2,e)}${encodePathForFileUrl(e===-1?``:r.slice(e))}`}return`${r.startsWith(`/`)?`file://`:`file:///`}${encodePathForFileUrl(r)}`}function encodePathForFileUrl(t){let n=``;for(let r of t)n+=e.test(r)?r:percentEncode(r);return n}const e=/^[A-Za-z0-9!$&'()*+,\-./:;=@_]$/;function percentEncode(e){let t=``;for(let n of new TextEncoder().encode(e))t+=`%${n.toString(16).toUpperCase().padStart(2,`0`)}`;return t}export{encodePathForFileUrl,isWindowsPath,lastPathSeparatorIndex,pathToFileUrlHref,splitPathComponents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{lastPathSeparatorIndex as e,splitPathComponents as t}from"./path-shape.js";const n=`girepository-1.0`,r={darwin:[`/opt/homebrew/lib`,`/usr/local/lib`,`/opt/local/lib`]};function splitSearchPath(e,t=`:`){return(e??``).split(t).filter(Boolean)}function dirname(t){let n=e(t);return n<0?`.`:n===0?t.slice(0,1):t.slice(0,n)}function basename(e){let n=t(e).filter(Boolean);return n.length===0?``:n[n.length-1]}function systemGiLibraryDirs(e){let t=r[e.platform];if(!t)return[];let n=[],add=e=>{e&&e!==`/`&&!n.includes(e)&&n.push(e)};for(let t of splitSearchPath(e.typelibPath)){let n=dirname(t);e.existsDir(n)&&add(n)}let i=[];for(let t of e.pkgConfigDirs??[])basename(t)===`pkgconfig`&&i.push(dirname(t));i.push(...t);for(let t of i)e.existsDir(`${t}/girepository-1.0`)&&add(t);return n}export{r as PROBED_GI_LIBDIRS,n as TYPELIB_SUBDIR,splitSearchPath,systemGiLibraryDirs};
|
package/lib/types/core.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from './globals.js';
|
|
|
6
6
|
export * from './host-os.js';
|
|
7
7
|
export * from './message.js';
|
|
8
8
|
export * from './microtask.js';
|
|
9
|
+
export * from './path-shape.js';
|
|
10
|
+
export * from './system-gi-dirs.js';
|
|
9
11
|
export * from './platform-names.js';
|
|
10
12
|
export * from './structured-clone.js';
|
|
11
13
|
export * from './host-process.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A drive-letter absolute path (`C:\x`, `c:/x`) or a UNC path (`\\server\share\x`).
|
|
3
|
+
*
|
|
4
|
+
* Deliberately NOT "contains a backslash": `\` is a legal character in a POSIX
|
|
5
|
+
* filename, so `/tmp/we\ird` is a POSIX path and must keep being treated as one. A
|
|
6
|
+
* drive-letter or UNC prefix is the positive evidence; nothing else is.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isWindowsPath(path: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Index of the last path separator, or `-1` when the path has none.
|
|
11
|
+
*
|
|
12
|
+
* `\` counts only in a Windows-shaped path (see {@link isWindowsPath}). Returns an
|
|
13
|
+
* INDEX rather than a dirname on purpose — the four call sites this replaced each had
|
|
14
|
+
* their own established answer for "no separator" (`''`, `'.'`, return-the-input) and a
|
|
15
|
+
* shared `dirname` would have changed three of them while fixing the separator.
|
|
16
|
+
*/
|
|
17
|
+
export declare function lastPathSeparatorIndex(path: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* The path's components, in order, including empty ones — `split` on the separators
|
|
20
|
+
* this path actually uses, for callers that must inspect each component (`NAME_MAX`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function splitPathComponents(path: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* An ABSOLUTE path → the `file://` href naming it, percent-encoded.
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* /opt/app/dist → file:///opt/app/dist
|
|
28
|
+
* C:\app\dist → file:///C:/app/dist
|
|
29
|
+
* \\server\share\app → file://server/share/app
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The Windows forms are the WHATWG ones: a drive letter is part of the PATH behind an
|
|
33
|
+
* empty host (three slashes), while a UNC server is the URL's HOST. `new URL()` accepts
|
|
34
|
+
* `file://C:/x` and normalises it to `file:///C:/x` by the spec's drive-letter quirk,
|
|
35
|
+
* but relying on that would leave `\` unconverted, so both are spelled out here.
|
|
36
|
+
*
|
|
37
|
+
* @param options.windows force the win32 reading of a path whose shape does not say
|
|
38
|
+
* (a relative path, or `/foo` on a win32 host) — the same escape hatch Node added to
|
|
39
|
+
* `pathToFileURL` in v22 (`refs/node/lib/internal/url.js`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function pathToFileUrlHref(path: string, options?: {
|
|
42
|
+
windows?: boolean;
|
|
43
|
+
}): string;
|
|
44
|
+
/**
|
|
45
|
+
* Percent-encode a path for use as a URL path.
|
|
46
|
+
*
|
|
47
|
+
* An allowlist and not `encodeURI`, which leaves `#` and `?` intact — in a path those
|
|
48
|
+
* are DATA, and letting them through hands the caller a URL whose fragment or query is
|
|
49
|
+
* a piece of the filename.
|
|
50
|
+
*
|
|
51
|
+
* Iterated by CODE POINT, and encoded from UTF-8 bytes rather than with
|
|
52
|
+
* `encodeURIComponent`: fed one half of a surrogate pair that function raises
|
|
53
|
+
* `URIError: URI malformed`, so the index-based loop this replaced threw on every path
|
|
54
|
+
* containing a non-BMP character (an emoji, a CJK extension ideograph) instead of
|
|
55
|
+
* encoding it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function encodePathForFileUrl(path: string): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** The subdir GI installs typelibs into — historically `1.0` even for the girepository-2.0 API. */
|
|
2
|
+
export declare const TYPELIB_SUBDIR = "girepository-1.0";
|
|
3
|
+
/**
|
|
4
|
+
* Prefixes worth probing per platform, for the common case where GTK is installed
|
|
5
|
+
* and `pkg-config` is not.
|
|
6
|
+
*
|
|
7
|
+
* darwin only, and that is a statement about LOADERS rather than about GI. Linux
|
|
8
|
+
* resolves these leaves through `ld.so`'s system-wide cache (`/etc/ld.so.conf.d`),
|
|
9
|
+
* which a package install populates. dyld is the one loader that neither consults
|
|
10
|
+
* a system-wide config NOR re-reads its search path after launch. win32 is
|
|
11
|
+
* deliberately absent rather than proven unnecessary: `PATH` is the DLL search
|
|
12
|
+
* path, a Windows GTK distribution puts its own `bin` on it, and Windows re-reads
|
|
13
|
+
* it at every `LoadLibrary`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PROBED_GI_LIBDIRS: Readonly<Record<string, readonly string[]>>;
|
|
16
|
+
/** Split a `PATH`-shaped value. Empty entries dropped; `undefined` yields `[]`. */
|
|
17
|
+
export declare function splitSearchPath(value: string | undefined, separator?: string): string[];
|
|
18
|
+
export interface SystemGiLibraryDirsHost {
|
|
19
|
+
/** `process.platform`, or the platform being reasoned about. */
|
|
20
|
+
platform: string;
|
|
21
|
+
/** The host's `GI_TYPELIB_PATH`, unsplit. */
|
|
22
|
+
typelibPath?: string | undefined;
|
|
23
|
+
/** `pkg-config`'s `.pc` search directories, already resolved by the caller. */
|
|
24
|
+
pkgConfigDirs?: readonly string[];
|
|
25
|
+
/** Directory-existence predicate — the caller's `statSync` or a test double. */
|
|
26
|
+
existsDir: (dir: string) => boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Absolute library directories this platform's loader needs told about, or `[]`
|
|
30
|
+
* when it needs none.
|
|
31
|
+
*
|
|
32
|
+
* Three sources, in precedence order:
|
|
33
|
+
*
|
|
34
|
+
* 1. `GI_TYPELIB_PATH` — the host stating outright where typelibs live; the
|
|
35
|
+
* libraries are the sibling `dirname()`. Believed on directory existence
|
|
36
|
+
* alone, because an explicit statement is not second-guessed.
|
|
37
|
+
* 2. `pkg-config`'s `.pc` search path → each `<dir>/pkgconfig`'s parent. The
|
|
38
|
+
* general mechanism, covering a custom prefix.
|
|
39
|
+
* 3. {@link PROBED_GI_LIBDIRS}.
|
|
40
|
+
*
|
|
41
|
+
* Sources 2 and 3 are GUESSES at a prefix, so each must show the
|
|
42
|
+
* `girepository-1.0/` marker before it is believed. Source 1 is not a guess.
|
|
43
|
+
*/
|
|
44
|
+
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.39.0",
|
|
4
4
|
"description": "Utils module for gjsify",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"fs"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@gjsify/cli": "^0.
|
|
43
|
+
"@gjsify/cli": "^0.39.0",
|
|
44
44
|
"typescript": "^6.0.3"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|