@@ -2,13 +2,36 @@ import { createRequire } from 'node:module'
2
2
import { logger , useNuxt } from '@nuxt/kit'
3
3
import { readPackageJSON } from 'pkg-types'
4
4
import semver from 'semver'
5
+ import { joinURL } from 'ufo'
5
6
import { getPackageInfo } from 'local-pkg'
6
7
import type { PackageUpdateInfo } from '../types'
7
8
8
9
export async function getMainPackageJSON ( nuxt = useNuxt ( ) ) {
9
10
return readPackageJSON ( nuxt . options . rootDir )
10
11
}
11
12
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
+
12
35
export async function checkForUpdateOf ( name : string , current ?: string , nuxt = useNuxt ( ) ) : Promise < PackageUpdateInfo | undefined > {
13
36
try {
14
37
if ( ! current ) {
@@ -22,11 +45,18 @@ export async function checkForUpdateOf(name: string, current?: string, nuxt = us
22
45
if ( ! current )
23
46
return
24
47
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
27
57
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 )
30
60
31
61
return {
32
62
name,
0 commit comments