@@ -21,54 +21,63 @@ export function installWindowsSetup({
21
21
appName,
22
22
filepath,
23
23
} : InstallablePackage ) : InstalledAppInfo {
24
- const { LOCALAPPDATA : LOCAL_APPDATA_PATH } = process . env ;
25
- assert (
26
- typeof LOCAL_APPDATA_PATH === 'string' ,
27
- 'Expected a LOCALAPPDATA environment injected by the shell'
28
- ) ;
29
- const installDirectory = path . resolve ( LOCAL_APPDATA_PATH , appName ) ;
30
-
31
- function uninstall ( { expectMissing = false } : UninstallOptions = { } ) {
32
- const registryEntry = windowsRegistry . query (
24
+ function queryRegistry ( ) {
25
+ return windowsRegistry . query (
33
26
`HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${ appName } `
34
27
) ;
35
- if ( registryEntry ) {
28
+ }
29
+
30
+ function uninstall ( { expectMissing = false } : UninstallOptions = { } ) {
31
+ const entry = queryRegistry ( ) ;
32
+ if ( entry ) {
33
+ const {
34
+ InstallLocation : installLocation ,
35
+ UninstallString : uninstallCommand ,
36
+ } = entry ;
37
+ assert (
38
+ typeof installLocation === 'string' ,
39
+ 'Expected an entry in the registry with the install location'
40
+ ) ;
41
+ assert (
42
+ typeof uninstallCommand === 'string' ,
43
+ 'Expected an entry in the registry with the uninstall command'
44
+ ) ;
36
45
if ( expectMissing ) {
37
46
console . warn (
38
47
'Found an existing registry entry (likely from a previous run)'
39
48
) ;
40
49
}
41
- const { UninstallString : uninstallCommand } = registryEntry ;
42
50
assert (
43
51
typeof uninstallCommand === 'string' ,
44
52
'Expected an UninstallString in the registry entry'
45
53
) ;
46
54
console . log ( `Running command to uninstall: ${ uninstallCommand } ` ) ;
47
55
cp . execSync ( uninstallCommand , { stdio : 'inherit' } ) ;
56
+ // Removing the any remaining files manually
57
+ fs . rmSync ( installLocation , { recursive : true , force : true } ) ;
48
58
}
49
- // Removing the any remaining files
50
- fs . rmSync ( installDirectory , { recursive : true , force : true } ) ;
51
59
}
52
60
53
61
uninstall ( { expectMissing : true } ) ;
54
62
55
- // Assert the app is not on the filesystem at the expected location
56
- assert (
57
- ! fs . existsSync ( installDirectory ) ,
58
- `Delete any existing installations first (found ${ installDirectory } )`
59
- ) ;
60
-
61
63
// Run the installer
62
64
console . warn (
63
65
"Installing globally, since we haven't discovered a way to specify an install path"
64
66
) ;
65
67
execute ( filepath , [ ] ) ;
66
68
67
- const appPath = path . resolve ( installDirectory , `${ appName } .exe` ) ;
68
- execute ( appPath , [ '--version' ] ) ;
69
+ const entry = queryRegistry ( ) ;
70
+ assert ( entry !== null , 'Expected an entry in the registry after installing' ) ;
71
+ const { InstallLocation : appPath } = entry ;
72
+ assert (
73
+ typeof appPath === 'string' ,
74
+ 'Expected an entry in the registry with the install location'
75
+ ) ;
76
+ const appExecutablePath = path . resolve ( appPath , `${ appName } .exe` ) ;
77
+ execute ( appExecutablePath , [ '--version' ] ) ;
69
78
70
79
return {
71
- appPath : installDirectory ,
80
+ appPath,
72
81
uninstall,
73
82
} ;
74
83
}
0 commit comments