@@ -25,6 +25,7 @@ import * as BootService from "../cloud/bootService.ts";
2525import {
2626 ensurePinnedRuntimeInstalled ,
2727 findPosixLauncher ,
28+ generatedWindowsShimTarget ,
2829 launcherOwnsVersionsDir ,
2930 isUnpublishedRelease ,
3031 pinnedRuntimePaths ,
@@ -171,7 +172,7 @@ export const repointLauncher = Effect.fn("cli.update.repoint_launcher")(function
171172 ) ;
172173
173174 if ( platform === "win32" ) {
174- const shimPath = yield * findWindowsShim ( input . launchedAs ) ;
175+ const shimPath = yield * findWindowsShim ( input . launchedAs , versionsDir ) ;
175176 if ( shimPath === undefined ) return Option . none < string > ( ) ;
176177 const current = yield * fs . readFileString ( shimPath ) . pipe ( Effect . option ) ;
177178 const quoted = Option . isSome ( current ) ? windowsShimTarget ( current . value ) : undefined ;
@@ -203,22 +204,37 @@ export const repointLauncher = Effect.fn("cli.update.repoint_launcher")(function
203204 return Option . some ( launcher ) ;
204205} ) ;
205206
206- /** Windows executables see their own path, so find the installer shim by matching t3.cmd targets on PATH . */
207+ /** Windows executables see their own path, so locate the installer shim by matching its target . */
207208export const findWindowsShim = Effect . fn ( "cli.update.find_windows_shim" ) ( function * (
208209 executablePath : string ,
210+ versionsDir ?: string ,
209211) {
210212 const fs = yield * FileSystem . FileSystem ;
211213 const path = yield * Path . Path ;
212214 const environment = yield * HostProcess . Environment ;
213215 const candidates = [
214216 ...( environment [ "T3CODE_INSTALL_BIN_DIR" ] ? [ environment [ "T3CODE_INSTALL_BIN_DIR" ] ] : [ ] ) ,
215217 ...( environment [ "PATH" ] ?? environment [ "Path" ] ?? "" ) . split ( ";" ) ,
216- ] . filter ( ( entry ) => entry . trim ( ) . length > 0 ) ;
217- for ( const directory of candidates ) {
218- const shimPath = path . join ( directory , "t3.cmd" ) ;
218+ ]
219+ . filter ( ( entry ) => entry . trim ( ) . length > 0 )
220+ . map ( ( directory ) => ( {
221+ shimPath : path . join ( directory , "t3.cmd" ) ,
222+ parseTarget : windowsShimTarget ,
223+ } ) ) ;
224+ if ( versionsDir !== undefined ) {
225+ const recorded = yield * fs
226+ . readFileString ( path . join ( path . dirname ( versionsDir ) , "launchers" ) )
227+ . pipe ( Effect . orElseSucceed ( ( ) => "" ) ) ;
228+ for ( const shimPath of recorded . split ( / \r ? \n / ) ) {
229+ if ( path . isAbsolute ( shimPath ) && path . basename ( shimPath ) . toLowerCase ( ) === "t3.cmd" ) {
230+ candidates . push ( { shimPath, parseTarget : generatedWindowsShimTarget } ) ;
231+ }
232+ }
233+ }
234+ for ( const { shimPath, parseTarget } of candidates ) {
219235 const contents = yield * fs . readFileString ( shimPath ) . pipe ( Effect . option ) ;
220236 if ( Option . isNone ( contents ) ) continue ;
221- const target = windowsShimTarget ( contents . value ) ;
237+ const target = parseTarget ( contents . value ) ;
222238 if (
223239 target !== undefined &&
224240 path . resolve ( target ) . toLowerCase ( ) === path . resolve ( executablePath ) . toLowerCase ( )
0 commit comments