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

core(script-treemap-data): fix sourceRoot & missing coverage bugs #11825

Merged
merged 3 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 18 additions & 7 deletions lighthouse-core/audits/script-treemap-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ class ScriptTreemapDataAudit extends Audit {

const name = scriptElement.src;
const bundle = bundles.find(bundle => scriptElement.src === bundle.script.src);
const scriptCoverages = artifacts.JsUsage[scriptElement.src];
if (!bundle || !scriptCoverages) {
// No bundle or coverage information, so simply make a single node
const scriptCoverages = artifacts.JsUsage[scriptElement.src] || [];
if (!bundle && scriptCoverages.length === 0) {
// No bundle and no coverage information, so simply make a single node
// detailing how big the script is.

rootNodeContainers.push({
Expand All @@ -186,7 +186,7 @@ class ScriptTreemapDataAudit extends Audit {

/** @type {LH.Treemap.Node} */
let node;
if (unusedJavascriptSummary.sourcesWastedBytes && !('errorMessage' in bundle.sizes)) {
if (bundle && !('errorMessage' in bundle.sizes)) {
// Create nodes for each module in a bundle.

/** @type {Record<string, SourceData>} */
Expand All @@ -195,18 +195,29 @@ class ScriptTreemapDataAudit extends Audit {
/** @type {SourceData} */
const sourceData = {
resourceBytes: bundle.sizes.files[source],
unusedBytes: unusedJavascriptSummary.sourcesWastedBytes[source],
};

const key = ModuleDuplication.normalizeSource(source);
if (unusedJavascriptSummary.sourcesWastedBytes) {
sourceData.unusedBytes = unusedJavascriptSummary.sourcesWastedBytes[source];
}

// ModuleDuplication uses keys without the source root prepended, but
// bundle.sizes uses keys with it prepended, so we remove the source root before
// using it with duplicationByPath.
let sourceWithoutSourceRoot = source;
if (bundle.rawMap.sourceRoot && source.startsWith(bundle.rawMap.sourceRoot)) {
patrickhulce marked this conversation as resolved.
Show resolved Hide resolved
sourceWithoutSourceRoot = source.replace(bundle.rawMap.sourceRoot, '');
}

const key = ModuleDuplication.normalizeSource(sourceWithoutSourceRoot);
if (duplicationByPath.has(key)) sourceData.duplicatedNormalizedModuleName = key;

sourcesData[source] = sourceData;
}

node = this.prepareTreemapNodes(bundle.rawMap.sourceRoot || '', sourcesData);
} else {
// There was no source map for this script, so we can only produce a single node.
// No valid source map for this script, so we can only produce a single node.

node = {
name,
Expand Down
Loading