Ensure chunkFileNames do not include invalid characters (#8366)

This commit is contained in:
Nate Moore 2023-09-01 18:13:32 -05:00 committed by GitHub
parent 405ad95017
commit c5633434f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Update `chunkFileNames` to avoid emitting invalid characters

View file

@ -172,7 +172,21 @@ async function ssrBuild(
format: 'esm', format: 'esm',
// Server chunks can't go in the assets (_astro) folder // Server chunks can't go in the assets (_astro) folder
// We need to keep these separate // We need to keep these separate
chunkFileNames: `chunks/[name].[hash].mjs`, chunkFileNames(chunkInfo) {
const { name } = chunkInfo;
// Sometimes chunks have the `@_@astro` suffix due to SSR logic. Remove it!
// TODO: refactor our build logic to avoid this
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
return `chunks/${sanitizedName}_[hash].mjs`
}
// Injected routes include "pages/[name].[ext]" already. Clean those up!
if (name.startsWith('pages/')) {
const sanitizedName = name.split('.')[0];
return `chunks/${sanitizedName}_[hash].mjs`
}
return `chunks/[name]_[hash].mjs`
},
assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`, assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
...viteConfig.build?.rollupOptions?.output, ...viteConfig.build?.rollupOptions?.output,
entryFileNames(chunkInfo) { entryFileNames(chunkInfo) {
@ -189,7 +203,7 @@ async function ssrBuild(
} else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) { } else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) {
return 'renderers.mjs'; return 'renderers.mjs';
} else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) { } else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) {
return 'manifest.[hash].mjs'; return 'manifest_[hash].mjs';
} else { } else {
return '[name].mjs'; return '[name].mjs';
} }