Skip to content

Commit

Permalink
Fix sap-ui-custom-dbg.js
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Feb 22, 2022
1 parent 0c7bb6f commit e74779f
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lib/tasks/bundlers/generateStandaloneAppBundle.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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";
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -123,7 +149,8 @@ module.exports = async function({workspace, dependencies, taskUtil, options: {pr
}),
bundleOptions: {
optimize: false
}
},
moduleNameMapping: unoptimizedModuleNameMapping
}
})
]).then((results) => {
Expand Down

0 comments on commit e74779f

Please sign in to comment.