Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve loading of submodules #1940

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ const loadModule = (name) => {
const subKeys = Object.keys(pkg.exports).map((key) => key.substring(2));
const subNames = subKeys.filter(validSubmodules);
for (const subName of subNames) {
const sub = appRequire(name + '/' + subName);
lib[subName] = sub;
try {
const sub = appRequire(name + '/' + subName);
if (lib[subName] && lib[subName] === sub[subName]) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate expression: lib[subName]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is actually necessary here because in every other case (except the one I described above) lib[subName] and sub[subName] would be equal to undefined.

lib[subName] = sub;
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND' && pkg.peerDependenciesMeta) {
const moduleName = metautil.between(err.message, "'", "'");
const optional = pkg.peerDependenciesMeta[moduleName]?.optional;
if (optional) continue;
}
throw err;
}
}
return lib;
};
Expand Down
Loading