@ark/attest 0.44.3 → 0.44.5

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 +48 -14
  2. package/package.json +4 -4
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,39 @@ export const trace = async (args) => {
16
32
  }
17
33
  const traceDir = resolve(config.cacheDir, "trace");
18
34
  ensureDir(traceDir);
35
+ let tracingOutput = "";
36
+ outputCapture.clear();
19
37
  try {
20
- console.log(`⏳ Gathering type trace data for ${packageDir}...`);
21
- generateTraceData(traceDir, config.tsconfig, packageDir);
38
+ outputCapture.write(`⏳ Gathering type trace data for ${packageDir}...`);
39
+ tracingOutput = generateTraceData(traceDir, config.tsconfig, packageDir);
22
40
  }
23
41
  catch (e) {
24
42
  console.error(String(e));
25
43
  }
26
44
  finally {
27
- console.log(`⏳ Analyzing type trace data for ${packageDir}...`);
45
+ outputCapture.write(`⏳ Analyzing type trace data for ${packageDir}...`);
28
46
  analyzeTypeInstantiations(traceDir);
47
+ // Write summary file containing our messages followed by compiler output
48
+ // This ensures the initial message comes first in the file
49
+ const summaryPath = join(traceDir, "summary.txt");
50
+ const summaryContent = outputCapture.getBuffer().split("\n")[0] +
51
+ "\n" +
52
+ tracingOutput +
53
+ "\n" +
54
+ outputCapture.getBuffer().split("\n").slice(1).join("\n");
55
+ writeFile(summaryPath, summaryContent);
29
56
  }
30
57
  };
31
58
  const generateTraceData = (traceDir, tsconfigPath, packageDir) => {
32
- execSync(`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`, {
59
+ // Capture the output instead of just displaying it
60
+ const output = execSync(`${baseDiagnosticTscCmd} --project ${tsconfigPath} --generateTrace ${traceDir}`, {
33
61
  cwd: packageDir,
34
- stdio: "inherit"
62
+ stdio: "pipe", // Capture output instead of inheriting
63
+ encoding: "utf-8" // Return as string
35
64
  });
65
+ // Display the output to the console as before
66
+ process.stdout.write(output);
67
+ return output;
36
68
  };
37
69
  const initializeAnalysisContext = (traceDir) => {
38
70
  const tsServer = TsServer.instance;
@@ -58,7 +90,7 @@ const filterDurationEntries = (ctx) => {
58
90
  entry.args.path &&
59
91
  entry.args.pos &&
60
92
  entry.args.end);
61
- console.log(`Found ${ctx.durationEntries.length} traces with duration information`);
93
+ outputCapture.write(`Found ${ctx.durationEntries.length} traces with duration information`);
62
94
  };
63
95
  const processDurationEntry = (entry, ctx) => {
64
96
  try {
@@ -250,13 +282,14 @@ const analyzeTypeInstantiations = (traceDir) => {
250
282
  // Sort and rank functions
251
283
  sortAndRankFunctions(ctx);
252
284
  // Display summaries to console
253
- console.log("\n📊 Performance Analysis - Top Individual Calls:\n");
285
+ outputCapture.write("\n📊 Performance Analysis - Top Individual Calls:\n");
254
286
  displayIndividualSummary(ungroupedStats);
255
- console.log("\n📊 Performance Analysis - Functions by Self Time:\n");
287
+ outputCapture.write("\n📊 Performance Analysis - Functions by Self Time:\n");
256
288
  displayGroupedSummary(ctx.allFunctions);
257
289
  // Write CSV reports
258
290
  const rangesCsvPath = join(traceDir, "ranges.csv");
259
291
  const namesCsvPath = join(traceDir, "names.csv");
292
+ const summaryPath = join(traceDir, "summary.txt");
260
293
  // Export individual ranges to CSV
261
294
  writeToCsv(rangesCsvPath, ["Function Name", "Self (ms)", "Duration (ms)", "Location"], ungroupedStats.map(stat => [
262
295
  stat.functionName,
@@ -288,9 +321,10 @@ const analyzeTypeInstantiations = (traceDir) => {
288
321
  (topUsage.selfTime / 1000).toFixed(3)
289
322
  ];
290
323
  }));
291
- console.log(`\n✅ Analysis complete! Results exported to:\n` +
324
+ outputCapture.write(`\n✅ Analysis complete! Results exported to:\n` +
292
325
  ` - ${rangesCsvPath} (individual calls)\n` +
293
- ` - ${namesCsvPath} (grouped by function name)`);
326
+ ` - ${namesCsvPath} (grouped by function name)\n` +
327
+ ` - ${summaryPath} (complete analysis report)`);
294
328
  };
295
329
  /**
296
330
  * Collect statistics for individual (ungrouped) calls
@@ -322,7 +356,7 @@ const displayIndividualSummary = (stats) => {
322
356
  const typeNameFormatted = formatTypeName(stat.functionName, 20);
323
357
  const selfTimeMs = (stat.selfTime / 1000).toFixed(2).padStart(15);
324
358
  const location = formatLocation(stat.callSite);
325
- console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${selfTimeMs} | ${location}`);
359
+ outputCapture.write(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${selfTimeMs} | ${location}`);
326
360
  });
327
361
  };
328
362
  /**
@@ -343,8 +377,8 @@ const displayTableHeader = (columns) => {
343
377
  "---------------",
344
378
  ...columns.slice(3).map(col => "-".repeat(col.length))
345
379
  ].join("-|-");
346
- console.log(headerRow);
347
- console.log(separatorRow);
380
+ outputCapture.write(headerRow);
381
+ outputCapture.write(separatorRow);
348
382
  };
349
383
  /**
350
384
  * Display a combined summary of grouped functions showing both total and average times
@@ -374,7 +408,7 @@ const displayGroupedSummary = (functions) => {
374
408
  };
375
409
  const topUsageTime = (topUsage.selfTime / 1000).toFixed(2) + "ms";
376
410
  const topUsageLocation = formatLocation(`${topUsage.path}:${topUsage.pos}-${topUsage.end}`);
377
- console.log(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${totalTimeMs} | ${avgTimeMs} | ${calls} | ${topUsageLocation} (${topUsageTime})`);
411
+ outputCapture.write(`${(index + 1).toString().padStart(4)} | ${typeNameFormatted} | ${totalTimeMs} | ${avgTimeMs} | ${calls} | ${topUsageLocation} (${topUsageTime})`);
378
412
  });
379
413
  };
380
414
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.44.3",
3
+ "version": "0.44.5",
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.2",
40
- "@ark/util": "0.44.2",
41
- "arktype": "2.1.7"
39
+ "@ark/fs": "0.44.5",
40
+ "arktype": "2.1.9",
41
+ "@ark/util": "0.44.5"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "5.8.2"