From e74779f6acfcc699751f5c33b59a765f40f82d9e Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Tue, 22 Feb 2022 15:25:00 +0100 Subject: [PATCH] Fix sap-ui-custom-dbg.js --- .../bundlers/generateStandaloneAppBundle.js | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/tasks/bundlers/generateStandaloneAppBundle.js b/lib/tasks/bundlers/generateStandaloneAppBundle.js index 5fc1e90a0..6e15c5620 100644 --- a/lib/tasks/bundlers/generateStandaloneAppBundle.js +++ b/lib/tasks/bundlers/generateStandaloneAppBundle.js @@ -1,6 +1,7 @@ const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateStandaloneAppBundle"); const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized; const moduleBundler = require("../../processors/bundlers/moduleBundler"); +const ModuleName = require("../../lbt/utils/ModuleName"); function getBundleDefinition(config) { const bundleDefinition = { @@ -88,8 +89,7 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.IsDebugVariant); }); } - const results = await combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library,js.map}"); - const resources = Array.prototype.concat.apply([], results); + const resources = await combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library,js.map}"); const isEvo = resources.find((resource) => { return resource.getPath() === "/resources/ui5loader.js"; @@ -101,6 +101,32 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr filters = ["jquery.sap.global.js"]; } + const unoptimizedModuleNameMapping = {}; + let unoptimizedResources = resources; + if (taskUtil) { + unoptimizedResources = await new ReaderCollectionPrioritized({ + name: `generateStandaloneAppBundle - prioritize workspace over dependencies: ${projectName}`, + readers: [workspace, dependencies] + }).filter(function(resource) { + // Remove any non-debug variants + return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.HasDebugVariant); + }).byGlob("/resources/**/*.{js,json,xml,html,properties,library,js.map}"); + + // For "unoptimized" bundles, the non-debug files have already been filtered out + // Now rename the debug variants to the same name so that they appear like the original + // resource to the bundler + for (let i = unoptimizedResources.length - 1; i >= 0; i--) { + const resourcePath = unoptimizedResources[i].getPath(); + if (taskUtil.getTag(resourcePath, taskUtil.STANDARD_TAGS.IsDebugVariant)) { + const nonDbgPath = ModuleName.getNonDebugName(resourcePath); + if (!nonDbgPath) { + throw new Error(`Failed to resolve non-debug name for ${resourcePath}`); + } + unoptimizedModuleNameMapping[resourcePath] = nonDbgPath.slice("/resources/".length); + } + } + } + await Promise.all([ moduleBundler({ resources, @@ -114,7 +140,7 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr } }), moduleBundler({ - resources, + resources: unoptimizedResources, options: { bundleDefinition: getBundleDefinition({ name: "sap-ui-custom-dbg.js", @@ -123,7 +149,8 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr }), bundleOptions: { optimize: false - } + }, + moduleNameMapping: unoptimizedModuleNameMapping } }) ]).then((results) => {