diff --git a/.changeset/grumpy-trains-do.md b/.changeset/grumpy-trains-do.md new file mode 100644 index 000000000..fe4e20686 --- /dev/null +++ b/.changeset/grumpy-trains-do.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +fix links in error handling (console and vite overlay) diff --git a/packages/e2e-tests/e2e-server.js b/packages/e2e-tests/e2e-server.js index 1bfe1bf49..aa3d897de 100644 --- a/packages/e2e-tests/e2e-server.js +++ b/packages/e2e-tests/e2e-server.js @@ -85,7 +85,10 @@ export async function serve(root, isBuild, port) { try { const buildProcess = execa('pnpm', ['build'], { cwd: root, - stdio: 'pipe' + stdio: 'pipe', + env: { + NODE_ENV: 'production' + } }); logs.build = { out, err }; collectLogs(buildProcess, logs.build); diff --git a/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts index c28b21284..d2e6d23c9 100644 --- a/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts +++ b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts @@ -5,8 +5,11 @@ import { VERSION } from 'svelte/compiler'; function normalizeSnapshot(result: string) { // during dev, the import is rewritten but can vary on the v= hash. replace with stable short import return result + .replace( + /\/\* .* generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)? \*\//g, + '/* src/Dummy.svelte generated by Svelte vXXX */' + ) // ensure generated svelte compiler comment is stable .replace(/\.js\?v=[0-9a-f]{8}/g, '.js?v=XXX') // vite import analysis import rewrite version query - .replace(/generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)?/g, 'generated by Svelte vXXX') // compiler version comment .replace(/"total": *\d+\.\d+/g, '"total":0.123456789'); // svelte compile stats } diff --git a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts index 554ae7398..7e264592e 100644 --- a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts +++ b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts @@ -1,5 +1,4 @@ import { - editFile, editFileAndWaitForHmrComplete, getColor, getEl, @@ -8,14 +7,15 @@ import { testDir, sleep, untilMatches, - waitForNavigation, page, browserLogs, fetchPageText, - reloadPage + reloadPage, + readFileContent } from '~utils'; import glob from 'tiny-glob'; +import path from 'path'; describe('kit-node', () => { describe('index route', () => { @@ -105,6 +105,21 @@ describe('kit-node', () => { ); expect(includesClientOnlyModule).toBe(true); }); + + it('should produce hermetic build', async () => { + const outputFiles = await glob('./build/**/*', { cwd: testDir, filesOnly: true }); + expect(outputFiles.length).toBeGreaterThan(10); + const dir = path.basename(testDir); + const leakingFiles = outputFiles.filter( + (f) => !f.endsWith('.png') && readFileContent(f).includes(dir) + ); + if (leakingFiles.length > 0) { + console.error( + `These build output files leak parent dir: "${dir}"\n\t${leakingFiles.join('\n\t')}` + ); + } + expect(leakingFiles).toEqual([]); + }); } if (!isBuild) { diff --git a/packages/e2e-tests/kit-node/vite.config.js b/packages/e2e-tests/kit-node/vite.config.js index a9a9fc875..0b2c85a38 100644 --- a/packages/e2e-tests/kit-node/vite.config.js +++ b/packages/e2e-tests/kit-node/vite.config.js @@ -12,7 +12,8 @@ const config = { } }, build: { - minify: false + minify: false, + sourcemap: true // must be true for hermetic build test! }, plugins: [transformValidation(), sveltekit()], optimizeDeps: { diff --git a/packages/vite-plugin-svelte/src/utils/compile.js b/packages/vite-plugin-svelte/src/utils/compile.js index 0cefd73a4..dc9dfd4de 100644 --- a/packages/vite-plugin-svelte/src/utils/compile.js +++ b/packages/vite-plugin-svelte/src/utils/compile.js @@ -52,7 +52,7 @@ export const _createCompileSvelte = (makeHot) => { /** @type {import('../index.d.ts').CompileOptions} */ const compileOptions = { ...options.compilerOptions, - filename: normalizedFilename, // use normalized here to avoid bleeding absolute fs path + filename, generate: ssr ? 'ssr' : 'dom' }; if (isSvelte3) {