From d0aaac3e1443a84e673568ea2f649d70d74582b6 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 18 Dec 2024 06:45:24 -0500 Subject: [PATCH] Prevent server sourcemaps from being part of client output (#12757) * Revert "fix custom `assetFileNames` issue (#12449)" (#12746) * Revert "fix custom `assetFileNames` issue (#12449)" This reverts commit e6b80172391d5f9aa5b1de26a8694ba4a28a43f3. This change caused source maps to be left in the client folder, exposing them into the server. * Add changeset * Clean sourcemaps from static output (#12749) * Clean sourcemaps from static output * Add changeset * Update test to look at frontend sourcemaps * Revert "fix custom `assetFileNames` issue (#12449)" (#12746) * Revert "fix custom `assetFileNames` issue (#12449)" This reverts commit e6b80172391d5f9aa5b1de26a8694ba4a28a43f3. This change caused source maps to be left in the client folder, exposing them into the server. * Add changeset * Clean sourcemaps from static output (#12749) * Clean sourcemaps from static output * Add changeset * Update test to look at frontend sourcemaps * [ci] format * fix build * Skip experimental cc tests * remove unused params --- .changeset/loud-emus-look.md | 5 +++++ .changeset/tame-spoons-shop.md | 5 +++++ packages/astro/src/core/build/index.ts | 4 ++-- packages/astro/src/core/build/static-build.ts | 18 +++++------------- packages/astro/test/astro-basic.test.js | 8 ++++++++ ...rimental-content-collections-render.test.js | 4 ++-- .../test/fixtures/astro-basic/astro.config.mjs | 7 ++++++- packages/astro/test/sourcemap.test.js | 10 ++++++++-- 8 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 .changeset/loud-emus-look.md create mode 100644 .changeset/tame-spoons-shop.md diff --git a/.changeset/loud-emus-look.md b/.changeset/loud-emus-look.md new file mode 100644 index 0000000000..ec07dec9c1 --- /dev/null +++ b/.changeset/loud-emus-look.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Remove all assets created from the server build diff --git a/.changeset/tame-spoons-shop.md b/.changeset/tame-spoons-shop.md new file mode 100644 index 0000000000..e0d80ecdb9 --- /dev/null +++ b/.changeset/tame-spoons-shop.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Clean server sourcemaps from static output diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 4253b8802f..e6e4bac66f 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -204,8 +204,8 @@ class AstroBuilder { key: keyPromise, }; - const { internals, ssrOutputChunkNames, contentFileNames } = await viteBuild(opts); - await staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames); + const { internals, ssrOutputChunkNames } = await viteBuild(opts); + await staticBuild(opts, internals, ssrOutputChunkNames); // Write any additionally generated assets to disk. this.timer.assetsStart = performance.now(); diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 7bb73d5e5d..afd878f810 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -111,10 +111,6 @@ export async function viteBuild(opts: StaticBuildOptions) { const ssrOutputs = viteBuildReturnToRollupOutputs(ssrOutput); const clientOutputs = viteBuildReturnToRollupOutputs(clientOutput ?? []); await runPostBuildHooks(container, ssrOutputs, clientOutputs); - let contentFileNames: string[] | undefined = undefined; - if (opts.settings.config.experimental.contentCollectionCache) { - contentFileNames = await copyContentToCache(opts); - } settings.timer.end('Client build'); // Free up memory @@ -134,26 +130,24 @@ export async function viteBuild(opts: StaticBuildOptions) { } } - return { internals, ssrOutputChunkNames, contentFileNames }; + return { internals, ssrOutputChunkNames }; } export async function staticBuild( opts: StaticBuildOptions, internals: BuildInternals, ssrOutputChunkNames: string[], - contentFileNames?: string[], ) { const { settings } = opts; if (settings.config.output === 'static') { settings.timer.start('Static generate'); await generatePages(opts, internals); - await cleanServerOutput(opts, ssrOutputChunkNames, contentFileNames, internals); + await cleanServerOutput(opts, ssrOutputChunkNames, internals); settings.timer.end('Static generate'); } else if (isServerLikeOutput(settings.config)) { settings.timer.start('Server generate'); await generatePages(opts, internals); await cleanStaticOutput(opts, internals); - opts.logger.info(null, `\n${bgMagenta(black(' finalizing server assets '))}\n`); await ssrMoveAssets(opts); settings.timer.end('Server generate'); } @@ -412,14 +406,11 @@ async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInter async function cleanServerOutput( opts: StaticBuildOptions, ssrOutputChunkNames: string[], - contentFileNames: string[] | undefined, internals: BuildInternals, ) { const out = getOutDirWithinCwd(opts.settings.config.outDir); // The SSR output chunks for Astro are all .mjs files - const files = ssrOutputChunkNames - .filter((f) => f.endsWith('.mjs')) - .concat(contentFileNames ?? []); + const files = ssrOutputChunkNames.filter((f) => f.endsWith('.mjs')); if (internals.manifestFileName) { files.push(internals.manifestFileName); } @@ -428,7 +419,8 @@ async function cleanServerOutput( await Promise.all( files.map(async (filename) => { const url = new URL(filename, out); - await fs.promises.rm(url); + const map = new URL(url + '.map'); + await Promise.all([fs.promises.rm(url), fs.promises.rm(new URL(map)).catch(() => {})]); }), ); diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index 0fc87dd606..dc88a16949 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -172,6 +172,14 @@ describe('Astro basic build', () => { assert.doesNotMatch(otherHtml, /