Skip to content

Commit

Permalink
fix: use nearest pkg to resolved for moduleSideEffects (#12628)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 28, 2023
1 parent bd54f54 commit 1dfecc8
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -254,19 +254,20 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
}

if ((res = tryFsResolve(fsPath, options))) {
const resPkg = findNearestPackageData(
path.dirname(res),
options.packageCache,
)
res = ensureVersionQuery(res, id, options, depsOptimizer)
isDebug &&
debug(`[relative] ${colors.cyan(id)} -> ${colors.dim(res)}`)
const pkg =
importer &&
findNearestPackageData(path.dirname(importer), options.packageCache)
if (pkg) {
return {
id: res,
moduleSideEffects: pkg.hasSideEffects(res),
}
}
return res

return resPkg
? {
id: res,
moduleSideEffects: resPkg.hasSideEffects(res),
}
: res
}
}

Expand Down Expand Up @@ -1191,10 +1192,16 @@ function tryResolveBrowserMapping(
) {
isDebug &&
debug(`[browser mapped] ${colors.cyan(id)} -> ${colors.dim(res)}`)
const result = {
id: res,
moduleSideEffects: pkg.hasSideEffects(res),
}
const resPkg = findNearestPackageData(
path.dirname(res),
options.packageCache,
)
const result = resPkg
? {
id: res,
moduleSideEffects: resPkg.hasSideEffects(res),
}
: { id: res }
return externalize ? { ...result, external: true } : result
}
} else if (browserMappedPath === false) {
Expand Down

0 comments on commit 1dfecc8

Please sign in to comment.