-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpreuninstall.ts
45 lines (35 loc) · 1.32 KB
/
preuninstall.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as path from "path";
export class PreUninstallCommand implements ICommand {
public disableAnalytics = true;
public allowedParameters: ICommandParameter[] = [];
constructor(private $extensibilityService: IExtensibilityService,
private $fs: IFileSystem,
private $packageInstallationManager: IPackageInstallationManager,
private $settingsService: ISettingsService) { }
public async execute(args: string[]): Promise<void> {
if (this.isIntentionalUninstall()) {
this.handleIntentionalUninstall();
}
this.$fs.deleteFile(path.join(this.$settingsService.getProfileDir(), "KillSwitches", "cli"));
}
private isIntentionalUninstall(): boolean {
let isIntentionalUninstall = false;
if (process.env && process.env.npm_config_argv) {
try {
const npmConfigArgv = JSON.parse(process.env.npm_config_argv);
const uninstallAliases = ["uninstall", "remove", "rm", "r", "un", "unlink"];
if (_.intersection(npmConfigArgv.original, uninstallAliases).length > 0) {
isIntentionalUninstall = true;
}
} catch (error) {
// ignore
}
}
return isIntentionalUninstall;
}
private handleIntentionalUninstall(): void {
this.$extensibilityService.removeAllExtensions();
this.$packageInstallationManager.clearInspectorCache();
}
}
$injector.registerCommand("dev-preuninstall", PreUninstallCommand);