refactor(build): write sitemap through stream pipeline

pipeline() replaces the manual finish/error promise and also
surfaces SitemapStream errors, which pipe() never forwarded to the
write stream.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pull/5342/head
Divyansh Singh 4 weeks ago
parent de8d2862fd
commit 388577c6da

@ -1,5 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { pipeline } from 'node:stream/promises'
import {
SitemapStream,
type EnumChangefreq,
@ -66,14 +67,10 @@ export async function generateSitemap(
const sitemapPath = path.join(siteConfig.outDir, 'sitemap.xml')
const sitemapStream = new SitemapStream(siteConfig.sitemap)
const writeStream = fs.createWriteStream(sitemapPath)
sitemapStream.pipe(writeStream)
items.forEach((item) => sitemapStream.write(item))
sitemapStream.end()
await new Promise((resolve, reject) =>
writeStream.on('finish', resolve).on('error', reject)
)
await pipeline(sitemapStream, fs.createWriteStream(sitemapPath))
})
}

Loading…
Cancel
Save