Skip to content

Commit b9d397e

Browse files
committed
[FIX] generateResourcesJson: Make resources.json generation deterministic
Stop analyzing debug-resources if they correspond to a non-debug resource. Only analyze the non-debug resource and copy any dependency information to the corresponding debug-resource. While this might not be the best approach given that analyzing the source ("debug") version of a resource might result in finding more dependencies (i.e. those mangled during minification), this change ensures that we generate the same resources.json, independently from the order of debug and non-debug resources supplied to the resourceListCreator processor. Resolves SAP/ui5-tooling#274
1 parent e9458e7 commit b9d397e

File tree

3 files changed

+37
-45
lines changed

3 files changed

+37
-45
lines changed

lib/lbt/resources/ResourceCollector.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,25 @@ class ResourceCollector {
150150
});
151151
}
152152

153-
async determineResourceDetails({pool, debugResources, mergedResources, designtimeResources, supportResources}) {
153+
async determineResourceDetails({
154+
debugResources, mergedResources, designtimeResources, supportResources, debugBundles
155+
}) {
154156
const baseNames = new Set();
155157
const debugFilter = new ResourceFilterList(debugResources);
156158
const mergeFilter = new ResourceFilterList(mergedResources);
157159
const designtimeFilter = new ResourceFilterList(designtimeResources);
158160
const supportFilter = new ResourceFilterList(supportResources);
161+
const debugBundleFilter = new ResourceFilterList(debugBundles);
159162

160163
const promises = [];
164+
const nonBundledDebugResources = [];
161165

162166
for (const [name, info] of this._resources.entries()) {
167+
if ( debugFilter.matches(name) ) {
168+
info.isDebug = true;
169+
log.verbose(` found potential debug resource '${name}'`);
170+
}
171+
163172
// log.verbose(` checking ${name}`);
164173
let m;
165174
if ( m = LOCALE.exec(name) ) {
@@ -180,9 +189,14 @@ class ResourceCollector {
180189
}
181190

182191
if ( /(?:\.js|\.view\.xml|\.control\.xml|\.fragment\.xml)$/.test(name) ) {
183-
promises.push(
184-
this.enrichWithDependencyInfo(info)
185-
);
192+
if ( (!info.isDebug || debugBundleFilter.matches(name)) ) {
193+
// Only analyze non-debug files which are not special debug bundles (like sap-ui-core-dbg.js)
194+
promises.push(
195+
this.enrichWithDependencyInfo(info)
196+
);
197+
} else {
198+
nonBundledDebugResources.push(info);
199+
}
186200
}
187201

188202
// set the module name for .properties and .json
@@ -197,11 +211,6 @@ class ResourceCollector {
197211
}));
198212
}
199213

200-
if ( debugFilter.matches(name) ) {
201-
info.isDebug = true;
202-
log.verbose(` found potential debug resource '${name}'`);
203-
}
204-
205214
if ( mergeFilter.matches(name) ) {
206215
info.merged = true;
207216
log.verbose(` found potential merged resource '${name}'`);
@@ -226,7 +235,17 @@ class ResourceCollector {
226235
}
227236
}
228237

229-
return Promise.all(promises);
238+
await Promise.all(promises);
239+
240+
for (let i = nonBundledDebugResources.length - 1; i >= 0; i--) {
241+
const dbgInfo = nonBundledDebugResources[i];
242+
const nonDebugName = ResourceInfoList.getNonDebugName(dbgInfo.name);
243+
const nonDbgInfo = this._resources.get(nonDebugName);
244+
const newDbgInfo = new ResourceInfo(dbgInfo.name);
245+
newDbgInfo.copyFrom(null, nonDbgInfo);
246+
newDbgInfo.copyFrom(null, dbgInfo);
247+
this._resources.set(dbgInfo.name, newDbgInfo);
248+
}
230249
}
231250

