Skip to content

Commit 26676b6

Browse files
committed
Add file trace logging
1 parent 265e5ec commit 26676b6

File tree

1 file changed

+58
-24
lines changed
  • examples/publish-ci/are-the-types-wrong

1 file changed

+58
-24
lines changed

examples/publish-ci/are-the-types-wrong/main.tsx

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import path from 'path'
22
import fs from 'fs'
3-
import util from 'util'
43

54
import { fileURLToPath } from 'node:url'
6-
import {
7-
checkTgz,
8-
summarizeProblems,
9-
getProblems,
5+
import type {
106
Analysis,
117
ProblemSummary,
128
Problem,
139
ResolutionKind,
1410
ProblemKind,
1511
} from 'are-the-types-wrong-core'
12+
import {
13+
checkTgz,
14+
summarizeProblems,
15+
getProblems,
16+
} from 'are-the-types-wrong-core'
1617
import React from 'react'
1718
import { render, Text, Box } from 'ink'
1819

@@ -81,6 +82,44 @@ function Header({ text, width }: { text: string; width: number | string }) {
8182
)
8283
}
8384

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+
84123
function ChecksTable(props: { checks?: Checks }) {
85124
if (!props.checks || !props.checks.analysis.containsTypes) {
86125
return null
@@ -170,38 +209,33 @@ function ChecksTable(props: { checks?: Checks }) {
170209
</Box>
171210
)
172211
})}
212+
<Traces analysis={analysis} subpaths={subpaths} />
173213
</Box>
174214
)
175215
}
176216

177217
;(async function main() {
178218
const analysis = await checkTgz(rtkPackageTgzBytes)
219+
220+
const checks: Checks = {
221+
analysis,
222+
problems: undefined,
223+
problemSummaries: undefined,
224+
}
179225
if ('entrypointResolutions' in analysis) {
180226
const problems = analysis.containsTypes ? getProblems(analysis) : undefined
227+
checks.problems = problems
181228

182-
// console.log(
183-
// 'Analysis: ',
184-
// util.inspect(analysis.entrypointResolutions, { depth: 3 })
185-
// )
186229
if (problems) {
187-
// for (let problem of problems) {
188-
// console.log('Problem: ', problem)
189-
// }
190230
const problemSummaries = analysis.containsTypes
191231
? summarizeProblems(problems, analysis)
192232
: 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
205234
}
206235
}
236+
237+
render(<ChecksTable checks={checks} />)
238+
239+
const exitCode = checks.problems?.length ?? 0
240+
process.exit(exitCode)
207241
})()

0 commit comments

Comments
 (0)