@linxiraos/pi-utils 1.1.3 → 1.1.5
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/CHANGELOG.md +4 -0
- package/dist/types/dirs.d.ts +5 -0
- package/dist/types/json.d.ts +6 -0
- package/package.json +2 -2
- package/src/browsers.ts +14 -2
- package/src/dirs.ts +9 -0
- package/src/json.ts +23 -0
package/CHANGELOG.md
CHANGED
package/dist/types/dirs.d.ts
CHANGED
|
@@ -189,6 +189,11 @@ export declare function getGpuCachePath(): string;
|
|
|
189
189
|
* cache file without touching the rest of the config root.
|
|
190
190
|
*/
|
|
191
191
|
export declare function getGithubCacheDbPath(): string;
|
|
192
|
+
/**
|
|
193
|
+
* Get the conventional commit inference cache database path (~/.omp/cache/commit-inference.db).
|
|
194
|
+
* Honors `OMP_COMMIT_CACHE_DB` so tests and operators can isolate the cache.
|
|
195
|
+
*/
|
|
196
|
+
export declare function getCommitCacheDbPath(): string;
|
|
192
197
|
/** Get the legacy Pi extension parse cache database path. */
|
|
193
198
|
export declare function getLegacyPiExtensionCacheDbPath(): string;
|
|
194
199
|
/**
|
package/dist/types/json.d.ts
CHANGED
|
@@ -12,3 +12,9 @@ export declare function tryParseJson<T = unknown>(content: string): T | null;
|
|
|
12
12
|
* only lossless JSON representation.
|
|
13
13
|
*/
|
|
14
14
|
export declare function stringifyJson(value: unknown, space?: string | number): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Deterministically serialize JSON-shaped data by sorting object keys at every
|
|
17
|
+
* depth while preserving array order. Throws for values JSON cannot represent
|
|
18
|
+
* as a top-level value instead of returning an easy-to-misuse undefined.
|
|
19
|
+
*/
|
|
20
|
+
export declare function stableStringifyJson(value: unknown): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@linxiraos/pi-utils",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.5",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
6
|
"homepage": "https://linxira-os.github.io/zeta/",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"fmt": "biome format --write ."
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@linxiraos/pi-natives": "1.1.
|
|
34
|
+
"@linxiraos/pi-natives": "1.1.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/bun": "^1.3.14"
|
package/src/browsers.ts
CHANGED
|
@@ -4,11 +4,23 @@ import type * as fs from "node:fs";
|
|
|
4
4
|
import * as fsp from "node:fs/promises";
|
|
5
5
|
import * as os from "node:os";
|
|
6
6
|
import * as path from "node:path";
|
|
7
|
-
import { extractArchive } from "./ar";
|
|
7
|
+
import { type ArchiveLimits, extractArchive } from "./ar";
|
|
8
8
|
|
|
9
9
|
const CHROME_FOR_TESTING_BASE_URL = "https://storage.googleapis.com/chrome-for-testing-public";
|
|
10
10
|
const CHROME_METADATA_BASE_URL = "https://googlechromelabs.github.io/chrome-for-testing";
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Archive ceilings for the managed browser download. The default archive
|
|
14
|
+
* limits (64 MiB per member / 256 MiB in memory) guard against attacker-
|
|
15
|
+
* controlled archives, but the Chrome-for-Testing binary is a trusted
|
|
16
|
+
* first-party download whose `chrome` executable already exceeds both
|
|
17
|
+
* (~269 MB and growing), so extraction gets a ceiling sized for it.
|
|
18
|
+
*/
|
|
19
|
+
const BROWSER_ARCHIVE_LIMITS: Partial<ArchiveLimits> = {
|
|
20
|
+
maxMemberSize: 1024 * 1024 * 1024,
|
|
21
|
+
maxInMemorySize: 1024 * 1024 * 1024,
|
|
22
|
+
};
|
|
23
|
+
|
|
12
24
|
/** Supported browser products. */
|
|
13
25
|
export enum Browser {
|
|
14
26
|
CHROME = "chrome",
|
|
@@ -242,7 +254,7 @@ export async function install(options: InstallOptions): Promise<InstalledBrowser
|
|
|
242
254
|
archivePath,
|
|
243
255
|
options.downloadProgressCallback,
|
|
244
256
|
);
|
|
245
|
-
await extractArchive(archivePath, stagingPath);
|
|
257
|
+
await extractArchive(archivePath, stagingPath, { limits: BROWSER_ARCHIVE_LIMITS });
|
|
246
258
|
await fsp.mkdir(path.dirname(installPath), { recursive: true });
|
|
247
259
|
await fsp.rm(installPath, { recursive: true, force: true });
|
|
248
260
|
await fsp.rename(stagingPath, installPath);
|
package/src/dirs.ts
CHANGED
|
@@ -699,6 +699,15 @@ export function getGithubCacheDbPath(): string {
|
|
|
699
699
|
if (override) return override;
|
|
700
700
|
return dirs.rootSubdir(path.join("cache", "github-cache.db"), "cache");
|
|
701
701
|
}
|
|
702
|
+
/**
|
|
703
|
+
* Get the conventional commit inference cache database path (~/.omp/cache/commit-inference.db).
|
|
704
|
+
* Honors `OMP_COMMIT_CACHE_DB` so tests and operators can isolate the cache.
|
|
705
|
+
*/
|
|
706
|
+
export function getCommitCacheDbPath(): string {
|
|
707
|
+
const override = process.env.OMP_COMMIT_CACHE_DB;
|
|
708
|
+
if (override) return override;
|
|
709
|
+
return dirs.rootSubdir(path.join("cache", "commit-inference.db"), "cache");
|
|
710
|
+
}
|
|
702
711
|
|
|
703
712
|
/** Get the legacy Pi extension parse cache database path. */
|
|
704
713
|
export function getLegacyPiExtensionCacheDbPath(): string {
|
package/src/json.ts
CHANGED
|
@@ -21,3 +21,26 @@ export function tryParseJson<T = unknown>(content: string): T | null {
|
|
|
21
21
|
export function stringifyJson(value: unknown, space?: string | number): string | undefined {
|
|
22
22
|
return JSON.stringify(value, (_key, item) => (typeof item === "bigint" ? item.toString() : item), space);
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
function stableJsonClone(value: unknown): unknown {
|
|
26
|
+
if (Array.isArray(value)) return value.map(stableJsonClone);
|
|
27
|
+
if (value !== null && typeof value === "object") {
|
|
28
|
+
const sorted = Object.create(null) as Record<string, unknown>;
|
|
29
|
+
for (const key of Object.keys(value).sort()) {
|
|
30
|
+
sorted[key] = stableJsonClone(Reflect.get(value, key));
|
|
31
|
+
}
|
|
32
|
+
return sorted;
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Deterministically serialize JSON-shaped data by sorting object keys at every
|
|
39
|
+
* depth while preserving array order. Throws for values JSON cannot represent
|
|
40
|
+
* as a top-level value instead of returning an easy-to-misuse undefined.
|
|
41
|
+
*/
|
|
42
|
+
export function stableStringifyJson(value: unknown): string {
|
|
43
|
+
const serialized = JSON.stringify(stableJsonClone(value));
|
|
44
|
+
if (serialized === undefined) throw new TypeError("Value is not JSON-serializable");
|
|
45
|
+
return serialized;
|
|
46
|
+
}
|