diff --git a/lib/processors/manifestTransformer.js b/lib/processors/manifestTransformer.js index d9972e046..f5dc7cd3d 100644 --- a/lib/processors/manifestTransformer.js +++ b/lib/processors/manifestTransformer.js @@ -72,7 +72,7 @@ function hasBundleTerminologies(bundleConfig) { function getTerminologieBundles(bundleConfig, bundleConfigs) { const terminologyBundles = []; if (hasBundleTerminologies(bundleConfig)) { - Object.keys(bundleConfig.terminologies).forEach((key) =>{ + Object.keys(bundleConfig.terminologies).forEach((key) => { terminologyBundles.push(bundleConfig.terminologies[key]); }); } @@ -80,8 +80,10 @@ function getTerminologieBundles(bundleConfig, bundleConfigs) { } function getEnhanceWithBundles(bundleConfig, bundleConfigs) { - const enhanceWithBundles = []; - return bundleConfigs.concat(enhanceWithBundles); + if (!bundleConfig.enhanceWith) { + return bundleConfigs; + } + return bundleConfigs.concat(bundleConfig.enhanceWith); } function getSapAppBundle(manifest, bundleConfigs) { @@ -108,6 +110,7 @@ function getSapAppBundle(manifest, bundleConfigs) { }; } else { bundleConfigs = getTerminologieBundles(sapAppBundleConfig, bundleConfigs); + bundleConfigs = getEnhanceWithBundles(sapAppBundleConfig, bundleConfigs); } sapAppConfig.i18n = sapAppBundleConfig; @@ -123,6 +126,7 @@ function getSapUi5ModelBundles(manifest, bundleConfigs) { .map((model) => model.settings); sapui5ModelConfigBundles.forEach((bundleConfig) => { bundleConfigs = bundleConfigs.concat(getTerminologieBundles(bundleConfig, bundleConfigs)); + bundleConfigs = bundleConfigs.concat(getEnhanceWithBundles(bundleConfig, bundleConfigs)); }); return bundleConfigs.concat(sapui5ModelConfigBundles); } @@ -145,6 +149,7 @@ function getSapUi5LibrariesBundles(manifest, bundleConfigs) { }; } else { bundleConfigs = getTerminologieBundles(sapui5LibraryBundleConfig, bundleConfigs); + bundleConfigs = getEnhanceWithBundles(sapui5LibraryBundleConfig, bundleConfigs); } sapui5LibraryConfig.i18n = sapui5LibraryBundleConfig; diff --git a/test/lib/processors/manifestTransformer.js b/test/lib/processors/manifestTransformer.js index 5da8e3d99..d36150e2a 100644 --- a/test/lib/processors/manifestTransformer.js +++ b/test/lib/processors/manifestTransformer.js @@ -982,6 +982,82 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with terminolog t.true(t.context.logErrorSpy.notCalled, "No errors should be logged"); }); +test.serial("Library: sap.ui5/library: Replaces supportedLocales with deactivated terminologies", async (t) => { + t.plan(4); + const {manifestTransformer} = t.context; + const input = JSON.stringify({ + "_version": "1.58.0", + "sap.app": { + "id": "sap.ui.demo.lib", + "type": "library" + }, + "sap.ui5": { + "library": { + "i18n": { + "bundleUrl": "i18nc/messagebundlec.properties", + "terminologies": { + "sports": { + "bundleUrl": "i18nc_sports/messagebundle.sports.properties", + "supportedLocales": ["pt"] + } + } + } + } + } + }, null, 2); + + const expected = JSON.stringify({ + "_version": "1.58.0", + "sap.app": { + "id": "sap.ui.demo.lib", + "type": "library" + }, + "sap.ui5": { + "library": { + "i18n": { + "bundleUrl": "i18nc/messagebundlec.properties", + "terminologies": { + "sports": { + "bundleUrl": "i18nc_sports/messagebundle.sports.properties", + "supportedLocales": ["pt"] + } + }, + "supportedLocales": ["", "de", "en"], + } + } + } + }, null, 2); + + const resource = { + getString: () => Promise.resolve(input), + setString: (actual) => { + t.deepEqual(actual, expected, "Correct file content should be set"); + } + }; + + const processedResources = await manifestTransformer({ + resources: [resource], + fs: { + readdir: sinon.stub().callsFake((fsPath, callback) => { + if (fsPath && fsPath.endsWith("i18nc_sports/")) { + t.fail("Should never be called"); + } else { + return callback(null, [ + "messagebundlec_de.properties", + "messagebundlec_en.properties", + "messagebundlec.properties" + ]); + } + }) + } + }); + + t.deepEqual(processedResources, [resource], "Input resource is returned"); + + t.true(t.context.logWarnSpy.notCalled, "No warnings should be logged"); + t.true(t.context.logErrorSpy.notCalled, "No errors should be logged"); +}); + test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWith", async (t) => { t.plan(4); const {manifestTransformer} = t.context; @@ -1024,7 +1100,7 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit "supportedLocales": ["", "de", "en"] }, { - "bundleUrl": "myfolder1/messagebundlenc1.properties", + "bundleUrl": "myfolder2/messagebundlenc2.properties", "supportedLocales": ["", "de", "en"] } ], @@ -1045,13 +1121,13 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.startsWith("myfolder1")) { + if (fsPath && fsPath.endsWith("myfolder1/")) { return callback(null, [ "messagebundlenc1_de.properties", "messagebundlenc1_en.properties", "messagebundlenc1.properties" ]); - } else if (fsPath && fsPath.startsWith("myfolder2")) { + } else if (fsPath && fsPath.endsWith("myfolder2/")) { return callback(null, [ "messagebundlenc2_de.properties", "messagebundlenc2_en.properties", @@ -1170,31 +1246,31 @@ test.serial("Library: sap.ui5/library: Replaces supportedLocales with enhanceWit resources: [resource], fs: { readdir: sinon.stub().callsFake((fsPath, callback) => { - if (fsPath && fsPath.startsWith("myfolder1")) { + if (fsPath && fsPath.endsWith("myfolder1/")) { return callback(null, [ "messagebundlenc1_de.properties", "messagebundlenc1_en.properties", "messagebundlenc1.properties" ]); - } else if (fsPath && fsPath.startsWith("myfolder2")) { + } else if (fsPath && fsPath.endsWith("myfolder2/")) { return callback(null, [ "messagebundlenc2_de.properties", "messagebundlenc2_en.properties", "messagebundlenc2.properties" ]); - } else if (fsPath && fsPath.startsWith("i18nc_sports")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports/")) { return callback(null, [ "messagebundle.sports_de.properties", "messagebundle.sports_en.properties", "messagebundle.sports.properties" ]); - } else if (fsPath && fsPath.startsWith("i18nc_sports_soccer")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer/")) { return callback(null, [ "messagebundle.soccer_de.properties", "messagebundle.soccer_en.properties", "messagebundle.soccer.properties" ]); - } else if (fsPath && fsPath.startsWith("i18nc_sports_soccer_euroleague")) { + } else if (fsPath && fsPath.endsWith("i18nc_sports_soccer_euroleague/")) { return callback(null, [ "messagebundle.elsoccer_de.properties", "messagebundle.elsoccer_en.properties",