Skip to content

Commit

Permalink
[INTERNAL] generateLibraryPreload: Apply resource transformation for …
Browse files Browse the repository at this point in the history
…unoptimized sap.ui.core bundles

Only applicable to sap.ui.core versions <1.97.0. Same logic as for
custom bundles in the generateBundle task.
  • Loading branch information
RandomByte committed Dec 22, 2021
1 parent 342a224 commit 9b5eddf
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateLib
const moduleBundler = require("../../processors/bundlers/moduleBundler");
const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;
const {negateFilters} = require("../../lbt/resources/ResourceFilterList");
const ModuleName = require("../../lbt/utils/ModuleName");

function getDefaultLibraryPreloadFilters(namespace, excludes) {
const filters = [
Expand Down Expand Up @@ -284,7 +285,7 @@ module.exports = function({workspace, dependencies, taskUtil, options: {projectN
});
}

return combo.byGlob("/**/*.{js,json,xml,html,properties,library}").then((resources) => {
return combo.byGlob("/**/*.{js,json,xml,html,properties,library}").then(async (resources) => {
// Find all libraries and create a library-preload.js bundle

let p = Promise.resolve();
Expand All @@ -303,6 +304,27 @@ module.exports = function({workspace, dependencies, taskUtil, options: {projectN
const isEvo = resources.find((resource) => {
return resource.getPath() === "/resources/ui5loader.js";
});

let unoptimizedResources = resources;
if (taskUtil) {
unoptimizedResources = await new ReaderCollectionPrioritized({
name: `libraryBundler - prioritize workspace over dependencies: ${projectName}`,
readers: [workspace, dependencies]
}).filter(function(resource) {
// Remove any non-debug variants
return !taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.HasDebugVariant);
}).transformer(async function(resourcePath, getClonedResource) {
if (taskUtil.getTag(resourcePath, taskUtil.STANDARD_TAGS.IsDebugVariant)) {
const resource = await getClonedResource();
const nonDbgPath = ModuleName.getNonDebugName(resource.getPath());
if (!nonDbgPath) {
throw new Error(`Failed to resolve non-debug name for ${resource.getPath()}`);
}
resource.setPath(nonDbgPath);
}
}).byGlob("/**/*.{js,json,xml,html,properties,library}");
}

let filters;
if (isEvo) {
filters = ["ui5loader-autoconfig.js"];
Expand All @@ -316,7 +338,7 @@ module.exports = function({workspace, dependencies, taskUtil, options: {projectN
}),
moduleBundler({
options: getModuleBundlerOptions({name: "sap-ui-core-dbg.js", filters, preload: false}),
resources
resources: unoptimizedResources
}),
moduleBundler({
options: getModuleBundlerOptions({
Expand All @@ -328,7 +350,7 @@ module.exports = function({workspace, dependencies, taskUtil, options: {projectN
options: getModuleBundlerOptions({
name: "sap-ui-core-nojQuery-dbg.js", filters, preload: false, provided: true
}),
resources
resources: unoptimizedResources
}),
]).then((results) => {
const bundles = Array.prototype.concat.apply([], results);
Expand Down

0 comments on commit 9b5eddf

Please sign in to comment.