@bymaksym/loadline 0.1.0 → 1.0.0

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.
Files changed (54) hide show
  1. package/README.md +66 -7
  2. package/dist/cli/cli/args.js +33 -3
  3. package/dist/cli/cli/declared.js +52 -0
  4. package/dist/cli/cli/html-report.js +107 -0
  5. package/dist/cli/cli/locate.js +60 -0
  6. package/dist/cli/cli/main.js +118 -5
  7. package/dist/cli/cli/memory.js +78 -0
  8. package/dist/cli/cli/read-build.js +8 -4
  9. package/dist/cli/cli/render-json.js +8 -5
  10. package/dist/cli/cli/render-markdown.js +1 -1
  11. package/dist/cli/cli/render-pr.js +5 -3
  12. package/dist/cli/cli/render-sarif.js +3 -3
  13. package/dist/cli/cli/render-text.js +63 -28
  14. package/dist/cli/cli/report.js +9 -3
  15. package/dist/cli/cli/since-last.js +45 -0
  16. package/dist/cli/cli/text.js +54 -19
  17. package/dist/cli/src/app/core/analysis/analysis.js +8 -4
  18. package/dist/cli/src/app/core/analysis/barrels.js +9 -2
  19. package/dist/cli/src/app/core/analysis/entries.js +41 -6
  20. package/dist/cli/src/app/core/analysis/metafile.types.js +14 -6
  21. package/dist/cli/src/app/core/analysis/split-drift.js +12 -6
  22. package/dist/cli/src/app/core/assets/assets.js +4 -2
  23. package/dist/cli/src/app/core/caching/caching.js +3 -3
  24. package/dist/cli/src/app/core/deps/deps.js +37 -7
  25. package/dist/cli/src/app/core/deps/pins.js +63 -0
  26. package/dist/cli/src/app/core/export/summary.js +27 -9
  27. package/dist/cli/src/app/core/findings/actions.js +63 -6
  28. package/dist/cli/src/app/core/findings/assets.js +30 -5
  29. package/dist/cli/src/app/core/findings/boot-single.js +76 -0
  30. package/dist/cli/src/app/core/findings/caching.js +1 -1
  31. package/dist/cli/src/app/core/findings/dupes.js +65 -0
  32. package/dist/cli/src/app/core/findings/effort.js +2 -0
  33. package/dist/cli/src/app/core/findings/finding-html.js +14 -1
  34. package/dist/cli/src/app/core/findings/finding-text.js +104 -31
  35. package/dist/cli/src/app/core/findings/finding.types.js +1 -0
  36. package/dist/cli/src/app/core/findings/findings.js +22 -38
  37. package/dist/cli/src/app/core/findings/graph.js +4 -4
  38. package/dist/cli/src/app/core/findings/scan.js +13 -3
  39. package/dist/cli/src/app/core/findings/shipped.js +3 -5
  40. package/dist/cli/src/app/core/format/format.utils.js +16 -9
  41. package/dist/cli/src/app/core/i18n/en.js +108 -48
  42. package/dist/cli/src/app/core/i18n/es.js +114 -50
  43. package/dist/cli/src/app/core/intake/bundle-graph.js +6 -5
  44. package/dist/cli/src/app/core/intake/dist-files.js +5 -2
  45. package/dist/cli/src/app/core/intake/embedded.js +46 -0
  46. package/dist/cli/src/app/core/intake/index-html.js +66 -16
  47. package/dist/cli/src/app/core/project/budget-advice.js +14 -10
  48. package/dist/cli/src/app/core/project/project-context.js +74 -16
  49. package/dist/cli/src/app/core/scan/scan.js +59 -21
  50. package/dist/cli/src/app/core/scan/secrets.js +0 -0
  51. package/dist/cli/src/app/core/situation/situation.js +3 -4
  52. package/dist/cli/src/app/state/report-messages.utils.js +1 -4
  53. package/loadline.html +22 -24
  54. package/package.json +60 -30
@@ -12,6 +12,7 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.summaryText = void 0;
14
14
  const actions_1 = require("../findings/actions");
15
+ const finding_plain_1 = require("../findings/finding-plain");
15
16
  const format_utils_1 = require("../format/format.utils");
