Skip to content

Commit

Permalink
Don't load submodules with not installed optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryScaletta authored Nov 12, 2023
1 parent 4cabe81 commit 52dd114
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ 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);
lib[subName] = sub;
} catch (e) {
if (e.message.startsWith("Cannot find module '")) {
const moduleName = e.message.substring(20, e.message.indexOf("'\n"));
const optional = pkg.peerDependenciesMeta?.[moduleName].optional;
if (optional) continue; else throw e;
}
}
}
return lib;
};
Expand Down

0 comments on commit 52dd114

Please sign in to comment.