ticbuild 1.0.19 → 1.0.21

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 (63) hide show
  1. package/README.md +35 -0
  2. package/dist/backend/importers/LuaCodeImporter.d.ts +4 -1
  3. package/dist/backend/importers/LuaCodeImporter.d.ts.map +1 -1
  4. package/dist/backend/importers/LuaCodeImporter.js +18 -8
  5. package/dist/backend/importers/LuaCodeImporter.js.map +1 -1
  6. package/dist/buildInfo.d.ts +4 -4
  7. package/dist/buildInfo.js +4 -4
  8. package/dist/frontend/build.d.ts +2 -1
  9. package/dist/frontend/build.d.ts.map +1 -1
  10. package/dist/frontend/build.js +66 -2
  11. package/dist/frontend/build.js.map +1 -1
  12. package/dist/frontend/buildReporter.d.ts +86 -0
  13. package/dist/frontend/buildReporter.d.ts.map +1 -0
  14. package/dist/frontend/buildReporter.js +64 -0
  15. package/dist/frontend/buildReporter.js.map +1 -0
  16. package/dist/frontend/buildReporter.test.d.ts +2 -0
  17. package/dist/frontend/buildReporter.test.d.ts.map +1 -0
  18. package/dist/frontend/buildReporter.test.js +360 -0
  19. package/dist/frontend/buildReporter.test.js.map +1 -0
  20. package/dist/frontend/core.d.ts +2 -1
  21. package/dist/frontend/core.d.ts.map +1 -1
  22. package/dist/frontend/core.js +294 -68
  23. package/dist/frontend/core.js.map +1 -1
  24. package/dist/frontend/parseOptions.d.ts +1 -0
  25. package/dist/frontend/parseOptions.d.ts.map +1 -1
  26. package/dist/frontend/parseOptions.js.map +1 -1
  27. package/dist/index.js +1 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/utils/console.d.ts +7 -0
  30. package/dist/utils/console.d.ts.map +1 -1
  31. package/dist/utils/console.js +32 -9
  32. package/dist/utils/console.js.map +1 -1
  33. package/dist/utils/lua/lua_alias_expressions.d.ts +2 -0
  34. package/dist/utils/lua/lua_alias_expressions.d.ts.map +1 -1
  35. package/dist/utils/lua/lua_alias_expressions.js +29 -94
  36. package/dist/utils/lua/lua_alias_expressions.js.map +1 -1
  37. package/dist/utils/lua/lua_alias_expressions.test.d.ts +2 -0
  38. package/dist/utils/lua/lua_alias_expressions.test.d.ts.map +1 -0
  39. package/dist/utils/lua/lua_alias_expressions.test.js +212 -0
  40. package/dist/utils/lua/lua_alias_expressions.test.js.map +1 -0
  41. package/dist/utils/lua/lua_alias_literals.d.ts +2 -0
  42. package/dist/utils/lua/lua_alias_literals.d.ts.map +1 -1
  43. package/dist/utils/lua/lua_alias_literals.js +12 -79
  44. package/dist/utils/lua/lua_alias_literals.js.map +1 -1
  45. package/dist/utils/lua/lua_alias_shared.d.ts +49 -14
  46. package/dist/utils/lua/lua_alias_shared.d.ts.map +1 -1
  47. package/dist/utils/lua/lua_alias_shared.js +661 -184
  48. package/dist/utils/lua/lua_alias_shared.js.map +1 -1
  49. package/dist/utils/lua/lua_local_budget.test.d.ts +2 -0
  50. package/dist/utils/lua/lua_local_budget.test.d.ts.map +1 -0
  51. package/dist/utils/lua/lua_local_budget.test.js +167 -0
  52. package/dist/utils/lua/lua_local_budget.test.js.map +1 -0
  53. package/dist/utils/lua/lua_processor.d.ts +6 -0
  54. package/dist/utils/lua/lua_processor.d.ts.map +1 -1
  55. package/dist/utils/lua/lua_processor.js +18 -9
  56. package/dist/utils/lua/lua_processor.js.map +1 -1
  57. package/dist/utils/lua/lua_processor.test.js +36 -0
  58. package/dist/utils/lua/lua_processor.test.js.map +1 -1
  59. package/dist/utils/lua/lua_simplify.d.ts.map +1 -1
  60. package/dist/utils/lua/lua_simplify.js +5 -1
  61. package/dist/utils/lua/lua_simplify.js.map +1 -1
  62. package/package.json +1 -1
  63. package/templates/help/build.txt +9 -7
