extension-install 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/lib/browser-target.d.ts +2 -0
- package/dist/lib/messages.d.ts +4 -2
- package/dist/lib/messaging.d.ts +12 -0
- package/dist/lib/runner.d.ts +6 -0
- package/dist/module.cjs +234 -54
- package/dist/module.d.ts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ When `--where` is used together with a browser name, `--browser`, or `--all` on
|
|
|
17
17
|
|
|
18
18
|
Uninstall scope is limited to the Extension.js managed cache root (or `EXT_BROWSERS_CACHE_DIR` when set). It does not remove browser installations outside that managed location.
|
|
19
19
|
|
|
20
|
-
Linux note for `edge`: Playwright channel installs may require a privileged interactive session (`sudo` prompt). If channel install cannot proceed but a system Edge binary is already present, Extension.js will use that existing binary. Otherwise, install Edge system-wide first and then run `extension install edge` (or use `chromium`).
|
|
20
|
+
Linux note for `edge`: Playwright channel installs may require a privileged interactive session (`sudo` prompt). If channel install cannot proceed but a system Edge binary is already present, Extension.js will use that existing binary. Otherwise, install Edge system-wide first and then run `extension install edge` (or use `chromium`). The `sudo` password prompt waits 5 minutes (or `EXTENSION_INSTALL_TIMEOUT_MS`, when that is shorter). With no answer by then, the install is stopped with the same privilege error.
|
|
21
21
|
|
|
22
22
|
Default managed cache locations are stable and human-readable:
|
|
23
23
|
- macOS: `~/Library/Caches/extension.js/browsers`
|
|
@@ -44,11 +44,13 @@ export declare class BrowserInstallForeignFolderError extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
export declare function isBrowserInstallForeignFolderError(error: unknown): error is BrowserInstallForeignFolderError;
|
|
46
46
|
export type UninstallOutcome = 'removed' | 'absent' | 'system' | 'failed';
|
|
47
|
+
export type UninstallFailureKind = 'removal' | 'permission' | 'foreign' | 'installing';
|
|
47
48
|
export interface UninstallResult {
|
|
48
49
|
browser: InstallBrowserTarget;
|
|
49
50
|
removed: boolean;
|
|
50
51
|
path: string;
|
|
51
52
|
outcome: UninstallOutcome;
|
|
53
|
+
kind?: UninstallFailureKind;
|
|
52
54
|
reason?: string;
|
|
53
55
|
systemPath?: string;
|
|
54
56
|
}
|
package/dist/lib/messages.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare function edgeAlreadyInstalled(binary: string, launcherFinds?: boo
|
|
|
8
8
|
export declare function installFailed(browser: InstallBrowserTarget, command: string, args: string[], result: CommandResult): string;
|
|
9
9
|
export declare function installIncomplete(browser: InstallBrowserTarget, destination: string, removed: boolean): string;
|
|
10
10
|
export declare function installerNotFound(browser: InstallBrowserTarget, command: string): string;
|
|
11
|
+
export declare function installerDidNotStart(browser: InstallBrowserTarget, command: string, cause: unknown): string;
|
|
11
12
|
export declare function installTimedOut(browser: InstallBrowserTarget, timeoutMs: number, removed: boolean): string;
|
|
12
13
|
export declare function installInterrupted(browser: InstallBrowserTarget, signal: string, removed: boolean): string;
|
|
13
14
|
export declare function installBusy(browser: InstallBrowserTarget, pid: number | null, timeoutMs: number, lockDir: string): string;
|
|
@@ -18,6 +19,7 @@ export declare function brokenTreeLeftBehind(destination: string): string;
|
|
|
18
19
|
export declare function cacheRootUnusable(browser: InstallBrowserTarget, cacheRoot: string, problem: string): string;
|
|
19
20
|
export declare function edgeInstallNeedsInteractivePrivilegedSession(): string;
|
|
20
21
|
export declare function edgeInstallNeedsAdministratorPassword(): string;
|
|
22
|
+
export declare function edgePasswordPromptTimedOut(platform: NodeJS.Platform, waitMs: number): string;
|
|
21
23
|
export declare function edgeInstallUsingSystemBinary(path: string, launcherFinds?: boolean): string;
|
|
22
24
|
export declare function uninstallRequiresTarget(): string;
|
|
23
25
|
export declare function uninstallingBrowsers(cacheRoot: string, browsers: InstallBrowserTarget[]): string;
|
|
@@ -26,5 +28,5 @@ export declare function uninstallNoop(browser: InstallBrowserTarget, checkedPath
|
|
|
26
28
|
export declare function uninstallSkippedSystemEdge(binary: string): string;
|
|
27
29
|
export declare function uninstallReasonForeign(): string;
|
|
28
30
|
export declare function uninstallReasonInstalling(pid: number | null): string;
|
|
29
|
-
export
|
|
30
|
-
export declare function uninstallFailed(results: UninstallResult[]
|
|
31
|
+
export declare function uninstallAllWithBrowser(): string;
|
|
32
|
+
export declare function uninstallFailed(results: UninstallResult[]): string;
|
package/dist/lib/messaging.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export declare function browserDisplayName(browser: string): string;
|
|
|
33
33
|
export declare function browserRowValue(browser: string, versionLine?: string): string;
|
|
34
34
|
export declare function isCardKeyClaimed(key: string): boolean;
|
|
35
35
|
export declare function claimCardKey(key: string): boolean;
|
|
36
|
+
export declare function holdCardKey(key: string): (() => void) | undefined;
|
|
37
|
+
export declare function releaseCardKeysOf(outputPath: string): void;
|
|
36
38
|
export declare function artifactNoun(browser: string): 'Add-on' | 'Extension';
|
|
37
39
|
export declare const ENVELOPE_SCHEMA = 1;
|
|
38
40
|
export declare const CODES: {
|
|
@@ -40,6 +42,7 @@ export declare const CODES: {
|
|
|
40
42
|
readonly E_PROJECT_NOT_FOUND: 'E_PROJECT_NOT_FOUND';
|
|
41
43
|
readonly E_MANIFEST_NOT_FOUND: 'E_MANIFEST_NOT_FOUND';
|
|
42
44
|
readonly E_MANIFEST_INVALID: 'E_MANIFEST_INVALID';
|
|
45
|
+
readonly E_PACKAGE_JSON_INVALID: 'E_PACKAGE_JSON_INVALID';
|
|
43
46
|
readonly E_FIRST_COMPILE: 'E_FIRST_COMPILE';
|
|
44
47
|
readonly E_COMPILE: 'E_COMPILE';
|
|
45
48
|
readonly E_BROWSER_NOT_FOUND: 'E_BROWSER_NOT_FOUND';
|
|
@@ -99,6 +102,7 @@ export declare const CODES: {
|
|
|
99
102
|
readonly E_OPTIONAL_DEP_UNKNOWN: 'E_OPTIONAL_DEP_UNKNOWN';
|
|
100
103
|
readonly E_COMPANION_EXTENSION_PATH: 'E_COMPANION_EXTENSION_PATH';
|
|
101
104
|
readonly E_MANIFEST_IN_PUBLIC: 'E_MANIFEST_IN_PUBLIC';
|
|
105
|
+
readonly E_FOLDER_UNREADABLE: 'E_FOLDER_UNREADABLE';
|
|
102
106
|
readonly E_RUNTIME_NOT_FOUND: 'E_RUNTIME_NOT_FOUND';
|
|
103
107
|
readonly E_COMPILE_FATAL: 'E_COMPILE_FATAL';
|
|
104
108
|
readonly E_MODULE_NOT_FOUND: 'E_MODULE_NOT_FOUND';
|
|
@@ -151,6 +155,7 @@ export declare const CODES: {
|
|
|
151
155
|
readonly E_PROJECT_LAYOUT: 'E_PROJECT_LAYOUT';
|
|
152
156
|
readonly E_ASSET_IMPORT_SHAPE: 'E_ASSET_IMPORT_SHAPE';
|
|
153
157
|
readonly E_ENV_FILE_UNREADABLE: 'E_ENV_FILE_UNREADABLE';
|
|
158
|
+
readonly E_INLINE_SCRIPT_SYNTAX: 'E_INLINE_SCRIPT_SYNTAX';
|
|
154
159
|
readonly W_MANAGED_DEP_CONFLICT: 'W_MANAGED_DEP_CONFLICT';
|
|
155
160
|
readonly W_TYPES_EMIT: 'W_TYPES_EMIT';
|
|
156
161
|
readonly W_MODULE_NOT_FOUND: 'W_MODULE_NOT_FOUND';
|
|
@@ -195,6 +200,13 @@ export declare const CODES: {
|
|
|
195
200
|
readonly W_ENV_NAME_RESERVED: 'W_ENV_NAME_RESERVED';
|
|
196
201
|
readonly W_COMPANION_EXTENSION_PATH: 'W_COMPANION_EXTENSION_PATH';
|
|
197
202
|
readonly W_ENV_DEFINE_WRITTEN: 'W_ENV_DEFINE_WRITTEN';
|
|
203
|
+
readonly W_ENV_ASSET_NOT_UTF8: 'W_ENV_ASSET_NOT_UTF8';
|
|
204
|
+
readonly W_HTML_NOT_UTF8: 'W_HTML_NOT_UTF8';
|
|
205
|
+
readonly W_RELOAD_NOT_APPLIED: 'W_RELOAD_NOT_APPLIED';
|
|
206
|
+
readonly W_CONTENT_SCRIPT_NOT_INJECTED: 'W_CONTENT_SCRIPT_NOT_INJECTED';
|
|
207
|
+
readonly W_CONTENT_SCRIPT_CLEANUP: 'W_CONTENT_SCRIPT_CLEANUP';
|
|
208
|
+
readonly W_CONTENT_SCRIPT_MOUNT: 'W_CONTENT_SCRIPT_MOUNT';
|
|
209
|
+
readonly W_DEV_SERVER_SOCKET: 'W_DEV_SERVER_SOCKET';
|
|
198
210
|
};
|
|
199
211
|
export type ErrorCode = (typeof CODES)[keyof typeof CODES];
|
|
200
212
|
export declare const CDP_FAULT_STEMS: readonly ['CDP_NOT_CONNECTED', 'CDP_TIMEOUT', 'CDP_OP_FAILED', 'BROWSER_CONNECTION_CLOSED', 'EXTENSION_ID_UNKNOWN'];
|
package/dist/lib/runner.d.ts
CHANGED
|
@@ -27,8 +27,13 @@ export interface CommandResult {
|
|
|
27
27
|
stdout: string;
|
|
28
28
|
stderr: string;
|
|
29
29
|
timedOut?: boolean;
|
|
30
|
+
promptTimedOut?: boolean;
|
|
30
31
|
interrupted?: NodeJS.Signals;
|
|
31
32
|
}
|
|
33
|
+
export declare function windowsTaskkillPath(env?: Record<string, string | undefined>): string;
|
|
34
|
+
export declare const PRIVILEGE_PROMPT_WAIT_MS: number;
|
|
35
|
+
export declare function parseProcessTable(text: string): Array<[number, number]>;
|
|
36
|
+
export declare function descendantsOf(root: number, table: Array<[number, number]>): number[];
|
|
32
37
|
export declare function installTimeoutMs(env?: Env): number;
|
|
33
38
|
type ForwardedSignal = 'SIGINT' | 'SIGTERM';
|
|
34
39
|
export interface SignalSource {
|
|
@@ -41,6 +46,7 @@ export interface RunCommandOptions {
|
|
|
41
46
|
env: NodeJS.ProcessEnv;
|
|
42
47
|
timeoutMs?: number;
|
|
43
48
|
ownGroup?: boolean;
|
|
49
|
+
promptWaitMs?: number;
|
|
44
50
|
graceMs?: number;
|
|
45
51
|
platform?: NodeJS.Platform;
|
|
46
52
|
signals?: SignalSource;
|
package/dist/module.cjs
CHANGED
|
@@ -188,39 +188,83 @@ function normalizeBrowserName(input) {
|
|
|
188
188
|
throw new BrowserNotInstallableError(`${value} cannot be installed by Extension.js. This CLI never downloads it; it is located from the system when present. Managed installs cover: ${Object.keys(BROWSER_ALIASES).join(', ')}.`);
|
|
189
189
|
}
|
|
190
190
|
function resolveBrowsersCacheRoot(env = process.env, platform = process.platform, cwd) {
|
|
191
|
+
const p = 'win32' === platform ? external_node_path_default().win32 : external_node_path_default().posix;
|
|
191
192
|
const explicit = String(env.EXT_BROWSERS_CACHE_DIR || '').trim();
|
|
192
|
-
if (explicit)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
if (explicit) {
|
|
194
|
+
if (external_node_path_default().isAbsolute(explicit) || p.isAbsolute(explicit)) return explicit;
|
|
195
|
+
return void 0 === cwd ? external_node_path_default().resolve(explicit) : p.resolve(cwd, explicit);
|
|
196
|
+
}
|
|
197
|
+
const inWorkingDir = ()=>void 0 === cwd ? external_node_path_default().resolve(process.cwd(), '.cache', 'extension.js', 'browsers') : p.resolve(cwd, '.cache', 'extension.js', 'browsers');
|
|
198
|
+
if ('win32' === platform) {
|
|
196
199
|
const local = String(env.LOCALAPPDATA || '').trim();
|
|
197
|
-
if (local) return
|
|
200
|
+
if (local) return p.join(local, 'extension.js', 'browsers');
|
|
198
201
|
const userProfile = String(env.USERPROFILE || '').trim();
|
|
199
|
-
if (userProfile) return
|
|
200
|
-
return
|
|
202
|
+
if (userProfile) return p.join(userProfile, 'AppData', 'Local', 'extension.js', 'browsers');
|
|
203
|
+
return inWorkingDir();
|
|
201
204
|
}
|
|
202
|
-
if (
|
|
205
|
+
if ('darwin' === platform) {
|
|
203
206
|
const home = String(env.HOME || '').trim();
|
|
204
|
-
if (home) return
|
|
205
|
-
return
|
|
207
|
+
if (home) return p.join(home, 'Library', 'Caches', 'extension.js', 'browsers');
|
|
208
|
+
return inWorkingDir();
|
|
206
209
|
}
|
|
207
210
|
const xdg = String(env.XDG_CACHE_HOME || '').trim();
|
|
208
|
-
if (xdg) return
|
|
211
|
+
if (xdg) return p.join(xdg, 'extension.js', 'browsers');
|
|
209
212
|
const home = String(env.HOME || '').trim();
|
|
210
|
-
if (home) return
|
|
211
|
-
return
|
|
213
|
+
if (home) return p.join(home, '.cache', 'extension.js', 'browsers');
|
|
214
|
+
return inWorkingDir();
|
|
212
215
|
}
|
|
213
216
|
function resolveBrowserInstallDir(browser, cacheRoot = resolveBrowsersCacheRoot()) {
|
|
214
217
|
return external_node_path_default().join(cacheRoot, browser);
|
|
215
218
|
}
|
|
216
219
|
function cache_root_removeTree(dir) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
try {
|
|
221
|
+
external_node_fs_default().rmSync(dir, {
|
|
222
|
+
recursive: true,
|
|
223
|
+
force: true,
|
|
224
|
+
maxRetries: 4,
|
|
225
|
+
retryDelay: 100
|
|
226
|
+
});
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw explainRemovalFailure(dir, error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const REFUSED_REMOVAL = new Set([
|
|
232
|
+
'ENOTEMPTY',
|
|
233
|
+
'EACCES',
|
|
234
|
+
'EPERM'
|
|
235
|
+
]);
|
|
236
|
+
function explainRemovalFailure(dir, error) {
|
|
237
|
+
const code = error?.code;
|
|
238
|
+
if (!code || !REFUSED_REMOVAL.has(code)) return error;
|
|
239
|
+
const blocked = firstUnwritableFolder(dir);
|
|
240
|
+
if (!blocked) return error;
|
|
241
|
+
return Object.assign(new Error(`EACCES: permission denied, no write access to '${blocked}'`), {
|
|
242
|
+
code: 'EACCES',
|
|
243
|
+
path: blocked,
|
|
244
|
+
cause: error
|
|
222
245
|
});
|
|
223
246
|
}
|
|
247
|
+
function firstUnwritableFolder(dir) {
|
|
248
|
+
const queue = [
|
|
249
|
+
dir
|
|
250
|
+
];
|
|
251
|
+
for(let seen = 0; queue.length > 0 && seen < 10000; seen++){
|
|
252
|
+
const current = queue.shift();
|
|
253
|
+
try {
|
|
254
|
+
external_node_fs_default().accessSync(current, external_node_fs_default().constants.W_OK);
|
|
255
|
+
} catch {
|
|
256
|
+
return current;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
for (const entry of external_node_fs_default().readdirSync(current, {
|
|
260
|
+
withFileTypes: true
|
|
261
|
+
}))if (entry.isDirectory()) queue.push(external_node_path_default().join(current, entry.name));
|
|
262
|
+
} catch {
|
|
263
|
+
return current;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
224
268
|
const INSTALL_MARKER_FILE = '.extension-install.json';
|
|
225
269
|
const BUILD_FOLDER = /^(?:linux|linux_arm|mac|mac_arm|win32|win64)-[0-9A-Za-z][0-9A-Za-z._-]*$/;
|
|
226
270
|
const EDGE_BUILD_FOLDER = /^msedge(?:-[0-9A-Za-z][0-9A-Za-z._-]*)?$/;
|
|
@@ -583,6 +627,11 @@ function installerNotFound(browser, command) {
|
|
|
583
627
|
const runner = command.replace(/\.cmd$/i, '');
|
|
584
628
|
return `Couldn't install ${titleCase(browser)}. The package runner ${runner} wasn't found on this machine. Install ${RUNNER_OWNERS[runner] || runner}, or run this command through a package manager that is installed.`;
|
|
585
629
|
}
|
|
630
|
+
function installerDidNotStart(browser, command, cause) {
|
|
631
|
+
const runner = command.replace(/\.cmd$/i, '');
|
|
632
|
+
const code = cause?.code;
|
|
633
|
+
return `Couldn't install ${titleCase(browser)}. The package runner ${runner} didn't start` + (code ? ` (${code})` : '') + ", so nothing was downloaded.";
|
|
634
|
+
}
|
|
586
635
|
function plural(count, unit) {
|
|
587
636
|
return `${count} ${unit}${1 === count ? '' : 's'}`;
|
|
588
637
|
}
|
|
@@ -628,6 +677,11 @@ function edgeInstallNeedsInteractivePrivilegedSession() {
|
|
|
628
677
|
function edgeInstallNeedsAdministratorPassword() {
|
|
629
678
|
return "Edge needs an administrator password on macOS. Run this command in a terminal where the installer can ask for it, then run Extension.js with --browser=edge. Use --browser=chromium when an administrator password is unavailable.";
|
|
630
679
|
}
|
|
680
|
+
function edgePasswordPromptTimedOut(platform, waitMs) {
|
|
681
|
+
const waited = readableDuration(waitMs);
|
|
682
|
+
if ('darwin' === platform) return `Edge needs an administrator password on macOS, and none was entered within ${waited}, so the install was stopped. Run the install again and enter the password, then run Extension.js with --browser=edge. Use --browser=chromium when an administrator password is unavailable.`;
|
|
683
|
+
return `Edge needs your password for sudo on Linux, and none was entered within ${waited}, so the install was stopped. Run the install again and enter the password, or install Edge system-wide with your package manager (sudo apt install microsoft-edge-stable on Ubuntu and Debian, sudo dnf install microsoft-edge-stable on Fedora) and run Extension.js with --browser=edge. Use --browser=chromium when a privileged install is unavailable.`;
|
|
684
|
+
}
|
|
631
685
|
function edgeInstallUsingSystemBinary(path, launcherFinds = true) {
|
|
632
686
|
return `${prefix('warn')} Skipping the Edge channel install, it needs elevated privileges.\n${external_pintor_default().yellow('Using the Edge binary already on this system instead.')}\n${fmt.label('PATH')} ${fmt.val(path)}` + launcherHint(launcherFinds);
|
|
633
687
|
}
|
|
@@ -652,16 +706,20 @@ function uninstallReasonForeign() {
|
|
|
652
706
|
function uninstallReasonInstalling(pid) {
|
|
653
707
|
return null === pid ? 'an install of it is running' : `an install of it is running, PID ${pid}`;
|
|
654
708
|
}
|
|
709
|
+
function uninstallAllWithBrowser() {
|
|
710
|
+
return "Pass --browser <name> to remove one browser, or --all to remove every browser, not both.";
|
|
711
|
+
}
|
|
655
712
|
const UNINSTALL_REMEDIES = {
|
|
656
713
|
removal: 'Close any browser running from that folder, then run the uninstall again.',
|
|
714
|
+
permission: 'Give your user write access to that folder, or remove it yourself, then run the uninstall again.',
|
|
657
715
|
foreign: 'Extension.js removes only the folders it installed, so delete that one yourself if you mean to.',
|
|
658
716
|
installing: 'Wait for the install to finish, then run the uninstall again.'
|
|
659
717
|
};
|
|
660
|
-
function uninstallFailed(results
|
|
718
|
+
function uninstallFailed(results) {
|
|
661
719
|
const failed = results.filter((result)=>'failed' === result.outcome);
|
|
662
|
-
const kindOf = (index)=>
|
|
720
|
+
const kindOf = (index)=>failed[index].kind ?? 'removal';
|
|
663
721
|
const names = failed.map((result)=>titleCase(result.browser)).join(', ');
|
|
664
|
-
const evidence = failed.map((result, index)=>'removal' === kindOf(index) ? `${result.path} is still there (${result.reason}).` : `${result.path} was left untouched (${result.reason}).`).join(' ');
|
|
722
|
+
const evidence = failed.map((result, index)=>'removal' === kindOf(index) || 'permission' === kindOf(index) ? `${result.path} is still there (${result.reason}).` : `${result.path} was left untouched (${result.reason}).`).join(' ');
|
|
665
723
|
const remedies = Object.keys(UNINSTALL_REMEDIES).filter((kind)=>failed.some((_result, index)=>kindOf(index) === kind)).map((kind)=>UNINSTALL_REMEDIES[kind]).join(' ');
|
|
666
724
|
return `Couldn't remove ${names}. ${evidence} ${remedies}`;
|
|
667
725
|
}
|
|
@@ -720,9 +778,15 @@ function buildExecEnv(base, platform = process.platform, execPath = process.exec
|
|
|
720
778
|
if ('win32' !== platform) return base;
|
|
721
779
|
const nodeDir = external_node_path_default().win32.dirname(execPath);
|
|
722
780
|
const pathSep = external_node_path_default().win32.delimiter;
|
|
723
|
-
const existing = base.PATH || base.Path || '';
|
|
724
|
-
|
|
725
|
-
|
|
781
|
+
const existing = String(base.PATH || base.Path || '').trim();
|
|
782
|
+
const withoutLastSlashes = (entry)=>{
|
|
783
|
+
let end = entry.length;
|
|
784
|
+
while(end > 0 && '\\' === entry[end - 1])end--;
|
|
785
|
+
return entry.slice(0, end);
|
|
786
|
+
};
|
|
787
|
+
const same = (entry)=>withoutLastSlashes(entry.trim()).toLowerCase() === nodeDir.toLowerCase();
|
|
788
|
+
if (existing.split(pathSep).some(same)) return base;
|
|
789
|
+
const updated = existing ? `${nodeDir}${pathSep}${existing}` : nodeDir;
|
|
726
790
|
return {
|
|
727
791
|
...base,
|
|
728
792
|
PATH: updated,
|
|
@@ -844,6 +908,63 @@ const DEFAULT_INSTALL_TIMEOUT_MS = 1800000;
|
|
|
844
908
|
const LONGEST_TIMER_MS = 2147483647;
|
|
845
909
|
const KILL_GRACE_MS = 2000;
|
|
846
910
|
const KILL_SETTLE_MS = 1000;
|
|
911
|
+
const TASKKILL_BOUND_MS = 30000;
|
|
912
|
+
function windowsTaskkillPath(env = process.env) {
|
|
913
|
+
const root = env.SystemRoot || env.windir || 'C:\\Windows';
|
|
914
|
+
return external_node_path_default().win32.join(root, 'System32', 'taskkill.exe');
|
|
915
|
+
}
|
|
916
|
+
const ROOT_SWITCH_LINE = /^Switching to root user\b.*\r?\n/m;
|
|
917
|
+
const ROOT_SWITCH_OVERLAP = 64;
|
|
918
|
+
function parseProcessTable(text) {
|
|
919
|
+
const rows = [];
|
|
920
|
+
for (const line of String(text || '').split(/\r?\n/)){
|
|
921
|
+
const match = /^\s*(\d+)\s+(\d+)\s*$/.exec(line);
|
|
922
|
+
if (match) rows.push([
|
|
923
|
+
Number(match[1]),
|
|
924
|
+
Number(match[2])
|
|
925
|
+
]);
|
|
926
|
+
}
|
|
927
|
+
return rows;
|
|
928
|
+
}
|
|
929
|
+
function descendantsOf(root, table) {
|
|
930
|
+
const seen = new Set([
|
|
931
|
+
root
|
|
932
|
+
]);
|
|
933
|
+
const found = [];
|
|
934
|
+
const queue = [
|
|
935
|
+
root
|
|
936
|
+
];
|
|
937
|
+
while(queue.length > 0){
|
|
938
|
+
const parent = queue.shift();
|
|
939
|
+
for (const [pid, ppid] of table)if (!(ppid !== parent || seen.has(pid))) {
|
|
940
|
+
seen.add(pid);
|
|
941
|
+
found.push(pid);
|
|
942
|
+
queue.push(pid);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return found;
|
|
946
|
+
}
|
|
947
|
+
function readProcessTable() {
|
|
948
|
+
try {
|
|
949
|
+
const result = (0, external_node_child_process_namespaceObject.spawnSync)('ps', [
|
|
950
|
+
'-A',
|
|
951
|
+
'-o',
|
|
952
|
+
'pid=',
|
|
953
|
+
'-o',
|
|
954
|
+
'ppid='
|
|
955
|
+
], {
|
|
956
|
+
stdio: [
|
|
957
|
+
'ignore',
|
|
958
|
+
'pipe',
|
|
959
|
+
'ignore'
|
|
960
|
+
],
|
|
961
|
+
encoding: 'utf8'
|
|
962
|
+
});
|
|
963
|
+
return 0 === result.status ? String(result.stdout || '') : '';
|
|
964
|
+
} catch {
|
|
965
|
+
return '';
|
|
966
|
+
}
|
|
967
|
+
}
|
|
847
968
|
function installTimeoutMs(env = process.env) {
|
|
848
969
|
const text = String(env.EXTENSION_INSTALL_TIMEOUT_MS || '').trim();
|
|
849
970
|
const raw = /^\d+$/.test(text) ? Number(text) : 0;
|
|
@@ -867,40 +988,37 @@ async function runCommand(command, args, opts) {
|
|
|
867
988
|
const stderrDecoder = new external_node_string_decoder_namespaceObject.StringDecoder('utf8');
|
|
868
989
|
let stdout = '';
|
|
869
990
|
let stderr = '';
|
|
870
|
-
if (child.stdout) child.stdout.on('data', (chunk)=>{
|
|
871
|
-
stdout += stdoutDecoder.write(chunk);
|
|
872
|
-
progress.write(chunk);
|
|
873
|
-
});
|
|
874
|
-
if (child.stderr) child.stderr.on('data', (chunk)=>{
|
|
875
|
-
stderr += stderrDecoder.write(chunk);
|
|
876
|
-
process.stderr.write(chunk);
|
|
877
|
-
});
|
|
878
991
|
return new Promise((resolve, reject)=>{
|
|
879
992
|
let timedOut = false;
|
|
993
|
+
let promptTimedOut = false;
|
|
880
994
|
let interrupted;
|
|
881
995
|
let killTimer;
|
|
882
996
|
let settleTimer;
|
|
997
|
+
let taskkillTimer;
|
|
998
|
+
let ending = false;
|
|
999
|
+
let promptTimer;
|
|
1000
|
+
let promptState = opts.promptWaitMs ? 'unannounced' : 'answered';
|
|
883
1001
|
let settled = false;
|
|
1002
|
+
const below = new Set();
|
|
1003
|
+
const signalTree = (pid, signal)=>{
|
|
1004
|
+
const table = parseProcessTable(readProcessTable());
|
|
1005
|
+
const listed = new Set(table.map(([listedPid])=>listedPid));
|
|
1006
|
+
for (const found of descendantsOf(pid, table))below.add(found);
|
|
1007
|
+
for (const found of below)if (listed.has(found)) try {
|
|
1008
|
+
process.kill(found, signal);
|
|
1009
|
+
} catch {}
|
|
1010
|
+
};
|
|
884
1011
|
const signalChild = (signal)=>{
|
|
885
1012
|
if (void 0 === child.pid) return;
|
|
1013
|
+
if (!ownGroup && 'win32' !== platform) signalTree(child.pid, signal);
|
|
886
1014
|
try {
|
|
887
1015
|
if (ownGroup) process.kill(-child.pid, signal);
|
|
888
1016
|
else child.kill(signal);
|
|
889
1017
|
} catch {}
|
|
890
1018
|
};
|
|
891
|
-
const
|
|
892
|
-
if (killTimer) return;
|
|
893
|
-
|
|
894
|
-
spawnProcess('taskkill', [
|
|
895
|
-
'/pid',
|
|
896
|
-
String(child.pid),
|
|
897
|
-
'/T',
|
|
898
|
-
'/F'
|
|
899
|
-
], {
|
|
900
|
-
stdio: 'ignore'
|
|
901
|
-
}).on('error', ()=>{});
|
|
902
|
-
} catch {}
|
|
903
|
-
else signalChild(signal);
|
|
1019
|
+
const armKill = ()=>{
|
|
1020
|
+
if (killTimer || settled) return;
|
|
1021
|
+
clearTimeout(taskkillTimer);
|
|
904
1022
|
killTimer = setTimeout(()=>{
|
|
905
1023
|
signalChild('SIGKILL');
|
|
906
1024
|
settleTimer = setTimeout(()=>{
|
|
@@ -910,6 +1028,59 @@ async function runCommand(command, args, opts) {
|
|
|
910
1028
|
}, KILL_SETTLE_MS);
|
|
911
1029
|
}, graceMs);
|
|
912
1030
|
};
|
|
1031
|
+
const endChild = (signal)=>{
|
|
1032
|
+
if (ending) return;
|
|
1033
|
+
ending = true;
|
|
1034
|
+
if ('win32' === platform && void 0 !== child.pid) try {
|
|
1035
|
+
spawnProcess(windowsTaskkillPath(), [
|
|
1036
|
+
'/pid',
|
|
1037
|
+
String(child.pid),
|
|
1038
|
+
'/T',
|
|
1039
|
+
'/F'
|
|
1040
|
+
], {
|
|
1041
|
+
stdio: 'ignore'
|
|
1042
|
+
}).on('error', armKill).on('close', armKill);
|
|
1043
|
+
taskkillTimer = setTimeout(armKill, TASKKILL_BOUND_MS);
|
|
1044
|
+
} catch {
|
|
1045
|
+
armKill();
|
|
1046
|
+
}
|
|
1047
|
+
else {
|
|
1048
|
+
signalChild(signal);
|
|
1049
|
+
armKill();
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
const watchPrompt = (from, before)=>{
|
|
1053
|
+
if ('waiting' === promptState) {
|
|
1054
|
+
promptState = 'answered';
|
|
1055
|
+
clearTimeout(promptTimer);
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
if ('unannounced' !== promptState || 'stdout' !== from) return;
|
|
1059
|
+
const recent = stdout.slice(Math.max(0, before - ROOT_SWITCH_OVERLAP));
|
|
1060
|
+
const line = ROOT_SWITCH_LINE.exec(recent);
|
|
1061
|
+
if (!line) return;
|
|
1062
|
+
if (recent.slice(line.index + line[0].length).trim()) {
|
|
1063
|
+
promptState = 'answered';
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
promptState = 'waiting';
|
|
1067
|
+
promptTimer = setTimeout(()=>{
|
|
1068
|
+
promptTimedOut = true;
|
|
1069
|
+
endChild('SIGTERM');
|
|
1070
|
+
}, Math.min(opts.promptWaitMs, LONGEST_TIMER_MS));
|
|
1071
|
+
};
|
|
1072
|
+
if (child.stdout) child.stdout.on('data', (chunk)=>{
|
|
1073
|
+
const before = stdout.length;
|
|
1074
|
+
stdout += stdoutDecoder.write(chunk);
|
|
1075
|
+
progress.write(chunk);
|
|
1076
|
+
watchPrompt('stdout', before);
|
|
1077
|
+
});
|
|
1078
|
+
if (child.stderr) child.stderr.on('data', (chunk)=>{
|
|
1079
|
+
const before = stderr.length;
|
|
1080
|
+
stderr += stderrDecoder.write(chunk);
|
|
1081
|
+
process.stderr.write(chunk);
|
|
1082
|
+
watchPrompt('stderr', before);
|
|
1083
|
+
});
|
|
913
1084
|
const onInterrupt = ()=>forward('SIGINT');
|
|
914
1085
|
const onTerminate = ()=>forward('SIGTERM');
|
|
915
1086
|
function forward(signal) {
|
|
@@ -925,6 +1096,8 @@ async function runCommand(command, args, opts) {
|
|
|
925
1096
|
clearTimeout(timer);
|
|
926
1097
|
clearTimeout(killTimer);
|
|
927
1098
|
clearTimeout(settleTimer);
|
|
1099
|
+
clearTimeout(taskkillTimer);
|
|
1100
|
+
clearTimeout(promptTimer);
|
|
928
1101
|
signals.off('SIGINT', onInterrupt);
|
|
929
1102
|
signals.off('SIGTERM', onTerminate);
|
|
930
1103
|
}
|
|
@@ -940,6 +1113,9 @@ async function runCommand(command, args, opts) {
|
|
|
940
1113
|
...timedOut ? {
|
|
941
1114
|
timedOut
|
|
942
1115
|
} : {},
|
|
1116
|
+
...promptTimedOut ? {
|
|
1117
|
+
promptTimedOut
|
|
1118
|
+
} : {},
|
|
943
1119
|
...interrupted ? {
|
|
944
1120
|
interrupted
|
|
945
1121
|
} : {}
|
|
@@ -1145,6 +1321,9 @@ function refuseForeignFolder(target, destination) {
|
|
|
1145
1321
|
function isMissingRunner(error, cwd) {
|
|
1146
1322
|
return error?.code === 'ENOENT' && external_node_fs_default().existsSync(cwd);
|
|
1147
1323
|
}
|
|
1324
|
+
function isSystemError(error) {
|
|
1325
|
+
return /^E[A-Z0-9]+$/.test(String(error?.code ?? ''));
|
|
1326
|
+
}
|
|
1148
1327
|
function dropMarkerOnlyFolder(destination) {
|
|
1149
1328
|
try {
|
|
1150
1329
|
if (holdsOnlyMarker(destination)) removeMarkerOnlyFolder(destination);
|
|
@@ -1172,13 +1351,14 @@ async function installUnderLock({ defaulted, locateInstalledBinary, runInstaller
|
|
|
1172
1351
|
env: plan.env,
|
|
1173
1352
|
timeoutMs,
|
|
1174
1353
|
...needsTerminal ? {
|
|
1175
|
-
ownGroup: false
|
|
1354
|
+
ownGroup: false,
|
|
1355
|
+
promptWaitMs: Math.min(300000, timeoutMs)
|
|
1176
1356
|
} : {}
|
|
1177
1357
|
});
|
|
1178
1358
|
} catch (error) {
|
|
1179
1359
|
dropMarkerOnlyFolder(destination);
|
|
1180
|
-
if (!
|
|
1181
|
-
throw withCause(new BrowserInstallerNotFoundError(installerNotFound(target, cmd)), error);
|
|
1360
|
+
if (!isSystemError(error)) throw error;
|
|
1361
|
+
throw withCause(isMissingRunner(error, plan.cwd) ? new BrowserInstallerNotFoundError(installerNotFound(target, cmd)) : new BrowserInstallFailedError(installerDidNotStart(target, cmd, error)), error);
|
|
1182
1362
|
}
|
|
1183
1363
|
if (0 !== result.code) {
|
|
1184
1364
|
const discard = locateInstalledBinary(destination, target) ? {
|
|
@@ -1186,14 +1366,14 @@ async function installUnderLock({ defaulted, locateInstalledBinary, runInstaller
|
|
|
1186
1366
|
} : discardUnusableInstallTree(destination, target, removeTree, lock);
|
|
1187
1367
|
if (result.timedOut) throw withRemovalFailure((message)=>new BrowserInstallTimeoutError(message, timeoutMs), installTimedOut(target, timeoutMs, discard.removed), destination, discard);
|
|
1188
1368
|
if (result.interrupted) throw withRemovalFailure((message)=>new BrowserInstallFailedError(message), installInterrupted(target, result.interrupted, discard.removed), destination, discard);
|
|
1189
|
-
if ('edge' === target && isEdgePrivilegeEscalationFailure(`${result.stdout}\n${result.stderr}`)) {
|
|
1369
|
+
if ('edge' === target && (result.promptTimedOut || isEdgePrivilegeEscalationFailure(`${result.stdout}\n${result.stderr}`))) {
|
|
1190
1370
|
const installedEdge = locateSystemEdge(edgeLookup);
|
|
1191
1371
|
if (installedEdge) {
|
|
1192
1372
|
humanWarn(edgeInstallUsingSystemBinary(installedEdge.path, installedEdge.launcherFinds));
|
|
1193
1373
|
if ('failure' in discard) humanWarn(brokenTreeLeftBehind(destination));
|
|
1194
1374
|
return;
|
|
1195
1375
|
}
|
|
1196
|
-
throw withRemovalFailure((message)=>new BrowserInstallPrivilegeError(message), 'darwin' === platform ? edgeInstallNeedsAdministratorPassword() : edgeInstallNeedsInteractivePrivilegedSession(), destination, discard);
|
|
1376
|
+
throw withRemovalFailure((message)=>new BrowserInstallPrivilegeError(message), result.promptTimedOut ? edgePasswordPromptTimedOut(platform, Math.min(300000, timeoutMs)) : 'darwin' === platform ? edgeInstallNeedsAdministratorPassword() : edgeInstallNeedsInteractivePrivilegedSession(), destination, discard);
|
|
1197
1377
|
}
|
|
1198
1378
|
throw withRemovalFailure((message)=>new BrowserInstallFailedError(message), installFailed(target, cmd, args, result), destination, discard);
|
|
1199
1379
|
}
|
|
@@ -1292,7 +1472,7 @@ function removeManagedFolder(target, cacheRoot, remove, timeoutMs, seams) {
|
|
|
1292
1472
|
} catch (failure) {
|
|
1293
1473
|
return {
|
|
1294
1474
|
state: 'failed',
|
|
1295
|
-
kind: 'removal',
|
|
1475
|
+
kind: failure?.code === 'EACCES' ? 'permission' : 'removal',
|
|
1296
1476
|
reason: firstLine(failure),
|
|
1297
1477
|
failure
|
|
1298
1478
|
};
|
|
@@ -1303,6 +1483,7 @@ function removeManagedFolder(target, cacheRoot, remove, timeoutMs, seams) {
|
|
|
1303
1483
|
async function extensionUninstall({ browser, all, env, platform, systemEdge, removeTree = cache_root_removeTree, lock: lockSeams = {} }) {
|
|
1304
1484
|
const cacheRoot = resolveBrowsersCacheRoot(env, platform);
|
|
1305
1485
|
if (!all && !browser) throw new Error(uninstallRequiresTarget());
|
|
1486
|
+
if (all && String(browser || '').trim()) throw new Error(uninstallAllWithBrowser());
|
|
1306
1487
|
const named = all ? [
|
|
1307
1488
|
...ALL_BROWSER_TARGETS
|
|
1308
1489
|
] : String(browser || '').split(',').map((part)=>part.trim()).filter(Boolean).map((name)=>normalizeBrowserName(name));
|
|
@@ -1313,19 +1494,18 @@ async function extensionUninstall({ browser, all, env, platform, systemEdge, rem
|
|
|
1313
1494
|
humanLine(uninstallingBrowsers(cacheRoot, targets));
|
|
1314
1495
|
const timeoutMs = installTimeoutMs(env ?? process.env);
|
|
1315
1496
|
const results = [];
|
|
1316
|
-
const kinds = [];
|
|
1317
1497
|
const failures = [];
|
|
1318
1498
|
for (const target of targets){
|
|
1319
1499
|
const installDir = resolveBrowserInstallDir(target, cacheRoot);
|
|
1320
1500
|
const removal = removeManagedFolder(target, cacheRoot, removeTree, timeoutMs, lockSeams);
|
|
1321
1501
|
if ('failed' === removal.state) {
|
|
1322
|
-
kinds.push(removal.kind);
|
|
1323
1502
|
if ('failure' in removal) failures.push(removal.failure);
|
|
1324
1503
|
results.push({
|
|
1325
1504
|
browser: target,
|
|
1326
1505
|
removed: false,
|
|
1327
1506
|
path: installDir,
|
|
1328
1507
|
outcome: 'failed',
|
|
1508
|
+
kind: removal.kind,
|
|
1329
1509
|
reason: removal.reason
|
|
1330
1510
|
});
|
|
1331
1511
|
continue;
|
|
@@ -1364,7 +1544,7 @@ async function extensionUninstall({ browser, all, env, platform, systemEdge, rem
|
|
|
1364
1544
|
outcome: 'absent'
|
|
1365
1545
|
});
|
|
1366
1546
|
}
|
|
1367
|
-
if (results.some((result)=>'failed' === result.outcome)) throw withCause(new BrowserUninstallError(uninstallFailed(results
|
|
1547
|
+
if (results.some((result)=>'failed' === result.outcome)) throw withCause(new BrowserUninstallError(uninstallFailed(results), results), failures.length > 1 ? new AggregateError(failures) : failures[0]);
|
|
1368
1548
|
return results;
|
|
1369
1549
|
}
|
|
1370
1550
|
exports.BrowserCacheRootError = __webpack_exports__.BrowserCacheRootError;
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BrowserCacheRootError, BrowserInstallBusyError, BrowserInstallerNotFoundError, BrowserInstallFailedError, BrowserInstallForeignFolderError, BrowserInstallPrivilegeError, BrowserInstallTimeoutError, BrowserNotInstallableError, BrowserUninstallError, type InstallBrowserTarget, isBrowserCacheRootError, isBrowserInstallBusyError, isBrowserInstallerNotFoundError, isBrowserInstallFailedError, isBrowserInstallForeignFolderError, isBrowserInstallPrivilegeError, isBrowserInstallTimeoutError, isBrowserNotInstallableError, isBrowserUninstallError, normalizeBrowserName, type UninstallOutcome, type UninstallResult } from './lib/browser-target.js';
|
|
1
|
+
import { BrowserCacheRootError, BrowserInstallBusyError, BrowserInstallerNotFoundError, BrowserInstallFailedError, BrowserInstallForeignFolderError, BrowserInstallPrivilegeError, BrowserInstallTimeoutError, BrowserNotInstallableError, BrowserUninstallError, type InstallBrowserTarget, isBrowserCacheRootError, isBrowserInstallBusyError, isBrowserInstallerNotFoundError, isBrowserInstallFailedError, isBrowserInstallForeignFolderError, isBrowserInstallPrivilegeError, isBrowserInstallTimeoutError, isBrowserNotInstallableError, isBrowserUninstallError, normalizeBrowserName, type UninstallFailureKind, type UninstallOutcome, type UninstallResult } from './lib/browser-target.js';
|
|
2
2
|
export { BrowserCacheRootError, BrowserInstallBusyError, BrowserInstallerNotFoundError, BrowserInstallFailedError, BrowserInstallForeignFolderError, BrowserInstallPrivilegeError, BrowserInstallTimeoutError, BrowserNotInstallableError, BrowserUninstallError, isBrowserCacheRootError, isBrowserInstallBusyError, isBrowserInstallerNotFoundError, isBrowserInstallFailedError, isBrowserInstallForeignFolderError, isBrowserInstallPrivilegeError, isBrowserInstallTimeoutError, isBrowserNotInstallableError, isBrowserUninstallError, normalizeBrowserName };
|
|
3
|
-
export type { InstallBrowserTarget, UninstallOutcome, UninstallResult };
|
|
3
|
+
export type { InstallBrowserTarget, UninstallFailureKind, UninstallOutcome, UninstallResult };
|
|
4
4
|
export type { LockSeams } from './lib/install-lock.js';
|
|
5
5
|
import { type LockSeams } from './lib/install-lock.js';
|
|
6
6
|
import { type InstallPlanOptions, runCommand, type SystemEdgeLookup } from './lib/runner.js';
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"name": "extension-install",
|
|
25
|
-
"version": "4.
|
|
25
|
+
"version": "4.3.0",
|
|
26
26
|
"description": "Managed browser installer/uninstaller for Extension.js",
|
|
27
27
|
"author": {
|
|
28
28
|
"name": "Cezar Augusto",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"scripts": {
|
|
42
42
|
"watch": "node ../../scripts/run-locked.mjs watch \"rslib build --watch\"",
|
|
43
43
|
"compile": "node ../../scripts/run-locked.mjs compile \"rslib build\"",
|
|
44
|
-
"test": "
|
|
44
|
+
"test": "node ../../scripts/run-vitest.mjs"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|
|
47
47
|
"webextension",
|