diff options
author | 2023-09-01 18:13:32 -0500 | |
---|---|---|
committer | 2023-09-01 18:13:32 -0500 | |
commit | c5633434f02cc477ee8da380e22efaccfa55d459 (patch) | |
tree | 02e51d5c4619e53e3f8a1c2fc0160ea7d4fd6361 | |
parent | 405ad950173dadddc519cf1c2e7f2523bf5326a8 (diff) | |
download | astro-c5633434f02cc477ee8da380e22efaccfa55d459.tar.gz astro-c5633434f02cc477ee8da380e22efaccfa55d459.tar.zst astro-c5633434f02cc477ee8da380e22efaccfa55d459.zip |
Ensure `chunkFileNames` do not include invalid characters (#8366)
-rw-r--r-- | .changeset/eighty-laws-brake.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/build/static-build.ts | 18 |
2 files changed, 21 insertions, 2 deletions
diff --git a/.changeset/eighty-laws-brake.md b/.changeset/eighty-laws-brake.md new file mode 100644 index 000000000..b4947f1aa --- /dev/null +++ b/.changeset/eighty-laws-brake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update `chunkFileNames` to avoid emitting invalid characters diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 0bfb4e3ae..407e0ecde 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -172,7 +172,21 @@ async function ssrBuild( format: 'esm', // Server chunks can't go in the assets (_astro) folder // 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]`, ...viteConfig.build?.rollupOptions?.output, entryFileNames(chunkInfo) { @@ -189,7 +203,7 @@ async function ssrBuild( } else if (chunkInfo.facadeModuleId === RESOLVED_RENDERERS_MODULE_ID) { return 'renderers.mjs'; } else if (chunkInfo.facadeModuleId === RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID) { - return 'manifest.[hash].mjs'; + return 'manifest_[hash].mjs'; } else { return '[name].mjs'; } |