camoucore 0.3.0 → 0.6.1

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.
Files changed (168) hide show
  1. package/LICENSE +4 -3
  2. package/dist/camoufox/__main__.d.ts +10 -0
  3. package/dist/camoufox/__main__.js +1175 -0
  4. package/dist/camoufox/__version__.d.ts +31 -0
  5. package/dist/camoufox/__version__.js +32 -0
  6. package/dist/camoufox/_humanize_playwright.d.ts +54 -0
  7. package/dist/camoufox/_humanize_playwright.js +429 -0
  8. package/dist/camoufox/addons.d.ts +21 -0
  9. package/dist/camoufox/addons.js +56 -0
  10. package/dist/camoufox/async_api.d.ts +9 -0
  11. package/dist/camoufox/async_api.js +9 -0
  12. package/dist/camoufox/browser-pin.d.ts +46 -0
  13. package/dist/camoufox/browser-pin.js +96 -0
  14. package/dist/camoufox/cli.d.ts +7 -0
  15. package/dist/camoufox/cli.js +20 -0
  16. package/dist/camoufox/coherence.d.ts +141 -0
  17. package/dist/camoufox/coherence.js +708 -0
  18. package/dist/camoufox/data-files/browser-pin.json +7 -0
  19. package/dist/camoufox/data-files/essential-fonts.json +5 -0
  20. package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
  21. package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
  22. package/dist/camoufox/data-files/font-bases.json +1887 -0
  23. package/dist/camoufox/data-files/font-groups.json +716 -0
  24. package/dist/camoufox/data-files/fonts.json +240 -0
  25. package/dist/camoufox/data-files/fpgen.yml +44 -0
  26. package/dist/camoufox/data-files/launcher-constants.json +66 -0
  27. package/dist/camoufox/data-files/media-devices.json +148 -0
  28. package/dist/camoufox/data-files/repos.yml +40 -0
  29. package/dist/camoufox/data-files/voice-manifests.json +1864 -0
  30. package/dist/camoufox/data-files/voice-uris.json +188 -0
  31. package/dist/camoufox/data-files/warnings.yml +132 -0
  32. package/dist/camoufox/display_profile.d.ts +17 -0
  33. package/dist/camoufox/display_profile.js +72 -0
  34. package/dist/camoufox/driver_defaults.d.ts +25 -0
  35. package/dist/camoufox/driver_defaults.js +114 -0
  36. package/dist/camoufox/exceptions.d.ts +78 -0
  37. package/dist/camoufox/exceptions.js +135 -0
  38. package/dist/camoufox/fingerprints.d.ts +341 -0
  39. package/dist/camoufox/fingerprints.js +1682 -0
  40. package/dist/camoufox/gpudisplay.d.ts +158 -0
  41. package/dist/camoufox/gpudisplay.js +695 -0
  42. package/dist/camoufox/host_rendering.d.ts +38 -0
  43. package/dist/camoufox/host_rendering.js +180 -0
  44. package/dist/camoufox/humanize.d.ts +89 -0
  45. package/dist/camoufox/humanize.js +143 -0
  46. package/dist/camoufox/index.d.ts +21 -0
  47. package/dist/camoufox/index.js +21 -0
  48. package/dist/camoufox/ip.d.ts +45 -0
  49. package/dist/camoufox/ip.js +114 -0
  50. package/dist/camoufox/multiversion.d.ts +131 -0
  51. package/dist/camoufox/multiversion.js +489 -0
  52. package/dist/camoufox/node-floor.d.ts +5 -0
  53. package/dist/camoufox/node-floor.js +17 -0
  54. package/dist/camoufox/paths.d.ts +45 -0
  55. package/dist/camoufox/paths.js +59 -0
  56. package/dist/camoufox/pkgman.d.ts +331 -0
  57. package/dist/camoufox/pkgman.js +972 -0
  58. package/dist/camoufox/product.d.ts +8 -0
  59. package/dist/camoufox/product.js +8 -0
  60. package/dist/camoufox/pycompat.d.ts +97 -0
  61. package/dist/camoufox/pycompat.js +458 -0
  62. package/dist/camoufox/server.d.ts +36 -0
  63. package/dist/camoufox/server.js +82 -0
  64. package/dist/camoufox/sync_api.d.ts +77 -0
  65. package/dist/camoufox/sync_api.js +194 -0
  66. package/dist/camoufox/utils.d.ts +515 -0
  67. package/dist/camoufox/utils.js +1995 -0
  68. package/dist/camoufox/warnings.d.ts +16 -0
  69. package/dist/camoufox/warnings.js +65 -0
  70. package/dist/camoufox/webgl.d.ts +52 -0
  71. package/dist/camoufox/webgl.js +264 -0
  72. package/dist/camouwolf/__main__.d.ts +10 -0
  73. package/dist/camouwolf/__main__.js +1180 -0
  74. package/dist/camouwolf/__version__.d.ts +31 -0
  75. package/dist/camouwolf/__version__.js +32 -0
  76. package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
  77. package/dist/camouwolf/_humanize_playwright.js +427 -0
  78. package/dist/camouwolf/addons.d.ts +42 -0
  79. package/dist/camouwolf/addons.js +113 -0
  80. package/dist/camouwolf/async_api.d.ts +9 -0
  81. package/dist/camouwolf/async_api.js +9 -0
  82. package/dist/camouwolf/browser-pin.d.ts +46 -0
  83. package/dist/camouwolf/browser-pin.js +96 -0
  84. package/dist/camouwolf/cli.d.ts +7 -0
  85. package/dist/camouwolf/cli.js +20 -0
  86. package/dist/camouwolf/clienthints.d.ts +61 -0
  87. package/dist/camouwolf/clienthints.js +176 -0
  88. package/dist/camouwolf/coherence.d.ts +152 -0
  89. package/dist/camouwolf/coherence.js +554 -0
  90. package/dist/camouwolf/data-files/browser-pin.json +7 -0
  91. package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
  92. package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
  93. package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
  94. package/dist/camouwolf/data-files/data/properties.json +321 -0
  95. package/dist/camouwolf/data-files/data/system-colors.json +35 -0
  96. package/dist/camouwolf/data-files/data/ubo.json +6 -0
  97. package/dist/camouwolf/data-files/fpgen.yml +41 -0
  98. package/dist/camouwolf/data-files/launcher-constants.json +26 -0
  99. package/dist/camouwolf/data-files/repos.yml +23 -0
  100. package/dist/camouwolf/data-files/warnings.yml +96 -0
  101. package/dist/camouwolf/driver_defaults.d.ts +25 -0
  102. package/dist/camouwolf/driver_defaults.js +114 -0
  103. package/dist/camouwolf/exceptions.d.ts +95 -0
  104. package/dist/camouwolf/exceptions.js +150 -0
  105. package/dist/camouwolf/fingerprints.d.ts +227 -0
  106. package/dist/camouwolf/fingerprints.js +753 -0
  107. package/dist/camouwolf/gpudisplay.d.ts +171 -0
  108. package/dist/camouwolf/gpudisplay.js +711 -0
  109. package/dist/camouwolf/host_rendering.d.ts +18 -0
  110. package/dist/camouwolf/host_rendering.js +114 -0
  111. package/dist/camouwolf/humanize.d.ts +84 -0
  112. package/dist/camouwolf/humanize.js +128 -0
  113. package/dist/camouwolf/index.d.ts +22 -0
  114. package/dist/camouwolf/index.js +21 -0
  115. package/dist/camouwolf/multiversion.d.ts +131 -0
  116. package/dist/camouwolf/multiversion.js +491 -0
  117. package/dist/camouwolf/node-floor.d.ts +5 -0
  118. package/dist/camouwolf/node-floor.js +17 -0
  119. package/dist/camouwolf/paths.d.ts +34 -0
  120. package/dist/camouwolf/paths.js +58 -0
  121. package/dist/camouwolf/pkgman.d.ts +331 -0
  122. package/dist/camouwolf/pkgman.js +972 -0
  123. package/dist/camouwolf/product.d.ts +3 -0
  124. package/dist/camouwolf/product.js +3 -0
  125. package/dist/camouwolf/pycompat.d.ts +92 -0
  126. package/dist/camouwolf/pycompat.js +461 -0
  127. package/dist/camouwolf/server.d.ts +36 -0
  128. package/dist/camouwolf/server.js +81 -0
  129. package/dist/camouwolf/switches.d.ts +77 -0
  130. package/dist/camouwolf/switches.js +222 -0
  131. package/dist/camouwolf/sync_api.d.ts +84 -0
  132. package/dist/camouwolf/sync_api.js +173 -0
  133. package/dist/camouwolf/utils.d.ts +644 -0
  134. package/dist/camouwolf/utils.js +2057 -0
  135. package/dist/camouwolf/warnings.d.ts +14 -0
  136. package/dist/camouwolf/warnings.js +59 -0
  137. package/dist/camouwolf/webgl.d.ts +41 -0
  138. package/dist/camouwolf/webgl.js +198 -0
  139. package/dist/data.d.ts +1 -1
  140. package/dist/data.js +3 -3
  141. package/dist/download.js +1 -1
  142. package/dist/exceptions.d.ts +1 -1
  143. package/dist/exceptions.js +1 -1
  144. package/dist/geolocation.js +1 -1
  145. package/dist/host.js +1 -1
  146. package/dist/ip.js +1 -1
  147. package/dist/locales.js +1 -1
  148. package/dist/mcp/cli.d.ts +15 -0
  149. package/dist/mcp/cli.js +108 -0
  150. package/dist/mcp/index.d.ts +8 -0
  151. package/dist/mcp/index.js +8 -0
  152. package/dist/mcp/main.d.ts +2 -0
  153. package/dist/mcp/main.js +8 -0
  154. package/dist/mcp/secrets.d.ts +50 -0
  155. package/dist/mcp/secrets.js +193 -0
  156. package/dist/mcp/server.d.ts +48 -0
  157. package/dist/mcp/server.js +653 -0
  158. package/dist/mcp/tree.d.ts +10 -0
  159. package/dist/mcp/tree.js +36 -0
  160. package/dist/passthrough.d.ts +1 -1
  161. package/dist/product.js +1 -1
  162. package/dist/settings.js +1 -1
  163. package/dist/telemetry.d.ts +0 -1
  164. package/dist/telemetry.js +5 -4
  165. package/dist/virtdisplay.d.ts +1 -1
  166. package/dist/virtdisplay.js +1 -1
  167. package/dist/warnings.js +1 -1
  168. package/package.json +57 -13
