@bymaksym/loadline 0.1.0 → 1.1.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 (115) hide show
  1. package/README.md +272 -45
  2. package/dist/cli/cli/args.js +97 -116
  3. package/dist/cli/cli/gates.js +80 -14
  4. package/dist/cli/cli/main.js +275 -31
  5. package/dist/cli/cli/memory.js +114 -0
  6. package/dist/cli/cli/read/declared.js +52 -0
  7. package/dist/cli/cli/read/locate.js +214 -0
  8. package/dist/cli/cli/{read-build.js → read/read-build.js} +156 -87
  9. package/dist/cli/cli/read/read-config.js +120 -0
  10. package/dist/cli/cli/render/html-report.js +111 -0
  11. package/dist/cli/cli/render/render-agent.js +114 -0
  12. package/dist/cli/cli/render/render-asked.js +104 -0
  13. package/dist/cli/cli/render/render-badge.js +140 -0
  14. package/dist/cli/cli/{render-json.js → render/render-json.js} +26 -10
  15. package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +6 -6
  16. package/dist/cli/cli/{render-pr.js → render/render-pr.js} +37 -15
  17. package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +11 -6
  18. package/dist/cli/cli/{render-text.js → render/render-text.js} +169 -127
  19. package/dist/cli/cli/render/terminal.js +55 -0
  20. package/dist/cli/cli/report.js +76 -29
  21. package/dist/cli/cli/self-check.js +19 -23
  22. package/dist/cli/cli/since-last.js +45 -0
  23. package/dist/cli/cli/text/text-errors.js +124 -0
  24. package/dist/cli/cli/text/text.js +343 -0
  25. package/dist/cli/cli/text/usage.js +240 -0
  26. package/dist/cli/src/app/core/analysis/analysis.js +68 -24
  27. package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +10 -3
  28. package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
  29. package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
  30. package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
  31. package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
  32. package/dist/cli/src/app/core/analysis/invariant.js +1 -1
  33. package/dist/cli/src/app/core/analysis/metafile.types.js +21 -7
  34. package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
  35. package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +87 -11
  36. package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
  37. package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
  38. package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
  39. package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +13 -7
  40. package/dist/cli/src/app/core/analysis/tool.js +83 -0
  41. package/dist/cli/src/app/core/assets/assets.js +137 -16
  42. package/dist/cli/src/app/core/baseline/baseline.js +0 -0
  43. package/dist/cli/src/app/core/{intake → build-text}/index-html.js +234 -29
  44. package/dist/cli/src/app/core/build-text/route-table.js +178 -0
  45. package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
  46. package/dist/cli/src/app/core/caching/caching.js +123 -45
  47. package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
  48. package/dist/cli/src/app/core/config/config-text.js +90 -0
  49. package/dist/cli/src/app/core/config/config-values.js +358 -0
  50. package/dist/cli/src/app/core/config/loadline-config.js +81 -16
  51. package/dist/cli/src/app/core/config/merge-config.js +98 -0
  52. package/dist/cli/src/app/core/deps/deps.js +141 -23
  53. package/dist/cli/src/app/core/deps/pins.js +63 -0
  54. package/dist/cli/src/app/core/export/summary.js +54 -12
  55. package/dist/cli/src/app/core/findings/actions.js +65 -6
  56. package/dist/cli/src/app/core/findings/bundle/boot-single.js +76 -0
  57. package/dist/cli/src/app/core/findings/bundle/dupes.js +68 -0
  58. package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +32 -20
  59. package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
  60. package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
  61. package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +30 -18
  62. package/dist/cli/src/app/core/findings/compose.js +6 -1
  63. package/dist/cli/src/app/core/findings/effort.js +4 -0
  64. package/dist/cli/src/app/core/findings/finding.types.js +2 -0
  65. package/dist/cli/src/app/core/findings/findings.js +68 -55
  66. package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +65 -16
  67. package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +17 -10
  68. package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
  69. package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +37 -13
  70. package/dist/cli/src/app/core/findings/kind-names.js +163 -0
  71. package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
  72. package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
  73. package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
  74. package/dist/cli/src/app/core/findings/text/causes.js +39 -0
  75. package/dist/cli/src/app/core/findings/text/finding-html.js +33 -0
  76. package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +307 -103
  77. package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
  78. package/dist/cli/src/app/core/format/format.utils.js +172 -18
  79. package/dist/cli/src/app/core/format/ownership.js +93 -0
  80. package/dist/cli/src/app/core/i18n/en.js +180 -61
  81. package/dist/cli/src/app/core/i18n/es.js +192 -68
  82. package/dist/cli/src/app/core/intake/bundle-graph.js +285 -46
  83. package/dist/cli/src/app/core/intake/dist-files.js +87 -16
  84. package/dist/cli/src/app/core/intake/embedded.js +56 -0
  85. package/dist/cli/src/app/core/intake/unreached.js +139 -0
  86. package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
  87. package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
  88. package/dist/cli/src/app/core/project/budget-advice.js +14 -10
  89. package/dist/cli/src/app/core/project/project-context.js +89 -19
  90. package/dist/cli/src/app/core/project/project-name.js +36 -0
  91. package/dist/cli/src/app/core/scan/scan.js +116 -39
  92. package/dist/cli/src/app/core/scan/secrets.js +0 -0
  93. package/dist/cli/src/app/core/situation/situation-text.js +23 -0
  94. package/dist/cli/src/app/core/situation/situation.js +9 -8
  95. package/dist/cli/src/app/core/timing/timing.js +5 -2
  96. package/dist/cli/src/app/core/whatif/defer.js +29 -4
  97. package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
  98. package/dist/cli/src/app/core/whatif/why.js +102 -0
  99. package/dist/cli/src/app/state/report-messages.utils.js +1 -4
  100. package/docs/CONFIG-REFERENCE.md +230 -0
  101. package/docs/CONFIG.md +511 -0
  102. package/docs/HOW-IT-WORKS.md +286 -25
  103. package/loadline.html +26 -24
  104. package/loadline.schema.json +1209 -0
  105. package/package.json +71 -35
  106. package/dist/cli/cli/text.js +0 -180
  107. package/dist/cli/src/app/core/findings/finding-html.js +0 -13
  108. /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
  109. /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
  110. /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
  111. /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
  112. /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
  113. /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
  114. /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
  115. /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
