Skip to content

Commit

Permalink
fix(ui5-tooling-modules): monkey patch mapValueState for older versio…
Browse files Browse the repository at this point in the history
…ns of UI5 (#1137)
  • Loading branch information
petermuessig authored Dec 22, 2024
1 parent 0b5479b commit d0abfbf
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 23 deletions.
6 changes: 6 additions & 0 deletions packages/ui5-tooling-modules/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = async function ({ log, resources, options, middlewareUtil }) {
skipTransform: false,
watch: true,
watchDebounce: 100,
entryPoints: [],
},
options.configuration,
);
Expand Down Expand Up @@ -178,6 +179,11 @@ module.exports = async function ({ log, resources, options, middlewareUtil }) {
// logic which bundles and watches the modules coming from the
// node_modules or dependencies via NPM package names
const requestedModules = new Set();
// inject the entrypoints from the configuration
config.entryPoints?.forEach((entry) => {
requestedModules.add(entry);
});
// start bundling
let whenBundled, scanTime, bundleTime;
const bundleAndWatch = async ({ moduleName, force }) => {
if (moduleName && !requestedModules.has(moduleName)) {
Expand Down
29 changes: 20 additions & 9 deletions packages/ui5-tooling-modules/lib/rollup-plugin-webcomponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ module.exports = function ({ log, resolveModule, getPackageJson, framework, opti
// handlebars templates for the Web Components transformation
const webcTmplFnPackage = loadAndCompileTemplate("templates/Package.hbs");
const webcTmplFnControl = loadAndCompileTemplate("templates/WrapperControl.hbs");
const webcTmplFnMPAttributes = loadAndCompileTemplate("templates/monkey_patches/RenderAttributeProperties.hbs");
const webcTmplFnMPAllEvents = loadAndCompileTemplate("templates/monkey_patches/RegisterAllEvents.hbs");

// handlebars templates for the Web Components monkey patches
const webcTmplMPPreamble = loadAndCompileTemplate("templates/monkey_patches/_Preamble.hbs");
const webcTmplMPFnAttributes = loadAndCompileTemplate("templates/monkey_patches/RenderAttributeProperties.hbs");
const webcTmplMPFnAllEvents = loadAndCompileTemplate("templates/monkey_patches/RegisterAllEvents.hbs");
const webcTmplMPFnMapValueState = loadAndCompileTemplate("templates/monkey_patches/MapValueState.hbs");

// array of all web component classes
const webcModules = [];
Expand Down Expand Up @@ -291,16 +295,23 @@ module.exports = function ({ log, resolveModule, getPackageJson, framework, opti
});
// include the monkey patches for the Web Components base library
// only for UI5 versions < 1.128.0 we need the attributes fix
let monkeyPatches = [];
if (namespace === "@ui5/webcomponents-base" && lt(framework?.version || "0.0.0", "1.128.0")) {
const monkeyPatches = webcTmplFnMPAttributes();
return `${monkeyPatches}\n${code}`;
monkeyPatches.push(webcTmplMPFnAttributes());
}
// only for UI5 versions < 1.132.0 we need the events fix
if (namespace === "@ui5/webcomponents-base" && lt(framework?.version || "0.0.0", "1.132.0")) {
const monkeyPatches = webcTmplFnMPAllEvents();
return `${monkeyPatches}\n${code}`;
// only for UI5 versions < 1.133.0 we need...
if (namespace === "@ui5/webcomponents-base" && lt(framework?.version || "0.0.0", "1.133.0")) {
// ... the monkey patch to register all events
monkeyPatches.push(webcTmplMPFnAllEvents());
// ... the monkey patch to fix the value state mapping
monkeyPatches.push(webcTmplMPFnMapValueState());
}
// append the monkey patches to the code if needed
if (monkeyPatches.length > 0) {
return `${webcTmplMPPreamble()}\n${monkeyPatches.join("\n")}\n${code}`;
} else {
return code;
}
return code;
} else if (moduleInfo.attributes.ui5Type === "control") {
let clazz = moduleInfo.attributes.clazz;
// determine whether the clazz is based on the UI5Element superclass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Fixed with https://github.com/SAP/openui5/commit/111c4bcd1660f90714ed567fa8cb57fbc448591f in UI5 1.133.0

WebComponent.prototype._mapValueState ??= function(sValueState) {
console.warn("ValueState mapping is not implemented for Web Components yet. Please use UI5 version 1.133.0 or higher.");
return sValueState;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Will be fixed with TBD in UI5 1.130
import hyphenate from "sap/base/strings/hyphenate";
import WebComponent from "sap/ui/core/webc/WebComponent";
// Fixed with https://github.com/SAP/openui5/commit/a4b5fe00b49e0e26e5fd845607a2b95db870d55a in UI5 1.133.0

WebComponent.prototype.__attachCustomEventsListeners = function() {
// ##### MODIFICATION START #####
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Fixed with https://github.com/SAP/openui5/commit/7a4615e3fe55221ae9de9d876d3eed209f71a5b1 in UI5 1.128.0

import hyphenate from "sap/base/strings/hyphenate";
import WebComponentRenderer from "sap/ui/core/webc/WebComponentRenderer";

WebComponentRenderer.renderAttributeProperties = function (oRm, oWebComponent) {
var oAttrProperties = oWebComponent.getMetadata().getPropertiesByMapping("property");
// ##### MODIFICATION START #####
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// this file contains all imports which are shared between the Monkey Patch files

import hyphenate from "sap/base/strings/hyphenate";
import WebComponent from "sap/ui/core/webc/WebComponent";
import WebComponentRenderer from "sap/ui/core/webc/WebComponentRenderer";
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
sap.ui.define(['sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/base/DataType'], (function (hyphenate, WebComponent, DataType) { 'use strict';
sap.ui.define(['sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/webc/WebComponentRenderer', 'sap/ui/base/DataType'], (function (hyphenate, WebComponent, WebComponentRenderer, DataType) { 'use strict';

// Will be fixed with TBD in UI5 1.130
// this file contains all imports which are shared between the Monkey Patch files


// Fixed with https://github.com/SAP/openui5/commit/a4b5fe00b49e0e26e5fd845607a2b95db870d55a in UI5 1.133.0

WebComponent.prototype.__attachCustomEventsListeners = function() {
// ##### MODIFICATION START #####
Expand Down Expand Up @@ -29,6 +32,13 @@ sap.ui.define(['sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 's
}
};

// Fixed with https://github.com/SAP/openui5/commit/111c4bcd1660f90714ed567fa8cb57fbc448591f in UI5 1.133.0

WebComponent.prototype._mapValueState ??= function(sValueState) {
console.warn("ValueState mapping is not implemented for Web Components yet. Please use UI5 version 1.133.0 or higher.");
return sValueState;
};

const pkg = {
"_ui5metadata": {
"name": "@ui5/webcomponents-base",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(['./webcomponents-base', 'sap/ui/base/DataType', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent'], (function (_ui5_webcomponentsBase, DataType, hyphenate, WebComponent) { 'use strict';
sap.ui.define(['./webcomponents-base', 'sap/ui/base/DataType', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/webc/WebComponentRenderer'], (function (_ui5_webcomponentsBase, DataType, hyphenate, WebComponent, WebComponentRenderer) { 'use strict';

const pkg = {
"_ui5metadata": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(['ui5/ecosystem/demo/app/resources/@ui5/webcomponents', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/EnabledPropagator', 'ui5/ecosystem/demo/app/resources/@ui5/webcomponents-base', 'sap/base/strings/hyphenate', 'sap/ui/base/DataType'], (function (_ui5_webcomponents, WebComponent, EnabledPropagator, _ui5_webcomponentsBase, hyphenate, DataType) { 'use strict';
sap.ui.define(['ui5/ecosystem/demo/app/resources/@ui5/webcomponents', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/EnabledPropagator', 'ui5/ecosystem/demo/app/resources/@ui5/webcomponents-base', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponentRenderer', 'sap/ui/base/DataType'], (function (_ui5_webcomponents, WebComponent, EnabledPropagator, _ui5_webcomponentsBase, hyphenate, WebComponentRenderer, DataType) { 'use strict';

var class2type = {};
var hasOwn = class2type.hasOwnProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(['ui5/ecosystem/demo/app/resources/webcomponents-base', 'sap/ui/base/DataType', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent'], (function (_ui5_webcomponentsBase, DataType, hyphenate, WebComponent) { 'use strict';
sap.ui.define(['ui5/ecosystem/demo/app/resources/webcomponents-base', 'sap/ui/base/DataType', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/webc/WebComponentRenderer'], (function (_ui5_webcomponentsBase, DataType, hyphenate, WebComponent, WebComponentRenderer) { 'use strict';

const pkg = {
"_ui5metadata": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(['ui5/ecosystem/demo/app/resources/webcomponents-base', 'ui5/ecosystem/demo/app/resources/@ui5/webcomponents', 'sap/ui/core/webc/WebComponent', 'sap/base/strings/hyphenate', 'sap/ui/base/DataType'], (function (_ui5_webcomponentsBase, _ui5_webcomponents, WebComponent, hyphenate, DataType) { 'use strict';
sap.ui.define(['ui5/ecosystem/demo/app/resources/webcomponents-base', 'ui5/ecosystem/demo/app/resources/@ui5/webcomponents', 'sap/ui/core/webc/WebComponent', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponentRenderer', 'sap/ui/base/DataType'], (function (_ui5_webcomponentsBase, _ui5_webcomponents, WebComponent, hyphenate, WebComponentRenderer, DataType) { 'use strict';

const tasks = new WeakMap();
class AnimationQueue {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(['exports', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/base/DataType'], (function (exports, hyphenate, WebComponent, DataType) { 'use strict';
sap.ui.define(['exports', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebComponent', 'sap/ui/core/webc/WebComponentRenderer', 'sap/ui/base/DataType'], (function (exports, hyphenate, WebComponent, WebComponentRenderer, DataType) { 'use strict';

var class2type = {};
var hasOwn = class2type.hasOwnProperty;
Expand Down Expand Up @@ -1807,7 +1807,10 @@ sap.ui.define(['exports', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebCom
}
registerFeature("OpenUI5Support", OpenUI5Support);

// Will be fixed with TBD in UI5 1.130
// this file contains all imports which are shared between the Monkey Patch files


// Fixed with https://github.com/SAP/openui5/commit/a4b5fe00b49e0e26e5fd845607a2b95db870d55a in UI5 1.133.0

WebComponent.prototype.__attachCustomEventsListeners = function() {
// ##### MODIFICATION START #####
Expand Down Expand Up @@ -1835,6 +1838,13 @@ sap.ui.define(['exports', 'sap/base/strings/hyphenate', 'sap/ui/core/webc/WebCom
}
}
};

// Fixed with https://github.com/SAP/openui5/commit/111c4bcd1660f90714ed567fa8cb57fbc448591f in UI5 1.133.0

WebComponent.prototype._mapValueState ??= function(sValueState) {
console.warn("ValueState mapping is not implemented for Web Components yet. Please use UI5 version 1.133.0 or higher.");
return sValueState;
};
setCustomElementsScopingSuffix("mYsCoPeSuFfIx");

const pkg = {
Expand Down

0 comments on commit d0abfbf

Please sign in to comment.