Skip to content

Commit 703c377

Browse files
authored
fix: use full filename for svelte.compile (#700)
* fix: use full filename for svelte.compile to ensure errors work as expected * chore: add changeset * fix: normalize snapshots for difference in windows compiler comment output * fix: try harder to normalize comment * test: add testcase for hermetic build output * chore: log files that are leaking * fix: yeah, that was dumb * fix: set NODE_ENV to prodution in build tests
1 parent 20c214f commit 703c377

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

.changeset/grumpy-trains-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
fix links in error handling (console and vite overlay)

packages/e2e-tests/e2e-server.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export async function serve(root, isBuild, port) {
8585
try {
8686
const buildProcess = execa('pnpm', ['build'], {
8787
cwd: root,
88-
stdio: 'pipe'
88+
stdio: 'pipe',
89+
env: {
90+
NODE_ENV: 'production'
91+
}
8992
});
9093
logs.build = { out, err };
9194
collectLogs(buildProcess, logs.build);

packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { VERSION } from 'svelte/compiler';
55
function normalizeSnapshot(result: string) {
66
// during dev, the import is rewritten but can vary on the v= hash. replace with stable short import
77
return result
8+
.replace(
9+
/\/\* .* generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)? \*\//g,
10+
'/* src/Dummy.svelte generated by Svelte vXXX */'
11+
) // ensure generated svelte compiler comment is stable
812
.replace(/\.js\?v=[0-9a-f]{8}/g, '.js?v=XXX') // vite import analysis import rewrite version query
9-
.replace(/generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)?/g, 'generated by Svelte vXXX') // compiler version comment
1013
.replace(/"total": *\d+\.\d+/g, '"total":0.123456789'); // svelte compile stats
1114
}
1215

packages/e2e-tests/kit-node/__tests__/kit.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
editFile,
32
editFileAndWaitForHmrComplete,
43
getColor,
54
getEl,
@@ -8,14 +7,15 @@ import {
87
testDir,
98
sleep,
109
untilMatches,
11-
waitForNavigation,
1210
page,
1311
browserLogs,
1412
fetchPageText,
15-
reloadPage
13+
reloadPage,
14+
readFileContent
1615
} from '~utils';
1716

1817
import glob from 'tiny-glob';
18+
import path from 'path';
1919

2020
describe('kit-node', () => {
2121
describe('index route', () => {
@@ -105,6 +105,21 @@ describe('kit-node', () => {
105105
);
106106
expect(includesClientOnlyModule).toBe(true);
107107
});
108+
109+
it('should produce hermetic build', async () => {
110+
const outputFiles = await glob('./build/**/*', { cwd: testDir, filesOnly: true });
111+
expect(outputFiles.length).toBeGreaterThan(10);
112+
const dir = path.basename(testDir);
113+
const leakingFiles = outputFiles.filter(
114+
(f) => !f.endsWith('.png') && readFileContent(f).includes(dir)
115+
);
116+
if (leakingFiles.length > 0) {
117+
console.error(
118+
`These build output files leak parent dir: "${dir}"\n\t${leakingFiles.join('\n\t')}`
119+
);
120+
}
121+
expect(leakingFiles).toEqual([]);
122+
});
108123
}
109124

110125
if (!isBuild) {

packages/e2e-tests/kit-node/vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const config = {
1212
}
1313
},
1414
build: {
15-
minify: false
15+
minify: false,
16+
sourcemap: true // must be true for hermetic build test!
1617
},
1718
plugins: [transformValidation(), sveltekit()],
1819
optimizeDeps: {

packages/vite-plugin-svelte/src/utils/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const _createCompileSvelte = (makeHot) => {
5252
/** @type {import('../index.d.ts').CompileOptions} */
5353
const compileOptions = {
5454
...options.compilerOptions,
55-
filename: normalizedFilename, // use normalized here to avoid bleeding absolute fs path
55+
filename,
5656
generate: ssr ? 'ssr' : 'dom'
5757
};
5858
if (isSvelte3) {

0 commit comments

Comments
 (0)