@@ -7,43 +7,58 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.buildReport = void 0;
9
9
  const analysis_1 = require("../src/app/core/analysis/analysis");
10
- const sourcemap_1 = require("../src/app/core/analysis/sourcemap");
10
+ const marks_1 = require("../src/app/core/analysis/screens/marks");
11
+ const sourcemap_1 = require("../src/app/core/analysis/sourcemap/sourcemap");
12
+ const assets_1 = require("../src/app/core/assets/assets");
11
13
  const baseline_1 = require("../src/app/core/baseline/baseline");
12
14
  const from_analysis_1 = require("../src/app/core/caching/from-analysis");
13
15
  const loadline_config_1 = require("../src/app/core/config/loadline-config");
14
16
  const criteria_1 = require("../src/app/core/criteria/criteria");
15
17
  const deps_1 = require("../src/app/core/deps/deps");
16
- const assets_1 = require("../src/app/core/findings/assets");
17
- const caching_1 = require("../src/app/core/findings/caching");
18
+ const actions_1 = require("../src/app/core/findings/actions");
19
+ const shipped_1 = require("../src/app/core/findings/bundle/shipped");
18
20
  const compose_1 = require("../src/app/core/findings/compose");
19
- const deps_2 = require("../src/app/core/findings/deps");
20
21
  const findings_1 = require("../src/app/core/findings/findings");
21
- const page_1 = require("../src/app/core/findings/page");
22
- const scan_1 = require("../src/app/core/findings/scan");
23
- const shipped_1 = require("../src/app/core/findings/shipped");
24
- const situation_1 = require("../src/app/core/findings/situation");
22
+ const assets_2 = require("../src/app/core/findings/folder/assets");
23
+ const caching_1 = require("../src/app/core/findings/folder/caching");
24
+ const page_1 = require("../src/app/core/findings/folder/page");
25
+ const scan_1 = require("../src/app/core/findings/folder/scan");
26
+ const deps_2 = require("../src/app/core/findings/supplied/deps");
27
+ const forbidden_1 = require("../src/app/core/findings/supplied/forbidden");
28
+ const situation_1 = require("../src/app/core/findings/supplied/situation");
25
29
  const format_utils_1 = require("../src/app/core/format/format.utils");
26
30
  const ui_1 = require("../src/app/core/i18n/ui");
31
+ const project_name_1 = require("../src/app/core/project/project-name");
27
32
  const scan_2 = require("../src/app/core/scan/scan");
28
33
  const situation_2 = require("../src/app/core/situation/situation");
29
34
  const defer_1 = require("../src/app/core/whatif/defer");
30
- const read_build_1 = require("./read-build");
35
+ const source_importers_1 = require("../src/app/core/whatif/source-importers");
36
+ const why_1 = require("../src/app/core/whatif/why");
37
+ const read_build_1 = require("./read/read-build");
31
38
  /**
32
39
  * Which figure the report is in. Brotli when the folder brought the `.br` files, gzip when it
33
40
  * brought the assets, raw otherwise. Asking for a unit the folder cannot give is an error rather
34
41
  * than a silent downgrade: a gate written for gzip and checked against raw bytes passes for a
35
42
  * reason that has nothing to do with the build.
36
43
  */
