Skip to content

Commit

Permalink
fix: group failed scripts log (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien authored Sep 9, 2024
1 parent 69e6d8f commit 47e933d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
await fsp.rm(cacheDir, { recursive: true, force: true })
await fsp.mkdir(cacheDir, { recursive: true })
let banner = false
const failedScriptDownload = new Set<{ url: string, statusText: string, status: number }>()
for (const [filename, url] of renderedScriptSrc) {
const key = `data:scripts:${filename}`
// Use storage to cache the font data between builds
Expand All @@ -107,7 +108,8 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
let size = 0
res = await fetch(url).then((r) => {
if (!r.ok) {
throw new Error(`@nuxt/scripts - Failed to download script: ${url}. ${r.statusText} (${r.status})`)
failedScriptDownload.add({ url, statusText: r.statusText, status: r.status })
return Buffer.from('')
}
encoding = r.headers.get('content-encoding')
const contentLength = r.headers.get('content-length')
Expand All @@ -119,6 +121,9 @@ export function setupPublicAssetStrategy(options: ModuleOptions['assets'] = {})
}
await fsp.writeFile(join(cacheDir, filename), res)
}
if (failedScriptDownload.size) {
throw new Error(`@nuxt/script: Failed to download scripts:\n${[...failedScriptDownload].map(({ url, statusText, status }) => ` ├─ ${url} (${status} ${statusText})`).join('\n')}`)
}
if (banner)
logger.success('Scripts downloaded and cached.')
})
Expand Down

0 comments on commit 47e933d

Please sign in to comment.