16
17
  const WORDS = {
17
18
  en: {
@@ -22,7 +23,8 @@ const WORDS = {
22
23
  signals: 'Signals',
23
24
  actions: 'What to fix first',
24
25
  saving: 'All of it is worth',
25
- none: 'nothing that can be measured',
26
+ whatIf: 'What if it were deferred',
27
+ without: (target, saved, after) => ` without ${target}: ${saved} off the first load, which would then weigh ${after}`,
26
28
  tail: (unit) => `— Loadline, figures ${unit}`,
27
29
  },
28
30
  es: {
@@ -31,9 +33,10 @@ const WORDS = {
31
33
  screens: 'Pantallas',
32
34
  worst: 'Pantalla más pesada',
33
35
  signals: 'Señales',
34
- actions: 'Qué arreglar primero',
36
+ actions: 'Qué arreglo primero',
35
37
  saving: 'Todo junto vale',
36
- none: 'nada que se pueda medir',
38
+ whatIf: 'Y si se difiriera',
39
+ without: (target, saved, after) => ` sin ${target}: ${saved} menos en la primera carga, que pasaría a pesar ${after}`,
37
40
  tail: (unit) => `— Loadline, cifras ${unit}`,
38
41
  },
39
42
  };
@@ -46,7 +49,10 @@ const summaryText = (input) => {
46
49
  const { analysis, comparison } = input;
47
50
  const worst = analysis.screens[0];
48
51
  const problems = input.findings.filter(finding => finding.severity === 'high' || finding.severity === 'mid');
52
+ const scale = (0, actions_1.unitScale)(analysis);
49
53
  const total = (0, actions_1.totalSaving)(analysis, input.findings);
54
+ const actions = (0, actions_1.rankActions)(input.findings).slice(0, 3);
55
+ const whatIf = input.whatIf ?? [];
50
56
  const bootLine = comparison
51
57
  ? `${(0, format_utils_1.formatBytes)(analysis.bootBytes)} (${(0, format_utils_1.formatDelta)(comparison.boot.diff)} vs ${comparison.baselineName})`
52
58
  : (0, format_utils_1.formatBytes)(analysis.bootBytes);
@@ -54,17 +60,29 @@ const summaryText = (input) => {
54
60
  `Loadline · ${input.name}`,
55
61
  '',
56
62
  `${words.boot}: ${bootLine}`,
63
+ ...(input.since ? [input.since] : []),
57
64
  ...(input.firstTrip === null ? [] : [`${words.trip}: ${(0, format_utils_1.formatBytes)(input.firstTrip)}`]),
58
65
  `${words.screens}: ${analysis.screens.length}`,
59
66
  ...(worst ? [`${words.worst}: ${worst.label} — ${(0, format_utils_1.formatBytes)(worst.total)}`] : []),
60
67
  `${words.signals}: ${problems.length}`,
68
+ ...(actions.length > 0
69
+ ? [
70
+ '',
71
+ `${words.actions}:`,
72
+ ...actions.map((action, index) => ` ${index + 1}. ${(0, finding_plain_1.plainText)(action.finding.title)}${action.saving > 0 ? ` — ${(0, actions_1.formatSaving)(action.saving, scale)}` : ''}`),
73
+ ]
74
+ : []),
75
+ // Only when there is something to say. "All of it is worth: nothing that can be measured"
76
+ // was a line in every paste that carried no information at all.
77
+ ...(total.counted > 0 && total.bytes > 0 ? ['', `${words.saving}: ${(0, actions_1.formatSaving)(total.bytes, scale)}`] : []),
78
+ ...(whatIf.length > 0
79
+ ? [
80
+ '',
81
+ `${words.whatIf}:`,
82
+ ...whatIf.map(result => words.without(result.target, (0, actions_1.formatSaving)(result.saved, scale), (0, actions_1.formatRemaining)(analysis, result.saved, result.after))),
83
+ ]
84
+ : []),
61
85
  '',
62
- `${words.actions}:`,
63
- ...(0, actions_1.rankActions)(input.findings)
64
- .slice(0, 3)
65
- .map((action, index) => ` ${index + 1}. ${action.finding.title}${action.saving > 0 ? ` — ${(0, format_utils_1.formatBytes)(action.saving)}` : ''}`),
66
- '',
67
- `${words.saving}: ${total.counted > 0 ? (0, format_utils_1.formatBytes)(total.bytes) : words.none}`,
68
86
  words.tail(input.unit),
69
87
  ];
70
88
  return `${lines.join('\n')}\n`;
@@ -12,7 +12,8 @@
12
12
  * what removing both gives. It is one walk of the graph with every named file taken out at once.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.rankActions = exports.totalSaving = void 0;
15
+ exports.rankActions = exports.savingInUnit = exports.savingWords = exports.formatRemaining = exports.remainingInUnit = exports.formatSaving = exports.inUnit = exports.unitScale = exports.totalSaving = void 0;
16
+ const format_utils_1 = require("../format/format.utils");
16
17
  const effort_1 = require("./effort");
17
18
  /**
18
19
  * Everything the signals are worth together.
@@ -38,12 +39,67 @@ const totalSaving = (analysis, findings) => {
38
39
  return { bytes, before: insights.bootTotal, after: Math.max(0, insights.bootTotal - bytes), counted };
39
40
  };
40
41
  exports.totalSaving = totalSaving;
42
+ const unitScale = (analysis) => {
43
+ const estimated = analysis.bootRawBytes > 0 && analysis.bootBytes !== analysis.bootRawBytes;
44
+ return { ratio: estimated ? analysis.bootBytes / analysis.bootRawBytes : 1, estimated };
45
+ };
46
+ exports.unitScale = unitScale;
47
+ /** Raw bytes in the report's unit. */
48
+ const inUnit = (bytes, scale) => Math.round(bytes * scale.ratio);
49
+ exports.inUnit = inUnit;
50
+ /** A saving as it is printed: `≈93 kB` when it is an estimate, `302 kB` when it is not. Zero is exact. */
51
+ const formatSaving = (bytes, scale) => `${scale.estimated && bytes > 0 ? '≈' : ''}${(0, format_utils_1.formatBytes)((0, exports.inUnit)(bytes, scale))}`;
52
+ exports.formatSaving = formatSaving;
53
+ /**
54
+ * The first load a saving leaves, in the report's unit. Converted, it comes off the bootstrap the
55
+ * report heads with — not off the raw walk, which is a different figure in a different unit.
56
+ */
57
+ const remainingInUnit = (analysis, saved, rawAfter) => {
58
+ const scale = (0, exports.unitScale)(analysis);
59
+ return scale.estimated ? Math.max(0, analysis.bootBytes - (0, exports.inUnit)(saved, scale)) : rawAfter;
60
+ };
61
+ exports.remainingInUnit = remainingInUnit;
62
+ /** That first load as it is printed, with `≈` when it is an estimate. */
63
+ const formatRemaining = (analysis, saved, rawAfter) => `${(0, exports.unitScale)(analysis).estimated ? '≈' : ''}${(0, format_utils_1.formatBytes)((0, exports.remainingInUnit)(analysis, saved, rawAfter))}`;
64
+ exports.formatRemaining = formatRemaining;
65
+ /**
66
+ * The figures of "fixing all of it would take X off, leaving it at about Y", as text. `after`
67
+ * carries no `≈`: the sentence it goes into already says "about".
68
+ */
69
+ const savingWords = (analysis, total) => {
70
+ const scale = (0, exports.unitScale)(analysis);
71
+ return {
72
+ saving: (0, exports.formatSaving)(total.bytes, scale),
73
+ after: (0, format_utils_1.formatBytes)((0, exports.remainingInUnit)(analysis, total.bytes, total.after)),
74
+ estimated: scale.estimated,
75
+ };
76
+ };
77
+ exports.savingWords = savingWords;
78
+ /** What all of it is worth, in the report's unit: the saving and the first load it leaves. */
79
+ const savingInUnit = (analysis, total) => {
80
+ const scale = (0, exports.unitScale)(analysis);
81
+ return {
82
+ bytes: (0, exports.inUnit)(total.bytes, scale),
83
+ after: (0, exports.remainingInUnit)(analysis, total.bytes, total.after),
84
+ estimated: scale.estimated,
85
+ };
86
+ };
87
+ exports.savingInUnit = savingInUnit;
88
+ /** Most severe first. `ok` never reaches the list: a verdict that all is well is not a task. */
89
+ const SEVERITY_RANK = { high: 0, mid: 1, info: 2, ok: 3 };
41
90
  /**
42
91
  * The signals in the order somebody would do them.
43
92
  *
93
+ * **Severity first, then bytes per unit of effort.** Sorting by score alone put twelve medium and
94
+ * informative signals ahead of a high one that names no saving in kilobytes — a key leaked into the
95
+ * bundle saves nothing and is still the first thing anybody should touch. The score orders within a
96
+ * severity, which is where comparing kilobytes against effort makes sense.
97
+ *
44
98
  * Only what can be acted on: a signal whose effort is `none` is context — a verdict, a note about
45
99
  * the report itself, a growth against the baseline — and putting "the bootstrap has grown" on a
46
- * list of things to do would be a category mistake.
100
+ * list of things to do would be a category mistake. **A high one is the exception**: whatever its
101
+ * effort, leaving it out of "what to fix first" is how the summary came to list three medium
102
+ * signals and skip the one that mattered.
47
103
  */
48
104
  const rankActions = (findings) => findings
49
105
  .map((finding) => {
@@ -52,8 +108,9 @@ const rankActions = (findings) => findings
52
108
  const weight = effort_1.EFFORT_WEIGHT[effort];
53
109
  return { finding, saving, effort, score: weight > 0 ? saving / weight : 0 };
54
110
  })
55
- .filter(action => action.effort !== 'none')
56
- .toSorted((a, b) => b.score - a.score ||
57
- // With nothing to weigh them by, the severity the signal already carries decides.
58
- Number(b.finding.severity === 'high') - Number(a.finding.severity === 'high'));
111
+ .filter(action => action.effort !== 'none' || action.finding.severity === 'high')
112
+ .filter(action => action.finding.severity !== 'ok')
113
+ .toSorted((a, b) => SEVERITY_RANK[a.finding.severity] - SEVERITY_RANK[b.finding.severity] ||
114
+ b.score - a.score ||
115
+ b.saving - a.saving);
59
116
  exports.rankActions = rankActions;
@@ -16,7 +16,15 @@ const format_utils_1 = require("../format/format.utils");
16
16
  const finding_html_1 = require("./finding-html");
17
17
  const finding_text_1 = require("./finding-text");
18
18
  const named = (items) => items.map(item => (0, finding_html_1.mono)(item)).join(', ');
19
- const buildAssetFindings = (assets, lang, c) => {
19
+ /**
20
+ * @param repoPaths where in the repository each unreferenced file comes from, when `angular.json`
21
+ * copies it from an assets folder: build-folder path → repository path. Those are
22
+ * not leftovers of an old deploy — Angular empties the output before every build
23
+ * — and "clean the folder before building" is advice that changes nothing for them.
24
+ * @param verified whether those paths were checked on disk (the command) or only read off
25
+ * `angular.json` (the page).
26
+ */
27
+ const buildAssetFindings = (assets, lang, c, repoPaths = null, verified = false) => {
20
28
  const text = finding_text_1.TEXT[lang];
21
29
  const findings = [];
22
30
  // 1 · Fonts. The one place where "you are shipping the same face twice" is a fact rather than
@@ -36,7 +44,7 @@ const buildAssetFindings = (assets, lang, c) => {
36
44
  superseded: named(superseded),
37
45
  preloaded: named(fonts.flatMap(family => family.preloaded)),
38
46
  list: fonts
39
- .map(family => `${(0, finding_html_1.mono)(family.name)} — ${family.files.length} files, ${(0, format_utils_1.formatBytes)(family.bytes)}, ${family.formats.join('/')}`)
47
+ .map(family => `${(0, finding_html_1.mono)(family.name)} — ${text.fileCount(family.files.length)}, ${(0, format_utils_1.formatBytes)(family.bytes)}, ${family.formats.join('/')}`)
40
48
  .join(' · '),
41
49
  }),
42
50
  });
@@ -56,7 +64,7 @@ const buildAssetFindings = (assets, lang, c) => {
56
64
  outdated: outdated.length,
57
65
  outdatedList: named(outdated.map(file => `${file.name} → .${file.modernNeighbour}`)),
58
66
  list: media
59
- .map(file => `${(0, finding_html_1.mono)(file.name)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? ', in the page' : ''})`)
67
+ .map(file => `${(0, finding_html_1.mono)(file.name)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? `, ${text.inPage}` : ''})`)
60
68
  .join(' · '),
61
69
  }),
62
70
  });
