|
1 | 1 | import path from 'path' |
2 | 2 | import fs from 'fs' |
3 | | -import util from 'util' |
4 | 3 |
|
5 | 4 | import { fileURLToPath } from 'node:url' |
6 | | -import { |
7 | | - checkTgz, |
8 | | - summarizeProblems, |
9 | | - getProblems, |
| 5 | +import type { |
10 | 6 | Analysis, |
11 | 7 | ProblemSummary, |
12 | 8 | Problem, |
13 | 9 | ResolutionKind, |
14 | 10 | ProblemKind, |
15 | 11 | } from 'are-the-types-wrong-core' |
| 12 | +import { |
| 13 | + checkTgz, |
| 14 | + summarizeProblems, |
| 15 | + getProblems, |
| 16 | +} from 'are-the-types-wrong-core' |
16 | 17 | import React from 'react' |
17 | 18 | import { render, Text, Box } from 'ink' |
18 | 19 |
|
@@ -81,6 +82,44 @@ function Header({ text, width }: { text: string; width: number | string }) { |
81 | 82 | ) |
82 | 83 | } |
83 | 84 |
|
| 85 | +function Traces({ |
| 86 | + analysis, |
| 87 | + subpaths, |
| 88 | +}: { |
| 89 | + analysis: Analysis |
| 90 | + subpaths: string[] |
| 91 | +}) { |
| 92 | + if (!('entrypointResolutions' in analysis)) { |
| 93 | + return null |
| 94 | + } |
| 95 | + return ( |
| 96 | + <Box flexDirection="column" width="100%"> |
| 97 | + {subpaths.map((subpath) => { |
| 98 | + const resolutionDetails = Object.entries( |
| 99 | + analysis.entrypointResolutions[subpath] |
| 100 | + ) |
| 101 | + return ( |
| 102 | + <Box width="100%" key={'traces-' + subpath} flexDirection="column"> |
| 103 | + <Text color="blue" bold> |
| 104 | + {subpath} |
| 105 | + </Text> |
| 106 | + {resolutionDetails.map(([resolutionKind, details]) => { |
| 107 | + return ( |
| 108 | + <Box width="100%" key={subpath} flexDirection="column"> |
| 109 | + <Text bold>{resolutionKind} Traces:</Text> |
| 110 | + {details.trace.map((traceLine, i) => { |
| 111 | + return <Text key={i}>{traceLine}</Text> |
| 112 | + })} |
| 113 | + </Box> |
| 114 | + ) |
| 115 | + })} |
| 116 | + </Box> |
| 117 | + ) |
| 118 | + })} |
| 119 | + </Box> |
| 120 | + ) |
| 121 | +} |
| 122 | + |
84 | 123 | function ChecksTable(props: { checks?: Checks }) { |
85 | 124 | if (!props.checks || !props.checks.analysis.containsTypes) { |
86 | 125 | return null |
@@ -170,38 +209,33 @@ function ChecksTable(props: { checks?: Checks }) { |
170 | 209 | </Box> |
171 | 210 | ) |
172 | 211 | })} |
| 212 | + <Traces analysis={analysis} subpaths={subpaths} /> |
173 | 213 | </Box> |
174 | 214 | ) |
175 | 215 | } |
176 | 216 |
|
177 | 217 | ;(async function main() { |
178 | 218 | const analysis = await checkTgz(rtkPackageTgzBytes) |
| 219 | + |
| 220 | + const checks: Checks = { |
| 221 | + analysis, |
| 222 | + problems: undefined, |
| 223 | + problemSummaries: undefined, |
| 224 | + } |
179 | 225 | if ('entrypointResolutions' in analysis) { |
180 | 226 | const problems = analysis.containsTypes ? getProblems(analysis) : undefined |
| 227 | + checks.problems = problems |
181 | 228 |
|
182 | | - // console.log( |
183 | | - // 'Analysis: ', |
184 | | - // util.inspect(analysis.entrypointResolutions, { depth: 3 }) |
185 | | - // ) |
186 | 229 | if (problems) { |
187 | | - // for (let problem of problems) { |
188 | | - // console.log('Problem: ', problem) |
189 | | - // } |
190 | 230 | const problemSummaries = analysis.containsTypes |
191 | 231 | ? summarizeProblems(problems, analysis) |
192 | 232 | : undefined |
193 | | - // if (problemSummaries) { |
194 | | - // for (let summary of problemSummaries) { |
195 | | - // console.log('Summary: ', summary) |
196 | | - // } |
197 | | - // } |
198 | | - const checks: Checks = { |
199 | | - analysis, |
200 | | - problems, |
201 | | - problemSummaries, |
202 | | - } |
203 | | - |
204 | | - render(<ChecksTable checks={checks} />) |
| 233 | + checks.problemSummaries = problemSummaries |
205 | 234 | } |
206 | 235 | } |
| 236 | + |
| 237 | + render(<ChecksTable checks={checks} />) |
| 238 | + |
| 239 | + const exitCode = checks.problems?.length ?? 0 |
| 240 | + process.exit(exitCode) |
207 | 241 | })() |
0 commit comments