summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/tame-spoons-shop.md5
-rw-r--r--packages/astro/src/core/build/index.ts5
-rw-r--r--packages/astro/src/core/build/static-build.ts18
-rw-r--r--packages/astro/test/astro-basic.test.js8
-rw-r--r--packages/astro/test/fixtures/astro-basic/astro.config.mjs7
-rw-r--r--packages/astro/test/sourcemap.test.js10
6 files changed, 40 insertions, 13 deletions
diff --git a/.changeset/tame-spoons-shop.md b/.changeset/tame-spoons-shop.md
new file mode 100644
index 000000000..e0d80ecdb
--- /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 7a10d90de..14bc534dd 100644
--- a/packages/astro/src/core/build/index.ts
+++ b/packages/astro/src/core/build/index.ts
@@ -205,7 +205,8 @@ class AstroBuilder {
key: keyPromise,
};
- const { internals, ssrOutputChunkNames, contentFileNames } = await viteBuild(opts);
+ const { internals, ssrOutputChunkNames } =
+ await viteBuild(opts);
const hasServerIslands = this.settings.serverIslandNameMap.size > 0;
// Error if there are server islands but no adapter provided.
@@ -213,7 +214,7 @@ class AstroBuilder {
throw new AstroError(AstroErrorData.NoAdapterInstalledServerIslands);
}
- await staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames);
+ 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 5a86992b2..8023d9e3b 100644
--- a/packages/astro/src/core/build/static-build.ts
+++ b/packages/astro/src/core/build/static-build.ts
@@ -92,7 +92,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;
settings.timer.end('Client build');
// Free up memory
@@ -112,20 +111,19 @@ 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.buildOutput === '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 (settings.buildOutput === 'server') {
settings.timer.start('Server generate');
@@ -354,14 +352,12 @@ 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 ?? []);
+ .filter((f) => f.endsWith('.mjs'));
if (internals.manifestFileName) {
files.push(internals.manifestFileName);
}
@@ -370,7 +366,11 @@ 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((e) => {})
+ ]);
}),
);
@@ -426,6 +426,8 @@ async function ssrMoveAssets(opts: StaticBuildOptions) {
cwd: fileURLToPath(serverAssets),
});
+ console.log("FILES2", files);
+
if (files.length > 0) {
await Promise.all(
files.map(async function moveAsset(filename) {
diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js
index 144eec810..a780a6cb4 100644
--- a/packages/astro/test/astro-basic.test.js
+++ b/packages/astro/test/astro-basic.test.js
@@ -167,6 +167,14 @@ describe('Astro basic build', () => {
assert.doesNotMatch(otherHtml, /<style/);
});
+ it('server sourcemaps not included in output', async () => {
+ const files = await fixture.readdir('/');
+ const hasSourcemaps = files.some(fileName => {
+ return fileName.endsWith('.map');
+ });
+ assert.equal(hasSourcemaps, false, 'no sourcemap files in output');
+ });
+
describe('preview', () => {
it('returns 200 for valid URLs', async () => {
const result = await fixture.fetch('/');
diff --git a/packages/astro/test/fixtures/astro-basic/astro.config.mjs b/packages/astro/test/fixtures/astro-basic/astro.config.mjs
index f9eeace2c..bd934cab9 100644
--- a/packages/astro/test/fixtures/astro-basic/astro.config.mjs
+++ b/packages/astro/test/fixtures/astro-basic/astro.config.mjs
@@ -6,5 +6,10 @@ import { defineConfig } from 'astro/config';
export default defineConfig({
integrations: [preact(), mdx()],
// make sure CLI flags have precedence
- server: () => ({ port: 4321 })
+ server: () => ({ port: 4321 }),
+ vite: {
+ build: {
+ sourcemap: true,
+ }
+ }
});
diff --git a/packages/astro/test/sourcemap.test.js b/packages/astro/test/sourcemap.test.js
index a1e657dbd..36cd071a6 100644
--- a/packages/astro/test/sourcemap.test.js
+++ b/packages/astro/test/sourcemap.test.js
@@ -17,7 +17,13 @@ describe('Sourcemap', async () => {
});
it('Builds non-empty sourcemap', async () => {
- const map = await fixture.readFile('renderers.mjs.map');
- assert.equal(map.includes('"sources":[]'), false);
+ const assets = await fixture.readdir('/_astro');
+ const maps = assets.filter(file => file.endsWith('.map'));
+ assert.ok(maps.length > 0, 'got source maps');
+ for(const mapName of maps) {
+ const filename = `/_astro/${mapName}`;
+ const map = await fixture.readFile(filename);
+ assert.equal(map.includes('"sources":[]'), false);
+ }
});
});