Skip to content

Commit 86cce1f

Browse files
committed
fix(test-utils): Fix lint errors in spotlight.ts
- Remove unused eslint-disable directive - Type JSON.parse result properly - Add null check for stdout/stderr instead of non-null assertions
1 parent 4189085 commit 86cce1f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

dev-packages/test-utils/src/spotlight.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function getDirname(): string {
1616
return path.dirname(fileURLToPath(import.meta.url));
1717
}
1818
// CJS environment
19-
// eslint-disable-next-line no-restricted-globals
2019
return __dirname;
2120
}
2221

@@ -30,7 +29,7 @@ function findRepoRoot(startDir: string): string {
3029
const pkgPath = path.join(dir, 'package.json');
3130
if (fs.existsSync(pkgPath)) {
3231
try {
33-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
32+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) as { workspaces?: string[] };
3433
if (pkg.workspaces) {
3534
return dir;
3635
}
@@ -112,8 +111,13 @@ export async function startSpotlight(options: SpotlightOptions = {}): Promise<Sp
112111

113112
// Parse stderr for port information
114113
// Spotlight outputs something like "Spotlight listening on http://localhost:8969"
114+
if (!spotlightProcess.stderr || !spotlightProcess.stdout) {
115+
reject(new Error('Spotlight process has no stdout/stderr'));
116+
return;
117+
}
118+
115119
const stderrReader = readline.createInterface({
116-
input: spotlightProcess.stderr!,
120+
input: spotlightProcess.stderr,
117121
crlfDelay: Infinity,
118122
});
119123

@@ -128,9 +132,7 @@ export async function startSpotlight(options: SpotlightOptions = {}): Promise<Sp
128132
// - "http://localhost:8969"
129133
// - "port: 8969"
130134
const portMatch =
131-
line.match(/listening on (\d+)/i) ||
132-
line.match(/localhost:(\d+)/i) ||
133-
line.match(/port[:\s]+(\d+)/i);
135+
line.match(/listening on (\d+)/i) || line.match(/localhost:(\d+)/i) || line.match(/port[:\s]+(\d+)/i);
134136

135137
if (portMatch?.[1] && !resolvedPort) {
136138
resolvedPort = parseInt(portMatch[1], 10);
@@ -154,7 +156,7 @@ export async function startSpotlight(options: SpotlightOptions = {}): Promise<Sp
154156

155157
// Parse stdout for JSON events
156158
const stdoutReader = readline.createInterface({
157-
input: spotlightProcess.stdout!,
159+
input: spotlightProcess.stdout,
158160
crlfDelay: Infinity,
159161
});
160162

0 commit comments

Comments
 (0)