@@ -376,24 +376,22 @@ const runProbe = Effect.fn("runProbe")(function* (
376376 ) ;
377377} ) ;
378378
379- const decodePnpmOutdated = Schema . decodeUnknownOption (
379+ const decodeOutdated = Schema . decodeUnknownOption (
380380 Schema . fromJsonString (
381381 Schema . Record ( Schema . String , Schema . Struct ( { latest : Schema . optional ( Schema . String ) } ) ) ,
382382 ) ,
383383) ;
384- const decodePnpmList = Schema . decodeUnknownOption (
385- Schema . fromJsonString (
386- Schema . Array (
387- Schema . Struct ( {
388- dependencies : Schema . optional (
389- Schema . Record ( Schema . String , Schema . Struct ( { version : Schema . optional ( Schema . String ) } ) ) ,
390- ) ,
391- } ) ,
392- ) ,
384+ const GlobalPackageList = Schema . Struct ( {
385+ dependencies : Schema . optional (
386+ Schema . Record ( Schema . String , Schema . Struct ( { version : Schema . optional ( Schema . String ) } ) ) ,
393387 ) ,
388+ } ) ;
389+ const decodePnpmList = Schema . decodeUnknownOption (
390+ Schema . fromJsonString ( Schema . Array ( GlobalPackageList ) ) ,
394391) ;
392+ const decodeNpmList = Schema . decodeUnknownOption ( Schema . fromJsonString ( GlobalPackageList ) ) ;
395393
396- // Unlike npm 's latest tag, pnpm outdated respects minimumReleaseAge and its excludes.
394+ // Unlike the registry 's latest tag, pnpm outdated respects minimumReleaseAge and its excludes.
397395const resolvePnpmGlobalLatestVersion = Effect . fn ( "resolvePnpmGlobalLatestVersion" ) ( function * (
398396 packageName : string ,
399397) {
@@ -408,9 +406,7 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
408406 // pnpm outdated exits 1 when updates are available.
409407 [ 0 , 1 ] ,
410408 ) ;
411- const outdatedEntries = outdated
412- ? Option . getOrUndefined ( decodePnpmOutdated ( outdated ) )
413- : undefined ;
409+ const outdatedEntries = outdated ? Option . getOrUndefined ( decodeOutdated ( outdated ) ) : undefined ;
414410 if ( ! outdatedEntries ) return null ;
415411 const latest = nonEmptyString ( outdatedEntries [ packageName ] ?. latest ) ;
416412 if ( latest ) return latest ;
@@ -424,6 +420,39 @@ const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion
424420 return nonEmptyString ( listedEntries ?. [ 0 ] ?. dependencies ?. [ packageName ] ?. version ) ;
425421} ) ;
426422
423+ // `npm view` ignores min-release-age and before, but `outdated` applies them and
424+ // their excludes the way `install <pkg>@latest` does.
425+ const resolveNpmGlobalLatestVersion = Effect . fn ( "resolveNpmGlobalLatestVersion" ) ( function * (
426+ packageName : string ,
427+ npmPrefix : string ,
428+ ) {
429+ // Match the updater's npm and server environment, rather than the instance's.
430+ const npmPath = yield * resolveCommandPath ( "npm" ) ;
431+ if ( ! npmPath ) return null ;
432+ const outdated = yield * runProbe (
433+ npmPath ,
434+ [ "outdated" , "-g" , "--prefix" , npmPrefix , "--json" , packageName ] ,
435+ { } ,
436+ // npm outdated exits 1 when updates are available.
437+ [ 0 , 1 ] ,
438+ ) ;
439+ const outdatedEntries = outdated ? Option . getOrUndefined ( decodeOutdated ( outdated ) ) : undefined ;
440+ // npm prints failures such as an unreachable registry as `{"error": ...}`, also exiting 1.
441+ if ( ! outdatedEntries || "error" in outdatedEntries ) return null ;
442+ const latest = nonEmptyString ( outdatedEntries [ packageName ] ?. latest ) ;
443+ if ( latest ) return latest ;
444+ // An empty result means the installed version is still the eligible release.
445+ const listed = yield * runProbe (
446+ npmPath ,
447+ [ "ls" , "-g" , "--prefix" , npmPrefix , "--depth" , "0" , "--json" , packageName ] ,
448+ { } ,
449+ // npm ls still prints the tree but exits 1 when other globals have problems.
450+ [ 0 , 1 ] ,
451+ ) ;
452+ const listedEntries = listed ? Option . getOrUndefined ( decodeNpmList ( listed ) ) : undefined ;
453+ return nonEmptyString ( listedEntries ?. dependencies ?. [ packageName ] ?. version ) ;
454+ } ) ;
455+
427456export const resolvePackageManagedProviderMaintenance = Effect . fn (
428457 "resolvePackageManagedProviderMaintenance" ,
429458) ( function * (
@@ -546,6 +575,7 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
546575 // `Cellar/node/<ver>/lib/node_modules/`, and that is npm's install, not brew's.
547576 const npmPrefix = yield * resolveNpmGlobalPrefix ( context , packageName ) ;
548577 if ( npmPrefix ) {
578+ const services = yield * Effect . context < ProviderMaintenanceResolverServices > ( ) ;
549579 // npm 12 blocks install scripts by default (empty allow-scripts allowlist)
550580 // and still exits 0, so a package whose postinstall finishes the install
551581 // (claude copies its native binary over a placeholder stub) is left broken
@@ -564,6 +594,12 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
564594 `${ packageName } @latest` ,
565595 ] ,
566596 updateLockKey : `npm-global:${ normalizeCommandPath ( npmPrefix ) } ` ,
597+ // Inside min-release-age `@latest` installs an older release than the
598+ // registry's tag, so only npm's own answer is worth advertising.
599+ latestVersion : null ,
600+ lookupLatestVersion : resolveNpmGlobalLatestVersion ( packageName , npmPrefix ) . pipe (
601+ Effect . provideContext ( services ) ,
602+ ) ,
567603 } ) ;
568604 }
569605
0 commit comments