@@ -486,22 +486,34 @@ function parseNpmPackVersion(stdout: string, packageName: string): string | null
486486 return version && ! / \s / . test ( version ) ? version : null ;
487487}
488488
489- // `vp i -g` installs through npm, whose min-release-age and `before` `npm view` ignores;
490- // pack resolves `@latest` the way install does. `--json=false` keeps its output to the tarball name.
491- const resolveNpmInstallableLatestVersion = Effect . fn ( "resolveNpmInstallableLatestVersion" ) (
492- function * ( packageName : string , env : NodeJS . ProcessEnv ) {
493- const npmPath = yield * resolveCommandPath ( "npm" , {
494- env : { ...( yield * HostProcess . Environment ) , ...env } ,
495- } ) ;
496- if ( ! npmPath ) return null ;
497- const packed = yield * runProbe (
498- npmPath ,
499- [ "pack" , "--dry-run" , "--json=false" , "--global" , `${ packageName } @latest` ] ,
500- env ,
501- ) ;
502- return packed ? parseNpmPackVersion ( packed , packageName ) : null ;
503- } ,
504- ) ;
489+ // `vp i -g` installs through the npm beside Vite+'s Node, which can differ from PATH's npm.
490+ // Pack honours npm's min-release-age and `before`, which `npm view` ignores, and resolves
491+ // `@latest` the way install does. `--json=false` keeps its output to the tarball name.
492+ const resolveVitePlusInstallableLatestVersion = Effect . fn (
493+ "resolveVitePlusInstallableLatestVersion" ,
494+ ) ( function * ( packageName : string , env : NodeJS . ProcessEnv , platform : NodeJS . Platform ) {
495+ const path = yield * Path . Path ;
496+ const nodePath = nonEmptyString (
497+ yield * runProbe ( "vp" , [ "env" , "exec" , "node" , "-p" , "process.execPath" ] , env ) ,
498+ ) ;
499+ if ( ! nodePath || ! path . isAbsolute ( nodePath ) ) return null ;
500+ const npmPath = path . join ( path . dirname ( nodePath ) , platform === "win32" ? "npm.cmd" : "npm" ) ;
501+ const packed = yield * runProbe (
502+ npmPath ,
503+ [ "pack" , "--dry-run" , "--json=false" , "--global" , `${ packageName } @latest` ] ,
504+ env ,
505+ ) ;
506+ return packed ? parseNpmPackVersion ( packed , packageName ) : null ;
507+ } ) ;
508+
509+ /** Installers read settings from their environment, so each one gets its own cached answer. */
510+ function environmentCacheKey ( env : NodeJS . ProcessEnv ) : string {
511+ const hash = NodeCrypto . createHash ( "sha256" ) ;
512+ for ( const [ name , value ] of Object . entries ( env ) . toSorted ( ( [ a ] , [ b ] ) => ( a < b ? - 1 : 1 ) ) ) {
513+ hash . update ( `${ name } \0${ value ?? "" } \0` ) ;
514+ }
515+ return hash . digest ( "hex" ) ;
516+ }
505517
506518const MiseInstall = Schema . Struct ( {
507519 install_path : Schema . String ,
@@ -603,14 +615,6 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain
603615 }
604616 const args = [ "upgrade" , miseTool ] ;
605617 const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
606- // Mise reads its settings from this environment, so each one gets its own cached answer.
607- const envHash = NodeCrypto . createHash ( "sha256" ) ;
608- for ( const [ name , value ] of Object . entries ( context . env ) . toSorted ( ( [ a ] , [ b ] ) =>
609- a < b ? - 1 : 1 ,
610- ) ) {
611- envHash . update ( `${ name } \0${ value ?? "" } \0` ) ;
612- }
613- const envKey = envHash . digest ( "hex" ) ;
614618 const capabilities = makeProviderMaintenanceCapabilities ( {
615619 ...owner ,
616620 updateExecutable : misePath ,
@@ -633,7 +637,9 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain
633637 } ) ;
634638 return {
635639 ...capabilities ,
636- latestVersionCacheKey : [ "mise" , misePath , miseTool , envKey ] . join ( "\0" ) ,
640+ latestVersionCacheKey : [ "mise" , misePath , miseTool , environmentCacheKey ( context . env ) ] . join (
641+ "\0" ,
642+ ) ,
637643 } ;
638644 } ,
639645) ;
@@ -731,17 +737,27 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
731737 : native ;
732738 if ( commandPaths . some ( isVitePlusGlobalCommandPath ) ) {
733739 const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
734- return makeProviderMaintenanceCapabilities ( {
740+ const capabilities = makeProviderMaintenanceCapabilities ( {
735741 provider : definition . provider ,
736742 packageName,
737743 updateExecutable : "vp" ,
738744 updateArgs : [ "i" , "-g" , packageName ] ,
739745 updateLockKey : "vite-plus-global" ,
740746 env : context . env ,
741- lookupLatestVersion : resolveNpmInstallableLatestVersion ( packageName , context . env ) . pipe (
742- Effect . provideContext ( services ) ,
743- ) ,
747+ lookupLatestVersion : resolveVitePlusInstallableLatestVersion (
748+ packageName ,
749+ context . env ,
750+ context . platform ,
751+ ) . pipe ( Effect . provideContext ( services ) ) ,
744752 } ) ;
753+ return {
754+ ...capabilities ,
755+ latestVersionCacheKey : [
756+ "vite-plus-global" ,
757+ packageName ,
758+ environmentCacheKey ( context . env ) ,
759+ ] . join ( "\0" ) ,
760+ } ;
745761 }
746762 if ( commandPaths . some ( isBunGlobalCommandPath ) ) {
747763 return makeProviderMaintenanceCapabilities ( {
0 commit comments