232251
createOrphanFilters() {
@@ -253,19 +272,17 @@ class ResourceCollector {
253272

254273
groupResourcesByComponents(options) {
255274
const orphanFilters = this.createOrphanFilters();
256-
const debugBundlesFilter = new ResourceFilterList(options.debugBundles);
257275
for (const resource of this._resources.values()) {
258276
let contained = false;
259277
for (const [prefix, list] of this._components.entries()) {
260-
const isDebugBundle = debugBundlesFilter.matches(resource.name);
261278
if ( resource.name.startsWith(prefix) ) {
262-
list.add(resource, !isDebugBundle);
279+
list.add(resource);
263280
contained = true;
264281
} else if ( orphanFilters.has(prefix) ) {
265282
// log.verbose(` checking '${resource.name}' against orphan filter ` +
266283
// `'${orphanFilters.get(prefix)}' (${prefix})`);
267284
if ( orphanFilters.get(prefix).matches(resource.name) ) {
268-
list.add(resource, !isDebugBundle);
285+
list.add(resource);
269286
contained = true;
270287
}
271288
}

lib/lbt/resources/ResourceInfoList.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,12 @@ class ResourceInfoList {
3939
* Add ResourceInfo to list
4040
*
4141
* @param {ResourceInfo} info
42-
* @param {boolean} shareDebugInformation
4342
*/
44-
add(info, shareDebugInformation=true) {
43+
add(info) {
4544
const relativeName = ResourceInfoList.makePathRelativeTo(this.name, info.name);
46-
4745
// search for a resource with the same name
4846
let myInfo = this.resourcesByName.get(relativeName);
4947

50-
if ( myInfo == null && shareDebugInformation) {
51-
// when not found, check if the given resource is a debug resource and
52-
// share the information with the non-dbg version
53-
const nonDbgName = ResourceInfoList.getNonDebugName(relativeName);
54-
const dbgName = ResourceInfoList.getDebugName(relativeName);
55-
if ( nonDbgName != null && this.resourcesByName.has(nonDbgName) ) {
56-
// copy from source
57-
myInfo = new ResourceInfo(relativeName);
58-
const source = this.resourcesByName.get(nonDbgName);
59-
myInfo.copyFrom(this.name, source);
60-
this.resources.push(myInfo);
61-
this.resourcesByName.set(relativeName, myInfo);
62-
} else if (dbgName != null && this.resourcesByName.has(dbgName)) {
63-
// copy from debug
64-
myInfo = new ResourceInfo(relativeName);
65-
const source = this.resourcesByName.get(dbgName);
66-
myInfo.copyFrom(this.name, source);
67-
myInfo.module = ResourceInfoList.getNonDebugName(source.module);
68-
this.resources.push(myInfo);
69-
this.resourcesByName.set(relativeName, myInfo);
70-
}
71-
}
72-
7348
// this is the assumption, that the debug one is the same as the non-dbg one
7449
if ( myInfo == null ) {
7550
myInfo = new ResourceInfo(relativeName);

lib/processors/resourceListCreator.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ const DEFAULT_SUPPORT_RESOURCES_FILTER = [
7373
* @type {string[]}
7474
*/
7575
const DEBUG_BUNDLES = [
76-
"sap-ui-core-dbg.js"
76+
"sap-ui-core-dbg.js",
77+
"sap-ui-core-nojQuery-dbg.js"
7778
];
7879

7980
/**
@@ -159,13 +160,12 @@ module.exports = async function({resources, options}) {
159160
debugResources: options.debugResources,
160161
mergedResources: options.mergedResources,
161162
designtimeResources: options.designtimeResources,
162-
supportResources: options.supportResources
163+
supportResources: options.supportResources,
164+
debugBundles: options.debugBundles
163165
});
164166

165167
// group resources by components and create ResourceInfoLists
166-
collector.groupResourcesByComponents({
167-
debugBundles: options.debugBundles
168-
});
168+
collector.groupResourcesByComponents();
169169

170170
const resourceLists = [];
171171

0 commit comments

Comments
 (0)