@@ -46,26 +46,120 @@ const tic80_1 = require("../utils/tic80/tic80");
46
46
  const parseOptions_1 = require("./parseOptions");
47
47
  const node_fs_1 = require("node:fs");
48
48
  const path = __importStar(require("node:path"));
49
- async function buildCore(manifestPath, options) {
49
+ const buildReporter_1 = require("./buildReporter");
50
+ function createBuildReportSession(selectedReporter) {
51
+ const pendingBuildReportLines = [];
52
+ let buildReportFilePath;
53
+ const archivedReporter = new buildReporter_1.JsonlBuildReporter((line) => {
54
+ if (buildReportFilePath === undefined) {
55
+ pendingBuildReportLines.push(line);
56
+ return;
57
+ }
58
+ (0, node_fs_1.appendFileSync)(buildReportFilePath, `${line}\n`, "utf-8");
59
+ });
60
+ let renderingSelectedReporter = false;
61
+ const reporter = {
62
+ name: selectedReporter.name,
63
+ message: (message) => {
64
+ archivedReporter.message(message);
65
+ renderingSelectedReporter = true;
66
+ try {
67
+ selectedReporter.message(message);
68
+ }
69
+ finally {
70
+ renderingSelectedReporter = false;
71
+ }
72
+ },
73
+ };
74
+ const previousConsoleMessageSink = cons.getConsoleMessageSink();
75
+ const previousConsoleMessageObserver = cons.getConsoleMessageObserver();
76
+ const captureLegacyConsoleMessage = (level, message) => {
77
+ if (!renderingSelectedReporter) {
78
+ (0, buildReporter_1.reportCapturedConsoleMessage)(reporter, level, message);
79
+ }
80
+ };
81
+ if (selectedReporter.name === "jsonl") {
82
+ cons.setConsoleMessageSink(captureLegacyConsoleMessage);
83
+ }
84
+ else {
85
+ cons.setConsoleMessageObserver((level, message) => {
86
+ previousConsoleMessageObserver?.(level, message);
87
+ captureLegacyConsoleMessage(level, message);
88
+ });
89
+ }
90
+ return {
91
+ reporter,
92
+ initialize: (filePath) => {
93
+ (0, node_fs_1.writeFileSync)(filePath, pendingBuildReportLines.length === 0 ? "" : `${pendingBuildReportLines.join("\n")}\n`, "utf-8");
94
+ pendingBuildReportLines.length = 0;
95
+ buildReportFilePath = filePath;
96
+ },
97
+ reportFailure: (error) => {
98
+ if (buildReportFilePath === undefined) {
99
+ return;
100
+ }
101
+ try {
102
+ archivedReporter.message({
103
+ type: "build.failed",
104
+ data: {
105
+ message: error instanceof Error ? error.message : String(error),
106
+ },
107
+ humanReadable: () => undefined,
108
+ });
109
+ }
110
+ catch {
111
+ // Preserve the original build failure if the archival write also fails.
112
+ }
113
+ },
114
+ dispose: () => {
115
+ cons.setConsoleMessageSink(previousConsoleMessageSink);
116
+ cons.setConsoleMessageObserver(previousConsoleMessageObserver);
117
+ },
118
+ };
119
+ }
120
+ async function buildCore(manifestPath, options, reporter = new buildReporter_1.HumanBuildReporter()) {
121
+ const reportSession = createBuildReportSession(reporter);
122
+ try {
123
+ await executeBuildCore(manifestPath, options, reportSession.reporter, reportSession.initialize);
124
+ }
125
+ catch (error) {
126
+ reportSession.reportFailure(error);
127
+ throw error;
128
+ }
129
+ finally {
130
+ reportSession.dispose();
131
+ }
132
+ }
133
+ async function executeBuildCore(manifestPath, options, reporter, initializeBuildReport) {
50
134
  const buildStartTime = Date.now();
51
135
  let project;
52
136
  let projectLoadOptions = (0, parseOptions_1.parseBuildOptions)(manifestPath, options);
53
137
  const loadStartTime = Date.now();
54
138
  project = project_1.TicbuildProject.loadFromManifest(projectLoadOptions);
55
139
  const loadDuration = Date.now() - loadStartTime;
56
- // Set up build log file
140
+ // Set up build log and structured report files.
57
141
  const objDir = await project.resolvedCore.resolveObjPath();
58
142
  await (0, fileSystem_1.ensureDir)(objDir);
59
143
  const logFilePath = project.resolvedCore.resolveObjPath(`build.log`);
144
+ initializeBuildReport(project.resolvedCore.resolveObjPath(buildReporter_1.buildReportFileName));
60
145
  if (logFilePath) {
61
146
  // Initialize the log file from scratch otherwise you get a huge file over time.
62
147
  (0, node_fs_1.writeFileSync)(logFilePath, "", "utf-8");
63
148
  }
64
149
  cons.setLogFile(logFilePath);
65
- cons.h1("Project loaded from:");
66
- cons.info(` ${project.resolvedCore.manifestPath}`);
150
+ const resolvedManifestSourcePath = project.resolvedCore.manifestPath;
151
+ reporter.message({
152
+ type: "project.loadedFrom",
153
+ data: {
154
+ manifestPath: resolvedManifestSourcePath,
155
+ },
156
+ humanReadable: () => {
157
+ cons.h1("Project loaded from:");
158
+ cons.info(` ${resolvedManifestSourcePath}`);
159
+ },
160
+ });
67
161
  //cons.dim(` (loaded in ${loadDuration}ms)`);
68
- await syncManifestSchema(project);
162
+ await syncManifestSchema(project, reporter);
69
163
  // output variables
70
164
  const variablesOutputPath = project.resolvedCore.resolveObjPath("variables.json");
71
165
  const variablesObj = {};
@@ -74,19 +168,33 @@ async function buildCore(manifestPath, options) {
74
168
  }
75
169
  await (0, fileSystem_1.writeTextFile)(variablesOutputPath, JSON.stringify(variablesObj, null, 2), "utf-8");
76
170
  const outputPath = project.resolvedCore.resolveObjPath("resolvedManifest.ticbuild.jsonc");
77
- cons.h1("Outputting resolved manifest to");
78
- cons.info(` ${outputPath}`);
171
+ reporter.message({
172
+ type: "manifest.resolved",
173
+ data: {
174
+ resolvedManifestPath: outputPath,
175
+ },
176
+ humanReadable: () => {
177
+ cons.h1("Outputting resolved manifest to");
178
+ cons.info(` ${outputPath}`);
179
+ },
180
+ });
79
181
  const json = JSON.stringify(project.resolvedCore.manifest, null, 2);
80
182
  const objDirPath = await project.resolvedCore.resolveObjPath();
81
183
  await (0, fileSystem_1.ensureDir)(objDirPath);
82
184
  await (0, fileSystem_1.writeTextFile)(outputPath, json, "utf-8");
83
185
  // import resources.
84
- cons.h1("Loading imported resources...");
186
+ reporter.message({
187
+ type: "comment",
188
+ data: {
189
+ message: "Loading imported resources...",
190
+ },
191
+ humanReadable: () => cons.h1("Loading imported resources..."),
192
+ });
85
193
  const importStartTime = Date.now();
86
194
  await project.loadImports();
87
195
  const importDuration = Date.now() - importStartTime;
88
196
  //cons.dim(` (imported in ${importDuration}ms)`);
89
- warnExplicitCodeBanks(project);
197
+ warnExplicitCodeBanks(project, reporter);
90
198
  const importsLogPath = project.resolvedCore.resolveObjPath("imports.log");
91
199
  const importsLines = [];
92
200
  for (const [identifier, resource] of project.resourceMgr.items.entries()) {
@@ -99,7 +207,7 @@ async function buildCore(manifestPath, options) {
99
207
  const codeRequests = getLuaCodeAssemblyRequests(project, identifier);
100
208
  const stats = resource.getCodeSizeStats(project.resolvedCore);
101
209
  const compressedOutputs = await getLuaCompressedCodeOutputs(project, resource, codeRequests);
102
- logLuaCodeSize(identifier, stats, codeRequests, compressedOutputs);
210
+ logLuaCodeSize(reporter, identifier, stats, codeRequests, compressedOutputs);
103
211
  importsLines.push(` Code stats:`);
104
212
  importsLines.push(` Input : ${(0, utils_1.formatBytes)(stats.inputBytes)}`);
105
213
  importsLines.push(` Preprocessed : ${(0, utils_1.formatBytes)(stats.preprocessedBytes)}`);
@@ -108,12 +216,14 @@ async function buildCore(manifestPath, options) {
108
216
  importsLines.push(` Compressed : ${(0, utils_1.formatBytes)(compressedOutputs[0].bytes.length)}`);
109
217
  }
110
218
  const artifacts = resource.getCodeArtifacts(project.resolvedCore);
219
+ reportLuaMinification(reporter, identifier, artifacts.minificationReport);
111
220
  const preprocessedPath = project.resolvedCore.resolveObjPath(`${identifier}.01.preprocessed.lua`);
112
221
  const minifiedPath = project.resolvedCore.resolveObjPath(`${identifier}.02.minified.lua`);
113
222
  await (0, fileSystem_1.writeTextFile)(preprocessedPath, artifacts.preprocessedSource, "utf-8");
114
223
  await (0, fileSystem_1.writeTextFile)(minifiedPath, artifacts.minifiedSource, "utf-8");
115
224
  importsLines.push(` Wrote: ${preprocessedPath}`);
116
225
  importsLines.push(` Wrote: ${minifiedPath}`);
226
+ appendLuaMinificationLog(importsLines, artifacts.minificationReport);
117
227
  if (compressedOutputs.length > 0) {
118
228
  const compressedPath = project.resolvedCore.resolveObjPath(`${identifier}.03.compressed.bin`);
119
229
  await (0, fileSystem_1.writeBinaryFile)(compressedPath, compressedOutputs[0].bytes);
@@ -147,8 +257,8 @@ async function buildCore(manifestPath, options) {
147
257
  const assemblyOutput = await project.assembleOutput();
148
258
  const { output, chunks } = assemblyOutput;
149
259
  const assembleDuration = Date.now() - assembleStartTime;
150
- warnDeprecatedChunks(assemblyOutput);
151
- warnNonstandardCodeExtensions(assemblyOutput);
260
+ warnDeprecatedChunks(assemblyOutput, reporter);
261
+ warnNonstandardCodeExtensions(assemblyOutput, reporter);
152
262
  const outDir = await project.resolvedCore.resolveBinPath();
153
263
  await (0, fileSystem_1.ensureDir)(outDir);
154
264
  const outputFilePath = project.resolvedCore.getOutputFilePath();
@@ -156,11 +266,21 @@ async function buildCore(manifestPath, options) {
156
266
  const writeStartTime = Date.now();
157
267
  await (0, fileSystem_1.writeBinaryFile)(outputFilePath, output);
158
268
  const writeDuration = Date.now() - writeStartTime;
159
- logCartStats(assemblyOutput);
269
+ logCartStats(assemblyOutput, reporter);
160
270
  const totalDuration = Date.now() - buildStartTime;
161
- cons.success(`Build completed successfully in ${totalDuration}ms.`);
162
- cons.info(` Log : ${logFilePath}`);
163
- cons.info(` Cart: ${outputFilePath}`);
271
+ reporter.message({
272
+ type: "build.completed",
273
+ data: {
274
+ durationMs: totalDuration,
275
+ logPath: logFilePath,
276
+ cartPath: outputFilePath,
277
+ },
278
+ humanReadable: () => {
279
+ cons.success(`Build completed successfully in ${totalDuration}ms.`);
280
+ cons.info(` Log : ${logFilePath}`);
281
+ cons.info(` Cart: ${outputFilePath}`);
282
+ },
283
+ });
164
284
  }
165
285
  function getBundledManifestSchemaPath() {
166
286
  return path.resolve(__dirname, "..", "..", "ticbuild.schema.json");
@@ -168,7 +288,65 @@ function getBundledManifestSchemaPath() {
168
288
  function getManagedManifestSchemaPath(project) {
169
289
  return (0, fileSystem_2.canonicalizePath)(path.join(project.resolvedCore.projectDir, ".ticbuild", "ticbuild.schema.json"));
170
290
  }
171
- async function syncManifestSchema(project) {
291
+ function reportDiagnostic(reporter, severity, message) {
292
+ reporter.message({
293
+ type: "diagnostic",
294
+ data: {
295
+ severity,
296
+ message,
297
+ },
298
+ humanReadable: () => {
299
+ if (severity === "warning") {
300
+ cons.warning(message);
301
+ }
302
+ else {
303
+ cons.error(message);
304
+ }
305
+ },
306
+ });
307
+ }
308
+ function omittedAliasSummary(report) {
309
+ const ruleNames = ["aliasLiterals", "aliasRepeatedExpressions"];
310
+ return ruleNames
311
+ .filter((rule) => report.rules[rule].omitted > 0)
312
+ .map((rule) => `${rule}=${report.rules[rule].omitted}`)
313
+ .join(", ");
314
+ }
315
+ function reportLuaMinification(reporter, importName, report) {
316
+ if (report.constrainedFunctions.length === 0)
317
+ return;
318
+ reporter.message({
319
+ type: "lua.minification",
320
+ data: {
321
+ importName,
322
+ localLimit: report.localLimit,
323
+ constrainedFunctions: report.constrainedFunctions,
324
+ },
325
+ humanReadable: () => {
326
+ report.constrainedFunctions.forEach((fn) => {
327
+ const omittedBytes = fn.rules.aliasLiterals.estimatedBytesOmitted +
328
+ fn.rules.aliasRepeatedExpressions.estimatedBytesOmitted;
329
+ cons.warning(`Lua minification local budget reached in ${fn.functionName} ` +
330
+ `(minifier input line ${fn.sourceLine}): ${fn.peakActiveLocals}/${fn.localLimit} active locals; ` +
331
+ `omitted ${omittedAliasSummary(fn)} (${omittedBytes} estimated bytes not saved).`);
332
+ cons.info(` Peak composition: ${fn.existingLocalsAtPeak} existing, ${fn.generatedLocalsAtPeak} generated. ` +
333
+ `Reduce simultaneously active locals or narrow their scopes to admit more aliases.`);
334
+ });
335
+ },
336
+ });
337
+ }
338
+ function appendLuaMinificationLog(lines, report) {
339
+ if (report.constrainedFunctions.length === 0)
340
+ return;
341
+ lines.push(` Lua minification local budget:`);
342
+ report.constrainedFunctions.forEach((fn) => {
343
+ const omittedBytes = fn.rules.aliasLiterals.estimatedBytesOmitted + fn.rules.aliasRepeatedExpressions.estimatedBytesOmitted;
344
+ lines.push(` ${fn.functionName} (line ${fn.sourceLine}): peak ${fn.peakActiveLocals}/${fn.localLimit}; ` +
345
+ `existing ${fn.existingLocalsAtPeak}; generated ${fn.generatedLocalsAtPeak}; ` +
346
+ `omitted ${omittedAliasSummary(fn)}; estimated bytes not saved ${omittedBytes}`);
347
+ });
348
+ }
349
+ async function syncManifestSchema(project, reporter) {
172
350
  if (project.resolvedCore.manifest.project.autoUpdateManifestSchema === false) {
173
351
  return;
174
352
  }
@@ -180,12 +358,12 @@ async function syncManifestSchema(project) {
180
358
  const usesManagedSchemaPath = resolvedSchemaPath === managedSchemaPath;
181
359
  if (!usesManagedSchemaPath) {
182
360
  if (!(0, fileSystem_1.fileExists)(resolvedSchemaPath)) {
183
- cons.warning(`Manifest $schema points elsewhere and is missing: ${schemaRef}`);
361
+ reportDiagnostic(reporter, "warning", `Manifest $schema points elsewhere and is missing: ${schemaRef}`);
184
362
  return;
185
363
  }
186
364
  const existingSchema = await (0, fileSystem_1.readTextFileAsync)(resolvedSchemaPath, "utf-8");
187
365
  if (existingSchema !== bundledSchema) {
188
- cons.warning(`Manifest $schema points elsewhere and differs from bundled schema: ${schemaRef}`);
366
+ reportDiagnostic(reporter, "warning", `Manifest $schema points elsewhere and differs from bundled schema: ${schemaRef}`);
189
367
  }
190
368
  return;
191
369
  }
@@ -197,25 +375,45 @@ async function syncManifestSchema(project) {
197
375
  }
198
376
  await (0, fileSystem_1.ensureDir)(path.dirname(managedSchemaPath));
199
377
  await (0, fileSystem_1.writeTextFile)(managedSchemaPath, bundledSchema, "utf-8");
200
- cons.info(`Synced manifest schema: ${managedSchemaPath}`);
378
+ const message = `Synced manifest schema: ${managedSchemaPath}`;
379
+ reporter.message({
380
+ type: "comment",
381
+ data: {
382
+ message,
383
+ },
384
+ humanReadable: () => cons.info(message),
385
+ });
201
386
  }
202
- function logCartStats(assemblyOutput) {
203
- const cartStatsLines = buildCartStatsLines(assemblyOutput.chunks.map((chunk) => ({
387
+ function logCartStats(assemblyOutput, reporter) {
388
+ const cartUsage = buildCartUsage(assemblyOutput.chunks.map((chunk) => ({
204
389
  chunkType: chunk.chunkType,
205
390
  bank: chunk.bank,
206
391
  size: chunk.data.length,
207
- })), "", assemblyOutput.output.length);
392
+ })), assemblyOutput.output.length);
393
+ const cartStatsLines = formatCartUsageLines(cartUsage, "");
208
394
  if (cartStatsLines.length === 0) {
209
395
  return;
210
396
  }
211
- cons.h1(cartStatsLines[0]);
212
- for (const line of cartStatsLines.slice(1)) {
213
- cons.info(line);
214
- }
397
+ reporter.message({
398
+ type: "cart.usage",
399
+ data: cartUsage,
400
+ humanReadable: () => {
401
+ cons.h1(cartStatsLines[0]);
402
+ for (const line of cartStatsLines.slice(1)) {
403
+ cons.info(line);
404
+ }
405
+ },
406
+ });
215
407
  }
216
408
  function buildCartStatsLines(chunks, indent, totalSizeOverride) {
409
+ return formatCartUsageLines(buildCartUsage(chunks, totalSizeOverride), indent);
410
+ }
411
+ function buildCartUsage(chunks, totalSizeOverride) {
217
412
  if (chunks.length === 0) {
218
- return [];
413
+ return {
414
+ chunks: [],
415
+ totalSizeBytes: totalSizeOverride ?? 0,
416
+ };
219
417
  }
220
418
  const sizeByType = new Map();
221
419
  for (const chunk of chunks) {
@@ -225,32 +423,41 @@ function buildCartStatsLines(chunks, indent, totalSizeOverride) {
225
423
  const rows = Array.from(sizeByType.entries()).map(([chunkKey, size]) => {
226
424
  const { chunkType, bank } = parseChunkKey(chunkKey);
227
425
  const info = tic80_1.kTic80CartChunkTypes.coerceByKey(chunkType);
228
- const capacity = info ? info.sizePerBank : 0;
229
426
  return {
230
- chunkKey,
231
- size,
232
- capacity,
427
+ chunkType,
428
+ bank,
429
+ sizeBytes: size,
430
+ capacityBytes: info ? info.sizePerBank : null,
233
431
  };
234
432
  });
235
433
  const totalSize = totalSizeOverride ?? chunks.reduce((sum, chunk) => sum + chunk.size, 0);
236
- const labelWidth = Math.max(...rows.map((r) => r.chunkKey.length), 5);
237
- const sizeWidth = Math.max(...rows.map((r) => (0, utils_1.formatBytes)(r.size).length), 5);
238
- const capWidth = Math.max(...rows.map((r) => (r.capacity > 0 ? (0, utils_1.formatBytes)(r.capacity).length : 3)), 3);
434
+ return {
435
+ chunks: rows,
436
+ totalSizeBytes: totalSize,
437
+ };
438
+ }
439
+ function formatCartUsageLines(usage, indent) {
440
+ if (usage.chunks.length === 0) {
441
+ return [];
442
+ }
443
+ const labelWidth = Math.max(...usage.chunks.map((row) => formatChunkKey(row.chunkType, row.bank).length), 5);
444
+ const sizeWidth = Math.max(...usage.chunks.map((row) => (0, utils_1.formatBytes)(row.sizeBytes).length), 5);
445
+ const capWidth = Math.max(...usage.chunks.map((row) => (row.capacityBytes !== null ? (0, utils_1.formatBytes)(row.capacityBytes).length : 3)), 3);
239
446
  const lines = [];
240
447
  lines.push(`${indent}Chunk usage:`);
241
- for (const row of rows) {
242
- const label = row.chunkKey.padEnd(labelWidth, " ");
243
- const sizeStr = (0, utils_1.formatBytes)(row.size).padStart(sizeWidth, " ");
244
- const capStrRaw = row.capacity > 0 ? (0, utils_1.formatBytes)(row.capacity) : "n/a";
448
+ for (const row of usage.chunks) {
449
+ const label = formatChunkKey(row.chunkType, row.bank).padEnd(labelWidth, " ");
450
+ const sizeStr = (0, utils_1.formatBytes)(row.sizeBytes).padStart(sizeWidth, " ");
451
+ const capStrRaw = row.capacityBytes !== null ? (0, utils_1.formatBytes)(row.capacityBytes) : "n/a";
245
452
  const capStr = capStrRaw.padStart(capWidth, " ");
246
- const meter = row.capacity > 0 ? formatUsageMeter(row.size, row.capacity) : "";
247
- const usage = row.capacity > 0 ? `${meter} ${formatPercent(row.size, row.capacity)}` : "";
248
- lines.push(`${indent} ${label} ${sizeStr} / ${capStr}${usage ? " " + usage : ""}`);
453
+ const meter = row.capacityBytes !== null ? formatUsageMeter(row.sizeBytes, row.capacityBytes) : "";
454
+ const usageText = row.capacityBytes !== null ? `${meter} ${formatPercent(row.sizeBytes, row.capacityBytes)}` : "";
455
+ lines.push(`${indent} ${label} ${sizeStr} / ${capStr}${usageText ? " " + usageText : ""}`);
249
456
  }
250
- lines.push(`${indent}Total cart size: ${(0, utils_1.formatBytes)(totalSize)}`);
457
+ lines.push(`${indent}Total cart size: ${(0, utils_1.formatBytes)(usage.totalSizeBytes)}`);
251
458
  return lines;
252
459
  }
253
- function warnDeprecatedChunks(assemblyOutput) {
460
+ function warnDeprecatedChunks(assemblyOutput, reporter) {
254
461
  const warned = new Set();
255
462
  for (const chunk of assemblyOutput.chunks) {
256
463
  const info = tic80_1.kTic80CartChunkTypes.coerceByKey(chunk.chunkType);
@@ -262,16 +469,16 @@ function warnDeprecatedChunks(assemblyOutput) {
262
469
  continue;
263
470
  }
264
471
  warned.add(key);
265
- cons.warning(`Deprecated chunk emitted: ${key}`);
472
+ reportDiagnostic(reporter, "warning", `Deprecated chunk emitted: ${key}`);
266
473
  }
267
474
  }
268
- function warnNonstandardCodeExtensions(assemblyOutput) {
475
+ function warnNonstandardCodeExtensions(assemblyOutput, reporter) {
269
476
  const nativeCodeBankCount = tic80_1.kTic80CartChunkTypes.byKey.CODE.bankCount;
270
477
  const extendedCodeBank = assemblyOutput.chunks
271
478
  .filter((chunk) => chunk.chunkType === "CODE" && chunk.bank >= nativeCodeBankCount)
272
479
  .reduce((maxBank, chunk) => Math.max(maxBank, chunk.bank), -1);
273
480
  if (extendedCodeBank >= 0) {
274
- cons.warning(`Non-standard TIC-80 extension used: CODE emits bank ${extendedCodeBank}. Stock TIC-80 supports CODE banks 0..${nativeCodeBankCount - 1}; this cart requires the private TIC-80 build.`);
481
+ reportDiagnostic(reporter, "warning", `Non-standard TIC-80 extension used: CODE emits bank ${extendedCodeBank}. Stock TIC-80 supports CODE banks 0..${nativeCodeBankCount - 1}; this cart requires the private TIC-80 build.`);
275
482
  }
276
483
  const nativeCompressedBankCount = tic80_1.kTic80CartChunkTypes.byKey.CODE_COMPRESSED.bankCount;
277
484
  const compressedCodeChunks = assemblyOutput.chunks.filter((chunk) => chunk.chunkType === "CODE_COMPRESSED" && chunk.bank >= nativeCompressedBankCount);
@@ -279,7 +486,7 @@ function warnNonstandardCodeExtensions(assemblyOutput) {
279
486
  return;
280
487
  }
281
488
  const maxCompressedBank = compressedCodeChunks.reduce((maxBank, chunk) => Math.max(maxBank, chunk.bank), -1);
282
- cons.warning(`Non-standard TIC-80 extension used: CODE_COMPRESSED emits bank ${maxCompressedBank}. Stock TIC-80 supports one CODE_COMPRESSED chunk; this cart requires the private TIC-80 build.`);
489
+ reportDiagnostic(reporter, "warning", `Non-standard TIC-80 extension used: CODE_COMPRESSED emits bank ${maxCompressedBank}. Stock TIC-80 supports one CODE_COMPRESSED chunk; this cart requires the private TIC-80 build.`);
283
490
  }
284
491
  function getLuaCodeAssemblyRequests(project, identifier) {
285
492
  const requests = [];
@@ -320,19 +527,28 @@ async function getLuaCompressedCodeOutputs(project, resource, codeRequests) {
320
527
  }
321
528
  return outputs;
322
529
  }
323
- function logLuaCodeSize(identifier, stats, codeRequests, compressedOutputs) {
324
- const lines = buildLuaCodeSizeLines(identifier, stats, codeRequests, compressedOutputs);
325
- if (lines.length === 0) {
530
+ function logLuaCodeSize(reporter, identifier, stats, codeRequests, compressedOutputs) {
531
+ const report = buildLuaCodeSizeReport(identifier, stats, codeRequests, compressedOutputs);
532
+ if (!report) {
326
533
  return;
327
534
  }
328
- cons.h1(lines[0]);
329
- for (const line of lines.slice(1)) {
330
- cons.info(line);
331
- }
535
+ reporter.message({
536
+ type: "lua.codeSize",
537
+ data: {
538
+ importName: identifier,
539
+ chunks: report.chunks,
540
+ },
541
+ humanReadable: () => {
542
+ cons.h1(report.lines[0]);
543
+ for (const line of report.lines.slice(1)) {
544
+ cons.info(line);
545
+ }
546
+ },
547
+ });
332
548
  }
333
- function buildLuaCodeSizeLines(identifier, stats, codeRequests, compressedOutputs) {
549
+ function buildLuaCodeSizeReport(identifier, stats, codeRequests, compressedOutputs) {
334
550
  if (codeRequests.length === 0) {
335
- return [];
551
+ return undefined;
336
552
  }
337
553
  const codeInfo = tic80_1.kTic80CartChunkTypes.byKey.CODE;
338
554
  const compressedInfo = tic80_1.kTic80CartChunkTypes.byKey.CODE_COMPRESSED;
@@ -349,9 +565,12 @@ function buildLuaCodeSizeLines(identifier, stats, codeRequests, compressedOutput
349
565
  }
350
566
  const rows = [
351
567
  {
568
+ chunkType: "CODE",
352
569
  label: "CODE",
353
- size: stats.minifiedBytes,
354
- capacity: codeCapacity,
570
+ sizeBytes: stats.minifiedBytes,
571
+ capacityBytes: codeCapacity,
572
+ banksUsed: codeBankCount,
573
+ banksAvailable: codeBankLimit,
355
574
  note: codeBankNote,
356
575
  },
357
576
  ...compressedOutputs.map((output) => {
@@ -370,29 +589,36 @@ function buildLuaCodeSizeLines(identifier, stats, codeRequests, compressedOutput
370
589
  compressedBankNote += `; non-standard, stock TIC-80 max ${compressedInfo.bankCount}`;
371
590
  }
372
591
  return {
592
+ chunkType: "CODE_COMPRESSED",
373
593
  label: "CODE_COMPRESSED",
374
- size: output.bytes.length,
375
- capacity: compressedCapacity,
594
+ sizeBytes: output.bytes.length,
595
+ capacityBytes: compressedCapacity,
596
+ banksUsed: compressedBankCount,
597
+ banksAvailable: compressedBankLimit,
598
+ compressionMode: output.compressionMode,
376
599
  note: compressedBankNote,
377
600
  };
378
601
  }),
379
602
  ];
380
603
  const labelWidth = Math.max(...rows.map((row) => row.label.length));
381
- const sizeWidth = Math.max(...rows.map((row) => (0, utils_1.formatBytes)(row.size).length));
382
- const capWidth = Math.max(...rows.map((row) => (0, utils_1.formatBytes)(row.capacity).length));
604
+ const sizeWidth = Math.max(...rows.map((row) => (0, utils_1.formatBytes)(row.sizeBytes).length));
605
+ const capWidth = Math.max(...rows.map((row) => (0, utils_1.formatBytes)(row.capacityBytes).length));
383
606
  const lines = [`Lua code size: ${identifier}`];
384
607
  for (const row of rows) {
385
608
  const label = row.label.padEnd(labelWidth, " ");
386
- const size = (0, utils_1.formatBytes)(row.size).padStart(sizeWidth, " ");
387
- const capacity = (0, utils_1.formatBytes)(row.capacity).padStart(capWidth, " ");
609
+ const size = (0, utils_1.formatBytes)(row.sizeBytes).padStart(sizeWidth, " ");
610
+ const capacity = (0, utils_1.formatBytes)(row.capacityBytes).padStart(capWidth, " ");
388
611
  lines.push(` ${label} ${size} / ${capacity} ${row.note}`);
389
612
  }
390
- return lines;
613
+ return {
614
+ lines,
615
+ chunks: rows.map(({ label, note, ...entry }) => entry),
616
+ };
391
617
  }
392
618
  // warn if any assembly blocks specify explicit banks for CODE chunks.
393
619
  // generally you let ticbuild split code across multiple banks automatically.
394
620
  // so specifying banks is weird, but technically allowed.
395
- function warnExplicitCodeBanks(project) {
621
+ function warnExplicitCodeBanks(project, reporter) {
396
622
  if (!project.resourceMgr) {
397
623
  return;
398
624
  }
@@ -422,7 +648,7 @@ function warnExplicitCodeBanks(project) {
422
648
  continue;
423
649
  }
424
650
  const key = formatChunkKey("CODE", block.bank);
425
- cons.warning(`Explicit bank specified for CODE chunk: ${key}`);
651
+ reportDiagnostic(reporter, "warning", `Explicit bank specified for CODE chunk: ${key}`);
426
652
  }
427
653
  }
428
654
  function formatChunkKey(chunkType, bank) {