Skip to content

Commit

Permalink
refactor: use loadPackageData
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 22, 2023
1 parent ba3e478 commit 3a91f90
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
const resolveSubpathImports = (id: string, importer?: string) => {
if (!importer || !id.startsWith(subpathImportsPrefix)) return
const basedir = path.dirname(importer)
const importerPkgJson = lookupFile(basedir, ['package.json'], {
predicate: (content) => !!JSON.parse(content).name,
const pkgJsonPath = lookupFile(basedir, ['package.json'], {
pathOnly: true,
})
if (!importerPkgJson) return
if (!pkgJsonPath) return

const pkgData = loadPackageData(pkgJsonPath, options.preserveSymlinks)
return resolveExportsOrImports(
JSON.parse(importerPkgJson),
pkgData.data,
id,
options,
targetWeb,
Expand Down

0 comments on commit 3a91f90

Please sign in to comment.