Skip to content

Commit

Permalink
fix(ui5-tooling-modules): windows support and performance improvements (
Browse files Browse the repository at this point in the history
  • Loading branch information
petermuessig authored Oct 1, 2024
1 parent fee71a0 commit 170b462
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
18 changes: 9 additions & 9 deletions packages/ui5-tooling-modules/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ module.exports = async function ({ log, resources, options, middlewareUtil }) {
moduleName = moduleName.substring(0, moduleName.length - 3);
}

// check if the resource exists in node_modules
let resource = getResource(moduleName, { cwd, depPaths, isMiddleware: true });
let existsPackage;
if (!resource) {
// in some cases there is a request to a module of an NPM package and in this
// case we still need to trigger the bundle and watch process to create the
// bundle info from which we can extract the resource (e.g. webc libraries)
const npmPackage = getNpmPackageName(moduleName);
existsPackage = !!resolveModule(`${npmPackage}/package.json`, { cwd, depPaths, isMiddleware: true });
// in some cases there is a request to a module of an NPM package and in this
// case we still need to trigger the bundle and watch process to create the
// bundle info from which we can extract the resource (e.g. webc libraries)
const npmPackage = getNpmPackageName(moduleName);
const existsPackage = !!resolveModule(`${npmPackage}/package.json`, { cwd, depPaths, isMiddleware: true });
let resource;
if (existsPackage) {
// check if the resource exists in node_modules
resource = getResource(moduleName, { cwd, depPaths, isMiddleware: true });
}

// if a resource has been found in node_modules, we will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module.exports = function ({ log, resolveModule, framework, skip } = {}) {
let modulePath = resolveModule(source);
if (modulePath) {
modulePath = modulePath.substr(metadata.npmPackagePath.length + 1);
modulePath = modulePath.replace(/\\/g, "/");
const moduleName = `${npmPackage}/${modulePath}`;
const clazz = WebComponentRegistry.getClassDefinition(moduleName);
// TODO: base classes must be ignored as UI5Element is flagged as custom element although it is a base class
Expand Down Expand Up @@ -227,7 +228,7 @@ module.exports = function ({ log, resolveModule, framework, skip } = {}) {
designtime: `${ui5Metadata.namespace}/designtime/${clazz.name}.designtime`, // add a default designtime
});
const metadata = JSON.stringify(metadataObject, undefined, 2);
const webcClass = moduleInfo.attributes.absModulePath; // is the absolute path of the original Web Component class
const webcClass = moduleInfo.attributes.absModulePath.replace(/\\/g, "/"); // is the absolute path of the original Web Component class

// Determine the superclass UI5 module name and import it
let webcBaseClass = "sap/ui/core/webc/WebComponent";
Expand Down
4 changes: 3 additions & 1 deletion packages/ui5-tooling-modules/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ module.exports = function (log, projectInfo) {
*/
function resolveNodeModule(moduleName, cwd = process.cwd(), depPaths = []) {
let modulePath;
//let millis = Date.now();
const resolve = function (moduleName, options) {
try {
return require.resolve(moduleName, options);
Expand All @@ -270,6 +271,7 @@ module.exports = function (log, projectInfo) {
});
if (modulePath) break;
}
//console.log(`resolveNodeModule filter took ${Date.now() - millis}ms`, moduleName);
return modulePath;
}

Expand Down Expand Up @@ -710,7 +712,7 @@ module.exports = function (log, projectInfo) {
} else {
// derive the module path from the package.json entries browser, module or main
try {
const pkgJsonModuleName = path.join(moduleName, "package.json");
const pkgJsonModuleName = path.posix.join(moduleName, "package.json");
const pkgJson = require(pkgJsonModuleName);
const resolveModulePath = function (exports, fields) {
for (const field of fields) {
Expand Down

0 comments on commit 170b462

Please sign in to comment.