@@ -72,7 +80,9 @@ const buildAssetFindings = (assets, lang, c) => {
72
80
  ...text.duplicateAssets({
73
81
  count: duplicates.length,
74
82
  size: (0, format_utils_1.formatBytes)(duplicates.reduce((sum, entry) => sum + entry.wasted, 0)),
75
- list: duplicates.map(entry => `${named(entry.names)} (${(0, format_utils_1.formatBytes)(entry.bytes)} each)`).join(' · '),
83
+ list: duplicates
84
+ .map(entry => `${named(entry.names)} (${(0, format_utils_1.formatBytes)(entry.bytes)} ${text.each})`)
85
+ .join(' · '),
76
86
  }),
77
87
  });
78
88
  }
@@ -106,7 +116,22 @@ const buildAssetFindings = (assets, lang, c) => {
106
116
  ...text.unreferencedAssets({
107
117
  count: orphans.length,
108
118
  size: (0, format_utils_1.formatBytes)(orphanBytes),
109
- list: orphans.map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)})`).join(' · '),
119
+ list: orphans
120
+ .map(file => {
121
+ const repo = repoPaths?.get(file.path);
122
+ return `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${repo ? ` ← ${(0, finding_html_1.mono)(repo)}` : ''})`;
123
+ })
124
+ .join(' · '),
125
+ fromRepo: orphans.filter(file => repoPaths?.has(file.path)).length,
126
+ folders: [
127
+ ...new Set(orphans
128
+ .map(file => repoPaths?.get(file.path)?.split('/').slice(0, -1).join('/') ?? null)
129
+ .filter((folder) => !!folder)),
130
+ ]
131
+ .slice(0, 3)
132
+ .map(folder => (0, finding_html_1.mono)(`${folder}/`))
133
+ .join(', '),
134
+ verified,
110
135
  }),
111
136
  });
112
137
  }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * A package in the bootstrap that one file of the project imports, and that file is code everybody
4
+ * runs rather than a screen.
5
+ *
6
+ * `bootLazy` covers the case where that one importer is a lazy screen. This is the other one, and
7
+ * the one that came up in the field: Teams, Firebase and ua-parser-js each in the bootstrap of one
8
+ * application, each imported by a single service, and the only way to see it was to read the list
9
+ * of importers row by row. One importer is an address — one place to decide whether the package is
10
+ * needed before the first paint or only when something happens — and that is the whole signal.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.buildBootSingleFindings = void 0;
14
+ const format_utils_1 = require("../format/format.utils");
15
+ const finding_html_1 = require("./finding-html");
16
+ const finding_text_1 = require("./finding-text");
17
+ /**
18
+ * Packages a bootstrap needs by definition: the framework, its runtime and the helpers every file
19
+ * compiles against. One file importing `@angular/platform-browser` is `main.ts` starting the app,
20
+ * not a candidate for deferring.
21
+ */
22
+ const FRAMEWORK = /^(?:@angular\/|zone\.js$|tslib$|rxjs$|react$|react-dom$|vue$|@vue\/|svelte$|preact$|solid-js$)/;
23
+ /**
24
+ * The files the application starts from, and the root component it renders first. Whatever they
25
+ * import is on the path to the first paint by construction: an icon library the shell imports is
26
+ * drawn before anything else, and calling it a candidate for deferring was the first false positive
27
+ * this signal produced, on the example build.
28
+ */
29
+ const ENTRY_FILE = /(?:^|\/)(?:(?:main|polyfills|index)(?:\.[\w-]+)?|app(?:\.component)?)\.[cm]?[jt]sx?$/;
30
+ /**
31
+ * @param skip packages another signal already names, so the same package is not two cards.
32
+ */
33
+ const buildBootSingleFindings = (analysis, lang, c, skip) => {
34
+ const insights = analysis.insights();
35
+ const filesOf = (bucket) => insights.filesByBucket.get(bucket) ?? [];
36
+ const screens = new Set(analysis.screens.map(screen => screen.source));
37
+ const single = analysis.bootBuckets
38
+ .filter(bucket => !bucket.isProjectCode && bucket.bytes >= c.bootPackageMinBytes)
39
+ .filter(bucket => !skip.has(bucket.name) && !FRAMEWORK.test(bucket.name))
40
+ .map(bucket => ({ bucket, importers: [...(analysis.packageImporters.get(bucket.name) ?? [])] }))
41
+ .filter(({ importers }) => {
42
+ const [only] = importers;
43
+ return importers.length === 1 && !!only && !screens.has(only) && !ENTRY_FILE.test(only);
44
+ })
45
+ .map(({ bucket, importers }) => ({
46
+ name: bucket.name,
47
+ bytes: bucket.bytes,
48
+ importer: importers[0] ?? '',
49
+ saving: insights.exclusive.get(bucket.name) ?? 0,
50
+ }))
51
+ .toSorted((a, b) => b.saving - a.saving || b.bytes - a.bytes);
52
+ const first = single[0];
53
+ if (!first) {
54
+ return [];
55
+ }
56
+ const files = single.flatMap(entry => filesOf(entry.name));
57
+ return [
58
+ {
59
+ severity: 'mid',
60
+ target: { tab: 'boot', key: first.name },
61
+ kind: 'bootSingle',
62
+ saving: insights.exclusiveOf(files),
63
+ sources: files,
64
+ ...finding_text_1.TEXT[lang].bootSingle({
65
+ count: single.length,
66
+ pkg: first.name,
67
+ importer: (0, format_utils_1.baseName)(first.importer),
68
+ size: (0, format_utils_1.formatBytes)(single.reduce((sum, entry) => sum + entry.bytes, 0)),
69
+ list: single
70
+ .map(entry => `${(0, finding_html_1.mono)(entry.name)} (${(0, format_utils_1.formatBytes)(entry.bytes)}) ← ${(0, finding_html_1.mono)(entry.importer)}`)
71
+ .join(' · '),
72
+ }),
73
+ },
74
+ ];
75
+ };
76
+ exports.buildBootSingleFindings = buildBootSingleFindings;
@@ -155,7 +155,7 @@ const buildCachingFindings = (caching, lang, c, situation = situation_1.EMPTY_SI
155
155
  .map(file => (0, finding_html_1.mono)(file.path))
156
156
  .join(', '),
157
157
  list: unhashable
158
- .map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? ', in the page' : ''})`)
158
+ .map(file => `${(0, finding_html_1.mono)(file.path)} (${(0, format_utils_1.formatBytes)(file.bytes)}${file.inPage ? `, ${text.inPage}` : ''})`)
159
159
  .join(' · '),
