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.
- package/LICENSE +4 -3
- package/dist/camoufox/__main__.d.ts +10 -0
- package/dist/camoufox/__main__.js +1175 -0
- package/dist/camoufox/__version__.d.ts +31 -0
- package/dist/camoufox/__version__.js +32 -0
- package/dist/camoufox/_humanize_playwright.d.ts +54 -0
- package/dist/camoufox/_humanize_playwright.js +429 -0
- package/dist/camoufox/addons.d.ts +21 -0
- package/dist/camoufox/addons.js +56 -0
- package/dist/camoufox/async_api.d.ts +9 -0
- package/dist/camoufox/async_api.js +9 -0
- package/dist/camoufox/browser-pin.d.ts +46 -0
- package/dist/camoufox/browser-pin.js +96 -0
- package/dist/camoufox/cli.d.ts +7 -0
- package/dist/camoufox/cli.js +20 -0
- package/dist/camoufox/coherence.d.ts +141 -0
- package/dist/camoufox/coherence.js +708 -0
- package/dist/camoufox/data-files/browser-pin.json +7 -0
- package/dist/camoufox/data-files/essential-fonts.json +5 -0
- package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
- package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
- package/dist/camoufox/data-files/font-bases.json +1887 -0
- package/dist/camoufox/data-files/font-groups.json +716 -0
- package/dist/camoufox/data-files/fonts.json +240 -0
- package/dist/camoufox/data-files/fpgen.yml +44 -0
- package/dist/camoufox/data-files/launcher-constants.json +66 -0
- package/dist/camoufox/data-files/media-devices.json +148 -0
- package/dist/camoufox/data-files/repos.yml +40 -0
- package/dist/camoufox/data-files/voice-manifests.json +1864 -0
- package/dist/camoufox/data-files/voice-uris.json +188 -0
- package/dist/camoufox/data-files/warnings.yml +132 -0
- package/dist/camoufox/display_profile.d.ts +17 -0
- package/dist/camoufox/display_profile.js +72 -0
- package/dist/camoufox/driver_defaults.d.ts +25 -0
- package/dist/camoufox/driver_defaults.js +114 -0
- package/dist/camoufox/exceptions.d.ts +78 -0
- package/dist/camoufox/exceptions.js +135 -0
- package/dist/camoufox/fingerprints.d.ts +341 -0
- package/dist/camoufox/fingerprints.js +1682 -0
- package/dist/camoufox/gpudisplay.d.ts +158 -0
- package/dist/camoufox/gpudisplay.js +695 -0
- package/dist/camoufox/host_rendering.d.ts +38 -0
- package/dist/camoufox/host_rendering.js +180 -0
- package/dist/camoufox/humanize.d.ts +89 -0
- package/dist/camoufox/humanize.js +143 -0
- package/dist/camoufox/index.d.ts +21 -0
- package/dist/camoufox/index.js +21 -0
- package/dist/camoufox/ip.d.ts +45 -0
- package/dist/camoufox/ip.js +114 -0
- package/dist/camoufox/multiversion.d.ts +131 -0
- package/dist/camoufox/multiversion.js +489 -0
- package/dist/camoufox/node-floor.d.ts +5 -0
- package/dist/camoufox/node-floor.js +17 -0
- package/dist/camoufox/paths.d.ts +45 -0
- package/dist/camoufox/paths.js +59 -0
- package/dist/camoufox/pkgman.d.ts +331 -0
- package/dist/camoufox/pkgman.js +972 -0
- package/dist/camoufox/product.d.ts +8 -0
- package/dist/camoufox/product.js +8 -0
- package/dist/camoufox/pycompat.d.ts +97 -0
- package/dist/camoufox/pycompat.js +458 -0
- package/dist/camoufox/server.d.ts +36 -0
- package/dist/camoufox/server.js +82 -0
- package/dist/camoufox/sync_api.d.ts +77 -0
- package/dist/camoufox/sync_api.js +194 -0
- package/dist/camoufox/utils.d.ts +515 -0
- package/dist/camoufox/utils.js +1995 -0
- package/dist/camoufox/warnings.d.ts +16 -0
- package/dist/camoufox/warnings.js +65 -0
- package/dist/camoufox/webgl.d.ts +52 -0
- package/dist/camoufox/webgl.js +264 -0
- package/dist/camouwolf/__main__.d.ts +10 -0
- package/dist/camouwolf/__main__.js +1180 -0
- package/dist/camouwolf/__version__.d.ts +31 -0
- package/dist/camouwolf/__version__.js +32 -0
- package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
- package/dist/camouwolf/_humanize_playwright.js +427 -0
- package/dist/camouwolf/addons.d.ts +42 -0
- package/dist/camouwolf/addons.js +113 -0
- package/dist/camouwolf/async_api.d.ts +9 -0
- package/dist/camouwolf/async_api.js +9 -0
- package/dist/camouwolf/browser-pin.d.ts +46 -0
- package/dist/camouwolf/browser-pin.js +96 -0
- package/dist/camouwolf/cli.d.ts +7 -0
- package/dist/camouwolf/cli.js +20 -0
- package/dist/camouwolf/clienthints.d.ts +61 -0
- package/dist/camouwolf/clienthints.js +176 -0
- package/dist/camouwolf/coherence.d.ts +152 -0
- package/dist/camouwolf/coherence.js +554 -0
- package/dist/camouwolf/data-files/browser-pin.json +7 -0
- package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
- package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
- package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
- package/dist/camouwolf/data-files/data/properties.json +321 -0
- package/dist/camouwolf/data-files/data/system-colors.json +35 -0
- package/dist/camouwolf/data-files/data/ubo.json +6 -0
- package/dist/camouwolf/data-files/fpgen.yml +41 -0
- package/dist/camouwolf/data-files/launcher-constants.json +26 -0
- package/dist/camouwolf/data-files/repos.yml +23 -0
- package/dist/camouwolf/data-files/warnings.yml +96 -0
- package/dist/camouwolf/driver_defaults.d.ts +25 -0
- package/dist/camouwolf/driver_defaults.js +114 -0
- package/dist/camouwolf/exceptions.d.ts +95 -0
- package/dist/camouwolf/exceptions.js +150 -0
- package/dist/camouwolf/fingerprints.d.ts +227 -0
- package/dist/camouwolf/fingerprints.js +753 -0
- package/dist/camouwolf/gpudisplay.d.ts +171 -0
- package/dist/camouwolf/gpudisplay.js +711 -0
- package/dist/camouwolf/host_rendering.d.ts +18 -0
- package/dist/camouwolf/host_rendering.js +114 -0
- package/dist/camouwolf/humanize.d.ts +84 -0
- package/dist/camouwolf/humanize.js +128 -0
- package/dist/camouwolf/index.d.ts +22 -0
- package/dist/camouwolf/index.js +21 -0
- package/dist/camouwolf/multiversion.d.ts +131 -0
- package/dist/camouwolf/multiversion.js +491 -0
- package/dist/camouwolf/node-floor.d.ts +5 -0
- package/dist/camouwolf/node-floor.js +17 -0
- package/dist/camouwolf/paths.d.ts +34 -0
- package/dist/camouwolf/paths.js +58 -0
- package/dist/camouwolf/pkgman.d.ts +331 -0
- package/dist/camouwolf/pkgman.js +972 -0
- package/dist/camouwolf/product.d.ts +3 -0
- package/dist/camouwolf/product.js +3 -0
- package/dist/camouwolf/pycompat.d.ts +92 -0
- package/dist/camouwolf/pycompat.js +461 -0
- package/dist/camouwolf/server.d.ts +36 -0
- package/dist/camouwolf/server.js +81 -0
- package/dist/camouwolf/switches.d.ts +77 -0
- package/dist/camouwolf/switches.js +222 -0
- package/dist/camouwolf/sync_api.d.ts +84 -0
- package/dist/camouwolf/sync_api.js +173 -0
- package/dist/camouwolf/utils.d.ts +644 -0
- package/dist/camouwolf/utils.js +2057 -0
- package/dist/camouwolf/warnings.d.ts +14 -0
- package/dist/camouwolf/warnings.js +59 -0
- package/dist/camouwolf/webgl.d.ts +41 -0
- package/dist/camouwolf/webgl.js +198 -0
- package/dist/data.d.ts +1 -1
- package/dist/data.js +3 -3
- package/dist/download.js +1 -1
- package/dist/exceptions.d.ts +1 -1
- package/dist/exceptions.js +1 -1
- package/dist/geolocation.js +1 -1
- package/dist/host.js +1 -1
- package/dist/ip.js +1 -1
- package/dist/locales.js +1 -1
- package/dist/mcp/cli.d.ts +15 -0
- package/dist/mcp/cli.js +108 -0
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/main.d.ts +2 -0
- package/dist/mcp/main.js +8 -0
- package/dist/mcp/secrets.d.ts +50 -0
- package/dist/mcp/secrets.js +193 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +653 -0
- package/dist/mcp/tree.d.ts +10 -0
- package/dist/mcp/tree.js +36 -0
- package/dist/passthrough.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/settings.js +1 -1
- package/dist/telemetry.d.ts +0 -1
- package/dist/telemetry.js +5 -4
- package/dist/virtdisplay.d.ts +1 -1
- package/dist/virtdisplay.js +1 -1
- package/dist/warnings.js +1 -1
- package/package.json +57 -13
|
@@ -0,0 +1,1175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The `camoufox` CLI.
|
|
4
|
+
*
|
|
5
|
+
* TypeScript twin of python/camoucore/src/camoucore/camoufox/__main__.py. Every command is present,
|
|
6
|
+
* with the same arguments, output and config/cache files. The interactive
|
|
7
|
+
* pickers (`set`, `set --geoip`, `remove --select`) use a numbered
|
|
8
|
+
* prompt in place of inquirer's arrow-key list.
|
|
9
|
+
*/
|
|
10
|
+
// First: fail with the Node.js floor before any module needs it.
|
|
11
|
+
import "./node-floor.js";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import * as readline from "node:readline";
|
|
15
|
+
import { Argument, Command, Option } from "commander";
|
|
16
|
+
import { ensureModel } from "fpgen-js";
|
|
17
|
+
import { allowGeoip, downloadMmdb, GEOIP_DIR, getMmdbPath, loadGeoipConfig, loadGeoipRepos, saveGeoipConfig, warnIfDeprecated, } from "../geolocation.js";
|
|
18
|
+
import { LIBRARY_VERSION } from "./__version__.js";
|
|
19
|
+
import { effectivePin, loadPin, pinSpec, } from "./browser-pin.js";
|
|
20
|
+
import { FileNotFoundError } from "./exceptions.js";
|
|
21
|
+
import { BROWSERS_DIR, COMPAT_FLAG, CONFIG_FILE, findInstall, getDefaultChannel, installedLabel, latestPerBuild, listInstalled, loadConfig, loadRepoCache, printTree, REPO_CACHE_FILE, removeVersion, saveConfig, saveRepoCache, } from "./multiversion.js";
|
|
22
|
+
import { INSTALL_DIR, rprint, style } from "./paths.js";
|
|
23
|
+
import { AvailableVersion, CamoufoxFetcher, formatAssetDate, incompatibleMessage, installedPackageVersion, installedVerStr, interfaceSupported, listAvailableVersions, RepoConfig, resolvedPlaywrightVersionRaw, taggedVersions, upgradeMessage, Version, } from "./pkgman.js";
|
|
24
|
+
// --------------------------------------------------------------------------
|
|
25
|
+
// click-style output + prompts
|
|
26
|
+
// --------------------------------------------------------------------------
|
|
27
|
+
/** click.secho */
|
|
28
|
+
function secho(text, opts = {}) {
|
|
29
|
+
process.stdout.write(style(text, opts) + (opts.nl === false ? "" : "\n"));
|
|
30
|
+
}
|
|
31
|
+
/** click.echo */
|
|
32
|
+
function echo(text = "", nl = true) {
|
|
33
|
+
process.stdout.write(text + (nl ? "\n" : ""));
|
|
34
|
+
}
|
|
35
|
+
let rl = null;
|
|
36
|
+
const pendingLines = [];
|
|
37
|
+
const lineWaiters = [];
|
|
38
|
+
let stdinClosed = false;
|
|
39
|
+
function readLine() {
|
|
40
|
+
if (!rl) {
|
|
41
|
+
rl = readline.createInterface({ input: process.stdin });
|
|
42
|
+
rl.on("line", (line) => {
|
|
43
|
+
const waiter = lineWaiters.shift();
|
|
44
|
+
if (waiter)
|
|
45
|
+
waiter(line);
|
|
46
|
+
else
|
|
47
|
+
pendingLines.push(line);
|
|
48
|
+
});
|
|
49
|
+
rl.on("close", () => {
|
|
50
|
+
stdinClosed = true;
|
|
51
|
+
for (const waiter of lineWaiters.splice(0))
|
|
52
|
+
waiter(null);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const queued = pendingLines.shift();
|
|
56
|
+
if (queued !== undefined)
|
|
57
|
+
return Promise.resolve(queued);
|
|
58
|
+
if (stdinClosed)
|
|
59
|
+
return Promise.resolve(null);
|
|
60
|
+
return new Promise((resolve) => lineWaiters.push(resolve));
|
|
61
|
+
}
|
|
62
|
+
function closePrompts() {
|
|
63
|
+
rl?.close();
|
|
64
|
+
rl = null;
|
|
65
|
+
}
|
|
66
|
+
/** click.confirm (default No). EOF answers No. */
|
|
67
|
+
async function confirm(message) {
|
|
68
|
+
for (;;) {
|
|
69
|
+
process.stdout.write(`${message} [y/N]: `);
|
|
70
|
+
const answer = await readLine();
|
|
71
|
+
if (answer === null) {
|
|
72
|
+
echo();
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const value = answer.trim().toLowerCase();
|
|
76
|
+
if (value === "")
|
|
77
|
+
return false;
|
|
78
|
+
if (value === "y" || value === "yes")
|
|
79
|
+
return true;
|
|
80
|
+
if (value === "n" || value === "no")
|
|
81
|
+
return false;
|
|
82
|
+
echo("Error: invalid input");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generic selection, standing in for the Python twin's inquirer list.
|
|
87
|
+
* Returns the selected value, or null on cancel/EOF.
|
|
88
|
+
*/
|
|
89
|
+
async function select(choices, message) {
|
|
90
|
+
echo(`${style("[?]", { fg: "yellow" })} ${message}:`);
|
|
91
|
+
choices.forEach(([label], i) => {
|
|
92
|
+
echo(` ${style(String(i + 1).padStart(2), { fg: "cyan" })}) ${label}`);
|
|
93
|
+
});
|
|
94
|
+
for (;;) {
|
|
95
|
+
process.stdout.write(`Choice [1-${choices.length}]: `);
|
|
96
|
+
const answer = await readLine();
|
|
97
|
+
if (answer === null || answer.trim() === "") {
|
|
98
|
+
if (answer === null)
|
|
99
|
+
echo();
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const n = Number.parseInt(answer.trim(), 10);
|
|
103
|
+
if (Number.isInteger(n) && n >= 1 && n <= choices.length) {
|
|
104
|
+
return choices[n - 1][1];
|
|
105
|
+
}
|
|
106
|
+
echo(`Error: enter a number between 1 and ${choices.length}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// --------------------------------------------------------------------------
|
|
110
|
+
// helpers
|
|
111
|
+
// --------------------------------------------------------------------------
|
|
112
|
+
/** Find an installed version by channel path, build, or full version string. */
|
|
113
|
+
function findInstalled(specifier) {
|
|
114
|
+
const spec = specifier.toLowerCase();
|
|
115
|
+
const installed = listInstalled();
|
|
116
|
+
const parts = spec.split("/");
|
|
117
|
+
for (const v of installed) {
|
|
118
|
+
if (v.channelPath.toLowerCase() === spec ||
|
|
119
|
+
v.relativePath.toLowerCase() === spec ||
|
|
120
|
+
v.version.build.toLowerCase() === spec ||
|
|
121
|
+
v.version.fullString.toLowerCase() === spec) {
|
|
122
|
+
return v;
|
|
123
|
+
}
|
|
124
|
+
// Match repo/version without channel, for example official/134.0.2-beta.20
|
|
125
|
+
if (parts.length === 2) {
|
|
126
|
+
const [repo, ver] = parts;
|
|
127
|
+
if (v.repoName === repo && v.version.fullString.toLowerCase() === ver) {
|
|
128
|
+
return v;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Match repo/channel, for example official/stable gets the latest installed
|
|
133
|
+
// for that channel
|
|
134
|
+
if (parts.length === 2) {
|
|
135
|
+
const [repo, ctype] = parts;
|
|
136
|
+
if (ctype === "stable" || ctype === "prerelease") {
|
|
137
|
+
const isPre = ctype === "prerelease";
|
|
138
|
+
for (const v of installed) {
|
|
139
|
+
if (v.repoName === repo && v.isPrerelease === isPre)
|
|
140
|
+
return v;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Sync available versions from the remote repositories. Returns true on success.
|
|
148
|
+
*/
|
|
149
|
+
async function doSync(spoofOs, spoofArch) {
|
|
150
|
+
rprint("Syncing repositories...", "yellow");
|
|
151
|
+
const cache = {
|
|
152
|
+
repos: [],
|
|
153
|
+
incompatible: [],
|
|
154
|
+
spoof_os: spoofOs ?? null,
|
|
155
|
+
spoof_arch: spoofArch ?? null,
|
|
156
|
+
};
|
|
157
|
+
for (const repoConfig of RepoConfig.loadRepos()) {
|
|
158
|
+
rprint(` ${repoConfig.name}...`, "cyan", false);
|
|
159
|
+
try {
|
|
160
|
+
const listed = await listAvailableVersions(repoConfig, true, spoofOs, spoofArch, true);
|
|
161
|
+
const versions = listed.filter((v) => interfaceSupported(v.interface));
|
|
162
|
+
for (const v of listed) {
|
|
163
|
+
if (interfaceSupported(v.interface))
|
|
164
|
+
continue;
|
|
165
|
+
cache.incompatible.push({
|
|
166
|
+
repo: repoConfig.name,
|
|
167
|
+
version: v.version.version ?? "",
|
|
168
|
+
build: v.version.build,
|
|
169
|
+
interface: v.interface,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
cache.repos.push({
|
|
173
|
+
name: repoConfig.name,
|
|
174
|
+
repo: repoConfig.repo,
|
|
175
|
+
versions: versions.map((v) => ({
|
|
176
|
+
version: v.version.version ?? null,
|
|
177
|
+
build: v.version.build,
|
|
178
|
+
url: v.url,
|
|
179
|
+
is_prerelease: v.isPrerelease,
|
|
180
|
+
asset_id: v.assetId ?? null,
|
|
181
|
+
asset_size: v.assetSize ?? null,
|
|
182
|
+
asset_updated_at: v.assetUpdatedAt ?? null,
|
|
183
|
+
sha256: v.sha256 ?? null,
|
|
184
|
+
created_at: v.assetCreatedAt ?? null,
|
|
185
|
+
interface: v.interface,
|
|
186
|
+
})),
|
|
187
|
+
});
|
|
188
|
+
rprint(` ${versions.length} versions`, "green");
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
rprint(` Error: ${errorMessage(e)}`, "red");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
saveRepoCache(cache);
|
|
195
|
+
if (cache.incompatible.length) {
|
|
196
|
+
const versionOf = (v) => new Version(v.build, v.version);
|
|
197
|
+
const newest = cache.incompatible.reduce((a, b) => versionOf(b).compare(versionOf(a)) > 0 ? b : a);
|
|
198
|
+
rprint(upgradeMessage(versionOf(newest), newest.interface), "yellow");
|
|
199
|
+
}
|
|
200
|
+
const total = cache.repos.reduce((sum, r) => sum + r.versions.length, 0);
|
|
201
|
+
const platformStr = spoofOs ? ` (${spoofOs}/${spoofArch})` : "";
|
|
202
|
+
rprint(`\nSynced ${total} versions from ${cache.repos.length} repos${platformStr}.`, "green");
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
function errorMessage(e) {
|
|
206
|
+
return e instanceof Error ? e.message : String(e);
|
|
207
|
+
}
|
|
208
|
+
/** Ensure a repo cache exists. Returns true if synced. */
|
|
209
|
+
function ensureSynced() {
|
|
210
|
+
if (!fs.existsSync(REPO_CACHE_FILE)) {
|
|
211
|
+
rprint("No repo cache found. Run 'camoufox sync' first.", "red");
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
/** Cache block for a repo by name. */
|
|
217
|
+
function repoData(cache, repoName) {
|
|
218
|
+
return ((cache.repos ?? []).find((r) => r.name.toLowerCase() === repoName.toLowerCase()) ?? null);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolve a version-build or version-build-sha8 spec against cache entries.
|
|
222
|
+
* Returns [asset, sha] for a specific date, [latest, null] to follow the
|
|
223
|
+
* latest, or [null, null] when the spec is unknown.
|
|
224
|
+
*/
|
|
225
|
+
function resolveSpec(repo, spec) {
|
|
226
|
+
const versions = repo.versions ?? [];
|
|
227
|
+
for (const v of versions) {
|
|
228
|
+
const sha = v.sha256 || "";
|
|
229
|
+
if (sha && spec === `${v.version}-${v.build}-${sha.slice(0, 8)}`) {
|
|
230
|
+
return [v, sha];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
for (const v of latestPerBuild(versions)) {
|
|
234
|
+
if (spec === `${v.version}-${v.build}`)
|
|
235
|
+
return [v, null];
|
|
236
|
+
}
|
|
237
|
+
return [null, null];
|
|
238
|
+
}
|
|
239
|
+
/** Cache entry a pin resolves to: the specific sha asset or the build's latest. */
|
|
240
|
+
function pinTarget(repo, pinned, pinnedSha) {
|
|
241
|
+
const versions = repo.versions ?? [];
|
|
242
|
+
if (pinnedSha) {
|
|
243
|
+
return versions.find((v) => v.sha256 === pinnedSha) ?? null;
|
|
244
|
+
}
|
|
245
|
+
return (latestPerBuild(versions).find((v) => `${v.version}-${v.build}` === pinned) ?? null);
|
|
246
|
+
}
|
|
247
|
+
/** Set to track a channel (fetches the latest on fetch). */
|
|
248
|
+
function setChannel(repoName, channelType) {
|
|
249
|
+
const config = loadConfig();
|
|
250
|
+
config.channel = `${repoName}/${channelType}`;
|
|
251
|
+
delete config.pinned;
|
|
252
|
+
delete config.pinned_sha;
|
|
253
|
+
// Check if the latest for this channel is already installed
|
|
254
|
+
const isPre = channelType === "prerelease";
|
|
255
|
+
const cache = loadRepoCache();
|
|
256
|
+
for (const repo of cache.repos ?? []) {
|
|
257
|
+
if (repo.name.toLowerCase() !== repoName.toLowerCase())
|
|
258
|
+
continue;
|
|
259
|
+
const candidates = (repo.versions ?? []).filter((v) => (v.is_prerelease ?? false) === isPre);
|
|
260
|
+
if (candidates.length) {
|
|
261
|
+
const latestBuild = candidates[0].build;
|
|
262
|
+
for (const inst of listInstalled()) {
|
|
263
|
+
if (inst.version.build === latestBuild &&
|
|
264
|
+
inst.repoName === repoName.toLowerCase()) {
|
|
265
|
+
config.active_version = inst.relativePath;
|
|
266
|
+
saveConfig(config);
|
|
267
|
+
secho(`Channel: ${repoName.toLowerCase()}/${channelType}`, {
|
|
268
|
+
fg: "cyan",
|
|
269
|
+
bold: true,
|
|
270
|
+
});
|
|
271
|
+
secho(`Using latest: ${inst.channelPath} (installed)`, {
|
|
272
|
+
fg: "green",
|
|
273
|
+
});
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
delete config.active_version;
|
|
281
|
+
saveConfig(config);
|
|
282
|
+
secho(`Channel: ${repoName.toLowerCase()}/${channelType}`, {
|
|
283
|
+
fg: "cyan",
|
|
284
|
+
bold: true,
|
|
285
|
+
});
|
|
286
|
+
secho("Run 'camoufox fetch' to install latest.", { fg: "yellow" });
|
|
287
|
+
}
|
|
288
|
+
/** Pin a version-build, optionally to a specific dated asset by sha. */
|
|
289
|
+
function setPinned(repoName, channelType, verData, inst, sha) {
|
|
290
|
+
const config = loadConfig();
|
|
291
|
+
config.channel = `${repoName.toLowerCase()}/${channelType}`;
|
|
292
|
+
config.pinned = `${verData.version}-${verData.build}`;
|
|
293
|
+
if (sha) {
|
|
294
|
+
config.pinned_sha = sha;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
delete config.pinned_sha;
|
|
298
|
+
}
|
|
299
|
+
const tag = sha ? ` (${sha.slice(0, 8)})` : "";
|
|
300
|
+
const display = `${repoName.toLowerCase()}/${channelType}/${verData.version}-${verData.build}${tag}`;
|
|
301
|
+
if (inst) {
|
|
302
|
+
config.active_version = inst.relativePath;
|
|
303
|
+
saveConfig(config);
|
|
304
|
+
secho(`Pinned: ${display} (installed)`, { fg: "green" });
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
delete config.active_version;
|
|
308
|
+
saveConfig(config);
|
|
309
|
+
secho(`Pinned: ${display}`, { fg: "cyan", bold: true });
|
|
310
|
+
secho("Run 'camoufox fetch' to install.", { fg: "yellow" });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** A command's failure, printed as its message, with exit code 1. */
|
|
314
|
+
class CommandFailed extends Error {
|
|
315
|
+
}
|
|
316
|
+
/** Stop the command with an error, so a script or CI step stops here. */
|
|
317
|
+
function fail(message) {
|
|
318
|
+
throw new CommandFailed(message);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The build `spec` names, read from its own release with one API call. Null
|
|
322
|
+
* when the source has no such tag: early builds were published under others.
|
|
323
|
+
*/
|
|
324
|
+
async function taggedBuild(repoName, tag, spec) {
|
|
325
|
+
const repoConfig = RepoConfig.findByName(repoName);
|
|
326
|
+
if (!repoConfig)
|
|
327
|
+
return null;
|
|
328
|
+
const match = (await taggedVersions(repoConfig, tag)).find((v) => v.version.fullString === spec);
|
|
329
|
+
return match ? [repoConfig, match] : null;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Sync every source, then resolve against the cache the build fetch was asked
|
|
333
|
+
* for: `spec`, the release's pin, or the user's pin or channel.
|
|
334
|
+
*/
|
|
335
|
+
async function syncedBuild(config, repoName, spec, pin) {
|
|
336
|
+
await doSync();
|
|
337
|
+
const cache = loadRepoCache();
|
|
338
|
+
let repo = null;
|
|
339
|
+
let verData = null;
|
|
340
|
+
if (pin && repoName && spec) {
|
|
341
|
+
repo = repoData(cache, repoName);
|
|
342
|
+
if (repo)
|
|
343
|
+
verData = pinTarget(repo, spec, undefined);
|
|
344
|
+
if (!verData) {
|
|
345
|
+
fail(`${pin.tag}, the browser this camoufox release pairs with, is not in ` +
|
|
346
|
+
`${repoName}'s releases. Run 'camoufox sync' and try again.`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else if (repoName && spec) {
|
|
350
|
+
repo = repoData(cache, repoName);
|
|
351
|
+
if (repo)
|
|
352
|
+
[verData] = resolveSpec(repo, spec);
|
|
353
|
+
}
|
|
354
|
+
else if (config.pinned) {
|
|
355
|
+
const channel = config.channel ?? "";
|
|
356
|
+
repoName = channel.includes("/") ? channel.split("/")[0] : channel;
|
|
357
|
+
repo = repoData(cache, repoName);
|
|
358
|
+
if (repo)
|
|
359
|
+
verData = pinTarget(repo, config.pinned, config.pinned_sha);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
const channel = config.channel || getDefaultChannel();
|
|
363
|
+
const slash = channel.indexOf("/");
|
|
364
|
+
const name = slash === -1 ? channel : channel.slice(0, slash);
|
|
365
|
+
const ctype = slash === -1 ? "stable" : channel.slice(slash + 1);
|
|
366
|
+
repoName = name;
|
|
367
|
+
repo = repoData(cache, repoName);
|
|
368
|
+
if (repo) {
|
|
369
|
+
const isPre = ctype === "prerelease";
|
|
370
|
+
const latest = latestPerBuild(repo.versions ?? []).filter((v) => (v.is_prerelease ?? false) === isPre);
|
|
371
|
+
verData = latest[0] ?? null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (!verData || !repo) {
|
|
375
|
+
const incompatible = (cache.incompatible ?? []).find((v) => spec &&
|
|
376
|
+
v.repo.toLowerCase() === (repoName ?? "").toLowerCase() &&
|
|
377
|
+
`${v.version}-${v.build}` === spec);
|
|
378
|
+
if (incompatible) {
|
|
379
|
+
fail(incompatibleMessage(new Version(incompatible.build, incompatible.version), incompatible.interface));
|
|
380
|
+
}
|
|
381
|
+
fail(`Version '${spec || repoName}' not found in cache. Run 'camoufox sync'.`);
|
|
382
|
+
}
|
|
383
|
+
const selected = new AvailableVersion({
|
|
384
|
+
version: new Version(verData.build, verData.version),
|
|
385
|
+
url: verData.url,
|
|
386
|
+
isPrerelease: verData.is_prerelease ?? false,
|
|
387
|
+
sha256: verData.sha256 ?? undefined,
|
|
388
|
+
assetCreatedAt: verData.created_at ?? undefined,
|
|
389
|
+
interface: verData.interface ?? 1,
|
|
390
|
+
});
|
|
391
|
+
return [RepoConfig.findByName(repo.name), selected];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Checks & updates Camoufox.
|
|
395
|
+
*/
|
|
396
|
+
class CamoufoxUpdate extends CamoufoxFetcher {
|
|
397
|
+
currentVerStr = null;
|
|
398
|
+
async init() {
|
|
399
|
+
await super.init();
|
|
400
|
+
try {
|
|
401
|
+
this.currentVerStr = installedVerStr();
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
if (!(error instanceof FileNotFoundError))
|
|
405
|
+
throw error;
|
|
406
|
+
this.currentVerStr = null;
|
|
407
|
+
}
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
isUpdatedNeeded() {
|
|
411
|
+
return this.currentVerStr === null || this.currentVerStr !== this.verstr;
|
|
412
|
+
}
|
|
413
|
+
async update(replace = false, iKnowWhatImDoing = false) {
|
|
414
|
+
if (!this.isUpdatedNeeded() && !replace) {
|
|
415
|
+
rprint("Camoufox binaries up to date!", "green");
|
|
416
|
+
rprint(`Current version: v${this.currentVerStr}`, "green");
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (this.isPrerelease && !iKnowWhatImDoing) {
|
|
420
|
+
rprint(`Warning: v${this.verstr} is a prerelease version!`, "yellow");
|
|
421
|
+
if (!(await confirm("Continue with prerelease installation?"))) {
|
|
422
|
+
fail("Installation cancelled.");
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const action = this.currentVerStr ? "Installing" : "Fetching";
|
|
426
|
+
rprint(`${action} Camoufox v${this.verstr}...`, "yellow");
|
|
427
|
+
await this.install(replace);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// --------------------------------------------------------------------------
|
|
431
|
+
// commands
|
|
432
|
+
// --------------------------------------------------------------------------
|
|
433
|
+
const program = new Command();
|
|
434
|
+
program.name("camoufox").version(LIBRARY_VERSION);
|
|
435
|
+
program
|
|
436
|
+
.command("sync")
|
|
437
|
+
.description("Sync available versions from remote repositories")
|
|
438
|
+
.addOption(new Option("--spoof-os <os>", "Spoof OS (auto = native)").choices([
|
|
439
|
+
"auto",
|
|
440
|
+
"mac",
|
|
441
|
+
"win",
|
|
442
|
+
"lin",
|
|
443
|
+
]))
|
|
444
|
+
.addOption(new Option("--spoof-arch <arch>", "Spoof architecture (auto = native)").choices(["auto", "x86_64", "i686", "arm64"]))
|
|
445
|
+
.action(async ({ spoofOs, spoofArch }) => {
|
|
446
|
+
await doSync(spoofOs === "auto" ? undefined : spoofOs, spoofArch === "auto" ? undefined : spoofArch);
|
|
447
|
+
});
|
|
448
|
+
program
|
|
449
|
+
.command("fetch")
|
|
450
|
+
.description("Install the active version, or a specific version")
|
|
451
|
+
.argument("[version]", "e.g. official/135.0-beta.25")
|
|
452
|
+
.action(async (version) => {
|
|
453
|
+
// Clean up an incompatible old data directory
|
|
454
|
+
if (fs.existsSync(INSTALL_DIR) &&
|
|
455
|
+
fs.readdirSync(INSTALL_DIR).length > 0 &&
|
|
456
|
+
!fs.existsSync(COMPAT_FLAG)) {
|
|
457
|
+
rprint("Cleaning old data...", "yellow");
|
|
458
|
+
fs.rmSync(INSTALL_DIR, { recursive: true, force: true });
|
|
459
|
+
}
|
|
460
|
+
await fetchPublic(loadConfig(), version);
|
|
461
|
+
if (allowGeoip()) {
|
|
462
|
+
await downloadMmdb();
|
|
463
|
+
}
|
|
464
|
+
// Fetch the pinned fpgen model now rather than on the first launch.
|
|
465
|
+
await ensureModel();
|
|
466
|
+
});
|
|
467
|
+
async function fetchPublic(config, version) {
|
|
468
|
+
const pin = version ? null : effectivePin(config);
|
|
469
|
+
let repoName = null;
|
|
470
|
+
let spec = null;
|
|
471
|
+
let tag = null;
|
|
472
|
+
if (version) {
|
|
473
|
+
const parts = version.toLowerCase().split("/");
|
|
474
|
+
if (parts.length === 1) {
|
|
475
|
+
repoName = RepoConfig.getDefaultName();
|
|
476
|
+
spec = parts[0];
|
|
477
|
+
}
|
|
478
|
+
else if (parts.length === 2 || parts.length === 3) {
|
|
479
|
+
repoName = parts[0];
|
|
480
|
+
spec = parts[parts.length - 1];
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
fail("Format: version-build, repo/version-build, or repo/channel/version-build");
|
|
484
|
+
}
|
|
485
|
+
spec = spec.replace(/^v+/, "");
|
|
486
|
+
tag = `v${spec}`;
|
|
487
|
+
}
|
|
488
|
+
else if (pin) {
|
|
489
|
+
// This library release pairs with exactly one browser build.
|
|
490
|
+
repoName = pin.repoName;
|
|
491
|
+
spec = pinSpec(pin);
|
|
492
|
+
tag = pin.tag;
|
|
493
|
+
}
|
|
494
|
+
const [repoConfig, selected] = (repoName && spec && tag && (await taggedBuild(repoName, tag, spec))) ||
|
|
495
|
+
(await syncedBuild(config, repoName, spec, pin));
|
|
496
|
+
try {
|
|
497
|
+
const updater = await new CamoufoxUpdate(repoConfig, selected).init();
|
|
498
|
+
// The paired build is what this release was tested with; installing
|
|
499
|
+
// it needs no "this is a prerelease" confirmation even when it is one.
|
|
500
|
+
await updater.update(false, pin !== null);
|
|
501
|
+
}
|
|
502
|
+
catch (e) {
|
|
503
|
+
if (e instanceof CommandFailed)
|
|
504
|
+
throw e;
|
|
505
|
+
const msg = errorMessage(e);
|
|
506
|
+
if (msg.includes("404") || msg.includes("Not Found")) {
|
|
507
|
+
rprint("Release not found (404). Asset may have been removed.", "red");
|
|
508
|
+
fail("Run 'camoufox sync' to refresh available versions.");
|
|
509
|
+
}
|
|
510
|
+
fail(`Error: ${msg}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
program
|
|
514
|
+
.command("set")
|
|
515
|
+
.description("Set the active Camoufox version to use & fetch.\n" +
|
|
516
|
+
"By default, this opens an interactive selector for versions and settings.\n" +
|
|
517
|
+
"You can also pass a specifier to activate directly:\n" +
|
|
518
|
+
"Pin version:\n" +
|
|
519
|
+
" camoufox set official/stable/134.0.2-beta.20\n" +
|
|
520
|
+
"Automatically find latest in a channel source:\n" +
|
|
521
|
+
" camoufox set official/stable")
|
|
522
|
+
.argument("[specifier]")
|
|
523
|
+
.option("--geoip", "Select GeoIP source instead")
|
|
524
|
+
.option("--release", "Forget any explicit choice and use the browser this camoufox release pairs with")
|
|
525
|
+
.action(async (specifier, { geoip, release }) => {
|
|
526
|
+
if (geoip) {
|
|
527
|
+
await selectGeoIPSource();
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (release) {
|
|
531
|
+
const releasePin = loadPin();
|
|
532
|
+
if (!releasePin) {
|
|
533
|
+
rprint("This camoufox is a development copy; it pairs with no particular browser.", "yellow");
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const config = loadConfig();
|
|
537
|
+
delete config.channel;
|
|
538
|
+
delete config.pinned;
|
|
539
|
+
delete config.pinned_sha;
|
|
540
|
+
delete config.active_version;
|
|
541
|
+
saveConfig(config);
|
|
542
|
+
rprint(`Using the paired browser: ${releasePin.repoName} ${pinSpec(releasePin)} (${releasePin.tag})`, "green");
|
|
543
|
+
rprint("Run 'camoufox fetch' if it is not installed.", "yellow");
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (specifier) {
|
|
547
|
+
const parts = specifier.toLowerCase().split("/");
|
|
548
|
+
// 2-part sets a channel like official/stable
|
|
549
|
+
if (parts.length === 2) {
|
|
550
|
+
const [repoName, ctype] = parts;
|
|
551
|
+
if (ctype !== "stable" && ctype !== "prerelease") {
|
|
552
|
+
rprint(`Unknown channel type '${ctype}'. Use 'stable' or 'prerelease'.`, "red");
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
setChannel(repoName, ctype);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
// 1-part pins in the default repo, 3-part names the repo and channel
|
|
559
|
+
let repoName;
|
|
560
|
+
let spec;
|
|
561
|
+
if (parts.length === 1) {
|
|
562
|
+
repoName = RepoConfig.getDefaultName();
|
|
563
|
+
spec = parts[0];
|
|
564
|
+
}
|
|
565
|
+
else if (parts.length === 3) {
|
|
566
|
+
const ctype = parts[1];
|
|
567
|
+
[repoName, , spec] = parts;
|
|
568
|
+
if (ctype !== "stable" && ctype !== "prerelease") {
|
|
569
|
+
rprint(`Unknown channel type '${ctype}'. Use 'stable' or 'prerelease'.`, "red");
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
rprint(`Invalid specifier '${specifier}'.`, "red");
|
|
575
|
+
rprint("Use: version-build, repo/channel, or repo/channel/version-build", "yellow");
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
if (!ensureSynced())
|
|
579
|
+
return;
|
|
580
|
+
const repo = repoData(loadRepoCache(), repoName);
|
|
581
|
+
if (!repo) {
|
|
582
|
+
rprint(`Repo '${repoName.toLowerCase()}' not in cache. Run 'camoufox sync'.`, "red");
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const [verData, sha] = resolveSpec(repo, spec.replace(/^v+/, ""));
|
|
586
|
+
if (!verData) {
|
|
587
|
+
rprint(`Version '${spec}' not found in ${repoName.toLowerCase()}.`, "red");
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const ctype = verData.is_prerelease ? "prerelease" : "stable";
|
|
591
|
+
const vb = `${verData.version}-${verData.build}`;
|
|
592
|
+
const count = (repo.versions ?? []).filter((x) => `${x.version}-${x.build}` === vb).length;
|
|
593
|
+
const inst = findInstall(vb, verData.sha256, listInstalled(), count);
|
|
594
|
+
setPinned(repo.name, ctype, verData, inst, sha);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (!ensureSynced())
|
|
598
|
+
return;
|
|
599
|
+
await interactiveSet();
|
|
600
|
+
});
|
|
601
|
+
async function interactiveSet() {
|
|
602
|
+
const cache = loadRepoCache();
|
|
603
|
+
const installedList = listInstalled();
|
|
604
|
+
if (!cache.repos?.length) {
|
|
605
|
+
rprint("No versions in cache. Run 'camoufox sync' first.", "red");
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const channels = [];
|
|
609
|
+
for (const repo of cache.repos) {
|
|
610
|
+
const versions = repo.versions ?? [];
|
|
611
|
+
const stable = latestPerBuild(versions.filter((v) => !v.is_prerelease));
|
|
612
|
+
const prereleases = latestPerBuild(versions.filter((v) => v.is_prerelease));
|
|
613
|
+
if (stable.length)
|
|
614
|
+
channels.push([repo.name, "stable", stable[0]]);
|
|
615
|
+
if (prereleases.length) {
|
|
616
|
+
channels.push([repo.name, "prerelease", prereleases[0]]);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const config = loadConfig();
|
|
620
|
+
const channel = config.channel || getDefaultChannel();
|
|
621
|
+
const pinned = config.pinned;
|
|
622
|
+
const pinnedSha = config.pinned_sha;
|
|
623
|
+
if (pinned) {
|
|
624
|
+
secho(`Pinned: ${channel.toLowerCase()}/${pinned}`, { fg: "cyan" });
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
secho(`Channel: ${channel.toLowerCase()}`, { fg: "cyan" });
|
|
628
|
+
}
|
|
629
|
+
echo();
|
|
630
|
+
// Full dated lists so the pin picker can show every date, not just the latest
|
|
631
|
+
const channelVersions = [];
|
|
632
|
+
for (const repo of cache.repos) {
|
|
633
|
+
const versions = repo.versions ?? [];
|
|
634
|
+
const stable = versions.filter((v) => !v.is_prerelease);
|
|
635
|
+
const prereleases = versions.filter((v) => v.is_prerelease);
|
|
636
|
+
if (stable.length)
|
|
637
|
+
channelVersions.push([repo.name, "stable", stable]);
|
|
638
|
+
if (prereleases.length) {
|
|
639
|
+
channelVersions.push([repo.name, "prerelease", prereleases]);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
for (;;) {
|
|
643
|
+
const choices = [["Set channel", "channel"]];
|
|
644
|
+
for (const [name, ctype, versions] of channelVersions) {
|
|
645
|
+
const label = `Pin version: ${style(`${name.toLowerCase()}/${ctype}`, { fg: "cyan", bold: true })}`;
|
|
646
|
+
choices.push([label, ["pin", name, ctype, versions]]);
|
|
647
|
+
}
|
|
648
|
+
choices.push([style("Exit", { fg: "bright_black" }), "exit"]);
|
|
649
|
+
const action = await select(choices, "Select");
|
|
650
|
+
if (action === null || action === "exit")
|
|
651
|
+
return;
|
|
652
|
+
if (action === "channel") {
|
|
653
|
+
const chChoices = [];
|
|
654
|
+
for (const [name, ctype, latest] of channels) {
|
|
655
|
+
const verStr = `v${latest.version}-${latest.build}`;
|
|
656
|
+
const isCurrent = channel === `${name}/${ctype}`;
|
|
657
|
+
let label = `${name.toLowerCase()}/${ctype} (latest: ${verStr})`;
|
|
658
|
+
if (isCurrent) {
|
|
659
|
+
label = `${style(label, { fg: "green", bold: true })} (current)`;
|
|
660
|
+
}
|
|
661
|
+
chChoices.push([label, [name, ctype]]);
|
|
662
|
+
}
|
|
663
|
+
chChoices.push([style("Back", { fg: "bright_black" }), null]);
|
|
664
|
+
const chAnswer = await select(chChoices, "Set channel");
|
|
665
|
+
if (!chAnswer)
|
|
666
|
+
continue;
|
|
667
|
+
setChannel(chAnswer[0], chAnswer[1]);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const [, rname, ctype, versions] = action;
|
|
671
|
+
const vbCounts = new Map();
|
|
672
|
+
for (const x of versions) {
|
|
673
|
+
const key = `${x.version}-${x.build}`;
|
|
674
|
+
vbCounts.set(key, (vbCounts.get(key) ?? 0) + 1);
|
|
675
|
+
}
|
|
676
|
+
const vChoices = [];
|
|
677
|
+
for (const v of versions) {
|
|
678
|
+
const vb = `${v.version}-${v.build}`;
|
|
679
|
+
const sha = v.sha256 || "";
|
|
680
|
+
const date = formatAssetDate(v.created_at ?? undefined);
|
|
681
|
+
const inst = findInstall(vb, v.sha256 ?? undefined, installedList, vbCounts.get(vb) ?? 0);
|
|
682
|
+
const isPinned = pinned === vb && (pinnedSha ?? null) === (sha || null);
|
|
683
|
+
let color;
|
|
684
|
+
let bold;
|
|
685
|
+
let status;
|
|
686
|
+
if (isPinned) {
|
|
687
|
+
[color, bold, status] = ["green", true, "(pinned)"];
|
|
688
|
+
}
|
|
689
|
+
else if (inst) {
|
|
690
|
+
[color, bold, status] = [null, false, "(installed)"];
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
[color, bold, status] = ["bright_black", false, ""];
|
|
694
|
+
}
|
|
695
|
+
const cells = [date, sha ? `(${sha.slice(0, 8)})` : "", status].filter(Boolean);
|
|
696
|
+
const meta = cells.length ? ` ${cells.join(" ")}` : "";
|
|
697
|
+
vChoices.push([style(`v${vb}`, { fg: color, bold }) + meta, v]);
|
|
698
|
+
}
|
|
699
|
+
vChoices.push([style("Back", { fg: "bright_black" }), null]);
|
|
700
|
+
const verData = await select(vChoices, `Pin version (${rname.toLowerCase()}/${ctype})`);
|
|
701
|
+
if (!verData)
|
|
702
|
+
continue;
|
|
703
|
+
const vb = `${verData.version}-${verData.build}`;
|
|
704
|
+
const inst = findInstall(vb, verData.sha256 ?? undefined, installedList, vbCounts.get(vb) ?? 0);
|
|
705
|
+
setPinned(rname, ctype, verData, inst, verData.sha256);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
/** Interactive selection of the GeoIP source. */
|
|
710
|
+
async function selectGeoIPSource() {
|
|
711
|
+
const [repos] = loadGeoipRepos();
|
|
712
|
+
if (!repos.length) {
|
|
713
|
+
rprint("No GeoIP sources configured.", "red");
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
let current = "";
|
|
717
|
+
try {
|
|
718
|
+
current = loadGeoipConfig().name ?? "";
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
// unreadable config: nothing is marked active
|
|
722
|
+
}
|
|
723
|
+
const choices = repos.map((r) => [
|
|
724
|
+
r.name +
|
|
725
|
+
(r.deprecated ? " (deprecated)" : "") +
|
|
726
|
+
(r.name === current ? " [active]" : ""),
|
|
727
|
+
r,
|
|
728
|
+
]);
|
|
729
|
+
const selected = await select(choices, "Select GeoIP source");
|
|
730
|
+
if (!selected)
|
|
731
|
+
return;
|
|
732
|
+
saveGeoipConfig(selected, true);
|
|
733
|
+
rprint(`GeoIP source: ${selected.name}`, "green");
|
|
734
|
+
warnIfDeprecated(selected);
|
|
735
|
+
}
|
|
736
|
+
program
|
|
737
|
+
.command("list")
|
|
738
|
+
.description("List Camoufox versions\n\n" +
|
|
739
|
+
"installed Show installed versions (default)\n" +
|
|
740
|
+
"all Show all available versions from synced repos")
|
|
741
|
+
.addArgument(new Argument("[mode]").choices(["installed", "all"]).default("installed"))
|
|
742
|
+
.option("--path", "Show full paths")
|
|
743
|
+
.action((mode, { path: showPaths }) => {
|
|
744
|
+
if (mode === "all") {
|
|
745
|
+
listAll(Boolean(showPaths));
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
listInstalledVersions(Boolean(showPaths));
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
function listInstalledVersions(showPaths) {
|
|
752
|
+
printTree(true, showPaths);
|
|
753
|
+
echo();
|
|
754
|
+
secho("geoip/", { fg: "cyan", bold: true, nl: false });
|
|
755
|
+
if (showPaths && fs.existsSync(GEOIP_DIR)) {
|
|
756
|
+
secho(` -> ${GEOIP_DIR}`, { fg: "bright_black" });
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
echo();
|
|
760
|
+
}
|
|
761
|
+
if (fs.existsSync(GEOIP_DIR)) {
|
|
762
|
+
let config;
|
|
763
|
+
try {
|
|
764
|
+
config = loadGeoipConfig();
|
|
765
|
+
}
|
|
766
|
+
catch (e) {
|
|
767
|
+
// the saved source is gone from the GeoIP list
|
|
768
|
+
rprint(` └── ${e.message}`, "red");
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
const mmdb = getMmdbPath("ipv4", config);
|
|
772
|
+
if (fs.existsSync(mmdb)) {
|
|
773
|
+
echo(` └── ${path.basename(mmdb)} `, false);
|
|
774
|
+
secho(`(${config.name ?? "Default"})`, { fg: "green" });
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
rprint(" └── Not downloaded", "yellow");
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
rprint(" └── Not configured", "yellow");
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function listAll(showPaths) {
|
|
785
|
+
if (!ensureSynced())
|
|
786
|
+
return;
|
|
787
|
+
const cache = loadRepoCache();
|
|
788
|
+
const installed = new Map(listInstalled().map((v) => [v.version.build, v]));
|
|
789
|
+
rprint("Available versions:\n", "yellow");
|
|
790
|
+
for (const repo of cache.repos ?? []) {
|
|
791
|
+
const versions = latestPerBuild(repo.versions ?? []);
|
|
792
|
+
secho(`${repo.name}/`, { fg: "cyan", bold: true });
|
|
793
|
+
versions.forEach((v, i) => {
|
|
794
|
+
const fullVer = `${v.version}-${v.build}`;
|
|
795
|
+
const inst = installed.get(v.build);
|
|
796
|
+
const isLast = i === versions.length - 1;
|
|
797
|
+
const prefix = isLast ? "└── " : "├── ";
|
|
798
|
+
const active = Boolean(inst?.isActive);
|
|
799
|
+
echo(` ${prefix}`, false);
|
|
800
|
+
secho(`v${fullVer}`, {
|
|
801
|
+
fg: active ? "green" : null,
|
|
802
|
+
bold: active,
|
|
803
|
+
nl: false,
|
|
804
|
+
});
|
|
805
|
+
if (v.is_prerelease) {
|
|
806
|
+
secho(" (prerelease)", { fg: "yellow", nl: false });
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
secho(" (stable)", { fg: "blue", nl: false });
|
|
810
|
+
}
|
|
811
|
+
if (inst) {
|
|
812
|
+
if (inst.isActive) {
|
|
813
|
+
secho(" (installed, active)", { fg: "green", bold: true, nl: false });
|
|
814
|
+
}
|
|
815
|
+
else {
|
|
816
|
+
secho(" (installed)", { fg: "green", nl: false });
|
|
817
|
+
}
|
|
818
|
+
if (showPaths) {
|
|
819
|
+
secho(` -> ${inst.path}`, { fg: "bright_black", nl: false });
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
echo();
|
|
823
|
+
});
|
|
824
|
+
echo();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
program
|
|
828
|
+
.command("remove")
|
|
829
|
+
.description("Remove downloaded data. By default, this removes everything.\n" +
|
|
830
|
+
"Pass --select to pick a browser version to remove.")
|
|
831
|
+
.argument("[version_path]")
|
|
832
|
+
.option("--select", "Interactively select a version to remove")
|
|
833
|
+
.option("-y, --yes", "Skip confirmation prompts")
|
|
834
|
+
.action(async (versionPath, { select: doSelect, yes }) => {
|
|
835
|
+
// Select mode: interactively pick a single version
|
|
836
|
+
if (doSelect) {
|
|
837
|
+
const installed = listInstalled();
|
|
838
|
+
if (!installed.length) {
|
|
839
|
+
rprint("No browser versions installed.", "yellow");
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const choices = installed.map((v) => {
|
|
843
|
+
const tag = installedLabel(v);
|
|
844
|
+
const suffix = tag ? ` (${tag})` : "";
|
|
845
|
+
return [
|
|
846
|
+
v.channelPath + suffix + (v.isActive ? " [active]" : ""),
|
|
847
|
+
v,
|
|
848
|
+
];
|
|
849
|
+
});
|
|
850
|
+
const target = await select(choices, "Select version to remove");
|
|
851
|
+
if (!target) {
|
|
852
|
+
rprint("Cancelled.", "yellow");
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
if (yes || (await confirm(`Remove ${target.channelPath}?`))) {
|
|
856
|
+
removeVersion(target.path);
|
|
857
|
+
rprint(`Removed ${target.channelPath}`, "green");
|
|
858
|
+
}
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
// Specific version: remove just that one
|
|
862
|
+
if (versionPath) {
|
|
863
|
+
const target = findInstalled(versionPath);
|
|
864
|
+
if (!target) {
|
|
865
|
+
rprint(`Version '${versionPath}' not found.`, "red");
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
if (yes || (await confirm(`Remove ${target.channelPath}?`))) {
|
|
869
|
+
removeVersion(target.path);
|
|
870
|
+
rprint(`Removed ${target.channelPath}`, "green");
|
|
871
|
+
}
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
// Default: remove everything
|
|
875
|
+
if (!fs.existsSync(INSTALL_DIR) ||
|
|
876
|
+
fs.readdirSync(INSTALL_DIR).length === 0) {
|
|
877
|
+
rprint("Nothing to remove.", "yellow");
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (yes ||
|
|
881
|
+
(await confirm(`Remove the camoufox data directory (${INSTALL_DIR})?`))) {
|
|
882
|
+
fs.rmSync(INSTALL_DIR, { recursive: true, force: true });
|
|
883
|
+
rprint("Removed camoufox data directory.", "green");
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
program
|
|
887
|
+
.command("test")
|
|
888
|
+
.description("Open the Playwright inspector")
|
|
889
|
+
.argument("[url]")
|
|
890
|
+
.option("--executable-path <path>", "Path to the Camoufox executable")
|
|
891
|
+
.action(async (url, { executablePath }) => {
|
|
892
|
+
const { Camoufox } = await import("./sync_api.js");
|
|
893
|
+
const browser = await Camoufox({
|
|
894
|
+
headless: false,
|
|
895
|
+
env: process.env,
|
|
896
|
+
config: { showcursor: false },
|
|
897
|
+
executable_path: executablePath,
|
|
898
|
+
});
|
|
899
|
+
try {
|
|
900
|
+
const page = await browser.newPage();
|
|
901
|
+
if (url) {
|
|
902
|
+
await page.goto(url);
|
|
903
|
+
}
|
|
904
|
+
await page.pause();
|
|
905
|
+
}
|
|
906
|
+
finally {
|
|
907
|
+
await browser.close();
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
program
|
|
911
|
+
.command("server")
|
|
912
|
+
.description("Launch a Playwright server")
|
|
913
|
+
.action(async () => {
|
|
914
|
+
// The Python twin hands launch options to launchServer.js, which logs
|
|
915
|
+
// exactly this; the server runs until the process is told to stop.
|
|
916
|
+
const { launchServer } = await import("./server.js");
|
|
917
|
+
const started = performance.now();
|
|
918
|
+
console.info("Launching server...");
|
|
919
|
+
const server = await launchServer();
|
|
920
|
+
console.log(`Server launched: ${(performance.now() - started).toFixed(3)}ms`);
|
|
921
|
+
console.log("Websocket endpoint:\x1b[93m", server.wsEndpoint(), "\x1b[0m");
|
|
922
|
+
await new Promise((resolve) => {
|
|
923
|
+
const stop = () => resolve();
|
|
924
|
+
process.once("SIGINT", stop);
|
|
925
|
+
process.once("SIGTERM", stop);
|
|
926
|
+
});
|
|
927
|
+
await server.close();
|
|
928
|
+
});
|
|
929
|
+
// --------------------------------------------------------------------------
|
|
930
|
+
// version
|
|
931
|
+
// --------------------------------------------------------------------------
|
|
932
|
+
class VersionInfo {
|
|
933
|
+
rows = [];
|
|
934
|
+
row(label, value, fg = "green") {
|
|
935
|
+
this.rows.push([
|
|
936
|
+
style(` ${label}`, { dim: true }),
|
|
937
|
+
value,
|
|
938
|
+
fg === "dim" ? { dim: true } : { fg },
|
|
939
|
+
]);
|
|
940
|
+
}
|
|
941
|
+
header(title) {
|
|
942
|
+
this.rows.push([style(title, { bold: true }), "", {}]);
|
|
943
|
+
}
|
|
944
|
+
pkg(label, version) {
|
|
945
|
+
if (version)
|
|
946
|
+
this.row(label, `v${version}`);
|
|
947
|
+
else
|
|
948
|
+
this.row(label, "?", "dim");
|
|
949
|
+
}
|
|
950
|
+
packages() {
|
|
951
|
+
this.header("Packages");
|
|
952
|
+
this.pkg("Camoufox", LIBRARY_VERSION);
|
|
953
|
+
this.pkg("fpgen", installedPackageVersion("fpgen-js"));
|
|
954
|
+
this.pkg("Playwright", resolvedPlaywrightVersionRaw());
|
|
955
|
+
}
|
|
956
|
+
browser() {
|
|
957
|
+
this.header("Browser");
|
|
958
|
+
const config = loadConfig();
|
|
959
|
+
const pinned = config.pinned;
|
|
960
|
+
const channel = config.channel || getDefaultChannel();
|
|
961
|
+
// Active: what was set (channel or pinned version)
|
|
962
|
+
if (pinned) {
|
|
963
|
+
this.row("Active", `${channel.toLowerCase()}/${pinned}`);
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
this.row("Active", channel.toLowerCase());
|
|
967
|
+
}
|
|
968
|
+
// Find the active installed version
|
|
969
|
+
const activeV = listInstalled().find((v) => v.isActive) ?? null;
|
|
970
|
+
if (activeV) {
|
|
971
|
+
this.row("Current browser", `v${activeV.version.fullString}`);
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
this.row("Current browser", "Not installed", "dim");
|
|
975
|
+
}
|
|
976
|
+
if (activeV?.createdAt) {
|
|
977
|
+
this.row("Build date", formatAssetDate(activeV.createdAt), "dim");
|
|
978
|
+
}
|
|
979
|
+
if (activeV?.sha256) {
|
|
980
|
+
this.row("SHA256", activeV.sha256.slice(0, 12), "dim");
|
|
981
|
+
}
|
|
982
|
+
if (activeV) {
|
|
983
|
+
this.row("Installed", "Yes", "green");
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
this.row("Installed", "No", "red");
|
|
987
|
+
}
|
|
988
|
+
// Check if the installed version is the latest in its own channel
|
|
989
|
+
if (activeV) {
|
|
990
|
+
const ctype = activeV.isPrerelease ? "prerelease" : "stable";
|
|
991
|
+
const repoCh = `${activeV.repoName}/${ctype}`;
|
|
992
|
+
let isLatest = false;
|
|
993
|
+
for (const repo of loadRepoCache().repos ?? []) {
|
|
994
|
+
if (repo.name.toLowerCase() !== activeV.repoName.toLowerCase()) {
|
|
995
|
+
continue;
|
|
996
|
+
}
|
|
997
|
+
const candidates = (repo.versions ?? []).filter((v) => (v.is_prerelease ?? false) === activeV.isPrerelease);
|
|
998
|
+
if (candidates.length &&
|
|
999
|
+
activeV.version.build === candidates[0].build) {
|
|
1000
|
+
isLatest = true;
|
|
1001
|
+
}
|
|
1002
|
+
break;
|
|
1003
|
+
}
|
|
1004
|
+
this.row(`Latest in ${repoCh}?`, isLatest ? "Yes" : "No", isLatest ? "green" : "red");
|
|
1005
|
+
}
|
|
1006
|
+
// Last repo sync time from the cache file mtime
|
|
1007
|
+
if (fs.existsSync(REPO_CACHE_FILE)) {
|
|
1008
|
+
this.row("Last Sync", localTimestamp(fs.statSync(REPO_CACHE_FILE).mtime), "dim");
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
this.row("Last Sync", "Never", "red");
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
geoip() {
|
|
1015
|
+
this.header("GeoIP");
|
|
1016
|
+
if (!allowGeoip()) {
|
|
1017
|
+
this.row("Status", "Not supported (install camoufox[geoip])", "dim");
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
let config;
|
|
1021
|
+
try {
|
|
1022
|
+
config = loadGeoipConfig();
|
|
1023
|
+
}
|
|
1024
|
+
catch (e) {
|
|
1025
|
+
// the saved source is gone from the GeoIP list
|
|
1026
|
+
this.row("Database", e.message, "red");
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
const mmdbPath = getMmdbPath("ipv4", config);
|
|
1030
|
+
if (fs.existsSync(mmdbPath)) {
|
|
1031
|
+
this.row("Database", config.name ?? "Unknown");
|
|
1032
|
+
this.row("Updated", localTimestamp(fs.statSync(mmdbPath).mtime), "dim");
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
this.row("Database", "Not installed", "dim");
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
storage() {
|
|
1039
|
+
this.header("Storage");
|
|
1040
|
+
this.row("Install path", INSTALL_DIR, "cyan");
|
|
1041
|
+
this.row("Browser(s) directory size", dirSize(BROWSERS_DIR), "dim");
|
|
1042
|
+
if (allowGeoip()) {
|
|
1043
|
+
this.row("GeoIP database size", dirSize(GEOIP_DIR), "dim");
|
|
1044
|
+
}
|
|
1045
|
+
this.row("Config file", CONFIG_FILE, "cyan");
|
|
1046
|
+
this.row("Repo cache", REPO_CACHE_FILE, "cyan");
|
|
1047
|
+
}
|
|
1048
|
+
async printAll() {
|
|
1049
|
+
this.packages();
|
|
1050
|
+
this.browser();
|
|
1051
|
+
this.geoip();
|
|
1052
|
+
this.storage();
|
|
1053
|
+
// rich's Table.grid(padding=(0, 2)): the first column padded to its
|
|
1054
|
+
// widest cell, then two spaces.
|
|
1055
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: strips ANSI codes to measure
|
|
1056
|
+
const visible = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
1057
|
+
const width = Math.max(...this.rows.map(([label]) => visible(label)));
|
|
1058
|
+
for (const [label, value, st] of this.rows) {
|
|
1059
|
+
const pad = " ".repeat(width - visible(label));
|
|
1060
|
+
echo(value ? `${label}${pad} ${style(value, st)}` : label);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
/** "%Y-%m-%d %H:%M" in local time. */
|
|
1065
|
+
function localTimestamp(d) {
|
|
1066
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
1067
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
|
|
1068
|
+
}
|
|
1069
|
+
function dirSize(dir) {
|
|
1070
|
+
if (!fs.existsSync(dir))
|
|
1071
|
+
return "Nothing here";
|
|
1072
|
+
let total = 0;
|
|
1073
|
+
const walk = (current) => {
|
|
1074
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
1075
|
+
const full = path.join(current, entry.name);
|
|
1076
|
+
if (entry.isDirectory())
|
|
1077
|
+
walk(full);
|
|
1078
|
+
else if (entry.isFile())
|
|
1079
|
+
total += fs.statSync(full).size;
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
walk(dir);
|
|
1083
|
+
let size = total;
|
|
1084
|
+
for (const unit of ["B", "KB", "MB"]) {
|
|
1085
|
+
if (size < 1024) {
|
|
1086
|
+
return unit === "B" ? `${size} B` : `${size.toFixed(1)} ${unit}`;
|
|
1087
|
+
}
|
|
1088
|
+
size /= 1024;
|
|
1089
|
+
}
|
|
1090
|
+
return `${size.toFixed(1)} GB`;
|
|
1091
|
+
}
|
|
1092
|
+
program
|
|
1093
|
+
.command("gpu-xorg-config")
|
|
1094
|
+
.description('Print the Xorg config headless="virtual-gpu" needs for GPU')
|
|
1095
|
+
.argument("[gpu]")
|
|
1096
|
+
.action(async (gpu) => {
|
|
1097
|
+
const { selectGpu, xorgConfig } = await import("./gpudisplay.js");
|
|
1098
|
+
process.stdout.write(xorgConfig(selectGpu(gpu)));
|
|
1099
|
+
});
|
|
1100
|
+
program
|
|
1101
|
+
.command("gpu-setup")
|
|
1102
|
+
.description('Print a root script that sets this machine up for headless="virtual-gpu" on GPU')
|
|
1103
|
+
.argument("[gpu]")
|
|
1104
|
+
.action(async (gpu) => {
|
|
1105
|
+
const { selectGpu, setupScript } = await import("./gpudisplay.js");
|
|
1106
|
+
process.stdout.write(setupScript(selectGpu(gpu)));
|
|
1107
|
+
});
|
|
1108
|
+
program
|
|
1109
|
+
.command("version")
|
|
1110
|
+
.description("Display version, package, browser, and storage info")
|
|
1111
|
+
.action(async () => {
|
|
1112
|
+
await new VersionInfo().printAll();
|
|
1113
|
+
});
|
|
1114
|
+
program
|
|
1115
|
+
.command("active")
|
|
1116
|
+
.description("Print the current active version")
|
|
1117
|
+
.action(() => {
|
|
1118
|
+
const config = loadConfig();
|
|
1119
|
+
const pinned = config.pinned;
|
|
1120
|
+
const channel = config.channel || getDefaultChannel();
|
|
1121
|
+
const installed = listInstalled();
|
|
1122
|
+
const label = (v) => {
|
|
1123
|
+
const sha8 = (v.sha256 ?? "").slice(0, 8);
|
|
1124
|
+
return sha8 ? `${v.channelPath} (${sha8})` : v.channelPath;
|
|
1125
|
+
};
|
|
1126
|
+
const pin = effectivePin(config);
|
|
1127
|
+
if (pin) {
|
|
1128
|
+
const target = findInstalled(`${pin.repoName}/${pinSpec(pin)}`);
|
|
1129
|
+
if (target) {
|
|
1130
|
+
echo(`${label(target)} (paired with this release)`);
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
echo(`${pin.repoName}/${pinSpec(pin)} (paired with this release) `, false);
|
|
1134
|
+
rprint("(not fetched)", "yellow");
|
|
1135
|
+
}
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
if (pinned) {
|
|
1139
|
+
const pinnedSha = config.pinned_sha;
|
|
1140
|
+
const target = pinnedSha
|
|
1141
|
+
? (installed.find((v) => v.sha256 === pinnedSha) ?? null)
|
|
1142
|
+
: findInstalled(`${channel.toLowerCase()}/${pinned}`);
|
|
1143
|
+
if (target) {
|
|
1144
|
+
echo(label(target));
|
|
1145
|
+
}
|
|
1146
|
+
else {
|
|
1147
|
+
echo(`${channel.toLowerCase()}/${pinned} `, false);
|
|
1148
|
+
rprint("(not fetched)", "yellow");
|
|
1149
|
+
}
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
for (const v of installed) {
|
|
1153
|
+
if (v.isActive) {
|
|
1154
|
+
echo(label(v));
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
echo(`${channel.toLowerCase()} `, false);
|
|
1159
|
+
rprint("(not fetched)", "yellow");
|
|
1160
|
+
});
|
|
1161
|
+
program
|
|
1162
|
+
.command("path")
|
|
1163
|
+
.description("Print the install directory path")
|
|
1164
|
+
.action(() => {
|
|
1165
|
+
echo(INSTALL_DIR);
|
|
1166
|
+
});
|
|
1167
|
+
program
|
|
1168
|
+
.parseAsync(process.argv)
|
|
1169
|
+
.catch((error) => {
|
|
1170
|
+
rprint(error instanceof CommandFailed
|
|
1171
|
+
? error.message
|
|
1172
|
+
: `Error: ${errorMessage(error)}`, "red");
|
|
1173
|
+
process.exitCode = 1;
|
|
1174
|
+
})
|
|
1175
|
+
.finally(closePrompts);
|