Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not copy vite manifest instead of removing during build #10782

Merged
merged 11 commits into from
Sep 26, 2023
5 changes: 5 additions & 0 deletions .changeset/young-wolves-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only remove Vite manifest when copying files
16 changes: 14 additions & 2 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export function create_builder({
},

writeClient(dest) {
return copy(`${config.kit.outDir}/output/client`, dest);
const files = copy(`${config.kit.outDir}/output/client`, dest);
// avoid making vite files public
rimraf(`${dest}/.vite`);
return filter_vite_files(files);
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved
},

writePrerendered(dest) {
Expand All @@ -190,7 +193,8 @@ export function create_builder({
},

writeServer(dest) {
return copy(`${config.kit.outDir}/output/server`, dest);
const files = copy(`${config.kit.outDir}/output/server`, dest);
return filter_vite_files(files);
}
};
}
Expand All @@ -216,3 +220,11 @@ async function compress_file(file, format = 'gz') {

await pipe(source, compress, destination);
}

/**
* @param {string[]} files
* @returns {string[]}
*/
export function filter_vite_files(files) {
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved
return files.filter((file) => !file.startsWith('.vite/'));
}
6 changes: 3 additions & 3 deletions packages/kit/src/core/adapt/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, rmSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { assert, expect, test } from 'vitest';
import { create_builder } from './builder.js';
import { create_builder, filter_vite_files } from './builder.js';
import { posixify } from '../../utils/filesystem.js';
import { list_files } from '../utils.js';

Expand Down Expand Up @@ -47,12 +47,12 @@ test('copy files', () => {
rmSync(dest, { recursive: true, force: true });

expect(builder.writeClient(dest)).toEqual(list_files(dest).map(posixify));
expect(list_files(`${outDir}/output/client`)).toEqual(list_files(dest));
expect(filter_vite_files(list_files(`${outDir}/output/client`))).toEqual(list_files(dest));

rmSync(dest, { recursive: true, force: true });

expect(builder.writeServer(dest)).toEqual(list_files(dest).map(posixify));
expect(list_files(`${outDir}/output/server`)).toEqual(list_files(dest));
expect(filter_vite_files(list_files(`${outDir}/output/server`))).toEqual(list_files(dest));

rmSync(dest, { force: true, recursive: true });
});
Expand Down
6 changes: 1 addition & 5 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ function kit({ svelte_config }) {
cssCodeSplit: true,
cssMinify: initial_config.build?.minify == null ? true : !!initial_config.build.minify,
// don't use the default name to avoid collisions with 'static/manifest.json'
manifest: 'vite-manifest.json',
manifest: '.vite/manifest.json', // TODO: we can remove this when vite 5 comes out
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved
outDir: `${out}/${ssr ? 'server' : 'client'}`,
rollupOptions: {
input,
Expand Down Expand Up @@ -805,10 +805,6 @@ function kit({ svelte_config }) {
.cyan('npm run preview')} to preview your production build locally.`
);

// avoid making the manifest available to users
fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);

if (kit.adapter) {
const { adapt } = await import('../../core/adapt/index.js');
await adapt(svelte_config, build_data, metadata, prerendered, prerender_map, log);
Expand Down
Loading