Skip to content

Commit 8d364b1

Browse files
committed
refactor: replace NodeJS.WriteStream with simple Writer type
Add a simple Writer interface ({ write(s: string): void }) to avoid dependency on Node.js-specific types. This is more idiomatic for Bun while maintaining testability through the context pattern. Files updated: - types/index.ts: Add Writer type - formatters/json.ts: Use Writer - All command files: Use Writer instead of NodeJS.WriteStream
1 parent 1dfdb68 commit 8d364b1

File tree

10 files changed

+30
-19
lines changed

10 files changed

+30
-19
lines changed

packages/cli/src/commands/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { buildCommand } from "@stricli/core";
99
import type { SentryContext } from "../context.js";
1010
import { rawApiRequest } from "../lib/api-client.js";
11+
import type { Writer } from "../types/index.js";
1112

1213
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
1314

@@ -124,7 +125,7 @@ function parseHeaders(headers: string[]): Record<string, string> {
124125
* Write response headers to stdout
125126
*/
126127
function writeResponseHeaders(
127-
stdout: NodeJS.WriteStream,
128+
stdout: Writer,
128129
status: number,
129130
headers: Headers
130131
): void {
@@ -138,7 +139,7 @@ function writeResponseHeaders(
138139
/**
139140
* Write response body to stdout
140141
*/
141-
function writeResponseBody(stdout: NodeJS.WriteStream, body: unknown): void {
142+
function writeResponseBody(stdout: Writer, body: unknown): void {
142143
if (body === null || body === undefined) {
143144
return;
144145
}

packages/cli/src/commands/auth/status.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
readConfig,
1616
} from "../../lib/config.js";
1717
import { formatExpiration, maskToken } from "../../lib/formatters/human.js";
18-
import type { SentryConfig } from "../../types/index.js";
18+
import type { SentryConfig, Writer } from "../../types/index.js";
1919

2020
type StatusFlags = {
2121
readonly showToken: boolean;
@@ -25,7 +25,7 @@ type StatusFlags = {
2525
* Write token information
2626
*/
2727
function writeTokenInfo(
28-
stdout: NodeJS.WriteStream,
28+
stdout: Writer,
2929
config: SentryConfig,
3030
showToken: boolean
3131
): void {
@@ -46,7 +46,7 @@ function writeTokenInfo(
4646
/**
4747
* Write default settings
4848
*/
49-
async function writeDefaults(stdout: NodeJS.WriteStream): Promise<void> {
49+
async function writeDefaults(stdout: Writer): Promise<void> {
5050
const defaultOrg = await getDefaultOrganization();
5151
const defaultProject = await getDefaultProject();
5252

@@ -66,7 +66,7 @@ async function writeDefaults(stdout: NodeJS.WriteStream): Promise<void> {
6666
/**
6767
* Verify credentials by fetching organizations
6868
*/
69-
async function verifyCredentials(stdout: NodeJS.WriteStream): Promise<void> {
69+
async function verifyCredentials(stdout: Writer): Promise<void> {
7070
stdout.write("\nVerifying credentials...\n");
7171

7272
try {

packages/cli/src/commands/event/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type GetFlags = {
2626
* @param detectedFrom - Optional source description for auto-detection
2727
*/
2828
function writeHumanOutput(
29-
stdout: NodeJS.WriteStream,
29+
stdout: Writer,
3030
event: SentryEvent,
3131
detectedFrom?: string
3232
): void {

packages/cli/src/commands/issue/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function tryGetLatestEvent(
4343
* Write human-readable issue output
4444
*/
4545
function writeHumanOutput(
46-
stdout: NodeJS.WriteStream,
46+
stdout: Writer,
4747
issue: SentryIssue,
4848
event?: SentryEvent
4949
): void {

packages/cli/src/commands/issue/list.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function parseSort(value: string): SortValue {
4848
* Write the issue list header with column titles.
4949
*/
5050
function writeListHeader(
51-
stdout: NodeJS.WriteStream,
51+
stdout: Writer,
5252
org: string,
5353
project: string,
5454
count: number
@@ -61,10 +61,7 @@ function writeListHeader(
6161
/**
6262
* Write formatted issue rows to stdout.
6363
*/
64-
function writeIssueRows(
65-
stdout: NodeJS.WriteStream,
66-
issues: SentryIssue[]
67-
): void {
64+
function writeIssueRows(stdout: Writer, issues: SentryIssue[]): void {
6865
for (const issue of issues) {
6966
stdout.write(`${formatIssueRow(issue)}\n`);
7067
}
@@ -73,7 +70,7 @@ function writeIssueRows(
7370
/**
7471
* Write footer with usage tip.
7572
*/
76-
function writeListFooter(stdout: NodeJS.WriteStream): void {
73+
function writeListFooter(stdout: Writer): void {
7774
stdout.write(
7875
"\nTip: Use 'sentry issue get <SHORT_ID>' to view issue details.\n"
7976
);

packages/cli/src/commands/org/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type GetFlags = {
2323
* @param detectedFrom - Optional source description if org was auto-detected
2424
*/
2525
function writeHumanOutput(
26-
stdout: NodeJS.WriteStream,
26+
stdout: Writer,
2727
org: Parameters<typeof formatOrgDetails>[0],
2828
detectedFrom?: string
2929
): void {

packages/cli/src/commands/project/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type GetFlags = {
2424
* @param detectedFrom - Optional source description if project was auto-detected
2525
*/
2626
function writeHumanOutput(
27-
stdout: NodeJS.WriteStream,
27+
stdout: Writer,
2828
project: Parameters<typeof formatProjectDetails>[0],
2929
detectedFrom?: string
3030
): void {

packages/cli/src/commands/project/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ function filterByPlatform(
8282
/**
8383
* Write the column header row for project list output.
8484
*/
85-
function writeHeader(stdout: NodeJS.WriteStream, slugWidth: number): void {
85+
function writeHeader(stdout: Writer, slugWidth: number): void {
8686
stdout.write(`${"SLUG".padEnd(slugWidth)} ${"PLATFORM".padEnd(20)} NAME\n`);
8787
}
8888

8989
/**
9090
* Write formatted project rows to stdout.
9191
*/
9292
function writeRows(
93-
stdout: NodeJS.WriteStream,
93+
stdout: Writer,
9494
projects: ProjectWithOrg[],
9595
slugWidth: number,
9696
showOrg: boolean

packages/cli/src/lib/formatters/json.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* JSON output utilities
33
*/
44

5+
import type { Writer } from "../../types/index.js";
6+
57
/**
68
* Format data as pretty-printed JSON
79
*/
@@ -12,6 +14,6 @@ export function formatJson<T>(data: T): string {
1214
/**
1315
* Output JSON to a write stream
1416
*/
15-
export function writeJson<T>(stream: NodeJS.WriteStream, data: T): void {
17+
export function writeJson<T>(stream: Writer, data: T): void {
1618
stream.write(`${formatJson(data)}\n`);
1719
}

packages/cli/src/types/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ export type {
2424
SentryOrganization,
2525
SentryProject,
2626
} from "./sentry.js";
27+
28+
// I/O types
29+
30+
/**
31+
* Simple writer interface for output streams.
32+
* Compatible with process.stdout, process.stderr, and test mocks.
33+
* Avoids dependency on Node.js-specific types like NodeJS.WriteStream.
34+
*/
35+
export type Writer = {
36+
write(data: string): void;
37+
};

0 commit comments

Comments
 (0)