@@ -21,54 +21,63 @@ export function installWindowsSetup({
2121 appName,
2222 filepath,
2323} : 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 (
3326 `HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${ appName } `
3427 ) ;
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+ ) ;
3645 if ( expectMissing ) {
3746 console . warn (
3847 'Found an existing registry entry (likely from a previous run)'
3948 ) ;
4049 }
41- const { UninstallString : uninstallCommand } = registryEntry ;
4250 assert (
4351 typeof uninstallCommand === 'string' ,
4452 'Expected an UninstallString in the registry entry'
4553 ) ;
4654 console . log ( `Running command to uninstall: ${ uninstallCommand } ` ) ;
4755 cp . execSync ( uninstallCommand , { stdio : 'inherit' } ) ;
56+ // Removing the any remaining files manually
57+ fs . rmSync ( installLocation , { recursive : true , force : true } ) ;
4858 }
49- // Removing the any remaining files
50- fs . rmSync ( installDirectory , { recursive : true , force : true } ) ;
5159 }
5260
5361 uninstall ( { expectMissing : true } ) ;
5462
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-
6163 // Run the installer
6264 console . warn (
6365 "Installing globally, since we haven't discovered a way to specify an install path"
6466 ) ;
6567 execute ( filepath , [ ] ) ;
6668
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' ] ) ;
6978
7079 return {
71- appPath : installDirectory ,
80+ appPath,
7281 uninstall,
7382 } ;
7483}
0 commit comments