From df51ca0b9f530f1c0475d9a79c23efe45ccda4fe Mon Sep 17 00:00:00 2001 From: Christian V Date: Wed, 24 Apr 2019 12:27:58 +0200 Subject: [PATCH] [INTERNAL][FIX] Fix of the flexChangesBundler.js to sort correctly (#198) The flexChangesBundler used the wrong operation to sort the files contained in the /changes/ folder of an application. Thus the sorting may be incorrect. This commit changes the operator to sort accordingly. --- lib/processors/bundlers/flexChangesBundler.js | 22 +-- .../build/application.h/dest/manifest.json | 2 +- .../application.i/dest/Component-preload.js | 11 ++ .../build/application.i/dest/Component.js | 1 + .../dest/changes/changes-bundle.json | 1 + .../dest/changes/coding/MyExtension.js | 1 + .../changes/fragments/MyFragment.fragment.xml | 3 + .../dest/changes/id_123_addField.change | 20 +++ .../dest/changes/id_456_addField.change | 20 +++ .../build/application.i/dest/manifest.json | 13 ++ test/fixtures/application.h/ui5.yaml | 2 +- .../application.h/webapp/manifest.json | 2 +- test/fixtures/application.i/package.json | 10 ++ test/fixtures/application.i/ui5.yaml | 25 +++ .../application.i/webapp/Component.js | 8 + .../webapp/changes/coding/MyExtension.js | 3 + .../changes/fragments/MyFragment.fragment.xml | 3 + .../webapp/changes/id_123_addField.change | 20 +++ .../webapp/changes/id_456_addField.change | 20 +++ .../application.i/webapp/manifest.json | 13 ++ test/lib/builder/builder.js | 48 ++++++ .../processors/bundlers/flexChangesBundler.js | 155 +++++++++--------- 22 files changed, 304 insertions(+), 99 deletions(-) create mode 100644 test/expected/build/application.i/dest/Component-preload.js create mode 100644 test/expected/build/application.i/dest/Component.js create mode 100644 test/expected/build/application.i/dest/changes/changes-bundle.json create mode 100644 test/expected/build/application.i/dest/changes/coding/MyExtension.js create mode 100644 test/expected/build/application.i/dest/changes/fragments/MyFragment.fragment.xml create mode 100644 test/expected/build/application.i/dest/changes/id_123_addField.change create mode 100644 test/expected/build/application.i/dest/changes/id_456_addField.change create mode 100644 test/expected/build/application.i/dest/manifest.json create mode 100644 test/fixtures/application.i/package.json create mode 100644 test/fixtures/application.i/ui5.yaml create mode 100644 test/fixtures/application.i/webapp/Component.js create mode 100644 test/fixtures/application.i/webapp/changes/coding/MyExtension.js create mode 100644 test/fixtures/application.i/webapp/changes/fragments/MyFragment.fragment.xml create mode 100644 test/fixtures/application.i/webapp/changes/id_123_addField.change create mode 100644 test/fixtures/application.i/webapp/changes/id_456_addField.change create mode 100644 test/fixtures/application.i/webapp/manifest.json diff --git a/lib/processors/bundlers/flexChangesBundler.js b/lib/processors/bundlers/flexChangesBundler.js index c17e3f391..8f68ff3cc 100644 --- a/lib/processors/bundlers/flexChangesBundler.js +++ b/lib/processors/bundlers/flexChangesBundler.js @@ -10,29 +10,15 @@ const resourceFactory = require("@ui5/fs").resourceFactory; * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed * @param {Object} parameters.options Options * @param {string} parameters.options.pathPrefix Prefix for bundle path - * @returns {Promise} Promise resolving with flexchange bundle resources + * @returns {Promise} Promise resolving with flex changes bundle resources */ module.exports = function({resources, options}) { - const layers = { - VENDOR: 0, - INDUSTRY: 1, - PARTNER: 2, - CUSTOMER_BASE: 3, - CUSTOMER: 4, - USER: 5 - }; - - function sortByLayer(a, b) { - return layers[a.layer] - layers[b.layer]; - } - function sortByTimeStamp(a, b) { - return a.creation - b.creation; + return a.creation > b.creation ? 1 : -1; } function sortAndStringify(changesContent) { changesContent = changesContent.sort(sortByTimeStamp); - changesContent = changesContent.sort(sortByLayer); changesContent = changesContent.map(function(change) { return JSON.stringify(change); }); @@ -45,13 +31,13 @@ module.exports = function({resources, options}) { }); })).then((changesContent) => { const nNumberOfChanges = changesContent.length; - log.verbose("Changes collected. Number of changes: " + nNumberOfChanges); + log.info("Changes collected. Number of changes: " + nNumberOfChanges); const result = []; if (nNumberOfChanges > 0) { changesContent = sortAndStringify(changesContent); result.push(resourceFactory.createResource({ path: `${options.pathPrefix}/changes/changes-bundle.json`, - string: "{ \"changes\": [" + changesContent.join(",") + "]}" + string: "[" + changesContent.join(",") + "]" })); } return result; diff --git a/test/expected/build/application.h/dest/manifest.json b/test/expected/build/application.h/dest/manifest.json index 0c7cbf74c..32b7e4a84 100644 --- a/test/expected/build/application.h/dest/manifest.json +++ b/test/expected/build/application.h/dest/manifest.json @@ -2,7 +2,7 @@ "_version": "1.1.0", "sap.app": { "_version": "1.1.0", - "id": "application.g", + "id": "application.h", "type": "application", "applicationVersion": { "version": "1.2.2" diff --git a/test/expected/build/application.i/dest/Component-preload.js b/test/expected/build/application.i/dest/Component-preload.js new file mode 100644 index 000000000..8a88b6c69 --- /dev/null +++ b/test/expected/build/application.i/dest/Component-preload.js @@ -0,0 +1,11 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/i/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.i.Component",{metadata:{manifest:"json"}})}); +}, + "application/i/changes/changes-bundle.json":'[{"fileName":"id_456_addField","fileType":"change","changeType":"hideControl","component":"application.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.Component/changes","creation":"2023-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}},{"fileName":"id_123_addField","fileType":"change","changeType":"hideControl","component":"application.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}]', + "application/i/changes/coding/MyExtension.js":function(){sap.ui.define([],function(){return{}}); +}, + "application/i/changes/fragments/MyFragment.fragment.xml":'', + "application/i/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.i","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' +}}); diff --git a/test/expected/build/application.i/dest/Component.js b/test/expected/build/application.i/dest/Component.js new file mode 100644 index 000000000..f172a1f15 --- /dev/null +++ b/test/expected/build/application.i/dest/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.i.Component",{metadata:{manifest:"json"}})}); \ No newline at end of file diff --git a/test/expected/build/application.i/dest/changes/changes-bundle.json b/test/expected/build/application.i/dest/changes/changes-bundle.json new file mode 100644 index 000000000..31bc12a8b --- /dev/null +++ b/test/expected/build/application.i/dest/changes/changes-bundle.json @@ -0,0 +1 @@ +[{"fileName":"id_456_addField","fileType":"change","changeType":"hideControl","component":"application.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.Component/changes","creation":"2023-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}},{"fileName":"id_123_addField","fileType":"change","changeType":"hideControl","component":"application.i.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.i.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}] \ No newline at end of file diff --git a/test/expected/build/application.i/dest/changes/coding/MyExtension.js b/test/expected/build/application.i/dest/changes/coding/MyExtension.js new file mode 100644 index 000000000..b9e475d8e --- /dev/null +++ b/test/expected/build/application.i/dest/changes/coding/MyExtension.js @@ -0,0 +1 @@ +sap.ui.define([],function(){return{}}); \ No newline at end of file diff --git a/test/expected/build/application.i/dest/changes/fragments/MyFragment.fragment.xml b/test/expected/build/application.i/dest/changes/fragments/MyFragment.fragment.xml new file mode 100644 index 000000000..39ce6859b --- /dev/null +++ b/test/expected/build/application.i/dest/changes/fragments/MyFragment.fragment.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/test/expected/build/application.i/dest/changes/id_123_addField.change b/test/expected/build/application.i/dest/changes/id_123_addField.change new file mode 100644 index 000000000..b1b1e9cda --- /dev/null +++ b/test/expected/build/application.i/dest/changes/id_123_addField.change @@ -0,0 +1,20 @@ +{ + "fileName": "id_123_addField", + "fileType": "change", + "changeType": "hideControl", + "component": "application.i.Component", + "content": {}, + "selector": { + "id": "control1" + }, + "layer": "VENDOR", + "texts": {}, + "namespace": "apps/application.i.Component/changes", + "creation": "2025-10-30T13:52:40.4754350Z", + "originalLanguage": "", + "conditions": {}, + "support": { + "generator": "did it", + "user": "Max Mustermann" + } +} diff --git a/test/expected/build/application.i/dest/changes/id_456_addField.change b/test/expected/build/application.i/dest/changes/id_456_addField.change new file mode 100644 index 000000000..0ca9acd3b --- /dev/null +++ b/test/expected/build/application.i/dest/changes/id_456_addField.change @@ -0,0 +1,20 @@ +{ + "fileName": "id_456_addField", + "fileType": "change", + "changeType": "hideControl", + "component": "application.i.Component", + "content": {}, + "selector": { + "id": "control1" + }, + "layer": "VENDOR", + "texts": {}, + "namespace": "apps/application.i.Component/changes", + "creation": "2023-10-30T13:52:40.4754350Z", + "originalLanguage": "", + "conditions": {}, + "support": { + "generator": "did it", + "user": "Max Mustermann" + } +} diff --git a/test/expected/build/application.i/dest/manifest.json b/test/expected/build/application.i/dest/manifest.json new file mode 100644 index 000000000..91f21cb85 --- /dev/null +++ b/test/expected/build/application.i/dest/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.i", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} diff --git a/test/fixtures/application.h/ui5.yaml b/test/fixtures/application.h/ui5.yaml index d461b90a8..07bdb70d7 100644 --- a/test/fixtures/application.h/ui5.yaml +++ b/test/fixtures/application.h/ui5.yaml @@ -2,7 +2,7 @@ specVersion: "0.1" type: application metadata: - name: application.g + name: application.h builder: bundles: - name: sap/ushell/bootstrap/cdm.js diff --git a/test/fixtures/application.h/webapp/manifest.json b/test/fixtures/application.h/webapp/manifest.json index 0c7cbf74c..32b7e4a84 100644 --- a/test/fixtures/application.h/webapp/manifest.json +++ b/test/fixtures/application.h/webapp/manifest.json @@ -2,7 +2,7 @@ "_version": "1.1.0", "sap.app": { "_version": "1.1.0", - "id": "application.g", + "id": "application.h", "type": "application", "applicationVersion": { "version": "1.2.2" diff --git a/test/fixtures/application.i/package.json b/test/fixtures/application.i/package.json new file mode 100644 index 000000000..f9c175bd6 --- /dev/null +++ b/test/fixtures/application.i/package.json @@ -0,0 +1,10 @@ +{ + "name": "application.i", + "version": "1.0.0", + "description": "Simple SAPUI5 based application", + "main": "index.html", + "dependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.i/ui5.yaml b/test/fixtures/application.i/ui5.yaml new file mode 100644 index 000000000..7c526c7e8 --- /dev/null +++ b/test/fixtures/application.i/ui5.yaml @@ -0,0 +1,25 @@ +--- +specVersion: "0.1" +type: application +metadata: + name: application.i +builder: + bundles: + - name: sap/ushell/bootstrap/cdm.js + defaultFileTypes: + - ".js" + sections: + - mode: raw + filters: + - ui5loader.js + - ui5loader-autoconfig.js + declareModules: false + resolve: true + - mode: preload + name: sap/ushell/bootstrap/common + filters: + - sap/ushell/bootstrap/cdm/cdm-def.js + resolve: true + - mode: require + filters: + - sap/ushell/bootstrap/cdm/cdm-def.js \ No newline at end of file diff --git a/test/fixtures/application.i/webapp/Component.js b/test/fixtures/application.i/webapp/Component.js new file mode 100644 index 000000000..f402cb140 --- /dev/null +++ b/test/fixtures/application.i/webapp/Component.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.i.Component', { + metadata: { + manifest: "json" + } + }); +}); diff --git a/test/fixtures/application.i/webapp/changes/coding/MyExtension.js b/test/fixtures/application.i/webapp/changes/coding/MyExtension.js new file mode 100644 index 000000000..dfb3da014 --- /dev/null +++ b/test/fixtures/application.i/webapp/changes/coding/MyExtension.js @@ -0,0 +1,3 @@ +sap.ui.define([],function () { + return {}; +}); diff --git a/test/fixtures/application.i/webapp/changes/fragments/MyFragment.fragment.xml b/test/fixtures/application.i/webapp/changes/fragments/MyFragment.fragment.xml new file mode 100644 index 000000000..39ce6859b --- /dev/null +++ b/test/fixtures/application.i/webapp/changes/fragments/MyFragment.fragment.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/test/fixtures/application.i/webapp/changes/id_123_addField.change b/test/fixtures/application.i/webapp/changes/id_123_addField.change new file mode 100644 index 000000000..b1b1e9cda --- /dev/null +++ b/test/fixtures/application.i/webapp/changes/id_123_addField.change @@ -0,0 +1,20 @@ +{ + "fileName": "id_123_addField", + "fileType": "change", + "changeType": "hideControl", + "component": "application.i.Component", + "content": {}, + "selector": { + "id": "control1" + }, + "layer": "VENDOR", + "texts": {}, + "namespace": "apps/application.i.Component/changes", + "creation": "2025-10-30T13:52:40.4754350Z", + "originalLanguage": "", + "conditions": {}, + "support": { + "generator": "did it", + "user": "Max Mustermann" + } +} diff --git a/test/fixtures/application.i/webapp/changes/id_456_addField.change b/test/fixtures/application.i/webapp/changes/id_456_addField.change new file mode 100644 index 000000000..0ca9acd3b --- /dev/null +++ b/test/fixtures/application.i/webapp/changes/id_456_addField.change @@ -0,0 +1,20 @@ +{ + "fileName": "id_456_addField", + "fileType": "change", + "changeType": "hideControl", + "component": "application.i.Component", + "content": {}, + "selector": { + "id": "control1" + }, + "layer": "VENDOR", + "texts": {}, + "namespace": "apps/application.i.Component/changes", + "creation": "2023-10-30T13:52:40.4754350Z", + "originalLanguage": "", + "conditions": {}, + "support": { + "generator": "did it", + "user": "Max Mustermann" + } +} diff --git a/test/fixtures/application.i/webapp/manifest.json b/test/fixtures/application.i/webapp/manifest.json new file mode 100644 index 000000000..91f21cb85 --- /dev/null +++ b/test/fixtures/application.i/webapp/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.i", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} diff --git a/test/lib/builder/builder.js b/test/lib/builder/builder.js index e2d872777..1a0792cde 100644 --- a/test/lib/builder/builder.js +++ b/test/lib/builder/builder.js @@ -12,6 +12,7 @@ const builder = ui5Builder.builder; const applicationAPath = path.join(__dirname, "..", "..", "fixtures", "application.a"); const applicationGPath = path.join(__dirname, "..", "..", "fixtures", "application.g"); const applicationHPath = path.join(__dirname, "..", "..", "fixtures", "application.h"); +const applicationIPath = path.join(__dirname, "..", "..", "fixtures", "application.i"); const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d"); const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e"); const libraryHPath = path.join(__dirname, "..", "..", "fixtures", "library.h"); @@ -171,6 +172,26 @@ test("Build application.h", (t) => { }); }); +test("Build application.i", (t) => { + const destPath = "./test/tmp/build/application.i/dest"; + const expectedPath = path.join("test", "expected", "build", "application.i", "dest"); + + return builder.build({ + tree: applicationITree, + destPath, + excludedTasks: ["createDebugFiles", "generateStandaloneAppBundle", "generateVersionInfo"] + }).then(() => { + return findFiles(expectedPath); + }).then((expectedFiles) => { + // Check for all directories and files + assert.directoryDeepEqual(destPath, expectedPath); + // Check for all file contents + return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath); + }).then(() => { + t.pass(); + }); +}); + test("Build library.d with copyright from .library file", (t) => { const destPath = "./test/tmp/build/library.d/dest"; const expectedPath = path.join("test", "expected", "build", "library.d", "dest"); @@ -549,6 +570,33 @@ const applicationHTree = { } }; +const applicationITree = { + "id": "application.i", + "version": "1.0.0", + "path": applicationIPath, + "_level": 0, + "specVersion": "0.1", + "type": "application", + "metadata": { + "name": "application.i", + "namespace": "application/i" + }, + "dependencies": [], + "resources": { + "configuration": { + "paths": { + "webapp": "webapp" + } + }, + "pathMappings": { + "/": "webapp" + } + }, + "builder": { + "bundles": [] + } +}; + const libraryDTree = { "id": "library.d", "version": "1.0.0", diff --git a/test/lib/processors/bundlers/flexChangesBundler.js b/test/lib/processors/bundlers/flexChangesBundler.js index 04ccf675d..5a6d8f687 100644 --- a/test/lib/processors/bundlers/flexChangesBundler.js +++ b/test/lib/processors/bundlers/flexChangesBundler.js @@ -10,87 +10,86 @@ test("flexChangesBundler with empty resources", async (t) => { }); test("flexChangesBundler with 2 changes", async (t) => { - const singleFlexChange = { - "changes": [ - { - "fileName": "id_1504764957625_7_rename1", - "fileType": "change", - "changeType": "rename", - "reference": "rta.performance.Component", - "packageName": "$TMP", - "content": { - "originalControlType": "sap.m.Label" - }, - "selector": { - "id": "initialLabel", - "idIsLocal": false - }, - "layer": "CUSTOMER", - "texts": { - "newText": { - "value": "rename_0", - "type": "XFLD" - } - }, - "namespace": "apps/MyComponent/changes/", - "creation": "2017-09-06T11:54:55.238Z", - "originalLanguage": "EN", - "conditions": {}, - "context": "", - "support": { - "generator": "Change.createInitialFileContent", - "service": "", - "user": "", - "sapui5Version": "1.51.0-SNAPSHOT" - }, - "dependentSelector": {}, - "validAppVersions": { - "creation": "1.0.0", - "from": "1.0.0", - "to": "1.0.0" + const flexBundle = [ + { + "fileName": "id_1504764957630_7_rename2", + "fileType": "change", + "changeType": "rename", + "reference": "rta.performance.Component", + "packageName": "$TMP", + "content": { + "originalControlType": "sap.m.Label" + }, + "selector": { + "id": "initialLabel", + "idIsLocal": false + }, + "layer": "USER", + "texts": { + "newText": { + "value": "rename_5", + "type": "XFLD" } - }, { - "fileName": "id_1504764957630_7_rename2", - "fileType": "change", - "changeType": "rename", - "reference": "rta.performance.Component", - "packageName": "$TMP", - "content": { - "originalControlType": "sap.m.Label" - }, - "selector": { - "id": "initialLabel", - "idIsLocal": false - }, - "layer": "USER", - "texts": { - "newText": { - "value": "rename_5", - "type": "XFLD" - } - }, - "namespace": "apps/MyComponent/changes/", - "creation": "2017-09-01T11:54:55.238Z", - "originalLanguage": "EN", - "conditions": {}, - "context": "", - "support": { - "generator": "Change.createInitialFileContent", - "service": "", - "user": "", - "sapui5Version": "1.51.0-SNAPSHOT" - }, - "dependentSelector": {}, - "validAppVersions": { - "creation": "1.0.0", - "from": "1.0.0", - "to": "1.0.0" + }, + "namespace": "apps/MyComponent/changes/", + "creation": "2017-09-01T11:54:55.238Z", + "originalLanguage": "EN", + "conditions": {}, + "context": "", + "support": { + "generator": "Change.createInitialFileContent", + "service": "", + "user": "", + "sapui5Version": "1.51.0-SNAPSHOT" + }, + "dependentSelector": {}, + "validAppVersions": { + "creation": "1.0.0", + "from": "1.0.0", + "to": "1.0.0" + } + }, { + "fileName": "id_1504764957625_7_rename1", + "fileType": "change", + "changeType": "rename", + "reference": "rta.performance.Component", + "packageName": "$TMP", + "content": { + "originalControlType": "sap.m.Label" + }, + "selector": { + "id": "initialLabel", + "idIsLocal": false + }, + "layer": "CUSTOMER", + "texts": { + "newText": { + "value": "rename_0", + "type": "XFLD" } + }, + "namespace": "apps/MyComponent/changes/", + "creation": "2017-09-06T11:54:55.238Z", + "originalLanguage": "EN", + "conditions": {}, + "context": "", + "support": { + "generator": "Change.createInitialFileContent", + "service": "", + "user": "", + "sapui5Version": "1.51.0-SNAPSHOT" + }, + "dependentSelector": {}, + "validAppVersions": { + "creation": "1.0.0", + "from": "1.0.0", + "to": "1.0.0" } - ] - }; + } + ]; + const resources = []; - singleFlexChange.changes.forEach((change) => { + flexBundle.forEach((change) => { resources.push({ name: "flexChange", getBuffer: async () => JSON.stringify(change) @@ -110,5 +109,5 @@ test("flexChangesBundler with 2 changes", async (t) => { // check content const content = await oResult.getString(); const parsedContent = JSON.parse(content); - t.deepEqual(parsedContent, singleFlexChange, "Result must contain the content"); + t.deepEqual(parsedContent, flexBundle, "Result must contain the content"); });