37
- const resolveMode = (input, asked) => {
44
+ /**
45
+ * The unit of the report: `--mode`, then the `mode` of `loadline.json`, then the best the folder
46
+ * allows. The file's is not a label: its thresholds are written in it, and read in another unit a
47
+ * `maxBoot` of 100 kB written in raw bytes passed a build of 110 kB raw because it was shown 43 kB
48
+ * of gzip.
49
+ */
50
+ const resolveMode = (input, typed) => {
38
51
  const best = input.brotli ? 'brotli' : input.gzip ? 'gzip' : 'raw';
52
+ const asked = typed ?? input.config?.mode ?? null;
39
53
  if (!asked) {
40
54
  return best;
41
55
  }
56
+ const by = (t) => (typed ? `--mode ${asked}` : t.modeInConfig(asked));
42
57
  if (asked === 'brotli' && !input.brotli) {
43
- throw new read_build_1.InputError('--mode brotli needs the .js.br files of the build in --dist.');
58
+ throw new read_build_1.InputError(t => t.needsBrotli(by(t)));
44
59
  }
45
60
  if (asked === 'gzip' && !input.gzip) {
46
- throw new read_build_1.InputError('--mode gzip needs the build folder in --dist.');
61
+ throw new read_build_1.InputError(t => t.needsDist(by(t)));
47
62
  }
48
63
  return asked;
49
64
  };
@@ -52,9 +67,8 @@ const resolveMode = (input, asked) => {
52
67
  *
53
68
  * That order is the one people expect and the one that makes the file useful: the committed file
54
69
  * is what the team agreed to, and a flag typed on a command line is somebody overriding it for one
55
- * run on purpose. The file's own `mode` is not checked against the report's, because a threshold
56
- * written in gzip and applied to raw bytes is a real mismatch and the report already has a signal
57
- * for that shape of mistake elsewhere; here it would only be a second place to look.
70
+ * run on purpose. The file's own `mode` is the report's unit unless `--mode` says otherwise (see
71
+ * `resolveMode`), so the thresholds in it are read in the unit they were written in.
58
72
  */
59
73
  const resolveCriteria = (mode, config, overrides) => ({
60
74
  ...criteria_1.RECOMMENDED[mode],
@@ -83,15 +97,19 @@ const comparisonOf = (input, shown, raw, mode, findings) => {
83
97
  const buildReport = (input, options) => {
84
98
  const mode = resolveMode(input, options.mode);
85
99
  const sizes = mode === 'brotli' ? input.brotli : mode === 'gzip' ? input.gzip : null;
86
- const exact = (0, sourcemap_1.resolveSplits)(input.splits, Object.keys(input.meta.inputs ?? {}));
100
+ const exact = (0, sourcemap_1.resolveSplits)(input.splits, Object.keys(input.meta.inputs));
87
101
  const lang = options.lang;
88
102
  const criteria = resolveCriteria(mode, input.config, input.criteria);
89
103
  // The language only decides the decimal separator, and it is set before anything is formatted.
90
104
  (0, format_utils_1.setNumberLang)(lang);
91
- const analysis = (0, analysis_1.analyze)(input.meta, sizes, exact, input.announced, null, criteria, input.parallel);
105
+ // What `build.screens` of `loadline.json` says is a screen or a piece of one: the page's buttons, written down.
106
+ const marks = (0, marks_1.configuredMarks)(input.config?.build?.screens, input.meta);
107
+ const analysis = (0, analysis_1.analyze)(input.meta, sizes, exact, input.announced, marks, criteria, input.parallel, input.routes);
92
108
  // The same build in raw bytes, for comparing against a raw baseline while showing compressed
93
109
  // figures. It is the shown analysis itself when nothing is compressed, so it costs nothing then.
94
- const raw = sizes ? (0, analysis_1.analyze)(input.meta, null, exact, input.announced, null, criteria, input.parallel) : analysis;
110
+ const raw = sizes
111
+ ? (0, analysis_1.analyze)(input.meta, null, exact, input.announced, marks, criteria, input.parallel, input.routes)
112
+ : analysis;
95
113
  // What the team answered about itself, out of the committed file. Unlike a measurement, this
96
114
  // half of the context does reach the terminal: it is the same for everybody who runs the
97
115
  // command, which is exactly why it lives in `loadline.json` rather than in a browser.
@@ -106,7 +124,7 @@ const buildReport = (input, options) => {
106
124
  const cssBytes = pageCss ? (mode === 'brotli' ? (pageCss.brotli ?? pageCss.gzip) : pageCss[mode]) : null;
107
125
  // What an update costs. It needs the baseline's file names, which only a snapshot carrying them
108
126
  // has; without one the delta is absent and the other two caching figures still come out.
109
- const caching = (0, from_analysis_1.cachingOf)(analysis, input.baseline, input.assets ?? null, new Set(input.announced), input.hrefs);
127
+ const caching = (0, from_analysis_1.cachingOf)(analysis, input.baseline, input.assets ?? null, new Set(input.announced), input.hrefs, sizes);
110
128
  // What the text of the build says, and what the two dependency files say about what ships. Both
111
129
  // are empty rather than absent when nothing was given: `null` inside them says which.
112
130
  const scan = (input.texts?.size ?? 0) > 0
@@ -122,7 +140,7 @@ const buildReport = (input, options) => {
122
140
  advisories: input.advisories ?? null,
123
141
  modules: analysis.modules,
124
142
  boot: new Set(analysis.bootChunks),
125
- direct: new Set(input.context.pkg?.dependencies),
143
+ direct: new Set(input.context.pkg?.dependencies ?? input.lockDirect),
126
144
  });
127
145
  // The signals of this build alone, built once. They are what the comparison needs to say which
128
146
  // of them are new, what the snapshot carries so the *next* run can ask the same question, and
@@ -130,27 +148,43 @@ const buildReport = (input, options) => {
130
148
  // drifted: the one the snapshot kept was missing caching, scan and deps, so a `devLeftovers`
131
149
  // somebody had actually fixed could never show as gone, and a page export — which does carry
132
150
  // them — read as three signals fixed the moment the terminal compared against it.
133
- const base = (0, findings_1.buildFindings)(analysis, lang, mode, criteria, situation);
134
- const fromContext = (0, findings_1.buildContextFindings)(input.context, analysis, lang, criteria);
151
+ const base = (0, findings_1.buildFindings)(analysis, lang, mode, criteria, situation, input.declared ?? null);
152
+ // What `loadline.json` forbids goes with the project's own files: it is the team's rule, read
153
+ // from the repository, like a budget in `angular.json`.
154
+ const fromContext = [
155
+ ...(0, findings_1.buildContextFindings)(input.context, analysis, lang, criteria),
156
+ ...(0, forbidden_1.buildForbiddenFindings)(analysis, input.config?.forbidden, lang),
157
+ ];
135
158
  const fromBuild = [
136
159
  ...(0, shipped_1.buildFolderFindings)({
137
160
  sourceMaps: input.splits?.size ?? 0,
138
161
  derived: !!input.graph,
139
162
  screens: analysis.screens.map(s => s.label),
140
163
  drift: analysis.splitDrift,
164
+ tool: analysis.tool,
141
165
  }, lang),
142
- ...(input.assets ? (0, assets_1.buildAssetFindings)(input.assets, lang, criteria) : []),
166
+ ...(input.assets ? (0, assets_2.buildAssetFindings)(input.assets, lang, criteria, input.assetSources ?? null, true) : []),
143
167
  ...(0, page_1.buildPageFindings)(input.pageOrigins ?? null, lang),
144
- ...(0, caching_1.buildCachingFindings)(caching, lang, criteria, situation),
145
- ...(scan ? (0, scan_1.buildScanFindings)(scan, lang, criteria) : []),
146
- ...(0, deps_2.buildDepsFindings)(deps, lang, criteria),
168
+ ...(0, caching_1.buildCachingFindings)(caching, lang, criteria, situation, analysis.tool),
169
+ ...(scan ? (0, scan_1.buildScanFindings)(scan, lang, criteria, (0, actions_1.unitScale)(analysis), analysis.tool) : []),
170
+ ...(0, deps_2.buildDepsFindings)(deps, lang, criteria, (0, actions_1.unitScale)(analysis)),
147
171
  ];
148
172
  const own = [...base, ...fromContext, ...fromBuild];
149
173
  const { comparison, blocked } = comparisonOf(input, analysis, raw, mode, own);
174
+ // The bootstrap chunks the page does not name are part of the first trip too, weighed with the
175
+ // same figures the folder weighed the rest of it with.
176
+ // In the unit of the report, which `--mode` may have made something other than the best one.
177
+ const lateBoot = (analysis.startup?.discovered ?? []).map(chunk => sizes?.get((0, format_utils_1.baseName)(chunk)) ?? input.meta.outputs[chunk]?.bytes ?? 0);
178
+ const trip = input.firstTrips?.[mode] ?? input.assets?.firstTrip;
179
+ const assets = input.assets && trip ? { ...input.assets, firstTrip: (0, assets_1.withLateBoot)(trip, lateBoot) } : null;
150
180
  // This build as the next run's baseline. Written whether or not `--export` was asked for: it
151
181
  // costs a walk over lists that are already in memory, and having it here is what keeps the
152
182
  // exported file and the compared-against file the same shape by construction.
153
183
  const snapshot = (0, baseline_1.snapshotOf)(analysis, mode, input.statsName, new Date(), own);
184
+ // The last run, when it was in the same unit: a gzip figure against a raw one would read as a
185
+ // saving that never happened, which is the rule the explicit baseline follows too.
186
+ const last = input.lastRun ?? null;
187
+ const sinceLast = last?.mode === mode ? (0, baseline_1.compare)(snapshot, last) : null;
154
188
  const composed = (0, compose_1.composeFindings)({
155
189
  base,
156
190
  fromComparison: comparison ? (0, findings_1.buildComparisonFindings)(comparison, lang, criteria) : [],
@@ -173,12 +207,21 @@ const buildReport = (input, options) => {
173
207
  pageCssBytes: cssBytes,
174
208
  pageCssRawBytes: pageCss?.raw ?? null,
175
209
  pageCssFiles: pageCss?.files.length ?? 0,
176
- assets: input.assets ?? null,
210
+ assets,
177
211
  caching,
178
212
  scan,
179
213
  deps,
180
- whatIf: options.whatIf.map(name => (0, defer_1.simulateDefer)(analysis, name)),
181
- projectName: input.context.pkg?.name ?? input.context.angular?.project ?? null,
214
+ // A folder read alone carries no file-to-file imports: see `DeferResult.measurable`.
215
+ whatIf: options.whatIf.map(name => (0, defer_1.simulateDefer)(analysis, name, !input.graph)),
216
+ // A folder build says which chunk holds what and not who imports whom; the sources in its
217
+ // maps do, which is what lets `--why` answer for a Vite or Nuxt build at all.
218
+ why: options.why.map(name => (0, why_1.explainWhy)(analysis, name, !input.graph, input.graph ? pkg => (0, source_importers_1.importersInSources)(input.maps ?? [], pkg) : null)),
219
+ projectName: (0, project_name_1.projectNameOf)({
220
+ packageName: input.context.pkg?.name ?? input.packageName,
221
+ angularProject: input.context.angular?.project,
222
+ pageTitle: input.pageTitle,
223
+ folder: input.statsName,
224
+ }),
182
225
  mode,
183
226
  unit: units[mode],
184
227
  lang,
@@ -186,6 +229,10 @@ const buildReport = (input, options) => {
186
229
  analysis,
187
230
  comparison,
188
231
  comparisonBlocked: blocked,
232
+ baselineMode: input.baseline?.mode ?? null,
233
+ sinceLast,
234
+ sinceLastBranch: sinceLast ? (input.lastRunBranch ?? null) : null,
235
+ located: [],
189
236
  findings: kept,
190
237
  accepted,
191
238
  config: input.config ?? null,
@@ -12,13 +12,14 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.selfCheck = void 0;
14
14
  const invariant_1 = require("../src/app/core/analysis/invariant");
15
+ const text_errors_1 = require("./text/text-errors");
15
16
  const list = (chunks) => chunks.map(chunk => ` ${chunk}`).join('\n');
16
- const selfCheck = (meta, analysis, announced) => {
17
+ const selfCheck = (meta, analysis, announced, t = text_errors_1.ERROR_TEXT.en) => {
17
18
  if (!announced) {
18
19
  return {
19
20
  ok: false,
20
- report: 'Self-check needs the index.html of the build: it is the second, independent answer.\n' +
21
- 'Pass the build folder as the target, or add --dist pointing at it.',
21
+ ran: false,
22
+ report: t.selfNoPage,
22
23
  };
23
24
  }
24
25
  // What the analysis calls a screen's chunk, so a page that preloads its own route's chunks is
@@ -28,58 +29,53 @@ const selfCheck = (meta, analysis, announced) => {
28
29
  if (!check) {
29
30
  return {
30
31
  ok: false,
31
- report: 'Self-check could not run: the index.html of the build names no chunk of it.\n' +
32
- 'Either the page belongs to another build, or the output shape changed enough that\n' +
33
- 'nothing lines up — which is the thing this check is for.',
32
+ ran: false,
33
+ report: t.selfNoChunk,
34
34
  };
35
35
  }
36
36
  if ((0, invariant_1.isSameBoot)(check)) {
37
- const passed = `Self-check passed: the import graph and index.html agree on all ${check.agreed} bootstrap chunks.`;
37
+ const passed = t.selfPassed(check.agreed);
38
38
  if (check.onlyInPage.length > 0) {
39
39
  // Said, not swallowed: these are bytes of the first load that no figure of the report
40
40
  // accounts for, and knowing which they are is the difference between "fine" and "fine
41
41
  // as far as anything here can tell".
42
42
  return {
43
43
  ok: true,
44
+ ran: true,
44
45
  report: [
45
46
  passed,
46
47
  '',
47
- `It also announces ${check.onlyInPage.length} chunk(s) the import graph cannot place:`,
48
+ t.selfUnplaced(check.onlyInPage.length),
48
49
  list(check.onlyInPage),
49
- 'Usually a dynamic import whose path is built at run time — VitePress writes one per',
50
- 'page — which no reader of the files can follow. Too few to be the build changing shape.',
50
+ t.selfUnplacedWhy,
51
51
  ].join('\n'),
52
52
  };
53
53
  }
54
54
  if (check.preloadedRoutes.length === 0) {
55
- return { ok: true, report: passed };
55
+ return { ok: true, ran: true, report: passed };
56
56
  }
57
57
  // Said out loud rather than dropped: these chunks really are fetched with the first load of
58
58
  // this page, and a build that prerenders one page per route is a different kind of build.
59
59
  return {
60
60
  ok: true,
61
+ ran: true,
61
62
  report: [
62
63
  passed,
63
64
  '',
64
- `This page also announces ${check.preloadedRoutes.length} chunk(s) the graph attributes to a screen:`,
65
+ t.selfPreloaded(check.preloadedRoutes.length),
65
66
  list(check.preloadedRoutes),
66
- 'That is a build with one page per route — index.html is the home route, not a shell —',
67
- 'so those are preloaded route chunks and not part of what every screen pays.',
67
+ t.selfPreloadedWhy,
68
68
  ].join('\n'),
69
69
  };
70
70
  }
71
- const parts = [
72
- 'Self-check FAILED: the two ways of working out the bootstrap disagree.',
73
- '',
74
- `Agreed on ${check.agreed} chunk(s).`,
75
- ];
71
+ const parts = [t.selfFailed, '', t.selfAgreed(check.agreed)];
76
72
  if (check.onlyInGraph.length > 0) {
77
- parts.push('', 'Called bootstrap by the import graph, never reached from index.html:', list(check.onlyInGraph));
73
+ parts.push('', t.selfOnlyGraph, list(check.onlyInGraph));
78
74
  }
79
75
  if (check.onlyInPage.length > 0) {
80
- parts.push('', 'Reached from index.html, not called bootstrap by the import graph:', list(check.onlyInPage));
76
+ parts.push('', t.selfOnlyPage, list(check.onlyInPage));
81
77
  }
82
- parts.push('', 'One of the two readers is wrong about this build. Every per-screen figure is measured', 'against the bootstrap, so they are all suspect until this passes.');
83
- return { ok: false, report: parts.join('\n') };
78
+ parts.push('', t.selfSuspect);
79
+ return { ok: false, ran: true, report: parts.join('\n') };
84
80
  };
85
81
  exports.selfCheck = selfCheck;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * The line that answers "did that change help?": what moved since the last run of the same build,
4
+ * remembered in `node_modules/.cache/loadline` without anybody passing a `--baseline`.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.sinceLastLine = void 0;
8
+ const format_utils_1 = require("../src/app/core/format/format.utils");
9
+ const ui_1 = require("../src/app/core/i18n/ui");
10
+ const text_1 = require("./text/text");
11
+ /**
12
+ * What moved since the last run of this build, in one line: "bootstrap 156 kB → 129 kB (−27 kB)",
13
+ * then the screens that changed. `null` when there is nothing to compare against.
14
+ */
15
+ const sinceLastLine = (report) => {
16
+ const since = report.sinceLast;
17
+ if (!since) {
18
+ return null;
19
+ }
20
+ const text = text_1.CLI_TEXT[report.lang];
21
+ const strings = ui_1.UI[report.lang];
22
+ // What each screen adds on top of the bootstrap: a bootstrap that shrank moves every screen's
23
+ // total by the same amount, and listing that once per screen repeats the first figure.
24
+ const moved = [...since.screens.values()].filter(screen => screen.lazy.diff !== 0);
25
+ const parts = [
26
+ ...(since.boot.diff === 0
27
+ ? []
28
+ : [
29
+ `${strings.tabBoot.toLowerCase()} ${(0, format_utils_1.formatBytes)(since.boot.before)} → ${(0, format_utils_1.formatBytes)(since.boot.after)} (${(0, format_utils_1.formatDelta)(since.boot.diff)})`,
30
+ ]),
31
+ ...moved
32
+ .toSorted((a, b) => Math.abs(b.lazy.diff) - Math.abs(a.lazy.diff))
33
+ .slice(0, 3)
34
+ .map(screen => `${screen.label} ${(0, format_utils_1.formatDelta)(screen.lazy.diff)}`),
35
+ ...(moved.length > 3 ? [`+${moved.length - 3}`] : []),
36
+ ];
37
+ // Local time: it is the person's own last run, on their own machine.
38
+ const when = new Date(since.baselineDate);
39
+ const two = (value) => String(value).padStart(2, '0');
40
+ const date = Number.isNaN(when.getTime())
41
+ ? since.baselineDate
42
+ : `${when.getFullYear()}-${two(when.getMonth() + 1)}-${two(when.getDate())} ${two(when.getHours())}:${two(when.getMinutes())}`;
43
+ return text.sinceLast(date, parts.length > 0 ? parts.join(' · ') : text.lastRunUnchanged, report.sinceLastBranch);
44
+ };
45
+ exports.sinceLastLine = sinceLastLine;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * What the command says when it cannot do what it was asked, and what the self-check answers, in
4
+ * the language of the report.
5
+ *
6
+ * Apart from `text.ts` because none of it is a report: it is what is printed instead of one. Under
7
+ * `--lang es` these were the last lines left in English, and they are the ones read when something
8
+ * has already gone wrong. The flags and file names inside them stay as they are typed.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ERROR_TEXT = void 0;
12
+ /** "chunk" is the word in both languages. */
13
+ const chunks = (count) => (count === 1 ? '1 chunk' : `${count} chunks`);
14
+ const EN = {
15
+ needsValue: flag => `${flag} needs a value.`,
16
+ badMode: value => `--mode takes raw, gzip or brotli, not "${value}".`,
17
+ badLang: value => `--lang takes en or es, not "${value}".`,
18
+ badFormat: value => `--format takes text, json, markdown, pr-comment, sarif, summary, agent or badge, not "${value}".`,
19
+ badFailOn: value => `--fail-on takes high, mid or none, not "${value}".`,
20
+ badPct: value => `--max-growth-pct takes a number, not "${value}".`,
21
+ badSize: (flag, value) => `${flag} takes a size like 350kB, 1.5MB or a number of bytes, not "${value}".`,
22
+ bareSize: (flag, typed) => `${flag} ${typed} would be ${typed} bytes. Write ${typed}kB, or ${typed}B if bytes are meant.`,
23
+ unknownFlag: flag => `Unknown flag: ${flag}`,
24
+ missingTarget: 'Missing the stats.json or the build folder to analyse.',
25
+ unexpected: argument => `Unexpected argument: ${argument}`,
26
+ openNeedsHtml: '--open opens what --html writes: add --html <file>.',
27
+ seeHelp: 'Run loadline --help to see the options.',
28
+ distTwice: '--dist is the folder already being analysed; drop one of the two.',
29
+ growthNeedsBaseline: '--max-growth and --max-growth-pct need a --baseline to compare against.',
30
+ cannotWrite: (path, why) => `Could not write ${path}: ${why}`,
31
+ cannotRead: path => `Could not read ${path}.`,
32
+ notJson: path => `${path} is not valid JSON.`,
33
+ extendsNotFound: (name, from) => `${from} extends "${name}", and there is no such file, nor an installed package with a loadline.json. A package has to ship that file at its root, and list it in "exports" if it has them.`,
34
+ extendsCycle: chain => `loadline.json extends itself: ${chain.join(' → ')}.`,
35
+ noConfigToPrint: 'There is no loadline.json in this folder to print. Pass one with --config <file>.',
36
+ cannotReadFolder: folder => `Could not read the folder ${folder}.`,
37
+ noAssets: folder => `No .js or .css files under ${folder}. Is that the browser/ folder of the build?`,
38
+ notLock: path => `${path} is not a package-lock.json, a pnpm-lock.yaml or a yarn.lock.`,
39
+ notAudit: path => `${path} is not the JSON output of npm audit, pnpm audit or yarn audit.`,
40
+ notStats: path => `${path} is neither a stats.json nor an analysis exported from Loadline.`,
41
+ noProject: folder => `No angular.json, package.json or pipeline file under ${folder}.`,
42
+ projectNotBuilt: folder => `${folder} is a project, not a build, and no build was found inside it: no folder holding an index.html with ` +
43
+ 'scripts, nor a stats.json. Build it the way you deploy it (npm run build) and run this again, or pass the ' +
44
+ 'output folder itself: dist/, build/, www/ or wherever your tool writes it.',
45
+ notThresholds: path => `${path} has to be an object of thresholds.`,
46
+ needsBrotli: by => `${by} needs the .js.br files of the build in --dist.`,
47
+ needsDist: by => `${by} needs the build folder in --dist.`,
48
+ modeInConfig: mode => `"mode": "${mode}" in loadline.json`,
49
+ htmlMissing: 'loadline.html is missing from this install, so --html has nothing to write. Run: pnpm build',
50
+ selfNoPage: 'Self-check needs the index.html of the build: it is the second, independent answer.\n' +
51
+ 'Pass the build folder as the target, or add --dist pointing at it.',
52
+ selfNoChunk: 'Self-check could not run: the index.html of the build names no chunk of it.\n' +
53
+ 'Either the page belongs to another build, or the output shape changed enough that\n' +
54
+ 'nothing lines up — which is the thing this check is for.',
55
+ selfPassed: agreed => `Self-check passed: the import graph and index.html agree on all ${agreed} bootstrap chunks.`,
56
+ selfUnplaced: count => `It also announces ${chunks(count)} the import graph cannot place:`,
57
+ selfUnplacedWhy: 'Usually a dynamic import whose path is built at run time — VitePress writes one per\n' +
58
+ 'page — which no reader of the files can follow. Too few to be the build changing shape.',
59
+ selfPreloaded: count => `This page also announces ${chunks(count)} the graph attributes to a screen:`,
60
+ selfPreloadedWhy: 'That is a build with one page per route — index.html is the home route, not a shell —\n' +
61
+ 'so those are preloaded route chunks and not part of what every screen pays.',
62
+ selfFailed: 'Self-check FAILED: the two ways of working out the bootstrap disagree.',
63
+ selfAgreed: count => `Agreed on ${chunks(count)}.`,
64
+ selfOnlyGraph: 'Called bootstrap by the import graph, never reached from index.html:',
65
+ selfOnlyPage: 'Reached from index.html, not called bootstrap by the import graph:',
66
+ selfSuspect: 'One of the two readers is wrong about this build. Every per-screen figure is measured\n' +
67
+ 'against the bootstrap, so they are all suspect until this passes.',
68
+ };
69
+ const ES = {
70
+ needsValue: flag => `${flag} necesita un valor.`,
71
+ badMode: value => `--mode acepta raw, gzip o brotli, no "${value}".`,
72
+ badLang: value => `--lang acepta en o es, no "${value}".`,
73
+ badFormat: value => `--format acepta text, json, markdown, pr-comment, sarif, summary, agent o badge, no "${value}".`,
74
+ badFailOn: value => `--fail-on acepta high, mid o none, no "${value}".`,
75
+ badPct: value => `--max-growth-pct acepta un número, no "${value}".`,
76
+ badSize: (flag, value) => `${flag} acepta un tamaño como 350kB, 1.5MB o un número de bytes, no "${value}".`,
77
+ bareSize: (flag, typed) => `${flag} ${typed} serían ${typed} bytes. Escribe ${typed}kB, o ${typed}B si de verdad son bytes.`,
78
+ unknownFlag: flag => `Opción desconocida: ${flag}`,
79
+ missingTarget: 'Falta el stats.json o la carpeta del build que analizar.',
80
+ unexpected: argument => `Argumento de más: ${argument}`,
81
+ openNeedsHtml: '--open abre lo que escribe --html: añade --html <fichero>.',
82
+ seeHelp: 'Ejecuta loadline --help para ver las opciones.',
83
+ distTwice: '--dist es la carpeta que ya se está analizando; quita una de las dos.',
84
+ growthNeedsBaseline: '--max-growth y --max-growth-pct necesitan una --baseline con la que comparar.',
85
+ cannotWrite: (path, why) => `No se pudo escribir ${path}: ${why}`,
86
+ cannotRead: path => `No se pudo leer ${path}.`,
87
+ notJson: path => `${path} no es un JSON válido.`,
88
+ extendsNotFound: (name, from) => `${from} hereda de "${name}", y no hay ningún fichero así ni un paquete instalado con un loadline.json. Un paquete tiene que llevar ese fichero en su raíz, y nombrarlo en "exports" si los tiene.`,
89
+ extendsCycle: chain => `loadline.json hereda de sí mismo: ${chain.join(' → ')}.`,
90
+ noConfigToPrint: 'No hay ningún loadline.json en esta carpeta que mostrar. Pásale uno con --config <fichero>.',
91
+ cannotReadFolder: folder => `No se pudo leer la carpeta ${folder}.`,
92
+ noAssets: folder => `No hay ficheros .js ni .css en ${folder}. ¿Es la carpeta browser/ del build?`,
93
+ notLock: path => `${path} no es un package-lock.json, un pnpm-lock.yaml ni un yarn.lock.`,
94
+ notAudit: path => `${path} no es la salida JSON de npm audit, pnpm audit ni yarn audit.`,
95
+ notStats: path => `${path} no es un stats.json ni un análisis exportado de Loadline.`,
96
+ noProject: folder => `No hay angular.json, package.json ni fichero de pipeline en ${folder}.`,
97
+ projectNotBuilt: folder => `${folder} es un proyecto, no un build, y dentro no hay ningún build: ninguna carpeta con un index.html y ` +
98
+ 'scripts, ni un stats.json. Compílalo como lo despliegas (npm run build) y vuelve a lanzarlo, o pasa la ' +
99
+ 'carpeta de salida directamente: dist/, build/, www/ o donde la escriba tu herramienta.',
100
+ notThresholds: path => `${path} tiene que ser un objeto de umbrales.`,
101
+ needsBrotli: by => `${by} necesita los ficheros .js.br del build en --dist.`,
102
+ needsDist: by => `${by} necesita la carpeta del build en --dist.`,
103
+ modeInConfig: mode => `"mode": "${mode}" de loadline.json`,
104
+ htmlMissing: 'Falta loadline.html en esta instalación, así que --html no tiene nada que escribir. Ejecuta: pnpm build',
105
+ selfNoPage: 'El self-check necesita el index.html del build: es la segunda respuesta, la independiente.\n' +
106
+ 'Pasa la carpeta del build como objetivo, o añade --dist apuntando a ella.',
107
+ selfNoChunk: 'El self-check no pudo ejecutarse: el index.html del build no nombra ningún chunk suyo.\n' +
108
+ 'O la página es de otro build, o la forma de la salida ha cambiado tanto que nada\n' +
109
+ 'encaja, que es justo lo que esta comprobación vigila.',
110
+ selfPassed: agreed => `Self-check correcto: el grafo de imports y el index.html coinciden en los ${agreed} chunks del arranque.`,
111
+ selfUnplaced: count => `También anuncia ${chunks(count)} que el grafo de imports no sabe colocar:`,
112
+ selfUnplacedWhy: 'Suele ser un import dinámico cuya ruta se construye al ejecutarse (VitePress escribe uno por\n' +
113
+ 'página), que nadie que lea los ficheros puede seguir. Son muy pocos para que el build haya cambiado de forma.',
114
+ selfPreloaded: count => `Esta página también anuncia ${chunks(count)} que el grafo asigna a una pantalla:`,
115
+ selfPreloadedWhy: 'Es un build con una página por ruta (el index.html es la ruta de inicio, no un shell),\n' +
116
+ 'así que son chunks de ruta precargados y no forman parte de lo que paga cada pantalla.',
117
+ selfFailed: 'Self-check FALLIDO: las dos formas de calcular el arranque no coinciden.',
118
+ selfAgreed: count => `Coinciden en ${chunks(count)}.`,
119
+ selfOnlyGraph: 'El grafo de imports los llama arranque, pero el index.html nunca llega a ellos:',
120
+ selfOnlyPage: 'El index.html llega a ellos, pero el grafo de imports no los llama arranque:',
121
+ selfSuspect: 'Uno de los dos lectores se equivoca con este build. Cada cifra por pantalla se mide contra\n' +
122
+ 'el arranque, así que todas son dudosas hasta que esto pase.',
123
+ };
124
+ exports.ERROR_TEXT = { en: EN, es: ES };