Skip to content

Commit

Permalink
fix(ui5-tooling-modules): properly resolve local dependencies
Browse files Browse the repository at this point in the history
Fixes #1068
  • Loading branch information
petermuessig committed Aug 30, 2024
1 parent 8c1f5e3 commit d1d204c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
18 changes: 16 additions & 2 deletions packages/ui5-tooling-modules/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,23 @@ module.exports = function (log, projectInfo) {
knownDeps.push(npmPackage);
let depRoot;
try {
const depPath = resolveNodeModule(dep, cwd, depPaths, knownDeps);
let depPath = resolveNodeModule(dep, cwd, depPaths, knownDeps);
if (depPath !== dep) {
depRoot = depPath.substring(0, depPath.lastIndexOf("node_modules") + "node_modules".length + 1 + npmPackage.length);
// find the closest package.json to the resolved module
// (maybe we should break when a package.json is found even though it is not the right one)
while (!depRoot && depPath !== cwd && depPath !== "/" && path.basename(depPath) !== "node_modules") {
depPath = path.dirname(depPath);
const pkgJsonDepPath = path.join(depPath, "package.json");
if (existsSync(pkgJsonDepPath)) {
const pkgJsonDep = JSON.parse(readFileSync(pkgJsonDepPath, { encoding: "utf8" }));
// only if the package.json name matches the dependency name
// we consider it as the root of the dependency
if (pkgJsonDep.name === dep) {
depRoot = depPath;
break;
}
}
}
} else {
// native modules are not part of the node_modules directory
// so we need to resolve it late with the package.json
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions showcases/ui5-app/local/mypackage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function mypackage() {
return "mypackage";
};
5 changes: 5 additions & 0 deletions showcases/ui5-app/local/mypackage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "mypackage",
"version": "1.0.0",
"private": true
}
1 change: 1 addition & 0 deletions showcases/ui5-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"cmis": "^1.0.3",
"firebase": "^10.12.4",
"is-plain-object": "^5.0.0",
"mypackage": "file:local/mypackage",
"node-fetch": "^2.7.0",
"pdfmake": "^0.2.10",
"punycode": "^2.3.1",
Expand Down
4 changes: 3 additions & 1 deletion showcases/ui5-app/webapp/controller/Thirdparty.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ sap.ui.define(
"firebase/app", // requires node-fetch@2
"firebase/firestore/lite",
"signalr",
"mypackage",
],
(Controller, MessageToast, jQuery, xlsx, cmis, supabase, octokit, axios, temporal, stompjs, react, reactdom, zod, pdfMake, pdfFonts, xmljs, firebase, firestore, signalr) => {
(Controller, MessageToast, jQuery, xlsx, cmis, supabase, octokit, axios, temporal, stompjs, react, reactdom, zod, pdfMake, pdfFonts, xmljs, firebase, firestore, signalr, mypackage) => {
"use strict";

console.log("[3rdParty] xlsx", xlsx);
Expand Down Expand Up @@ -51,6 +52,7 @@ sap.ui.define(
}

console.log("[3rdParty] signalr", signalr, jQuery.connection.hub);
console.log("[3rdParty] mypackage", mypackage);

return Controller.extend("ui5.ecosystem.demo.app.controller.Thirdparty", {
onInit() {
Expand Down

0 comments on commit d1d204c

Please sign in to comment.