Skip to content

Commit

Permalink
[FIX] versionInfoGenerator: fix hasOwnPreload flag (#591)
Browse files Browse the repository at this point in the history
hasOwnPreload is only true if the library has embeds field set in manifest
and embedded manifest does not have a backlink (embeddedBy) to the library.

restructure component object such that hasOwnPreload comes as first property
  • Loading branch information
tobiasso85 committed Mar 4, 2021
1 parent 42f6474 commit 73a0f8b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
19 changes: 10 additions & 9 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ const getManifestHints = (dependencyInfo, dependencyInfoMap) => {

/**
* Common type for Library and Component
* embeds and bundled components makes only sense for library
* embeds and bundled components make only sense for library
*
* @typedef {object} ArtifactInfo
* @property {string} componentName The library name, e.g. "lib.x"
* @property {Set<string>} bundledComponents The embedded components which have a embeddedBy reference to the library
* @property {Set<string>} bundledComponents The embedded components which have an embeddedBy reference to the library
* @property {DependencyInfo} dependencyInfo The dependency info object
* @property {ArtifactInfo[]} embeds The embedded artifact infos
*/
Expand Down Expand Up @@ -423,18 +423,19 @@ module.exports = async function({options}) {
let components;
artifactInfos.forEach((artifactInfo) => {
artifactInfo.embeds.forEach((embeddedArtifactInfo) => {
const componentObject = {
library: artifactInfo.componentName
};
const componentObject = {};
const bundledComponents = artifactInfo.bundledComponents;
const componentName = embeddedArtifactInfo.componentName;
if (!bundledComponents.has(componentName)) {
componentObject.hasOwnPreload = true;
}
componentObject.library = artifactInfo.componentName;

const manifestHints = getManifestHints(embeddedArtifactInfo.dependencyInfo, dependencyInfoMap);
if (manifestHints) {
componentObject.manifestHints = manifestHints;
}
const bundledComponents = artifactInfo.bundledComponents;
if (bundledComponents.has(componentName)) {
componentObject.hasOwnPreload = true;
}

components = components || {};
components[componentName] = componentObject;
});
Expand Down
2 changes: 1 addition & 1 deletion test/lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ test.serial("versionInfoGenerator library infos with embeds", async (t) => {
],
"components": {
"lib.a.sub": {
"hasOwnPreload": true,
"library": "lib.a"
}
}
Expand Down Expand Up @@ -439,7 +440,6 @@ test.serial("versionInfoGenerator library infos with embeds and embeddedBy (hasO
],
"components": {
"lib.a.sub": {
"hasOwnPreload": true,
"library": "lib.a"
}
}
Expand Down
7 changes: 6 additions & 1 deletion test/lib/tasks/generateVersionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ test.serial("integration: Library with dependencies and subcomponent complex sce
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a",
"manifestHints": {
"dependencies": {
Expand Down Expand Up @@ -863,6 +864,7 @@ test.serial("integration: Library with dependencies and subcomponent bigger scen
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a",
"manifestHints": {
"dependencies": {
Expand Down Expand Up @@ -917,7 +919,6 @@ test.serial("integration: Library without dependencies and embeds and embeddedBy
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a"
}
},
Expand Down Expand Up @@ -964,6 +965,7 @@ test.serial("integration: Library without dependencies and embeddedBy undefined"
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a"
}
},
Expand Down Expand Up @@ -1014,6 +1016,7 @@ test.serial("integration: Library without dependencies and embeddedBy not a stri
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a"
}
},
Expand Down Expand Up @@ -1065,6 +1068,7 @@ test.serial("integration: Library without dependencies and embeddedBy empty stri
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a"
}
},
Expand Down Expand Up @@ -1116,6 +1120,7 @@ test.serial("integration: Library without dependencies and embeddedBy path not c
}],
"components": {
"lib.a.sub.fold": {
"hasOwnPreload": true,
"library": "lib.a"
}
},
Expand Down

0 comments on commit 73a0f8b

Please sign in to comment.