@@ -2,13 +2,36 @@ import { createRequire } from 'node:module'
22import { logger , useNuxt } from '@nuxt/kit'
33import { readPackageJSON } from 'pkg-types'
44import semver from 'semver'
5+ import { joinURL } from 'ufo'
56import { getPackageInfo } from 'local-pkg'
67import type { PackageUpdateInfo } from '../types'
78
89export async function getMainPackageJSON ( nuxt = useNuxt ( ) ) {
910 return readPackageJSON ( nuxt . options . rootDir )
1011}
1112
13+ export interface Packument {
14+ 'name' : string
15+ /**
16+ * An object where each key is a version, and each value is the manifest for
17+ * that version.
18+ */
19+ 'versions' : Record < string , Omit < Packument , 'versions' > >
20+ /**
21+ * An object mapping dist-tags to version numbers. This is how `foo@latest`
22+ * gets turned into `foo@1.2.3`.
23+ */
24+ 'dist-tags' : { latest : string } & Record < string , string >
25+ /**
26+ * In the full packument, an object mapping version numbers to publication
27+ * times, for the `opts.before` functionality.
28+ */
29+ 'time' : Record < string , string > & {
30+ created : string
31+ modified : string
32+ }
33+ }
34+
1235export async function checkForUpdateOf ( name : string , current ?: string , nuxt = useNuxt ( ) ) : Promise < PackageUpdateInfo | undefined > {
1336 try {
1437 if ( ! current ) {
@@ -22,11 +45,18 @@ export async function checkForUpdateOf(name: string, current?: string, nuxt = us
2245 if ( ! current )
2346 return
2447
25- const packument = await import ( 'pacote' ) . then ( r => r . default ?. packument || r . packument )
26- const manifest = await packument ( name )
48+ const { pickRegistry, json : fetchMeta } = await import ( 'npm-registry-fetch' )
49+ const reg = pickRegistry ( name )
50+ const manifest = await fetchMeta ( joinURL ( reg , name ) , {
51+ headers : {
52+ 'user-agent' : `npm node/${ process . version } ` ,
53+ 'accept' : 'application/json' ,
54+ } ,
55+ spec : name ,
56+ } ) as unknown as Packument
2757
28- const latest = manifest [ 'dist-tags' ] . latest
29- const needsUpdate = latest !== current && semver . lt ( current , latest )
58+ const latest = manifest ?. [ 'dist-tags' ] ? .latest
59+ const needsUpdate = ! ! latest && latest !== current && semver . lt ( current , latest )
3060
3161 return {
3262 name,
0 commit comments