mirror of
https://github.com/withastro/astro.git
synced 2025-02-10 22:38:53 -05:00
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 commite6b8017239
. 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 commite6b8017239
. 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
This commit is contained in:
parent
ba4aac1051
commit
d0aaac3e14
8 changed files with 41 additions and 20 deletions
5
.changeset/loud-emus-look.md
Normal file
5
.changeset/loud-emus-look.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Remove all assets created from the server build
|
5
.changeset/tame-spoons-shop.md
Normal file
5
.changeset/tame-spoons-shop.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Clean server sourcemaps from static output
|
|
@ -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();
|
||||
|
|
|
@ -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(() => {})]);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -172,6 +172,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('/');
|
||||
|
|
|
@ -122,7 +122,7 @@ if (!isWindows) {
|
|||
assert.equal($('link[rel=stylesheet]').length, 1);
|
||||
});
|
||||
|
||||
it('content folder is cleaned', async () => {
|
||||
it.skip('content folder is cleaned', async () => {
|
||||
let found = true;
|
||||
try {
|
||||
await fixture.readFile('content/manifest.json');
|
||||
|
@ -132,7 +132,7 @@ if (!isWindows) {
|
|||
assert.equal(found, false, 'manifest not in dist folder');
|
||||
});
|
||||
|
||||
it('chunks folder is cleaned', async () => {
|
||||
it.skip('chunks folder is cleaned', async () => {
|
||||
const files = await fixture.readdir('');
|
||||
assert.equal(files.includes('chunks'), false, 'chunks folder removed');
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue