@ark/attest 0.44.4 → 0.44.6

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 (2) hide show
  1. package/out/cli/trace.js +49 -22
  2. package/package.json +3 -3
package/out/cli/trace.js CHANGED
@@ -7,6 +7,22 @@ import ts from "typescript";
7
7
  import { TsServer, getDescendants, getStringifiableType, nearestBoundingCallExpression } from "../cache/ts.js";
8
8
  import { getConfig } from "../config.js";
9
9
  import { baseDiagnosticTscCmd } from "./shared.js";
10
+ /**
11
+ * Helper to write output to both console and collect for file output
12
+ */
13
+ const outputCapture = (() => {
14
+ let buffer = [];
15
+ return {
16
+ write: (text) => {
17
+ console.log(text);
18
+ buffer.push(text);
19
+ },
20
+ getBuffer: () => buffer.join("\n"),
21
+ clear: () => {
22
+ buffer = [];
23
+ }
24
+ };
25
+ })();
10
26
  export const trace = async (args) => {
11
27
  const packageDir = resolve(args[0] ?? process.cwd());
12
28
  const config = getConfig();
@@ -16,23 +32,32 @@ export const trace = async (args) => {
16
32
  }
17
33
  const traceDir = resolve(config.cacheDir, "trace");
18
34
  ensureDir(traceDir);
19
- try {
20
- console.log(`⏳ Gathering type trace data for ${packageDir}...`);
21
- generateTraceData(traceDir, config.tsconfig, packageDir);
22
- }
23
- catch (e) {
24
- console.error(String(e));
25
- }
26
- finally {
27
- console.log(`⏳ Analyzing type trace data for ${packageDir}...`);
28
- analyzeTypeInstantiations(traceDir);
29
- }
35
+ let tracingOutput = "";
36
+ outputCapture.clear();
37
+ outputCapture.write(`⏳ Gathering type trace data for ${packageDir}...`);
38
+ tracingOutput = generateTraceData(traceDir, config.tsconfig, packageDir);
39
+ outputCapture.write(`⏳ Analyzing type trace data for ${packageDir}...`);
40
+ analyzeTypeInstantiations(traceDir);
41
+ // Write summary file containing our messages followed by compiler output
42
+ // This ensures the initial message comes first in the file
43
+ const summaryPath = join(traceDir, "summary.txt");
44
+ const summaryContent = outputCapture.getBuffer().split("\n")[0] +
45
+ "\n" +
46
+ tracingOutput +
47
+ "\n" +
48
+ outputCapture.getBuffer().split("\n").slice(1).join("\n");
49
+ writeFile(summaryPath, summaryContent);
30
50
  };
31
51
  const generateTraceData = (traceDir, tsconfigPath, packageDir) => {
32
- execSync(`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`, {
52
+ // Capture the output instead of just displaying it
53
+ const output = execSync(`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`, {
33
54
  cwd: packageDir,
34
- stdio: "inherit"
55
+ stdio: "pipe", // Capture output instead of inheriting
56
+ encoding: "utf-8" // Return as string
35
57
  });
58
+ // Display the output to the console as before
59
+ process.stdout.write(output);
60
+ return output;
36
61
  };
37
62
  const initializeAnalysisContext = (traceDir) => {
38
63
  const tsServer = TsServer.instance;
@@ -58,7 +83,7 @@ const filterDurationEntries = (ctx) => {
58
83
  entry.args.path &&
59
84
  entry.args.pos &&
60
85
  entry.args.end);
61
- console.log(`Found ${ctx.durationEntries.length} traces with duration information`);
86
+ outputCapture.write(`Found ${ctx.durationEntries.length} traces with duration information`);
62
87
  };
63
88
  const processDurationEntry = (entry, ctx) => {
64
89
  try {
@@ -250,13 +275,14 @@ const analyzeTypeInstantiations = (traceDir) => {
250
275
  // Sort and rank functions
251
276
  sortAndRankFunctions(ctx);
252
277
  // Display summaries to console
253
- console.log("\n📊 Performance Analysis - Top Individual Calls:\n");
278
+ outputCapture.write("\n📊 Performance Analysis - Top Individual Calls:\n");
254
279
  displayIndividualSummary(ungroupedStats);
255
- console.log("\n📊 Performance Analysis - Functions by Self Time:\n");
280
+ outputCapture.write("\n📊 Performance Analysis - Functions by Self Time:\n");
256
281
  displayGroupedSummary(ctx.allFunctions);
257
282
  // Write CSV reports
258
283
  const rangesCsvPath = join(traceDir, "ranges.csv");
259
284
  const namesCsvPath = join(traceDir, "names.csv");
285
+ const summaryPath = join(traceDir, "summary.txt");
260
286
  // Export individual ranges to CSV
261
287
  writeToCsv(rangesCsvPath, ["Function Name", "Self (ms)", "Duration (ms)", "Location"], ungroupedStats.map(stat => [
262
288
  stat.functionName,
@@ -288,9 +314,10 @@ const analyzeTypeInstantiations = (traceDir) => {
288
314
  (topUsage.selfTime / 1000).toFixed(3)
289
315
  ];
290
316
  }));
291
- console.log(`\n✅ Analysis complete! Results exported to:\n` +
317
+ outputCapture.write(`\n✅ Analysis complete! Results exported to:\n` +
292
318
  ` - ${rangesCsvPath} (individual calls)\n` +
293
- ` - ${namesCsvPath} (grouped by function name)`);
319
+ ` - ${namesCsvPath} (grouped by function name)\n` +
320
+ ` - ${summaryPath} (complete analysis report)`);
294
321
  };
295
322
  /**
296
323
  * Collect statistics for individual (ungrouped) calls
@@ -322,7 +349,7 @@ const displayIndividualSummary = (stats) => {
322
349
  const typeNameFormatted = formatTypeName(stat.functionName, 20);
323
350
  const selfTimeMs = (stat.selfTime / 1000).toFixed(2).padStart(15);
324
351
  const location = formatLocation(stat.callSite);
325
- console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${selfTimeMs} | ${location}`);
352
+ outputCapture.write(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${selfTimeMs} | ${location}`);
326
353
  });
327
354
  };
328
355
  /**
@@ -343,8 +370,8 @@ const displayTableHeader = (columns) => {
343
370
  "---------------",
344
371
  ...columns.slice(3).map(col => "-".repeat(col.length))
345
372
  ].join("-|-");
346
- console.log(headerRow);
347
- console.log(separatorRow);
373
+ outputCapture.write(headerRow);
374
+ outputCapture.write(separatorRow);
348
375
  };
349
376
  /**
350
377
  * Display a combined summary of grouped functions showing both total and average times
@@ -374,7 +401,7 @@ const displayGroupedSummary = (functions) => {
374
401
  };
375
402
  const topUsageTime = (topUsage.selfTime / 1000).toFixed(2) + "ms";
376
403
  const topUsageLocation = formatLocation(`${topUsage.path}:${topUsage.pos}-${topUsage.end}`);
377
- console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${totalTimeMs} | ${avgTimeMs} | ${calls} | ${topUsageLocation} (${topUsageTime})`);
404
+ outputCapture.write(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${totalTimeMs} | ${avgTimeMs} | ${calls} | ${topUsageLocation} (${topUsageTime})`);
378
405
  });
379
406
  };
380
407
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.44.4",
3
+ "version": "0.44.6",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "David Blass",
@@ -36,9 +36,9 @@
36
36
  "@typescript/analyze-trace": "0.10.1",
37
37
  "@typescript/vfs": "1.6.0",
38
38
  "prettier": "3.4.2",
39
- "@ark/fs": "0.44.4",
39
+ "@ark/fs": "0.44.5",
40
40
  "arktype": "2.1.9",
41
- "@ark/util": "0.44.4"
41
+ "@ark/util": "0.44.5"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "5.8.2"