MCPcopy
hub / github.com/vitejs/vite / resolvePackageData

Function resolvePackageData

packages/vite/src/node/packages.ts:63–127  ·  view source on GitHub ↗
(
  pkgName: string,
  basedir: string,
  preserveSymlinks = false,
  packageCache?: PackageCache,
)

Source from the content-addressed store, hash-verified

61}
62
63export function resolvePackageData(
64 pkgName: string,
65 basedir: string,
66 preserveSymlinks = false,
67 packageCache?: PackageCache,
68): PackageData | null {
69 if (pnp) {
70 const cacheKey = getRpdCacheKey(pkgName, basedir, preserveSymlinks)
71 if (packageCache?.has(cacheKey)) return packageCache.get(cacheKey)!
72
73 try {
74 const pkg = pnp.resolveToUnqualified(pkgName, basedir, {
75 considerBuiltins: false,
76 })
77 if (!pkg) return null
78
79 const pkgData = loadPackageData(path.join(pkg, 'package.json'))
80 packageCache?.set(cacheKey, pkgData)
81 return pkgData
82 } catch {
83 return null
84 }
85 }
86
87 const originalBasedir = basedir
88 while (basedir) {
89 if (packageCache) {
90 const cached = getRpdCache(
91 packageCache,
92 pkgName,
93 basedir,
94 originalBasedir,
95 preserveSymlinks,
96 )
97 if (cached) return cached
98 }
99
100 const pkg = path.join(basedir, 'node_modules', pkgName, 'package.json')
101 try {
102 if (fs.existsSync(pkg)) {
103 const pkgPath = preserveSymlinks ? pkg : safeRealpathSync(pkg)
104 const pkgData = loadPackageData(pkgPath)
105
106 if (packageCache) {
107 setRpdCache(
108 packageCache,
109 pkgData,
110 pkgName,
111 basedir,
112 originalBasedir,
113 preserveSymlinks,
114 )
115 }
116
117 return pkgData
118 }
119 } catch {}
120

Callers 4

tryNodeResolveFunction · 0.90
tryOptimizedResolveFunction · 0.90
expandGlobIdsFunction · 0.90
nestedResolveBasedirFunction · 0.90

Calls 7

getRpdCacheKeyFunction · 0.85
loadPackageDataFunction · 0.85
getRpdCacheFunction · 0.85
setRpdCacheFunction · 0.85
hasMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected