Skip to content

Commit bddf070

Browse files
committed
Fix Ink duplicate output rendering
1 parent 7ee3688 commit bddf070

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import type {
88
Problem,
99
ResolutionKind,
1010
ProblemKind,
11-
} from 'are-the-types-wrong-core'
11+
} from '@arethetypeswrong/core'
1212
import {
1313
checkTgz,
1414
summarizeProblems,
1515
getProblems,
16-
} from 'are-the-types-wrong-core'
16+
} from '@arethetypeswrong/core'
1717
import React from 'react'
18-
import { render, Text, Box } from 'ink'
18+
import { render, Text, Box, Static } from 'ink'
1919

2020
const allResolutionKinds: ResolutionKind[] = [
2121
'node10',
@@ -34,6 +34,8 @@ const problemEmoji: Record<ProblemKind, string> = {
3434
FallbackCondition: '🐛',
3535
CJSOnlyExportsDefault: '🤨',
3636
FalseExportDefault: '❗️',
37+
UnexpectedESMSyntax: '🚭',
38+
UnexpectedCJSSyntax: '🚱',
3739
}
3840

3941
const problemShortDescriptions: Record<ProblemKind, string> = {
@@ -46,6 +48,8 @@ const problemShortDescriptions: Record<ProblemKind, string> = {
4648
FallbackCondition: `${problemEmoji.FallbackCondition} Used fallback condition`,
4749
CJSOnlyExportsDefault: `${problemEmoji.CJSOnlyExportsDefault} CJS default export`,
4850
FalseExportDefault: `${problemEmoji.FalseExportDefault} Incorrect default export`,
51+
UnexpectedESMSyntax: `${problemEmoji.UnexpectedESMSyntax} Unexpected ESM syntax`,
52+
UnexpectedCJSSyntax: `${problemEmoji.UnexpectedCJSSyntax} Unexpected CJS syntax`,
4953
}
5054

5155
const resolutionKinds: Record<ResolutionKind, string> = {
@@ -92,6 +96,7 @@ function Traces({
9296
if (!('entrypointResolutions' in analysis)) {
9397
return null
9498
}
99+
95100
return (
96101
<Box flexDirection="column" width="100%">
97102
{subpaths.map((subpath) => {
@@ -101,15 +106,27 @@ function Traces({
101106
return (
102107
<Box width="100%" key={'traces-' + subpath} flexDirection="column">
103108
<Text color="blue" bold>
104-
{subpath}
109+
Traces for Subpath: {subpath}
105110
</Text>
106111
{resolutionDetails.map(([resolutionKind, details]) => {
107112
return (
108-
<Box width="100%" key={subpath} flexDirection="column">
113+
<Box
114+
width="100%"
115+
key={`resolutionDetails-${resolutionKind}-${subpath}`}
116+
flexDirection="column"
117+
>
109118
<Text bold>{resolutionKind} Traces:</Text>
110-
{details.trace.map((traceLine, i) => {
111-
return <Text key={i}>{traceLine}</Text>
112-
})}
119+
<Box flexDirection="column">
120+
{details.trace.map((traceLine, i) => {
121+
return (
122+
<Text
123+
key={`resolutionDetails-traces-${subpath}-${resolutionKind}-${i}`}
124+
>
125+
{traceLine}
126+
</Text>
127+
)
128+
})}
129+
</Box>
113130
</Box>
114131
)
115132
})}
@@ -182,7 +199,8 @@ function ChecksTable(props: { checks?: Checks }) {
182199
} else {
183200
content = (
184201
<Text>
185-
{'✅ ' + moduleKinds[resolution?.moduleKind || '']}
202+
{'✅ ' +
203+
moduleKinds[resolution?.moduleKind?.detectedKind || '']}
186204
</Text>
187205
)
188206
}
@@ -234,7 +252,16 @@ function ChecksTable(props: { checks?: Checks }) {
234252
}
235253
}
236254

237-
render(<ChecksTable checks={checks} />)
255+
// Ink will duplicate all of its output if it is longer than the terminal height.
256+
// Known bug with the underlying rendering: https://github.com/vadimdemedes/ink/issues/48
257+
// Solution is to mark the entire content as "static" so it won't get updated, but flushed.
258+
render(
259+
<Static items={[checks]}>
260+
{(checks: Checks, index: number) => {
261+
return <ChecksTable key={`checks-${index}`} checks={checks} />
262+
}}
263+
</Static>
264+
)
238265

239266
const exitCode = checks.problems?.length ?? 0
240267
process.exit(exitCode)

examples/publish-ci/are-the-types-wrong/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "are-the-types-wrong",
33
"packageManager": "yarn@3.2.4",
44
"type": "module",
5+
"scripts": {
6+
"build": "echo Nothing to build",
7+
"test": "yarn tsx main.tsx"
8+
},
59
"dependencies": {
610
"@tanstack/react-table": "^8.7.9",
711
"ink": "^4.0.0",

0 commit comments

Comments
 (0)