Skip to content

Commit

Permalink
[FIX] generateResourcesJson: Analyze debug bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Nov 25, 2021
1 parent 1ee32ad commit 082b06b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
48 changes: 33 additions & 15 deletions lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,16 @@ class ResourceCollector {
}

async determineResourceDetails({
debugResources, mergedResources, designtimeResources, supportResources, debugBundles
debugResources, mergedResources, designtimeResources, supportResources
}) {
const baseNames = new Set();
const debugFilter = new ResourceFilterList(debugResources);
const mergeFilter = new ResourceFilterList(mergedResources);
const designtimeFilter = new ResourceFilterList(designtimeResources);
const supportFilter = new ResourceFilterList(supportResources);
const debugBundleFilter = new ResourceFilterList(debugBundles);

const promises = [];
const nonBundledDebugResources = [];
const debugResourcesInfo = [];

for (const [name, info] of this._resources.entries()) {
if ( debugFilter.matches(name) ) {
Expand Down Expand Up @@ -231,13 +230,14 @@ class ResourceCollector {
}

if ( /(?:\.js|\.view\.xml|\.control\.xml|\.fragment\.xml)$/.test(name) ) {
if ( (!info.isDebug || debugBundleFilter.matches(name)) ) {
// Only analyze non-debug files and special debug bundles (like sap-ui-core-dbg.js)
if ( !info.isDebug ) {
// Only analyze non-dbg files in first run
promises.push(
this.enrichWithDependencyInfo(info)
);
} else {
nonBundledDebugResources.push(info);
// Collect dbg files to be handled in a second step (see below)
debugResourcesInfo.push(info);
}
}

Expand Down Expand Up @@ -279,19 +279,37 @@ class ResourceCollector {

await Promise.all(promises);

for (let i = nonBundledDebugResources.length - 1; i >= 0; i--) {
const dbgInfo = nonBundledDebugResources[i];
const debugBundlePromises = [];

for (let i = debugResourcesInfo.length - 1; i >= 0; i--) {
const dbgInfo = debugResourcesInfo[i];
const nonDebugName = ResourceInfoList.getNonDebugName(dbgInfo.name);
const nonDbgInfo = this._resources.get(nonDebugName);
const newDbgInfo = new ResourceInfo(dbgInfo.name);

// First copy info of analysis from non-dbg file (included, required, condRequired, ...)
newDbgInfo.copyFrom(null, nonDbgInfo);
// Then copy over info from dbg file to properly set name, isDebug, etc.
newDbgInfo.copyFrom(null, dbgInfo);

this._resources.set(dbgInfo.name, newDbgInfo);
// FIXME: "merged" property is only calculated in ResourceInfo#copyFrom
// Therefore using the same logic here to compute it.
if (nonDbgInfo.included != null && nonDbgInfo.included.size > 0) {
// We need to analyze the dbg resource if the non-dbg variant is a bundle
// because we will (usually) have different content.
debugBundlePromises.push(
this.enrichWithDependencyInfo(dbgInfo)
);
} else {
// If the non-dbg resource is not a bundle, we can just copy over the info and skip
// analyzing the dbg variant as both should have the same info.

const newDbgInfo = new ResourceInfo(dbgInfo.name);

// First copy info of analysis from non-dbg file (included, required, condRequired, ...)
newDbgInfo.copyFrom(null, nonDbgInfo);
// Then copy over info from dbg file to properly set name, isDebug, etc.
newDbgInfo.copyFrom(null, dbgInfo);

this._resources.set(dbgInfo.name, newDbgInfo);
}
}

await Promise.all(debugBundlePromises);
}

createOrphanFilters() {
Expand Down
17 changes: 2 additions & 15 deletions lib/processors/resourceListCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ const DEFAULT_SUPPORT_RESOURCES_FILTER = [
"**/*.support.js"
];

/**
* Hard coded debug bundle, to trigger separate analysis for this filename
* because sap-ui-core.js and sap-ui-core-dbg.js have different includes
*
* @type {string[]}
*/
const DEBUG_BUNDLES = [
"sap-ui-core-dbg.js",
"sap-ui-core-nojQuery-dbg.js"
];

/**
* Creates and adds resources.json entry (itself) to the list.
*
Expand Down Expand Up @@ -138,8 +127,7 @@ module.exports = async function({resources, dependencyResources = [], options})
debugResources: DEFAULT_DEBUG_RESOURCES_FILTER,
mergedResources: DEFAULT_BUNDLE_RESOURCES_FILTER,
designtimeResources: DEFAULT_DESIGNTIME_RESOURCES_FILTER,
supportResources: DEFAULT_SUPPORT_RESOURCES_FILTER,
debugBundles: DEBUG_BUNDLES
supportResources: DEFAULT_SUPPORT_RESOURCES_FILTER
}, options);

const pool = new LocatorResourcePool();
Expand All @@ -162,8 +150,7 @@ module.exports = async function({resources, dependencyResources = [], options})
debugResources: options.debugResources,
mergedResources: options.mergedResources,
designtimeResources: options.designtimeResources,
supportResources: options.supportResources,
debugBundles: options.debugBundles
supportResources: options.supportResources
});

// group resources by components and create ResourceInfoLists
Expand Down

0 comments on commit 082b06b

Please sign in to comment.