Skip to content

Commit 3a91f90

Browse files
committed
refactor: use loadPackageData
1 parent ba3e478 commit 3a91f90

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/vite/src/node/plugins/resolve.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
156156
const resolveSubpathImports = (id: string, importer?: string) => {
157157
if (!importer || !id.startsWith(subpathImportsPrefix)) return
158158
const basedir = path.dirname(importer)
159-
const importerPkgJson = lookupFile(basedir, ['package.json'], {
160-
predicate: (content) => !!JSON.parse(content).name,
159+
const pkgJsonPath = lookupFile(basedir, ['package.json'], {
160+
pathOnly: true,
161161
})
162-
if (!importerPkgJson) return
162+
if (!pkgJsonPath) return
163163

164+
const pkgData = loadPackageData(pkgJsonPath, options.preserveSymlinks)
164165
return resolveExportsOrImports(
165-
JSON.parse(importerPkgJson),
166+
pkgData.data,
166167
id,
167168
options,
168169
targetWeb,

0 commit comments

Comments
 (0)