@@ -482,6 +482,49 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
482482 return nonEmptyString ( listedEntries ?. [ 0 ] ?. dependencies ?. [ packageName ] ?. version ) ;
483483} ) ;
484484
485+ // npm names the tarball `${name}-${version}.tgz`, dropping a scope's `@` and its `/`.
486+ function parseNpmPackVersion ( stdout : string , packageName : string ) : string | null {
487+ const prefix = `${ packageName . replace ( / ^ @ / , "" ) . replace ( "/" , "-" ) } -` ;
488+ const filename = stdout . trim ( ) ;
489+ if ( ! filename . startsWith ( prefix ) || ! filename . endsWith ( ".tgz" ) ) return null ;
490+ const version = filename . slice ( prefix . length , - ".tgz" . length ) ;
491+ return version && ! / \s / . test ( version ) ? version : null ;
492+ }
493+
494+ const decodeVitePlusCurrentEnv = Schema . decodeUnknownOption (
495+ Schema . fromJsonString (
496+ Schema . Struct ( {
497+ node : Schema . Struct ( {
498+ source : Schema . String ,
499+ bin_path : Schema . String ,
500+ installed : Schema . Boolean ,
501+ } ) ,
502+ } ) ,
503+ ) ,
504+ ) ;
505+
506+ // `vp i -g` installs through the npm beside Vite+'s managed Node, even under `vp env off`, and
507+ // `vp env current` names that Node unless it reports a system one, which install does not use.
508+ // Pack honours npm's min-release-age and `before`, which `npm view` ignores, and resolves
509+ // `@latest` the way install does. `--json=false` keeps its output to the tarball name.
510+ const resolveVitePlusInstallableLatestVersion = Effect . fn (
511+ "resolveVitePlusInstallableLatestVersion" ,
512+ ) ( function * ( packageName : string , env : NodeJS . ProcessEnv , platform : NodeJS . Platform ) {
513+ const path = yield * Path . Path ;
514+ const current = yield * runProbe ( "vp" , [ "env" , "current" , "--json" ] , env ) ;
515+ const node = current ? Option . getOrUndefined ( decodeVitePlusCurrentEnv ( current ) ) ?. node : undefined ;
516+ if ( ! node ?. installed || node . source === "system PATH" || ! path . isAbsolute ( node . bin_path ) ) {
517+ return null ;
518+ }
519+ const npmPath = path . join ( path . dirname ( node . bin_path ) , platform === "win32" ? "npm.cmd" : "npm" ) ;
520+ const packed = yield * runProbe (
521+ npmPath ,
522+ [ "pack" , "--dry-run" , "--json=false" , "--global" , `${ packageName } @latest` ] ,
523+ env ,
524+ ) ;
525+ return packed ? parseNpmPackVersion ( packed , packageName ) : null ;
526+ } ) ;
527+
485528// `bun outdated` has no JSON output; its `Latest` column is what `@latest` installs
486529// under minimumReleaseAge (marked `*`). `Update` is only the global package.json range.
487530function parseBunOutdatedLatestVersion ( output : string , packageName : string ) : string | null {
@@ -613,14 +656,6 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain
613656 }
614657 const args = [ "upgrade" , miseTool ] ;
615658 const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
616- // Mise reads its settings from this environment, so each one gets its own cached answer.
617- const envHash = NodeCrypto . createHash ( "sha256" ) ;
618- for ( const [ name , value ] of Object . entries ( context . env ) . toSorted ( ( [ a ] , [ b ] ) =>
619- a < b ? - 1 : 1 ,
620- ) ) {
621- envHash . update ( `${ name } \0${ value ?? "" } \0` ) ;
622- }
623- const envKey = envHash . digest ( "hex" ) ;
624659 const capabilities = makeProviderMaintenanceCapabilities ( {
625660 ...owner ,
626661 updateExecutable : misePath ,
@@ -643,7 +678,9 @@ export const resolveMiseProviderMaintenance = Effect.fn("resolveMiseProviderMain
643678 } ) ;
644679 return {
645680 ...capabilities ,
646- latestVersionCacheKey : [ "mise" , misePath , miseTool , envKey ] . join ( "\0" ) ,
681+ latestVersionCacheKey : [ "mise" , misePath , miseTool , environmentCacheKey ( context . env ) ] . join (
682+ "\0" ,
683+ ) ,
647684 } ;
648685 } ,
649686) ;
@@ -797,14 +834,28 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
797834 ? manual
798835 : native ;
799836 if ( commandPaths . some ( isVitePlusGlobalCommandPath ) ) {
800- return makeProviderMaintenanceCapabilities ( {
837+ const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
838+ const capabilities = makeProviderMaintenanceCapabilities ( {
801839 provider : definition . provider ,
802840 packageName,
803841 updateExecutable : "vp" ,
804842 updateArgs : [ "i" , "-g" , packageName ] ,
805843 updateLockKey : "vite-plus-global" ,
806844 env : context . env ,
845+ lookupLatestVersion : resolveVitePlusInstallableLatestVersion (
846+ packageName ,
847+ context . env ,
848+ context . platform ,
849+ ) . pipe ( Effect . provideContext ( services ) ) ,
807850 } ) ;
851+ return {
852+ ...capabilities ,
853+ latestVersionCacheKey : [
854+ "vite-plus-global" ,
855+ packageName ,
856+ environmentCacheKey ( context . env ) ,
857+ ] . join ( "\0" ) ,
858+ } ;
808859 }
809860 if ( commandPaths . some ( isBunGlobalCommandPath ) ) {
810861 const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
0 commit comments