@bymaksym/loadline 1.0.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 (112) hide show
  1. package/README.md +211 -43
  2. package/dist/cli/cli/args.js +79 -128
  3. package/dist/cli/cli/gates.js +80 -14
  4. package/dist/cli/cli/main.js +164 -33
  5. package/dist/cli/cli/memory.js +40 -4
  6. package/dist/cli/cli/{declared.js → read/declared.js} +1 -1
  7. package/dist/cli/cli/read/locate.js +214 -0
  8. package/dist/cli/cli/{read-build.js → read/read-build.js} +149 -84
  9. package/dist/cli/cli/read/read-config.js +120 -0
  10. package/dist/cli/cli/{html-report.js → render/html-report.js} +14 -10
  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} +18 -5
  15. package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +5 -5
  16. package/dist/cli/cli/{render-pr.js → render/render-pr.js} +33 -13
  17. package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +8 -3
  18. package/dist/cli/cli/{render-text.js → render/render-text.js} +118 -111
  19. package/dist/cli/cli/render/terminal.js +55 -0
  20. package/dist/cli/cli/report.js +68 -27
  21. package/dist/cli/cli/self-check.js +19 -23
  22. package/dist/cli/cli/since-last.js +2 -2
  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 +63 -23
  27. package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +1 -1
  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 +7 -1
  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} +50 -9
  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} +1 -1
  40. package/dist/cli/src/app/core/analysis/tool.js +83 -0
  41. package/dist/cli/src/app/core/assets/assets.js +134 -15
  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 +168 -13
  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 +121 -43
  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 +104 -16
  53. package/dist/cli/src/app/core/export/summary.js +29 -5
  54. package/dist/cli/src/app/core/findings/actions.js +3 -1
  55. package/dist/cli/src/app/core/findings/{boot-single.js → bundle/boot-single.js} +3 -3
  56. package/dist/cli/src/app/core/findings/{dupes.js → bundle/dupes.js} +8 -5
  57. package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +30 -18
  58. package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
  59. package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
  60. package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +28 -14
  61. package/dist/cli/src/app/core/findings/compose.js +6 -1
  62. package/dist/cli/src/app/core/findings/effort.js +2 -0
  63. package/dist/cli/src/app/core/findings/finding.types.js +1 -0
  64. package/dist/cli/src/app/core/findings/findings.js +48 -19
  65. package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +38 -14
  66. package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +16 -9
  67. package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
  68. package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +25 -11
  69. package/dist/cli/src/app/core/findings/kind-names.js +163 -0
  70. package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
  71. package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
  72. package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
  73. package/dist/cli/src/app/core/findings/text/causes.js +39 -0
  74. package/dist/cli/src/app/core/findings/{finding-html.js → text/finding-html.js} +8 -1
  75. package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +208 -77
  76. package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
  77. package/dist/cli/src/app/core/format/format.utils.js +158 -11
  78. package/dist/cli/src/app/core/format/ownership.js +93 -0
  79. package/dist/cli/src/app/core/i18n/en.js +76 -17
  80. package/dist/cli/src/app/core/i18n/es.js +82 -22
  81. package/dist/cli/src/app/core/intake/bundle-graph.js +281 -43
  82. package/dist/cli/src/app/core/intake/dist-files.js +82 -14
  83. package/dist/cli/src/app/core/intake/embedded.js +11 -1
  84. package/dist/cli/src/app/core/intake/unreached.js +139 -0
  85. package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
  86. package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
  87. package/dist/cli/src/app/core/project/project-context.js +16 -4
  88. package/dist/cli/src/app/core/project/project-name.js +36 -0
  89. package/dist/cli/src/app/core/scan/scan.js +58 -19
  90. package/dist/cli/src/app/core/scan/secrets.js +23 -3
  91. package/dist/cli/src/app/core/situation/situation-text.js +23 -0
  92. package/dist/cli/src/app/core/situation/situation.js +6 -4
  93. package/dist/cli/src/app/core/timing/timing.js +5 -2
  94. package/dist/cli/src/app/core/whatif/defer.js +29 -4
  95. package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
  96. package/dist/cli/src/app/core/whatif/why.js +102 -0
  97. package/docs/CONFIG-REFERENCE.md +230 -0
  98. package/docs/CONFIG.md +511 -0
  99. package/docs/HOW-IT-WORKS.md +286 -25
  100. package/loadline.html +24 -20
  101. package/loadline.schema.json +1209 -0
  102. package/package.json +35 -29
  103. package/dist/cli/cli/locate.js +0 -60
  104. package/dist/cli/cli/text.js +0 -215
  105. /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
  106. /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
  107. /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
  108. /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
  109. /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
  110. /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
  111. /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
  112. /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
@@ -8,33 +8,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.run = exports.UNUSABLE = exports.FAILED = exports.OK = void 0;
9
9
  const promises_1 = require("node:fs/promises");
10
10
  const node_path_1 = require("node:path");
11
+ const loadline_config_1 = require("../src/app/core/config/loadline-config");
11
12
  const pins_1 = require("../src/app/core/deps/pins");
12
13
  const summary_1 = require("../src/app/core/export/summary");
