(args: string[])
| 204 | } |
| 205 | |
| 206 | export const trace = async (args: string[]): Promise<void> => { |
| 207 | const packageDir = resolve(args[0] ?? process.cwd()) |
| 208 | const config = getConfig() |
| 209 | |
| 210 | if (!config.tsconfig) { |
| 211 | // This message should go to console.error and also be captured if needed, |
| 212 | // but since it exits, direct console.error is fine. |
| 213 | console.error( |
| 214 | `attest trace must be run from a directory with a tsconfig.json file` |
| 215 | ) |
| 216 | process.exit(1) |
| 217 | } |
| 218 | |
| 219 | const traceDir = resolve(config.cacheDir, "trace") |
| 220 | ensureDir(traceDir) |
| 221 | |
| 222 | outputCapture.clear() |
| 223 | const initialMessages: string[] = [] |
| 224 | |
| 225 | initialMessages.push(`⏳ Gathering type trace data for ${packageDir}...`) |
| 226 | outputCapture.write(initialMessages[0]) // This goes to console and buffer |
| 227 | |
| 228 | const tracingOutput = generateTraceData(traceDir, config.tsconfig, packageDir) |
| 229 | |
| 230 | const traceFile = join(traceDir, "trace.json") |
| 231 | |
| 232 | if (!existsSync(traceFile)) { |
| 233 | outputCapture.write( |
| 234 | `❌ No trace data found (expected a file at ${traceFile}). TSC output:\n${tracingOutput}` |
| 235 | ) |
| 236 | const summaryPath = join(traceDir, "summary.txt") |
| 237 | writeFile(summaryPath, outputCapture.getBuffer()) |
| 238 | return |
| 239 | } |
| 240 | |
| 241 | // This message will be followed by the progress bar on the next line |
| 242 | outputCapture.write(`⏳ Analyzing type trace data for ${packageDir}...`) |
| 243 | analyzeTypeInstantiations(traceDir) // This function now handles its own progress display |
| 244 | |
| 245 | // Collect all messages for the summary file |
| 246 | // The progress bar output is not part of outputCapture.getLines() |
| 247 | const analysisMessages = outputCapture |
| 248 | .getLines() |
| 249 | .slice(initialMessages.length + 1) // +1 for the "Analyzing..." message |
| 250 | |
| 251 | const summaryContent = [ |
| 252 | ...initialMessages, |
| 253 | tracingOutput, |
| 254 | outputCapture.getLines()[initialMessages.length], // The "Analyzing..." message |
| 255 | ...analysisMessages |
| 256 | ].join("\n") |
| 257 | |
| 258 | const summaryPath = join(traceDir, "summary.txt") |
| 259 | writeFile(summaryPath, summaryContent) |
| 260 | } |
| 261 | |
| 262 | const generateTraceData = ( |
| 263 | traceDir: string, |
nothing calls this directly
no test coverage detected
searching dependent graphs…