apex-auditor 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +40 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -100,7 +100,16 @@ function buildConsoleTable(results, useColor) {
|
|
|
100
100
|
"| Label | Path | Device | P | A | BP | SEO | LCP (s) | FCP (s) | TBT (ms) | CLS |",
|
|
101
101
|
"|-------|------|--------|---|---|----|-----|---------|---------|----------|-----|",
|
|
102
102
|
].join("\n");
|
|
103
|
-
const rows =
|
|
103
|
+
const rows = [];
|
|
104
|
+
let previousKey;
|
|
105
|
+
for (const result of results) {
|
|
106
|
+
const key = `${result.label}:::${result.path}`;
|
|
107
|
+
if (previousKey !== undefined && key !== previousKey) {
|
|
108
|
+
rows.push("");
|
|
109
|
+
}
|
|
110
|
+
rows.push(buildConsoleRow(result, useColor));
|
|
111
|
+
previousKey = key;
|
|
112
|
+
}
|
|
104
113
|
return `${header}\n${rows.join("\n")}`;
|
|
105
114
|
}
|
|
106
115
|
function buildRow(result) {
|
|
@@ -166,15 +175,38 @@ function formatTopIssues(opportunities) {
|
|
|
166
175
|
if (opportunities.length === 0) {
|
|
167
176
|
return "";
|
|
168
177
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
178
|
+
const meaningful = opportunities.filter((opp) => hasMeaningfulSavings(opp));
|
|
179
|
+
const source = meaningful.length > 0 ? meaningful : opportunities;
|
|
180
|
+
const sorted = [...source].sort(compareOpportunitiesByImpact);
|
|
181
|
+
const limit = 2;
|
|
182
|
+
const top = sorted.slice(0, limit);
|
|
183
|
+
const items = top.map((opp) => formatOpportunityLabel(opp));
|
|
176
184
|
return items.join("; ");
|
|
177
185
|
}
|
|
186
|
+
function hasMeaningfulSavings(opportunity) {
|
|
187
|
+
const savingsMs = opportunity.estimatedSavingsMs ?? 0;
|
|
188
|
+
const savingsBytes = opportunity.estimatedSavingsBytes ?? 0;
|
|
189
|
+
return savingsMs > 0 || savingsBytes > 0;
|
|
190
|
+
}
|
|
191
|
+
function compareOpportunitiesByImpact(a, b) {
|
|
192
|
+
const aMs = a.estimatedSavingsMs ?? 0;
|
|
193
|
+
const bMs = b.estimatedSavingsMs ?? 0;
|
|
194
|
+
if (aMs !== bMs) {
|
|
195
|
+
return bMs - aMs;
|
|
196
|
+
}
|
|
197
|
+
const aBytes = a.estimatedSavingsBytes ?? 0;
|
|
198
|
+
const bBytes = b.estimatedSavingsBytes ?? 0;
|
|
199
|
+
return bBytes - aBytes;
|
|
200
|
+
}
|
|
201
|
+
function formatOpportunityLabel(opportunity) {
|
|
202
|
+
const savingsMs = opportunity.estimatedSavingsMs !== undefined ? `${Math.round(opportunity.estimatedSavingsMs)}ms` : "";
|
|
203
|
+
const savingsBytes = opportunity.estimatedSavingsBytes !== undefined
|
|
204
|
+
? `${Math.round(opportunity.estimatedSavingsBytes / 1024)}KB`
|
|
205
|
+
: "";
|
|
206
|
+
const parts = [savingsMs, savingsBytes].filter((part) => part.length > 0);
|
|
207
|
+
const suffix = parts.length > 0 ? ` (${parts.join(", ")})` : "";
|
|
208
|
+
return `${opportunity.id}${suffix}`;
|
|
209
|
+
}
|
|
178
210
|
function formatMetricSeconds(valueMs, goodThresholdMs, warnThresholdMs, useColor) {
|
|
179
211
|
if (valueMs === undefined) {
|
|
180
212
|
return "-";
|