14
+ const ownership_1 = require("../src/app/core/format/ownership");
13
15
  const ui_1 = require("../src/app/core/i18n/ui");
14
16
  const project_context_1 = require("../src/app/core/project/project-context");
15
17
  const report_messages_utils_1 = require("../src/app/state/report-messages.utils");
16
18
  const args_1 = require("./args");
17
- const declared_1 = require("./declared");
18
19
  const gates_1 = require("./gates");
19
- const html_report_1 = require("./html-report");
20
- const locate_1 = require("./locate");
21
20
  const memory_1 = require("./memory");
22
- const read_build_1 = require("./read-build");
23
- const render_json_1 = require("./render-json");
24
- const render_markdown_1 = require("./render-markdown");
25
- const render_pr_1 = require("./render-pr");
26
- const render_sarif_1 = require("./render-sarif");
27
- const render_text_1 = require("./render-text");
21
+ const declared_1 = require("./read/declared");
22
+ const locate_1 = require("./read/locate");
23
+ const read_build_1 = require("./read/read-build");
24
+ const read_config_1 = require("./read/read-config");
25
+ const html_report_1 = require("./render/html-report");
26
+ const render_agent_1 = require("./render/render-agent");
27
+ const render_badge_1 = require("./render/render-badge");
28
+ const render_json_1 = require("./render/render-json");
29
+ const render_markdown_1 = require("./render/render-markdown");
30
+ const render_pr_1 = require("./render/render-pr");
31
+ const render_sarif_1 = require("./render/render-sarif");
32
+ const render_text_1 = require("./render/render-text");
28
33
  const report_1 = require("./report");
29
34
  const self_check_1 = require("./self-check");
30
35
  const since_last_1 = require("./since-last");
31
- const text_1 = require("./text");
36
+ const text_1 = require("./text/text");
37
+ const text_errors_1 = require("./text/text-errors");
38
+ const usage_1 = require("./text/usage");
32
39
  /** The formats that print the `--what-if` answers. */
33
- const WHAT_IF_FORMATS = new Set(['text', 'summary', 'json']);
40
+ const WHAT_IF_FORMATS = new Set(['text', 'summary', 'json', 'agent']);
41
+ /** And the `--why` ones: a chain of imports does not fit in a paste, so not the summary. */
42
+ const WHY_FORMATS = new Set(['text', 'json', 'agent']);
34
43
  /** 0 ran clean · 1 a gate broke · 2 the arguments or the files could not be used. */
35
44
  exports.OK = 0;
36
45
  exports.FAILED = 1;
37
46
  exports.UNUSABLE = 2;
47
+ /**
48
+ * The build as the report names it: relative to where the command ran, with `/`. It ends up in the
49
+ * exported baseline and in SARIF, which travel to other machines: an absolute `C:\Users\…` there
50
+ * carried somebody's home folder into an artifact and read differently on a Linux runner.
51
+ */
52
+ const portableName = (target) => {
53
+ const named = (0, node_path_1.relative)(process.cwd(), (0, node_path_1.resolve)(target)).replaceAll('\\', '/');
54
+ return named === '' ? '.' : named;
55
+ };
56
+ /**
57
+ * What went wrong, as a word a script can branch on: the analysis's own codes (`NO_PAGE`,
58
+ * `NOT_ESM_GRAPH`…) as they were thrown, `input` for what the command was given, `unexpected` for
59
+ * the rest. The sentence beside it is for people and changes with the language.
60
+ */
61
+ const codeOf = (error) => {
62
+ if (error instanceof read_build_1.InputError) {
63
+ return 'input';
64
+ }
65
+ return error instanceof Error && /^[A-Z][A-Z_]+$/.test(error.message) ? error.message : 'unexpected';
66
+ };
38
67
  const write = (stream, value) => {
39
68
  stream.write(`${value}\n`);
40
69
  };
