Skip to content

Commit

Permalink
Use the closest package.json to an asset if it's a package entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Apr 6, 2022
1 parent de6c483 commit d591a93
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/utils/node-resolver-core/src/NodeResolver.js
Expand Up @@ -779,6 +779,7 @@ export default class NodeResolver {
let res =
(await this.loadAsFile({
file: entry.filename,
asPackageEntry: true,
extensions,
env,
pkg,
Expand Down Expand Up @@ -972,12 +973,14 @@ export default class NodeResolver {
extensions,
env,
pkg,
asPackageEntry,
ctx,
}: {|
file: string,
extensions: Array<string>,
env: Environment,
pkg: InternalPackageJSON | null,
asPackageEntry?: boolean,
ctx: ResolverContext,
|}): Promise<?ResolvedFile> {
// Try all supported extensions
Expand All @@ -997,7 +1000,14 @@ export default class NodeResolver {
}

if (found) {
return {path: found, pkg};
return {
path: found,
// If this is an entrypoint in package.json, it's possible pkg is not the
// closest package.json to the resolved file. Reload it instead.
pkg: asPackageEntry
? await this.readPackage(path.dirname(found), ctx)
: pkg,
};
}

return null;
Expand Down

0 comments on commit d591a93

Please sign in to comment.