Skip to content

Commit bbe4bdd

Browse files
committed
fix: lint errors in build-search-crawl.ts
1 parent edb023a commit bbe4bdd

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

scripts/build-search-crawl.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const PAGE_LOAD_TIMEOUT_MS = 15_000;
1515

1616
async function fileExists(p: string): Promise<boolean> {
1717
try {
18-
await Bun.file(p);
19-
return true;
18+
return await Bun.file(p).exists();
2019
} catch {
2120
return false;
2221
}
@@ -105,7 +104,7 @@ async function fetchUrlsFromSitemap(baseUrl: string): Promise<string[]> {
105104
urls.add(new URL(match[1]).pathname);
106105
}
107106
} catch (err) {
108-
console.warn(` Warning: failed to fetch ${sitemapUrl}: ${err}`);
107+
console.warn(` Warning: failed to fetch ${sitemapUrl}: ${String(err)}`);
109108
}
110109
}
111110

@@ -147,7 +146,7 @@ async function crawlPage(
147146
await writeFile(join(outputDir, filePath), html, "utf-8");
148147
return true;
149148
} catch (err) {
150-
console.warn(` Failed to crawl ${path}: ${err}`);
149+
console.warn(` Failed to crawl ${path}: ${String(err)}`);
151150
return false;
152151
} finally {
153152
await context.close();
@@ -170,7 +169,7 @@ async function crawlAll(
170169
batch.map((path) =>
171170
crawlPage(browser, baseUrl, path, outputDir).then((ok) => {
172171
completed++;
173-
ok ? success++ : failed++;
172+
if (ok) success++; else failed++;
174173
if (completed % 50 === 0 || completed === paths.length) {
175174
console.log(` Crawled ${completed}/${paths.length} pages...`);
176175
}

src/middleware.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ describe('middleware', () => {
2424
];
2525

2626
for (const { url, host, expectedLocation } of redirectCases) {
27-
const request = new Request(url, { headers: new Headers({ host }) });
27+
const request = new Request(url);
28+
// Bun's Request constructor strips the forbidden Host header,
29+
// so patch headers.get to return the test host value.
30+
const originalGet = request.headers.get.bind(request.headers);
31+
request.headers.get = (key: string) =>
32+
key.toLowerCase() === 'host' ? host : originalGet(key);
2833
const next = mock(() => Promise.resolve(new Response('next')));
2934

3035
const response = await onRequest({ request, locals: {} as App.Locals } as APIContext, next);

0 commit comments

Comments
 (0)