Skip to content

Commit

Permalink
Use the closest package.json to an asset if it's in a different subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Apr 6, 2022
1 parent d454fab commit 4e4b59f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/utils/node-resolver-core/src/NodeResolver.js
Expand Up @@ -997,7 +997,22 @@ export default class NodeResolver {
}

if (found) {
return {path: found, pkg};
let resolvedPkg;
if (pkg == null) {
resolvedPkg = null;
} else if (found.startsWith(pkg.pkgdir)) {
resolvedPkg = pkg;
} else {
// If the package.json is not in an ancestor directory of the resolved
// file, the package.json listed a file in a different subtree. Use the
// closest package.json to the resolved file instead.
resolvedPkg = await this.readPackage(path.dirname(found), ctx);
}

return {
path: found,
pkg: resolvedPkg,
};
}

return null;
Expand Down

0 comments on commit 4e4b59f

Please sign in to comment.