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: use full filename for svelte.compile #700

Merged
merged 9 commits into from
Aug 6, 2023
5 changes: 5 additions & 0 deletions .changeset/grumpy-trains-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

fix links in error handling (console and vite overlay)
5 changes: 4 additions & 1 deletion packages/e2e-tests/e2e-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 18 additions & 3 deletions packages/e2e-tests/kit-node/__tests__/kit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
editFile,
editFileAndWaitForHmrComplete,
getColor,
getEl,
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-tests/kit-node/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const config = {
}
},
build: {
minify: false
minify: false,
sourcemap: true // must be true for hermetic build test!
},
plugins: [transformValidation(), sveltekit()],
optimizeDeps: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/utils/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down