160
160
  }),
161
161
  });
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * The same package at two versions, each copy followed to whatever brings it in.
4
+ *
5
+ * Knowing there are two says nothing about what to do: the fix depends on where each one comes
6
+ * from. A copy your own code imports is aligned in `package.json`; one a dependency brings is
7
+ * forced with an override; and one a dependency **pins** to an exact version, a major away from the
8
+ * other, cannot be moved from the project at all without changing that dependency — which is the
9
+ * case the report used to answer with "force the resolution" and nothing else.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.buildDupesFindings = void 0;
13
+ const pins_1 = require("../deps/pins");
14
+ const format_utils_1 = require("../format/format.utils");
15
+ const finding_html_1 = require("./finding-html");
16
+ const finding_text_1 = require("./finding-text");
17
+ const buildDupesFindings = (analysis, lang, declared) => {
18
+ const text = finding_text_1.TEXT[lang];
19
+ const firstDupe = analysis.duplicates[0];
20
+ if (!firstDupe) {
21
+ return [];
22
+ }
23
+ const pins = (0, pins_1.pinsOf)(analysis.duplicates, declared);
24
+ const allPins = [...pins.values()].flat();
25
+ const parents = (apart) => {
26
+ const names = [...new Set(allPins.filter(pin => pin.majorApart === apart).map(pin => pin.parent))];
27
+ return names.length > 0 ? names.map(name => (0, finding_html_1.mono)(name)).join(', ') : null;
28
+ };
29
+ const list = analysis.duplicates
30
+ .map(dupe => {
31
+ const copies = dupe.copies
32
+ .map(copy => {
33
+ const pin = (pins.get(dupe.name) ?? []).find(one => copy.viaPackages.includes(one.parent));
34
+ return text.dupeCopy({
35
+ version: copy.version,
36
+ under: copy.under,
37
+ size: (0, format_utils_1.formatBytes)(copy.bytes),
38
+ zone: text.dupeZone[copy.zone],
39
+ chain: copy.chain ? (0, finding_html_1.chainHtml)((0, format_utils_1.chainSteps)(copy.chain)) : null,
40
+ own: copy.importers.length > 0 ? copy.importers.map(file => (0, finding_html_1.mono)(file)).join(', ') : null,
41
+ via: copy.viaPackages.length > 0 ? copy.viaPackages.map(pkg => (0, finding_html_1.mono)(pkg)).join(', ') : null,
42
+ pinned: pin ? { parent: (0, finding_html_1.mono)(pin.parent), range: (0, finding_html_1.mono)(pin.range) } : null,
43
+ });
44
+ })
45
+ .join(' ');
46
+ return `<strong>${dupe.name}</strong> — ${copies}`;
47
+ })
48
+ .join(' ');
49
+ return [
50
+ {
51
+ severity: 'mid',
52
+ target: { tab: 'search', key: firstDupe.name },
53
+ kind: 'dupes',
54
+ ...text.dupes({
55
+ count: analysis.duplicates.length,
56
+ list,
57
+ viaDependency: analysis.duplicates.some(dupe => dupe.copies.some(copy => copy.importers.length === 0)),
58
+ inBoot: analysis.duplicates.some(dupe => dupe.inBoot),
59
+ pinnedApart: parents(true),
60
+ pinnedSame: parents(false),
61
+ }),
62
+ },
63
+ ];
64
+ };
65
+ exports.buildDupesFindings = buildDupesFindings;
@@ -21,6 +21,8 @@ exports.EFFORT_WEIGHT = { config: 1, import: 2, refactor: 5, none: 0 };
21
21
  exports.EFFORT = {
22
22
  // One import moved, or one import narrowed.
23
23
  bootLazy: 'import',
24
+ // One import turned into an `await import()` where the package is used.
25
+ bootSingle: 'import',
24
26
  ownInBoot: 'refactor',
25
27
  mixedImport: 'import',
26
28
  ownBarrel: 'import',
@@ -4,10 +4,23 @@
4
4
  * name or a version number set apart from the sentence is what makes it findable at a glance.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.chainHtml = exports.mono = void 0;
7
+ exports.fewNamed = exports.chainHtml = exports.mono = void 0;
8
8
  /** A name as code: a file, a package, a configuration key. */
9
9
  const mono = (text) => `<span class="mono">${text}</span>`;
10
10
  exports.mono = mono;
11
11
  /** An import chain as HTML: each step in monospace, joined by a separator. */
12
12
  const chainHtml = (steps) => steps.map(step => (0, exports.mono)(step)).join(' › ');
13
13
  exports.chainHtml = chainHtml;
14
+ /**
15
+ * A list of names cut to the first few, with how many were left out. For the lists that grow with
16
+ * the project rather than with the problem: the hundred files importing `@angular/core` pasted into
17
+ * one paragraph said nothing the first five did not.
18
+ */
19
+ const fewNamed = (items, more, max = 5) => {
20
+ const shown = items
21
+ .slice(0, max)
22
+ .map(item => (0, exports.mono)(item))
23
+ .join(', ');
24
+ return items.length > max ? `${shown} ${more(items.length - max)}` : shown;
25
+ };
26
+ exports.fewNamed = fewNamed;