Skip to content

Commit a049c52

Browse files
committed
perf: use npm-registry-fetch instead of pacote to deduce the package size
1 parent 760f149 commit a049c52

4 files changed

Lines changed: 172 additions & 489 deletions

File tree

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@nuxt/schema": "^3.12.2",
3232
"@types/markdown-it": "^14.1.1",
3333
"@types/node": "^20.14.7",
34-
"@types/pacote": "^11.1.8",
3534
"@types/which": "^3.0.4",
3635
"@types/ws": "^8.5.10",
3736
"@unocss/eslint-config": "^0.61.0",

‎packages/devtools/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
"launch-editor": "^2.8.0",
6464
"local-pkg": "^0.5.0",
6565
"magicast": "^0.3.4",
66+
"npm-registry-fetch": "^17.1.0",
6667
"nypm": "^0.3.8",
6768
"ohash": "^1.1.3",
68-
"pacote": "^18.0.6",
6969
"pathe": "^1.1.2",
7070
"perfect-debounce": "^1.0.0",
7171
"pkg-types": "^1.1.1",
@@ -92,6 +92,7 @@
9292
"@nuxt/test-utils": "3.9.0",
9393
"@parcel/watcher": "^2.4.1",
9494
"@types/markdown-it-link-attributes": "^3.0.5",
95+
"@types/npm-registry-fetch": "^8.0.7",
9596
"@types/ua-parser-js": "^0.7.39",
9697
"@unocss/nuxt": "^0.61.0",
9798
"@unocss/preset-icons": "^0.61.0",

‎packages/devtools/src/npm/index.ts‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@ import { createRequire } from 'node:module'
22
import{logger,useNuxt}from'@nuxt/kit'
33
import{readPackageJSON}from'pkg-types'
44
importsemverfrom'semver'
5+
import{joinURL}from'ufo'
56
import{getPackageInfo}from'local-pkg'
67
importtype{PackageUpdateInfo}from'../types'
78

89
exportasyncfunctiongetMainPackageJSON(nuxt=useNuxt()){
910
returnreadPackageJSON(nuxt.options.rootDir)
1011
}
1112

13+
exportinterfacePackument{
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+
1235
exportasyncfunctioncheckForUpdateOf(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-
constpackument=awaitimport('pacote').then(r=>r.default?.packument||r.packument)
26-
constmanifest=awaitpackument(name)
48+
const{ pickRegistry,json: fetchMeta}=awaitimport('npm-registry-fetch')
49+
constreg=pickRegistry(name)
50+
constmanifest=awaitfetchMeta(joinURL(reg,name),{
51+
headers: {
52+
'user-agent': `npm node/${process.version}`,
53+
'accept': 'application/json',
54+
},
55+
spec: name,
56+
})asunknownasPackument
2757

28-
constlatest=manifest['dist-tags'].latest
29-
constneedsUpdate=latest!==current&&semver.lt(current,latest)
58+
constlatest=manifest?.['dist-tags']?.latest
59+
constneedsUpdate=!!latest&&latest!==current&&semver.lt(current,latest)
3060

3161
return{
3262
name,

0 commit comments

Comments
 (0)