Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] generateResourcesJson: Add raw-module info for debug bundles #736

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,37 +279,43 @@ class ResourceCollector {

await Promise.all(promises);

const debugBundlePromises = [];

for (let i = debugResourcesInfo.length - 1; i >= 0; i--) {
const dbgInfo = debugResourcesInfo[i];
const nonDebugName = ResourceInfoList.getNonDebugName(dbgInfo.name);
await Promise.all(debugResourcesInfo.map(async (dbgInfo) => {
const debugName = dbgInfo.name;
const nonDebugName = ResourceInfoList.getNonDebugName(debugName);
const nonDbgInfo = this._resources.get(nonDebugName);

// FIXME: "merged" property is only calculated in ResourceInfo#copyFrom
// Therefore using the same logic here to compute it.
if (!nonDbgInfo || (nonDbgInfo.included != null && nonDbgInfo.included.size > 0)) {
// We need to analyze the dbg resource if there is no non-dbg variant or
// it is a bundle because we will (usually) have different content.
debugBundlePromises.push(
this.enrichWithDependencyInfo(dbgInfo)
);

// In order to retrieve the correct raw module info, the name must be set
// to the non-debug name. The same happens during bundling, where also only
// the non-debug names are used.
dbgInfo.name = nonDebugName;
flovogt marked this conversation as resolved.
Show resolved Hide resolved

await this.enrichWithDependencyInfo(dbgInfo);

// After the analysis, the name needs to be set back
// The "module" property is now already set to the non-debug name, as expected
dbgInfo.name = debugName;
} 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);
const newDbgInfo = new ResourceInfo(debugName);

// 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);
// Finally, set the module name to the non-dbg name
newDbgInfo.module = nonDbgInfo.module;

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

await Promise.all(debugBundlePromises);
}));
}

createOrphanFilters() {
Expand Down
1 change: 0 additions & 1 deletion lib/lbt/resources/ResourceInfoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ResourceInfoList {
if ( myInfo == null ) {
myInfo = new ResourceInfo(relativeName);
myInfo.size = info.size;
myInfo.module = ResourceInfoList.getNonDebugName(info.name);
this.resources.push(myInfo);
this.resourcesByName.set(relativeName, myInfo);
}
Expand Down
83 changes: 83 additions & 0 deletions test/lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const test = require("ava");
const sinon = require("sinon");
const mock = require("mock-require");
const {Resource} = require("@ui5/fs");
const LocatorResourcePool = require("../../../../lib/lbt/resources/LocatorResourcePool");

let ResourceCollector = require("../../../../lib/lbt/resources/ResourceCollector");

Expand Down Expand Up @@ -286,3 +288,84 @@ test.serial("enrichWithDependencyInfo: add infos to resourceinfo", async (t) =>
requiresTopLevelScope: true
}, "all information gets used for the resourceInfo");
});

test.serial("integration: Raw Module Info for debug variant", async (t) => {
const resources = [
new Resource({
path: "/resources/mylib/myRawModuleBundle.js",
string: `define('a', () => 'a');define('b', ['a'], (a) => a + 'b');`
}),
new Resource({
path: "/resources/mylib/externalDependency.js",
string: `console.log('Foo');`
}),
new Resource({
path: "/resources/mylib/myRawModuleBundle-dbg.js",
string: `
define('a', () => 'a');
define('b', ['a'], (a) => a + 'b');
`
}),
new Resource({
path: "/resources/mylib/.library",
string: `
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd">
<name>mylib</name>
<vendor>Me</vendor>
<copyright>mylib</copyright>
<version>1.0.0</version>
<documentation>mylib</documentation>
<dependencies>
<dependency>
<libraryName>sap.ui.core</libraryName>
</dependency>
</dependencies>
<appData>
<packaging xmlns="http://www.sap.com/ui5/buildext/packaging" version="2.0">
<module-infos>
<raw-module
name="mylib/myRawModuleBundle.js"
depends="mylib/externalDependency.js"
/>
</module-infos>
</packaging>
</appData>
</library>`
}),
];

const pool = new LocatorResourcePool();
await pool.prepare( resources );

const collector = new ResourceCollector(pool);
await Promise.all(resources.map((resource) => collector.visitResource(resource)));

await collector.determineResourceDetails({
debugResources: ["**/*-dbg.js"]
});

collector.groupResourcesByComponents();

const resourceInfoList = collector.components.get("mylib/");

const myRawModuleBundle = resourceInfoList.resourcesByName.get("myRawModuleBundle.js");
t.is(myRawModuleBundle.name, "myRawModuleBundle.js");
t.is(myRawModuleBundle.module, "mylib/myRawModuleBundle.js");
t.is(myRawModuleBundle.format, "raw");
t.is(myRawModuleBundle.requiresTopLevelScope, false);
t.deepEqual(myRawModuleBundle.included,
new Set(["a.js", "b.js"]));
t.deepEqual(myRawModuleBundle.required,
new Set(["mylib/externalDependency.js"]));

const myRawModuleBundleDbg = resourceInfoList.resourcesByName.get("myRawModuleBundle-dbg.js");
t.is(myRawModuleBundleDbg.name, "myRawModuleBundle-dbg.js");
t.is(myRawModuleBundleDbg.module, "mylib/myRawModuleBundle.js");
t.is(myRawModuleBundleDbg.format, "raw");
t.is(myRawModuleBundleDbg.requiresTopLevelScope, false);
t.deepEqual(myRawModuleBundleDbg.included,
new Set(["a.js", "b.js"]));
t.deepEqual(myRawModuleBundleDbg.required,
new Set(["mylib/externalDependency.js"]));
});
3 changes: 2 additions & 1 deletion test/lib/lbt/resources/ResourceInfoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ test("add: add debug resources", (t) => {
t.is(resourceInfoList.resources.length, 1, "one resource added");

const resultDbg = resourceInfoList.resourcesByName.get("../myfile-dbg.js");
t.is(resultDbg.module, "myfile.js", "module is set");
// Note: "module" will be set properly for debug resources within ResourceCollector#determineResourceDetails
t.is(resultDbg.module, undefined, "module is not set");
t.deepEqual(resultDbg.required, new Set(["some-dep.js"]), "module is set");
});

Expand Down