@@ -0,0 +1,491 @@
1
+ /**
2
+ * Manager for handling multiple Camouwolf versions side by side.
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/multiversion.py.
5
+ */
6
+ import * as fs from "node:fs";
7
+ import * as os from "node:os";
8
+ import * as path from "node:path";
9
+ import { finished } from "node:stream/promises";
10
+ import { flattenSingleRoot, unzip, verifySha256 } from "../download.js";
11
+ import { effectivePin, pinMatches } from "./browser-pin.js";
12
+ import { INSTALL_DIR, OS_NAME, rprint } from "./paths.js";
13
+ // pkgman and multiversion are mutually dependent, exactly as the Python twin's
14
+ // function-local imports are. Every use of these sits inside a function body,
15
+ // so the ESM cycle resolves before any binding is read.
16
+ import { formatAssetDate, makeExecutable, RepoConfig, Version, } from "./pkgman.js";
17
+ import { comparePyStr } from "./pycompat.js";
18
+ export const BROWSERS_DIR = path.join(INSTALL_DIR, "browsers");
19
+ export const CONFIG_FILE = path.join(INSTALL_DIR, "config.json");
20
+ export const REPO_CACHE_FILE = path.join(INSTALL_DIR, "repo_cache.json");
21
+ export const COMPAT_FLAG = path.join(INSTALL_DIR, ".0.5_FLAG");
22
+ /**
23
+ * Load user config from disk, or return an empty object.
24
+ */
25
+ export function loadConfig() {
26
+ if (fs.existsSync(CONFIG_FILE)) {
27
+ try {
28
+ return JSON.parse(fs.readFileSync(CONFIG_FILE, "utf-8"));
29
+ }
30
+ catch {
31
+ // Corrupt config: treat as absent, exactly as the Python twin does.
32
+ }
33
+ }
34
+ return {};
35
+ }
36
+ /**
37
+ * Get the default repo's stable channel string (like official/stable).
38
+ */
39
+ export function getDefaultChannel() {
40
+ return `${RepoConfig.getDefaultName().toLowerCase()}/stable`;
41
+ }
42
+ /**
43
+ * Save user config to disk.
44
+ */
45
+ export function saveConfig(config) {
46
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
47
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
48
+ }
49
+ /**
50
+ * Load cached repo data from disk.
51
+ */
52
+ export function loadRepoCache() {
53
+ if (fs.existsSync(REPO_CACHE_FILE)) {
54
+ try {
55
+ return JSON.parse(fs.readFileSync(REPO_CACHE_FILE, "utf-8"));
56
+ }
57
+ catch {
58
+ // Corrupt cache: treat as absent.
59
+ }
60
+ }
61
+ return {};
62
+ }
63
+ /**
64
+ * Save repo cache to disk.
65
+ */
66
+ export function saveRepoCache(cache) {
67
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
68
+ fs.writeFileSync(REPO_CACHE_FILE, JSON.stringify(cache, null, 2));
69
+ }
70
+ /**
71
+ * Keep one cache entry per version-build, the newest by created_at.
72
+ */
73
+ export function latestPerBuild(versions) {
74
+ const best = new Map();
75
+ for (const v of versions) {
76
+ const key = `${v.version}-${v.build}`;
77
+ const cur = best.get(key);
78
+ if (!cur || (v.created_at ?? "") > (cur.created_at ?? "")) {
79
+ best.set(key, v);
80
+ }
81
+ }
82
+ return [...best.values()].sort((a, b) => {
83
+ const byVersion = comparePyStr(b.version, a.version);
84
+ if (byVersion !== 0)
85
+ return byVersion;
86
+ return comparePyStr(b.created_at ?? "", a.created_at ?? "");
87
+ });
88
+ }
89
+ /**
90
+ * Get the display name for a repo from the repo config, lowercased.
91
+ */
92
+ function getRepoName(githubRepo) {
93
+ for (const repo of RepoConfig.loadRepos()) {
94
+ if (repo.repos.includes(githubRepo)) {
95
+ return repo.name.toLowerCase();
96
+ }
97
+ }
98
+ return githubRepo.split("/")[0].toLowerCase();
99
+ }
100
+ /**
101
+ * Information about an installed Camouwolf version.
102
+ */
103
+ export class InstalledVersion {
104
+ repoName;
105
+ version;
106
+ path;
107
+ isActive;
108
+ isPrerelease;
109
+ assetId;
110
+ assetSize;
111
+ assetUpdatedAt;
112
+ sha256;
113
+ createdAt;
114
+ constructor(init) {
115
+ this.repoName = init.repoName;
116
+ this.version = init.version;
117
+ this.path = init.path;
118
+ this.isActive = init.isActive ?? false;
119
+ this.isPrerelease = init.isPrerelease ?? false;
120
+ this.assetId = init.assetId;
121
+ this.assetSize = init.assetSize;
122
+ this.assetUpdatedAt = init.assetUpdatedAt;
123
+ this.sha256 = init.sha256;
124
+ this.createdAt = init.createdAt;
125
+ }
126
+ /** Folder name, e.g. 150.0.2-beta.25-8020db3b. */
127
+ get folderName() {
128
+ return path.basename(this.path);
129
+ }
130
+ /** Path relative to INSTALL_DIR, e.g. browsers/official/150.0.2-beta.25. */
131
+ get relativePath() {
132
+ return `browsers/${this.repoName}/${this.folderName}`;
133
+ }
134
+ /** Channel display string (like official/stable/134.0.2-beta.20). */
135
+ get channelPath() {
136
+ const ctype = this.isPrerelease ? "prerelease" : "stable";
137
+ return `${this.repoName}/${ctype}/${this.version.fullString}`;
138
+ }
139
+ /**
140
+ * Compare with an available version and return change indicators.
141
+ */
142
+ getChanges(available) {
143
+ const changes = [];
144
+ if (this.isPrerelease && !available.isPrerelease) {
145
+ changes.push("prerelease -> stable");
146
+ }
147
+ else if (!this.isPrerelease && available.isPrerelease) {
148
+ changes.push("stable -> prerelease");
149
+ }
150
+ if (this.assetUpdatedAt && available.assetUpdatedAt) {
151
+ if (this.assetUpdatedAt !== available.assetUpdatedAt) {
152
+ changes.push("asset updated");
153
+ }
154
+ }
155
+ else if (this.assetSize && available.assetSize) {
156
+ if (this.assetSize !== available.assetSize) {
157
+ changes.push("asset updated");
158
+ }
159
+ }
160
+ return changes;
161
+ }
162
+ }
163
+ /**
164
+ * Install folder name with an optional sha8 suffix.
165
+ */
166
+ function versionFolderName(version, build, sha8 = "") {
167
+ const base = `${version}-${build}`;
168
+ return sha8 ? `${base}-${sha8}` : base;
169
+ }
170
+ /**
171
+ * The install folder for a catalog item: version-build-sha8/, else a legacy
172
+ * version-build/ when its sha matches or `count` says the item is unambiguous.
173
+ */
174
+ export function findInstall(versionBuild, sha256, installed, count = 1) {
175
+ const byFolder = new Map(installed.map((iv) => [iv.folderName, iv]));
176
+ const sha8 = (sha256 ?? "").slice(0, 8);
177
+ if (sha8) {
178
+ const exact = byFolder.get(`${versionBuild}-${sha8}`);
179
+ if (exact)
180
+ return exact;
181
+ }
182
+ const legacy = byFolder.get(versionBuild);
183
+ if (!legacy)
184
+ return null;
185
+ if (legacy.sha256) {
186
+ return legacy.sha256 === sha256 ? legacy : null;
187
+ }
188
+ return count <= 1 ? legacy : null;
189
+ }
190
+ /**
191
+ * Find an installed version by its build string.
192
+ */
193
+ function findInstalledByBuild(build, repoName) {
194
+ for (const v of listInstalled()) {
195
+ if (v.version.build === build && (!repoName || v.repoName === repoName)) {
196
+ return v;
197
+ }
198
+ }
199
+ return null;
200
+ }
201
+ /**
202
+ * Scan browsers/ for installed versions, sorted by repo then version descending.
203
+ */
204
+ export function listInstalled() {
205
+ const installed = [];
206
+ const active = loadConfig().active_version;
207
+ if (!fs.existsSync(BROWSERS_DIR))
208
+ return installed;
209
+ for (const repoEntry of fs.readdirSync(BROWSERS_DIR, {
210
+ withFileTypes: true,
211
+ })) {
212
+ if (!repoEntry.isDirectory() || repoEntry.name.startsWith("."))
213
+ continue;
214
+ const repoDir = path.join(BROWSERS_DIR, repoEntry.name);
215
+ for (const versionEntry of fs.readdirSync(repoDir, {
216
+ withFileTypes: true,
217
+ })) {
218
+ if (!versionEntry.isDirectory())
219
+ continue;
220
+ const versionDir = path.join(repoDir, versionEntry.name);
221
+ const versionJson = path.join(versionDir, "version.json");
222
+ if (!fs.existsSync(versionJson))
223
+ continue;
224
+ try {
225
+ const ver = Version.fromPath(versionDir);
226
+ const versionData = JSON.parse(fs.readFileSync(versionJson, "utf-8"));
227
+ const relPath = `browsers/${repoEntry.name}/${versionEntry.name}`;
228
+ installed.push(new InstalledVersion({
229
+ repoName: repoEntry.name,
230
+ version: ver,
231
+ path: versionDir,
232
+ isActive: relPath === active,
233
+ isPrerelease: versionData.prerelease ?? false,
234
+ assetId: versionData.asset_id,
235
+ assetSize: versionData.asset_size,
236
+ assetUpdatedAt: versionData.asset_updated_at,
237
+ sha256: versionData.sha256,
238
+ createdAt: versionData.created_at,
239
+ }));
240
+ }
241
+ catch {
242
+ // Missing/corrupt version.json: not an install we can use.
243
+ }
244
+ }
245
+ }
246
+ installed.sort((a, b) => {
247
+ const byRepo = comparePyStr(b.repoName, a.repoName);
248
+ if (byRepo !== 0)
249
+ return byRepo;
250
+ return b.version.compare(a.version);
251
+ });
252
+ return installed;
253
+ }
254
+ /**
255
+ * Get the path to the active version, or null if no version is active.
256
+ */
257
+ export function getActivePath() {
258
+ const config = loadConfig();
259
+ const active = config.active_version;
260
+ // A released library launches the build it was released with, whatever
261
+ // happens to be marked active, unless the user explicitly chose otherwise.
262
+ const pin = effectivePin(config);
263
+ if (pin) {
264
+ for (const inst of listInstalled()) {
265
+ if (pinMatches(pin, inst.repoName, inst.version.version ?? "", inst.version.build)) {
266
+ if (active !== inst.relativePath) {
267
+ config.active_version = inst.relativePath;
268
+ saveConfig(config);
269
+ }
270
+ return inst.path;
271
+ }
272
+ }
273
+ return null;
274
+ }
275
+ if (active) {
276
+ const activePath = path.join(INSTALL_DIR, active);
277
+ if (fs.existsSync(activePath) &&
278
+ fs.existsSync(path.join(activePath, "version.json"))) {
279
+ return activePath;
280
+ }
281
+ }
282
+ // Only auto-select if the user didn't set a channel or pin
283
+ if (!config.channel && !config.pinned) {
284
+ const installed = listInstalled();
285
+ if (installed.length) {
286
+ config.active_version = installed[0].relativePath;
287
+ saveConfig(config);
288
+ return installed[0].path;
289
+ }
290
+ }
291
+ return null;
292
+ }
293
+ /**
294
+ * Set the active version by its relative path.
295
+ */
296
+ export function setActive(relativePath) {
297
+ const config = loadConfig();
298
+ config.active_version = relativePath;
299
+ saveConfig(config);
300
+ }
301
+ /**
302
+ * Find an installed version by path, build, full version, or repo/build.
303
+ */
304
+ export function findInstalledVersion(specifier) {
305
+ const installed = listInstalled();
306
+ if (!installed.length)
307
+ return null;
308
+ const lower = specifier.toLowerCase();
309
+ for (const v of installed) {
310
+ if (v.relativePath === specifier ||
311
+ v.relativePath === `browsers/${specifier}`) {
312
+ return v.path;
313
+ }
314
+ if (`browsers/${v.repoName}/${v.version.fullString}`.endsWith(specifier) ||
315
+ `${v.repoName}/${v.version.build}`.toLowerCase() === lower ||
316
+ v.version.build.toLowerCase() === lower ||
317
+ v.version.fullString.toLowerCase() === lower ||
318
+ v.version.version?.toLowerCase() === lower) {
319
+ return v.path;
320
+ }
321
+ }
322
+ return null;
323
+ }
324
+ /**
325
+ * Install to browsers/{repoName}/{version}-{build}-{sha8}; the suffix is
326
+ * omitted when the release carries no sha.
327
+ */
328
+ export async function installVersioned(fetcher, replace = false) {
329
+ const repoName = getRepoName(fetcher.githubRepo);
330
+ const sha8 = fetcher._selectedVersion?.sha256
331
+ ? fetcher._selectedVersion.sha8
332
+ : fetcher.installedSha8;
333
+ const versionFolder = versionFolderName(fetcher.version, fetcher.build, sha8);
334
+ const installPath = path.join(BROWSERS_DIR, repoName, versionFolder);
335
+ if (fs.existsSync(installPath) &&
336
+ fs.existsSync(path.join(installPath, "version.json"))) {
337
+ if (!replace) {
338
+ const installedV = findInstalledByBuild(fetcher.build, repoName);
339
+ let changeMsg = "";
340
+ if (installedV && fetcher._selectedVersion) {
341
+ const changes = installedV.getChanges(fetcher._selectedVersion);
342
+ if (changes.length)
343
+ changeMsg = ` (${changes.join(", ")})`;
344
+ }
345
+ rprint(`Version v${fetcher.verstr} already installed${changeMsg}.`, "yellow");
346
+ rprint(changeMsg
347
+ ? "Use --replace to update with the new release."
348
+ : "Use --replace to reinstall.", "yellow");
349
+ if (!loadConfig().active_version) {
350
+ setActive(`browsers/${repoName}/${versionFolder}`);
351
+ }
352
+ return false;
353
+ }
354
+ rprint(`Replacing: ${installPath}`, "yellow");
355
+ fs.rmSync(installPath, { recursive: true, force: true });
356
+ }
357
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "camouwolf-"));
358
+ const tempFilePath = path.join(tempDir, "camouwolf.zip");
359
+ try {
360
+ fs.mkdirSync(installPath, { recursive: true });
361
+ const tempFileStream = fs.createWriteStream(tempFilePath);
362
+ // finished() listens for the stream's 'error' from the start. Without a
363
+ // listener, a failed write (disk full) is an uncaught 'error' event that
364
+ // kills the process before the catch below can remove the partial
365
+ // install.
366
+ const written = finished(tempFileStream);
367
+ written.catch(() => { }); // awaited below; a download error wins
368
+ try {
369
+ // Through the instance's class, as Python's fetcher.download_file(),
370
+ // so a subclass can override it.
371
+ await fetcher.constructor.downloadFile(tempFileStream, fetcher.url);
372
+ }
373
+ finally {
374
+ tempFileStream.end();
375
+ }
376
+ await written;
377
+ const expectedSha = fetcher._selectedVersion
378
+ ? fetcher._selectedVersion.sha256
379
+ : fetcher.installedSha256;
380
+ verifySha256(tempFilePath, expectedSha, `Camouwolf v${fetcher.verstr}`);
381
+ rprint(`Extracting Camouwolf: ${installPath}`);
382
+ unzip(tempFilePath, installPath);
383
+ flattenSingleRoot(installPath);
384
+ const metadata = fetcher._selectedVersion
385
+ ? fetcher._selectedVersion.toMetadata()
386
+ : {
387
+ version: fetcher.version,
388
+ build: fetcher.build,
389
+ prerelease: fetcher.isPrerelease,
390
+ sha256: fetcher.installedSha256 ?? null,
391
+ created_at: fetcher.installedCreatedAt ?? null,
392
+ interface: fetcher.installedInterface,
393
+ };
394
+ fs.writeFileSync(path.join(installPath, "version.json"), JSON.stringify(metadata));
395
+ if (OS_NAME !== "win") {
396
+ makeExecutable(installPath);
397
+ }
398
+ setActive(`browsers/${repoName}/${versionFolder}`);
399
+ // Mark the install dir as compatible with this version
400
+ fs.writeFileSync(COMPAT_FLAG, "");
401
+ rprint(`\nCamouwolf v${fetcher.verstr} installed.`, "green");
402
+ rprint(`Path: ${installPath}`, "green");
403
+ return true;
404
+ }
405
+ catch (error) {
406
+ rprint(`Error: ${error}`, "red");
407
+ if (fs.existsSync(installPath)) {
408
+ fs.rmSync(installPath, { recursive: true, force: true });
409
+ }
410
+ throw error;
411
+ }
412
+ finally {
413
+ fs.rmSync(tempDir, { recursive: true, force: true });
414
+ }
415
+ }
416
+ /**
417
+ * Remove a specific version installation.
418
+ */
419
+ export function removeVersion(versionPath) {
420
+ if (!fs.existsSync(versionPath))
421
+ return false;
422
+ rprint(`Removing: ${versionPath}`);
423
+ fs.rmSync(versionPath, { recursive: true, force: true });
424
+ const parent = path.dirname(versionPath);
425
+ if (fs.existsSync(parent) &&
426
+ parent !== BROWSERS_DIR &&
427
+ fs.readdirSync(parent).length === 0) {
428
+ fs.rmdirSync(parent);
429
+ }
430
+ if (fs.existsSync(BROWSERS_DIR) &&
431
+ fs.readdirSync(BROWSERS_DIR).length === 0) {
432
+ fs.rmdirSync(BROWSERS_DIR);
433
+ }
434
+ const config = loadConfig();
435
+ const relPath = path.relative(INSTALL_DIR, versionPath);
436
+ if (!relPath.startsWith("..") && config.active_version === relPath) {
437
+ const remaining = listInstalled();
438
+ config.active_version = remaining.length ? remaining[0].relativePath : null;
439
+ saveConfig(config);
440
+ }
441
+ return true;
442
+ }
443
+ /**
444
+ * Short tag to tell coexisting installs apart: date, else sha8.
445
+ */
446
+ export function installedLabel(iv) {
447
+ if (iv.createdAt) {
448
+ const date = formatAssetDate(iv.createdAt);
449
+ if (date)
450
+ return date;
451
+ }
452
+ return (iv.sha256 ?? "").slice(0, 8);
453
+ }
454
+ /**
455
+ * Print installed versions as a tree.
456
+ */
457
+ export function printTree(showHeader = true, showPaths = false) {
458
+ const installed = listInstalled();
459
+ if (!installed.length) {
460
+ rprint("No versions installed.", "yellow");
461
+ rprint("Run `camouwolf fetch` to install.", "yellow");
462
+ return;
463
+ }
464
+ if (showHeader) {
465
+ rprint("Installed versions:\n", "yellow");
466
+ }
467
+ let currentRepo = null;
468
+ for (let i = 0; i < installed.length; i++) {
469
+ const v = installed[i];
470
+ const isLast = i === installed.length - 1 || installed[i + 1].repoName !== v.repoName;
471
+ if (v.repoName !== currentRepo) {
472
+ currentRepo = v.repoName;
473
+ rprint(`${currentRepo}/`, "cyan", false);
474
+ if (showPaths) {
475
+ rprint(` -> ${path.join(BROWSERS_DIR, currentRepo)}`, "bright_black");
476
+ }
477
+ else {
478
+ rprint("");
479
+ }
480
+ }
481
+ rprint(` ${isLast ? "└── " : "├── "}`, undefined, false);
482
+ rprint(`v${v.version.fullString}`, v.isActive ? "green" : undefined, false);
483
+ rprint(v.isPrerelease ? " (prerelease)" : " (stable)", v.isPrerelease ? "yellow" : "blue", false);
484
+ const tag = installedLabel(v);
485
+ if (tag)
486
+ rprint(` (${tag})`, "bright_black", false);
487
+ if (v.isActive)
488
+ rprint(" (active)", "green", false);
489
+ rprint("");
490
+ }
491
+ }
@@ -0,0 +1,5 @@
1
+ export declare const NODE_FLOOR = "22.15";
2
+ /** Throws, naming the floor and this runtime, when node:zlib has no zstd. */
3
+ export declare function assertNodeFloor(z?: {
4
+ zstdDecompressSync?: unknown;
5
+ }, version?: string): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The Node.js floor (package.json `engines.node`), checked when the package
3
+ * loads. fpgen-js reads its model archive with node:zlib's zstd;
4
+ * Node.js added zstd in 22.15. Below that the first
5
+ * fingerprint draw died with "zlib.zstdDecompressSync is not a function" from
6
+ * inside fpgen-js; npm only warns on `engines`, so the package says it here.
7
+ */
8
+ import * as zlib from "node:zlib";
9
+ export const NODE_FLOOR = "22.15";
10
+ /** Throws, naming the floor and this runtime, when node:zlib has no zstd. */
11
+ export function assertNodeFloor(z = zlib, version = process.versions.node) {
12
+ if (typeof z.zstdDecompressSync !== "function") {
13
+ throw new Error(`camouwolf needs Node.js >= ${NODE_FLOOR} (node:zlib zstd, which the ` +
14
+ `fpgen model archive needs); this is Node.js ${version}.`);
15
+ }
16
+ }
17
+ assertNodeFloor();
@@ -0,0 +1,34 @@
1
+ export { rprint, style } from "../download.js";
2
+ export { ARCH_MAP, OS_MAP, OS_NAME } from "../host.js";
3
+ export declare const INSTALL_DIR: string;
4
+ /**
5
+ * The data files both launchers read. They live in python/camoucore/src/camoucore/camouwolf/, the one
6
+ * copy in the repo; `pnpm build` copies them into dist/data-files/ for the npm
7
+ * tarball, so one seed draws one identity in either launcher.
8
+ */
9
+ export declare const DATA_FILES: readonly string[];
10
+ /**
11
+ * Where DATA_FILES are read from: dist/data-files/ in a built package, else
12
+ * python/camoucore/src/camoucore/camouwolf/ itself when running from src/ in the repo.
13
+ */
14
+ export declare const LOCAL_DATA: string;
15
+ /** camouwolf.defaults.json: the documented default of each launch option. */
16
+ export declare const DEFAULTS_FILE: string;
17
+ /** A data file (relative to LOCAL_DATA), parsed as YAML or JSON by its extension. */
18
+ export declare function loadDataFile<T = any>(file: string): T;
19
+ /** Values both launchers use, kept in one file (python/camoucore/src/camoucore/camouwolf/launcher-constants.json). */
20
+ export interface LauncherConstants {
21
+ plausibleCoreCounts: number[];
22
+ appleSiliconCores: number[];
23
+ intelMacIgpCores: number[];
24
+ intelMacDgpuExtraCores: number[];
25
+ appleSiliconPanels: Record<string, [number, number][]>;
26
+ taskbarHeight: Record<"win" | "mac" | "lin", number>;
27
+ plausibleDpr: Record<"win" | "mac" | "lin", number[]>;
28
+ essentialFonts: Record<"win" | "mac" | "lin", string[]>;
29
+ cpuManufacturers: Record<"win" | "mac" | "lin", Record<string, string[]>>;
30
+ intelOnlyCoreCounts: number[];
31
+ }
32
+ export declare const LAUNCHER_CONSTANTS: Readonly<LauncherConstants>;
33
+ export declare const OS_ARCH_MATRIX: Record<string, string[]>;
34
+ export declare const LAUNCH_FILE: Record<string, string>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Platform constants, install paths and the bundled data files. A leaf of the
3
+ * module graph: pkgman.ts and multiversion.ts import each other, and both need
4
+ * these values while they are still being evaluated.
5
+ */
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ import { setModelDir } from "fpgen-js";
9
+ import { parse as parseYaml } from "yaml";
10
+ import { PRODUCT } from "./product.js";
11
+ export { rprint, style } from "../download.js";
12
+ export { ARCH_MAP, OS_MAP, OS_NAME } from "../host.js";
13
+ export const INSTALL_DIR = PRODUCT.cacheDir;
14
+ /**
15
+ * The data files both launchers read. They live in python/camoucore/src/camoucore/camouwolf/, the one
16
+ * copy in the repo; `pnpm build` copies them into dist/data-files/ for the npm
17
+ * tarball, so one seed draws one identity in either launcher.
18
+ */
19
+ export const DATA_FILES = [
20
+ "browser-pin.json",
21
+ "camouwolf.defaults.json",
22
+ "data/bundle-fonts.json",
23
+ "data/chrome-languages.json",
24
+ "data/properties.json",
25
+ "data/system-colors.json",
26
+ "data/ubo.json",
27
+ "fpgen.yml",
28
+ "launcher-constants.json",
29
+ "repos.yml",
30
+ "warnings.yml",
31
+ ];
32
+ /**
33
+ * Where DATA_FILES are read from: dist/data-files/ in a built package, else
34
+ * python/camoucore/src/camoucore/camouwolf/ itself when running from src/ in the repo.
35
+ */
36
+ export const LOCAL_DATA = fs.existsSync(path.join(import.meta.dirname, "data-files"))
37
+ ? path.join(import.meta.dirname, "data-files")
38
+ : path.resolve(import.meta.dirname, "..", "..", "..", "..", "python", "camoucore", "src", "camoucore", "camouwolf");
39
+ /** camouwolf.defaults.json: the documented default of each launch option. */
40
+ export const DEFAULTS_FILE = path.join(LOCAL_DATA, "camouwolf.defaults.json");
41
+ /** A data file (relative to LOCAL_DATA), parsed as YAML or JSON by its extension. */
42
+ export function loadDataFile(file) {
43
+ const text = fs.readFileSync(path.resolve(LOCAL_DATA, file), "utf-8");
44
+ return (file.endsWith(".yml") ? parseYaml(text) : JSON.parse(text));
45
+ }
46
+ export const LAUNCHER_CONSTANTS = loadDataFile("launcher-constants.json");
47
+ // Camouwolf keeps the fpgen model in its cache, beside the browsers.
48
+ setModelDir(process.env.CAMOUWOLF_FPGEN_DATA || path.join(INSTALL_DIR, "fpgen"));
49
+ export const OS_ARCH_MATRIX = {
50
+ win: ["x86_64", "i686"],
51
+ mac: ["x86_64", "arm64"],
52
+ lin: ["x86_64", "arm64", "i686"],
53
+ };
54
+ export const LAUNCH_FILE = {
55
+ win: "camouwolf.exe",
56
+ mac: "../MacOS/camouwolf",
57
+ lin: "camouwolf",
58
+ };