MCPcopy
hub / github.com/arktypeio/arktype / trace

Function trace

ark/attest/cli/trace.ts:206–260  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

204}
205
206export 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
262const generateTraceData = (
263 traceDir: string,

Callers

nothing calls this directly

Calls 9

getConfigFunction · 0.90
ensureDirFunction · 0.90
writeFileFunction · 0.90
resolveFunction · 0.85
generateTraceDataFunction · 0.85
joinFunction · 0.85
writeMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…