@@ -83,10 +112,17 @@ const readInputs = async (options) => {
83
112
  // A folder is the build itself, so it is both what is analysed and where the figures come from.
84
113
  const derive = await (0, read_build_1.isFolder)(options.target);
85
114
  if (derive && options.dist) {
86
- throw new read_build_1.InputError('--dist is the folder already being analysed; drop one of the two.');
115
+ throw new read_build_1.InputError(t => t.distTwice);
87
116
  }
88
117
  const folder = derive ? options.target : options.dist;
89
- const dist = folder ? await (0, read_build_1.readDist)(folder, derive) : NO_DIST;
118
+ // Before the folder: `build` of `loadline.json` says what the folder cannot say on its own.
119
+ const configRead = await (0, read_config_1.readLoadlineConfig)(options.config, process.cwd(), options.lang);
120
+ // Yours or theirs, for every path named from here on: the default unless the file says more.
121
+ (0, ownership_1.setOwnership)(configRead.config?.build);
122
+ // `--entry` adds to `build.entries`, for one run, what a file would say for every run.
123
+ const said = configRead.config?.build;
124
+ const build = options.entries.length > 0 ? { ...said, entries: [...(said?.entries ?? []), ...options.entries] } : said;
125
+ const dist = folder ? await (0, read_build_1.readDist)(folder, derive, build) : NO_DIST;
90
126
  const meta = dist.graph ? dist.graph.meta : await (0, read_build_1.readStats)(options.target, ui_1.UI[options.lang]);
91
127
  const deps = await (0, read_build_1.readDepsFiles)(options.lock, options.audit);
92
128
  const context = options.project ? await (0, read_build_1.readProject)(options.project) : { angular: null, pkg: null, pipelines: [] };
@@ -104,24 +140,53 @@ const readInputs = async (options) => {
104
140
  return {
105
141
  meta,
106
142
  parallel: dist.graph?.parallel ?? null,
107
- statsName: options.target,
143
+ routes: dist.graph?.routes ?? null,
144
+ statsName: portableName(options.target),
145
+ packageName: await (0, read_build_1.nearestPackageName)((await (0, read_build_1.isFolder)(options.target)) ? options.target : (0, node_path_1.dirname)(options.target)),
108
146
  ...dist,
109
- ...(await (0, read_build_1.readLoadlineConfig)(options.config, process.cwd()).then(read => ({
110
- config: read.config,
111
- configProblems: read.problems,
112
- configName: read.name,
113
- }))),
147
+ config: configRead.config,
148
+ configProblems: configRead.problems,
149
+ configName: configRead.name,
114
150
  ...deps,
115
151
  declared: declared.size > 0 ? declared : null,
116
152
  assetSources: await assetSourcesOf(dist.assets, context, options.project),
117
- baseline: options.baseline ? await (0, read_build_1.readBaseline)(options.baseline) : null,
153
+ // Named after the file it was given as, which is the name the person knows: an export keeps
154
+ // the name of the build it was made from, and "compared against dist/app/stats.json" read
155
+ // as the wrong file when base.json is what was passed.
156
+ baseline: options.baseline
157
+ ? { ...(await (0, read_build_1.readBaseline)(options.baseline)), name: portableName(options.baseline) }
158
+ : null,
118
159
  // Remembered only when nothing was asked for explicitly: a `--baseline` is a decision, the
119
160
  // memory is a convenience, and the two are never mixed in one report.
120
- lastRun: options.cache && !options.baseline ? await (0, memory_1.readLastRun)(process.cwd(), options.target) : null,
161
+ ...(await lastRunOf(options)),
121
162
  context,
122
- criteria: options.criteria ? await (0, read_build_1.readCriteria)(options.criteria) : null,
163
+ criteria: options.criteria ? await (0, read_build_1.readCriteria)(options.criteria, options.lang) : null,
123
164
  };
124
165
  };
166
+ /**
167
+ * The build folder that would hold the `--html` page, if any. The next build empties that folder,
168
+ * and the page somebody meant to keep — or to attach to an issue tomorrow — is gone with it.
169
+ */
170
+ const buildFolderHolding = (html, options) => {
171
+ const page = (0, node_path_1.resolve)(html);
172
+ const folders = [options.dist, options.target].filter((folder) => !!folder);
173
+ return (folders.find(folder => {
174
+ const within = (0, node_path_1.relative)((0, node_path_1.resolve)(folder), page);
175
+ return within !== '' && !within.startsWith('..') && !(0, node_path_1.isAbsolute)(within);
176
+ }) ?? null);
177
+ };
178
+ /**
179
+ * The previous run of this build, and its branch when that is not the one checked out now: a run
180
+ * on another branch is still worth comparing against, but not without saying so.
181
+ */
182
+ const lastRunOf = async (options) => {
183
+ const last = options.cache && !options.baseline ? await (0, memory_1.readLastRun)(process.cwd(), options.target) : null;
184
+ if (!last) {
185
+ return { lastRun: null, lastRunBranch: null };
186
+ }
187
+ const now = await (0, memory_1.branchOf)(process.cwd());
188
+ return { lastRun: last.snapshot, lastRunBranch: last.branch && last.branch !== now ? last.branch : null };
189
+ };
125
190
  /** The files the page needs to rebuild this report on its own, read once more as they are. */
126
191
  const writePage = async (options) => {
127
192
  if (!options.html) {
@@ -134,7 +199,8 @@ const writePage = async (options) => {
134
199
  options.project ? (0, node_path_1.join)(options.project, 'package.json') : null,
135
200
  options.lock,
136
201
  options.audit,
137
- options.config,
202
+ // With `--entry` the file goes in as the run read it, below, or the page would not find the entry.
203
+ options.entries.length > 0 ? null : options.config,
138
204
  ];
139
205
  const texts = [];
140
206
  for (const path of extras) {
@@ -146,6 +212,11 @@ const writePage = async (options) => {
146
212
  texts.push(text);
147
213
  }
148
214
  }
215
+ if (options.entries.length > 0) {
216
+ const { config } = await (0, read_config_1.readLoadlineConfig)(options.config, process.cwd(), options.lang);
217
+ const entries = [...(config?.build?.entries ?? []), ...options.entries];
218
+ texts.push({ name: 'loadline.json', text: (0, loadline_config_1.writeConfig)({ ...config, build: { ...config?.build, entries } }) });
219
+ }
149
220
  await (0, html_report_1.writeHtmlReport)(options.html, {
150
221
  version: 1,
151
222
  lang: options.lang,
@@ -165,41 +236,80 @@ const writePage = async (options) => {
165
236
  const requireBaseline = (options) => {
166
237
  const wantsGrowth = options.gates.maxGrowth !== null || options.gates.maxGrowthRatio !== null;
167
238
  if (wantsGrowth && !options.baseline) {
168
- throw new read_build_1.InputError('--max-growth and --max-growth-pct need a --baseline to compare against.');
239
+ throw new read_build_1.InputError(t => t.growthNeedsBaseline);
240
+ }
241
+ };
242
+ /**
243
+ * `--print-config`: the `loadline.json` this run would use, with everything it extends joined in,
244
+ * as a file that says it all itself. What `eslint --print-config` and `tsc --showConfig` are for:
245
+ * the answer to "which threshold won?" without reading three files. It is also how the page gets
246
+ * a configuration that extends another — the page has no disk to follow `extends` on, and this is
247
+ * the file to drop on it instead. Sizes come out in bytes, which is what they are once read.
248
+ */
249
+ const printConfig = async (options) => {
250
+ try {
251
+ const read = await (0, read_config_1.readLoadlineConfig)(options.config, process.cwd(), options.lang);
252
+ for (const problem of read.problems) {
253
+ write(process.stderr, problem);
254
+ }
255
+ if (!read.config) {
256
+ throw new read_build_1.InputError(t => t.noConfigToPrint);
257
+ }
258
+ write(process.stdout, (0, loadline_config_1.writeConfig)(read.config).trimEnd());
259
+ write(process.stderr, text_1.CLI_TEXT[options.lang].configRead(read.name ?? ''));
260
+ return exports.OK;
261
+ }
262
+ catch (error) {
263
+ if (error instanceof read_build_1.InputError) {
264
+ write(process.stderr, error.say(text_errors_1.ERROR_TEXT[options.lang]));
265
+ return exports.UNUSABLE;
266
+ }
267
+ throw error;
169
268
  }
170
269
  };
171
270
  const run = async (argv, version) => {
172
271
  const parsed = (0, args_1.parseArgs)(argv);
173
272
  if (!parsed.ok) {
174
- write(process.stderr, `${parsed.message}\n\nRun loadline --help to see the options.`);
273
+ write(process.stderr, `${parsed.message}\n\n${text_errors_1.ERROR_TEXT[parsed.lang].seeHelp}`);
175
274
  return exports.UNUSABLE;
176
275
  }
177
276
  let options = parsed.options;
178
277
  if (options.help) {
179
- write(process.stdout, args_1.USAGE);
278
+ write(process.stdout, usage_1.USAGE[options.lang]);
180
279
  return exports.OK;
181
280
  }
182
281
  if (options.version) {
183
282
  write(process.stdout, `loadline ${version}`);
184
283
  return exports.OK;
185
284
  }
285
+ if (options.printConfig) {
286
+ return printConfig(options);
287
+ }
186
288
  try {
187
289
  requireBaseline(options);
188
290
  // The root of a build is enough: the metafile and the browser folder are found inside it.
189
291
  const located = await (0, locate_1.locateBuild)(options.target, options.dist);
190
292
  options = { ...options, target: located.target, dist: located.dist };
293
+ // On stderr: which build was chosen is said, without getting into what a script parses.
294
+ if (located.others) {
295
+ write(process.stderr, text_1.CLI_TEXT[options.lang].alsoFound(located.others.join(', ')));
296
+ }
191
297
  const input = await readInputs(options);
192
298
  // The gates the file asks for, where the command line did not ask for that one. A flag typed
193
299
  // by hand is somebody overriding the committed decision on purpose, so it wins.
194
300
  const gates = (0, gates_1.mergeGates)(options.gates, input.config ?? null);
195
301
  const report = (0, report_1.buildReport)(input, { ...options, gates });
196
302
  report.located = located.found;
303
+ const unchecked = (0, gates_1.uncheckedGates)(report, gates, options.gates);
304
+ if (unchecked.refuse) {
305
+ throw new read_build_1.InputError(unchecked.refuse);
306
+ }
197
307
  // The self-check is about Loadline, not about the build, so it replaces the report rather
198
308
  // than being one more section of it — and it owns the exit code while it is asked for.
199
309
  if (options.selfCheck) {
200
- const checked = (0, self_check_1.selfCheck)(input.meta, report.analysis, input.announced);
310
+ const checked = (0, self_check_1.selfCheck)(input.meta, report.analysis, input.announced, text_errors_1.ERROR_TEXT[options.lang]);
201
311
  write(checked.ok ? process.stdout : process.stderr, checked.report);
202
- return checked.ok ? exports.OK : exports.FAILED;
312
+ return checked.ok ? exports.OK : checked.ran ? exports.FAILED : exports.UNUSABLE;
203
313
  }
204
314
  // Before the gates: a build that broke one is still the build that was made, and a
205
315
  // pipeline that only writes the baseline when it is under budget would compare tomorrow
@@ -211,8 +321,9 @@ const run = async (argv, version) => {
211
321
  // sends somebody to check the file that was read fine.
212
322
  const failed = await (0, promises_1.writeFile)(options.export, JSON.stringify(report.snapshot, null, 2), 'utf8').catch((error) => (error instanceof Error ? error.message : String(error)));
213
323
  if (failed) {
214
- throw new read_build_1.InputError(`Could not write ${options.export}: ${failed}`);
324
+ throw new read_build_1.InputError(t => t.cannotWrite(options.export ?? '', failed));
215
325
  }
326
+ write(process.stderr, text_1.CLI_TEXT[options.lang].exportWritten(options.export));
216
327
  }
217
328
  const asked = (0, gates_1.anyGate)(gates);
218
329
  const violations = (0, gates_1.checkGates)(report, gates);
@@ -224,16 +335,20 @@ const run = async (argv, version) => {
224
335
  markdown: () => (0, render_markdown_1.renderMarkdown)(report, violations, asked),
225
336
  'pr-comment': () => (0, render_pr_1.renderPrComment)(report, violations, asked),
226
337
  sarif: () => (0, render_sarif_1.renderSarif)(report),
338
+ agent: () => (0, render_agent_1.renderAgent)(report, violations, asked),
339
+ badge: () => (0, render_badge_1.renderBadge)(report),
227
340
  summary: () => (0, summary_1.summaryText)({
228
341
  analysis: report.analysis,
229
342
  findings: report.findings,
230
343
  comparison: report.comparison,
231
344
  unit: report.unit,
232
- name: report.statsName,
345
+ // The project first, as the text report heads with it, and the build it was read from.
346
+ name: report.projectName ? `${report.projectName} (${report.statsName})` : report.statsName,
233
347
  firstTrip: report.assets?.firstTrip.total ?? null,
234
348
  lang: report.lang,
235
349
  since: (0, since_last_1.sinceLastLine)(report),
236
350
  whatIf: report.whatIf,
351
+ ...(asked && { gates: violations.map(violation => violation.message) }),
237
352
  }),
238
353
  };
239
354
  // `--what-if` is answered in text, summary and json. The other three are a document for
@@ -242,27 +357,43 @@ const run = async (argv, version) => {
242
357
  if (options.whatIf.length > 0 && !WHAT_IF_FORMATS.has(options.format)) {
243
358
  write(process.stderr, text_1.CLI_TEXT[options.lang].whatIfNotHere(options.format));
244
359
  }
360
+ if (options.why.length > 0 && !WHY_FORMATS.has(options.format)) {
361
+ write(process.stderr, text_1.CLI_TEXT[options.lang].whyNotHere(options.format));
362
+ }
245
363
  // What is wrong with `loadline.json` goes to stderr, never into the report: something is
246
364
  // parsing stdout, and a warning in the middle of a SARIF document breaks it.
365
+ // Each line already names its file: with `extends` there can be more than one.
247
366
  for (const problem of report.configProblems) {
248
- write(process.stderr, text_1.CLI_TEXT[options.lang].configProblem(problem));
367
+ write(process.stderr, problem);
368
+ }
369
+ for (const line of [...(0, gates_1.unmatchedScreenLimits)(report, gates), ...unchecked.skipped]) {
370
+ write(process.stderr, line);
249
371
  }
250
372
  write(process.stdout, rendered[options.format]());
251
373
  // After the report, so a page that fails to write never costs the report somebody piped.
252
374
  if (options.html) {
253
375
  await writePage(options);
254
376
  write(process.stderr, text_1.CLI_TEXT[options.lang].htmlWritten(options.html));
377
+ const inside = buildFolderHolding(options.html, options);
378
+ if (inside) {
379
+ write(process.stderr, text_1.CLI_TEXT[options.lang].htmlInsideBuild(inside));
380
+ }
255
381
  }
256
382
  if (options.cache) {
257
- await (0, memory_1.writeLastRun)(process.cwd(), options.target, report.snapshot);
383
+ await (0, memory_1.writeLastRun)(process.cwd(), options.target, report.snapshot, await (0, memory_1.branchOf)(process.cwd()));
258
384
  }
259
385
  return violations.length > 0 ? exports.FAILED : exports.OK;
260
386
  }
261
387
  catch (error) {
262
388
  // The codes the analysis throws are translated with the same table the page uses; anything
263
389
  // else is printed as it came, because an unexpected failure should not be reworded.
264
- const message = error instanceof read_build_1.InputError ? error.message : (0, report_messages_utils_1.errorMessage)(error, ui_1.UI[options.lang]);
390
+ const message = error instanceof read_build_1.InputError ? error.say(text_errors_1.ERROR_TEXT[options.lang]) : (0, report_messages_utils_1.errorMessage)(error, ui_1.UI[options.lang]);
265
391
  write(process.stderr, message);
392
+ // A step piping `--format json` into `jq` got an empty input and an error about that,
393
+ // rather than the reason. The reason goes to stdout as well, in the shape it asked for.
394
+ if (options.format === 'json') {
395
+ write(process.stdout, JSON.stringify({ tool: 'loadline', ok: false, error: { code: codeOf(error), message } }));
396
+ }
266
397
  return exports.UNUSABLE;
267
398
  }
268
399
  };
@@ -13,7 +13,7 @@
13
13
  * memory, and every failure to read or write is silent: losing the comparison is not worth an error.
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.writeLastRun = exports.readLastRun = void 0;
16
+ exports.writeLastRun = exports.readLastRun = exports.branchOf = void 0;
17
17
  const node_crypto_1 = require("node:crypto");
18
18
  const promises_1 = require("node:fs/promises");
19
19
  const node_path_1 = require("node:path");
@@ -48,6 +48,38 @@ const fileFor = async (cwd, target) => {
48
48
  const key = (0, node_crypto_1.createHash)('sha1').update((0, node_path_1.resolve)(target)).digest('hex').slice(0, 12);
49
49
  return (0, node_path_1.join)(modules, '.cache', 'loadline', `last-${key}.json`);
50
50
  };
51
+ /**
52
+ * The branch checked out where the command runs, read from `.git/HEAD` — or from the folder a
53
+ * worktree's `.git` file points at. `null` outside a repository or on a detached HEAD.
54
+ *
55
+ * The memory is kept per build and not per branch, on purpose: the first run on a new branch is
56
+ * the one that most wants yesterday's `main` to compare against. What was wrong was saying nothing
57
+ * about it, so a run on `feature-a` after one on `feature-b` read as "what my change did". The
58
+ * branch is remembered, and the line names it when it is not this one.
59
+ */
60
+ const branchOf = async (cwd) => {
61
+ let folder = (0, node_path_1.resolve)(cwd);
62
+ for (;;) {
63
+ const dotGit = (0, node_path_1.join)(folder, '.git');
64
+ try {
65
+ const info = await (0, promises_1.stat)(dotGit);
66
+ const pointer = info.isDirectory() ? null : await (0, promises_1.readFile)(dotGit, 'utf8');
67
+ const gitDir = pointer === null ? dotGit : (0, node_path_1.resolve)(folder, pointer.replace(/^gitdir:\s*/, '').trim());
68
+ const text = await (0, promises_1.readFile)((0, node_path_1.join)(gitDir, 'HEAD'), 'utf8');
69
+ const head = text.trim();
70
+ return head.startsWith('ref: refs/heads/') ? head.slice('ref: refs/heads/'.length) : null;
71
+ }
72
+ catch {
73
+ // No repository here; one level up.
74
+ }
75
+ const parent = (0, node_path_1.dirname)(folder);
76
+ if (parent === folder) {
77
+ return null;
78
+ }
79
+ folder = parent;
80
+ }
81
+ };
82
+ exports.branchOf = branchOf;
51
83
  const readLastRun = async (cwd, target) => {
52
84
  const file = await fileFor(cwd, target);
53
85
  if (!file) {
@@ -55,21 +87,25 @@ const readLastRun = async (cwd, target) => {
55
87
  }
56
88
  try {
57
89
  const parsed = JSON.parse(await (0, promises_1.readFile)(file, 'utf8'));
58
- return (0, baseline_1.isSnapshot)(parsed) ? parsed : null;
90
+ if (!(0, baseline_1.isSnapshot)(parsed)) {
91
+ return null;
92
+ }
93
+ const branch = parsed.branch;
94
+ return { snapshot: parsed, branch: typeof branch === 'string' ? branch : null };
59
95
  }
60
96
  catch {
61
97
  return null;
62
98
  }
63
99
  };
64
100
  exports.readLastRun = readLastRun;
65
- const writeLastRun = async (cwd, target, snapshot) => {
101
+ const writeLastRun = async (cwd, target, snapshot, branch) => {
66
102
  const file = await fileFor(cwd, target);
67
103
  if (!file) {
68
104
  return;
69
105
  }
70
106
  try {
71
107
  await (0, promises_1.mkdir)((0, node_path_1.dirname)(file), { recursive: true });
72
- await (0, promises_1.writeFile)(file, JSON.stringify(snapshot), 'utf8');
108
+ await (0, promises_1.writeFile)(file, JSON.stringify({ ...snapshot, branch }), 'utf8');
73
109
  }
74
110
  catch {
75
111
  // A read-only checkout or a full disk: the report is still right, it just will not remember.
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.readDeclared = void 0;
15
15
  const promises_1 = require("node:fs/promises");
16
16
  const node_path_1 = require("node:path");
17
- const json_utils_1 = require("../src/app/core/json/json.utils");
17
+ const json_utils_1 = require("../../src/app/core/json/json.utils");
18
18
  /** `…/node_modules/@scope/name/` or `…/node_modules/name/`: the folder a package is installed in. */
19
19
  const PACKAGE_DIR = /^(.*node_modules\/(?:@[^/]+\/)?[^/]+)\//;
20
20
  /**
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ /**
3
+ * What to read when the command is pointed at the root of a build rather than at one of its files.
4
+ *
5
+ * `ng build` writes `dist/<app>/browser/` and, with `--stats-json`, the metafile next to it — called
6
+ * `stats.json` up to Angular 22.1 and `browser-stats.json` from 22.2, when the server half got a file
7
+ * of its own (`server-stats.json`). Read in @angular/build itself: 22.1.8 writes `stats.json` with or
8
+ * without a server, 22.2.0 writes `browser-stats.json` even when there is none. Asking for both paths by hand was the first thing anybody had to get right, and the
9
+ * README naming only the old file sent people looking for something that was not there. Pointed at
10
+ * `dist/<app>`, the command now finds both on its own and says which it found.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.locateBuild = void 0;
14
+ const promises_1 = require("node:fs/promises");
15
+ const node_path_1 = require("node:path");
16
+ const index_html_1 = require("../../src/app/core/build-text/index-html");
17
+ const dist_files_1 = require("../../src/app/core/intake/dist-files");
18
+ const read_build_1 = require("./read-build");
19
+ /**
20
+ * The stats files' names that mark a folder as a build. Vue CLI's `report.json` is looked for only
21
+ * inside the folder that was named: a name this plain is no sign of a build anywhere else.
22
+ */
23
+ const MARKS_A_BUILD = dist_files_1.STATS_NAMES.filter(name => name !== 'report.json');
24
+ /**
25
+ * Folders no build is written to, and the ones that make the walk slow. `public/` and `static/`
26
+ * hold the files a build copies, an `index.html` template among them; `src/` holds the code.
27
+ */
28
+ const NOT_A_BUILD = new Set(['node_modules', 'src', 'public', 'static', 'e2e', 'test', 'tests', 'coverage']);
29
+ /**
30
+ * How deep under a project a build is looked for: `dist/<app>/browser`, `build/esm-bundled`, and a
31
+ * workspace's `apps/admin/dist`, which at three was one level out of reach: `loadline .` at the root
32
+ * of a monorepo said there was no build in it.
33
+ */
34
+ const BUILD_DEPTH = 4;
35
+ /**
36
+ * Whether a folder is walked into. Nitro's `.output/public` is a build although it is called
37
+ * `public`: Nuxt writes the site there, and `loadline .` in a Nuxt project found nothing.
38
+ */
39
+ const walked = (parent, name) => (!name.startsWith('.') || name === '.output') &&
40
+ (!NOT_A_BUILD.has(name) || (name === 'public' && (0, node_path_1.basename)(parent) === '.output'));
41
+ const isFile = async (path) => {
42
+ try {
43
+ const info = await (0, promises_1.stat)(path);
44
+ return info.isFile();
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ };
50
+ const isDirectory = async (path) => {
51
+ try {
52
+ const info = await (0, promises_1.stat)(path);
53
+ return info.isDirectory();
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ };
59
+ /**
60
+ * A folder that is a build: a metafile in it, or a page naming a script that is there below it.
61
+ *
62
+ * The page has to name one. A folder of sources with an `index.html` template is no build — ember's
63
+ * `app/` names `{{rootURL}}assets/vendor.js`, which nothing below it is, and Vite's root names
64
+ * `/src/main.ts` — and taken for one it was offered as "also found".
65
+ */
66
+ const isBuild = async (folder, names) => {
67
+ if (MARKS_A_BUILD.some(name => names.includes(name))) {
68
+ return true;
69
+ }
70
+ const page = names.find(name => /^index(?:\.[\w-]+)?\.html$/i.test(name));
71
+ if (!page) {
72
+ return false;
73
+ }
74
+ try {
75
+ const scripts = (0, index_html_1.scriptsIn)(await (0, promises_1.readFile)((0, node_path_1.join)(folder, page), 'utf8'));
76
+ const named = new Set([...scripts.names, ...scripts.entries, ...scripts.legacy]);
77
+ const below = await (0, promises_1.readdir)(folder, { recursive: true });
78
+ return below.some(path => named.has((0, node_path_1.basename)(path)) && !path.includes('node_modules'));
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ };
84
+ /**
85
+ * Whether the page of a build starts it as ES modules: the build a current browser runs, when a
86
+ * project writes several at once — Polymer's `esm-bundled`, `es6-bundled` and `es5-bundled` come
87
+ * out of one command within the same second, and which of them was read was down to the clock.
88
+ */
89
+ const servesModules = async (folder) => {
90
+ try {
91
+ return /<script\s[^>]*\btype\s*=\s*["']?module/i.test(await (0, promises_1.readFile)((0, node_path_1.join)(folder, 'index.html'), 'utf8'));
92
+ }
93
+ catch {
94
+ return false;
95
+ }
96
+ };
97
+ /** Builds written this close together were written by one command: the time does not choose between them. */
98
+ const SAME_BUILD_MS = 5000;
99
+ /** When the page or the metafile of a build was last written: the newest build is the one meant. */
100
+ const writtenAt = async (folder, names) => {
101
+ const marker = [...MARKS_A_BUILD, 'index.html'].find(name => names.includes(name));
102
+ if (!marker) {
103
+ return 0;
104
+ }
105
+ try {
106
+ const info = await (0, promises_1.stat)((0, node_path_1.join)(folder, marker));
107
+ return info.mtimeMs;
108
+ }
109
+ catch {
110
+ return 0;
111
+ }
112
+ };
113
+ /**
114
+ * The builds inside a project folder, newest first.
115
+ *
116
+ * `loadline .` in the root of a project is the first thing anybody types, and it read the project as
117
+ * a build: a walk through `node_modules` that took 51 seconds on an Angular 8 project, then the
118
+ * `index.html` template of the root — or none — and a message saying the folder had no page. A build
119
+ * is wherever a page sits with scripts beside it, or a metafile, whatever the tool called the folder:
120
+ * `dist`, `build`, `www`, `out`, `__sapper__/export`, `dist/<app>`, `build/esm-bundled`. Not a list
121
+ * of names, so a tool that does not exist yet is found the same way.
122
+ */
123
+ const buildsUnder = async (project) => {
124
+ const found = [];
125
+ let level = [project];
126
+ for (let depth = 0; depth < BUILD_DEPTH && level.length > 0; depth++) {
127
+ const next = [];
128
+ for (const folder of level) {
129
+ let entries;
130
+ try {
131
+ entries = await (0, promises_1.readdir)(folder, { withFileTypes: true });
132
+ }
133
+ catch {
134
+ continue;
135
+ }
136
+ const names = entries.filter(entry => entry.isFile()).map(entry => entry.name);
137
+ if (folder !== project && (await isBuild(folder, names))) {
138
+ found.push({ folder, at: await writtenAt(folder, names), modules: await servesModules(folder) });
139
+ continue;
140
+ }
141
+ for (const entry of entries) {
142
+ if (entry.isDirectory() && walked(folder, entry.name)) {
143
+ next.push((0, node_path_1.join)(folder, entry.name));
144
+ }
145
+ }
146
+ }
147
+ level = next;
148
+ }
149
+ const newest = Math.max(...found.map(entry => entry.at));
150
+ const recent = (entry) => newest - entry.at < SAME_BUILD_MS;
151
+ // The builds of the last command first, the one a current browser runs first among them, then
152
+ // the rest by age; the path settles what is left, so the same folders always give the same answer.
153
+ return found
154
+ .toSorted((a, b) => Number(recent(b)) - Number(recent(a)) ||
155
+ (recent(a) ? Number(b.modules) - Number(a.modules) : 0) ||
156
+ b.at - a.at ||
157
+ a.folder.localeCompare(b.folder))
158
+ .map(entry => entry.folder);
159
+ };
160
+ /**
161
+ * @param target what was typed: a metafile, a browser folder or the root of a build.
162
+ * @param dist `--dist`, when it was given. Anything typed by hand wins: nothing is looked up then.
163
+ */
164
+ const locateBuild = async (target, dist) => {
165
+ // The page of the build named instead of its folder: what was meant is the folder it sits in,
166
+ // and reading the HTML as a stats file answered "is not valid JSON".
167
+ if (!dist && /\.html?$/i.test(target) && (await isFile(target))) {
168
+ const folder = (0, node_path_1.dirname)(target);
169
+ const located = await (0, exports.locateBuild)(folder, null);
170
+ return { ...located, found: located.found.length > 0 ? located.found : [folder] };
171
+ }
172
+ if (dist || !(await isDirectory(target))) {
173
+ return { target, dist, found: [] };
174
+ }
175
+ const browser = (0, node_path_1.join)(target, 'browser');
176
+ const hasBrowser = await isDirectory(browser);
177
+ let stats = null;
178
+ for (const name of dist_files_1.STATS_NAMES) {
179
+ const candidate = (0, node_path_1.join)(target, name);
180
+ if (await isFile(candidate)) {
181
+ stats = candidate;
182
+ break;
183
+ }
184
+ }
185
+ if (stats) {
186
+ // webpack writes its stats inside the folder it builds — Angular 8 `dist/stats-es2015.json`,
187
+ // Create React App `build/bundle-stats.json` — and that folder is the one to weigh. Taken
188
+ // for a folder with nothing but the stats in it, an Angular 8 build was read in raw bytes.
189
+ const home = (await isFile((0, node_path_1.join)(target, 'index.html'))) ? target : null;
190
+ const folder = hasBrowser ? browser : home;
191
+ return { target: stats, dist: folder, found: folder ? [stats, folder] : [stats] };
192
+ }
193
+ // No metafile: the browser folder is read as a graph, the way a folder always has been.
194
+ if (hasBrowser) {
195
+ return { target: browser, dist: null, found: [browser] };
196
+ }
197
+ // The root of a project rather than of a build: the build is somewhere inside it.
198
+ if (await isFile((0, node_path_1.join)(target, 'package.json'))) {
199
+ const [newest, ...others] = await buildsUnder(target);
200
+ if (newest) {
201
+ const located = await (0, exports.locateBuild)(newest, null);
202
+ return {
203
+ ...located,
204
+ found: located.found.length > 0 ? located.found : [newest],
205
+ ...(others.length > 0 && { others }),
206
+ };
207
+ }
208
+ if (!(await isFile((0, node_path_1.join)(target, 'index.html'))) || (await isDirectory((0, node_path_1.join)(target, 'node_modules')))) {
209
+ throw new read_build_1.InputError(t => t.projectNotBuilt(target));
210
+ }
211
+ }
212
+ return { target, dist, found: [] };
213
+ };
214
+ exports.locateBuild = locateBuild;