Skip to content

Commit

Permalink
fix(ui5-tooling-modules): advanced dependency detection (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermuessig authored and marianfoo committed Nov 5, 2024
1 parent a016180 commit cff2c71
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/ui5-tooling-modules/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ const npmPackageScopeRegEx = /^((?:(@[^/]+)\/)?([^/]+))(?:\/(.*))?$/;
function findDependency(dep, cwd = process.cwd(), depPaths = []) {
let modulePath;
try {
modulePath = resolve(dep, { paths: [cwd, ...depPaths] });
try {
modulePath = resolve(dep, { paths: [cwd, ...depPaths] });
} catch (err) {
// sometimes the package.json is not found, therefore we try to resolve the dependency
// without the package.json, just with the npm package name (and lookup the package.json manually)
if (dep.endsWith("/package.json") && err.code === "MODULE_NOT_FOUND") {
modulePath = resolve(dep.substring(0, dep.length - "/package.json".length), { paths: [cwd, ...depPaths] });
} else {
throw err;
}
}
} catch (err) {
// if the module is not exported, we try to resolve it manually
const [, npmPackage, , , module] = npmPackageScopeRegEx.exec(dep) || [];
Expand Down

0 comments on commit cff2c71

Please sign in to comment.