From c5633434f02cc477ee8da380e22efaccfa55d459 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 1 Sep 2023 18:13:32 -0500 Subject: [PATCH] Ensure `chunkFileNames` do not include invalid characters (#8366) --- .changeset/eighty-laws-brake.md | 5 +++++ packages/astro/src/core/build/static-build.ts | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/eighty-laws-brake.md 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'; }