From 58ea256f3af7282514012f239b93b2353e6ec5c4 Mon Sep 17 00:00:00 2001 From: dominikg Date: Fri, 28 Jul 2023 12:39:19 +0200 Subject: [PATCH 1/8] fix: use full filename for svelte.compile to ensure errors work as expected --- .../__tests__/__snapshots__/svelte-3/ssr-custom-element.txt | 2 +- .../__tests__/__snapshots__/svelte-3/ssr-script.txt | 4 ++-- .../__tests__/__snapshots__/svelte-4/ssr-custom-element.txt | 2 +- .../__tests__/__snapshots__/svelte-4/ssr-script.txt | 2 +- packages/vite-plugin-svelte/src/utils/compile.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt index 468eebd24..8fe958865 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt @@ -1,4 +1,4 @@ -/* src/Dummy.svelte generated by Svelte vXXX */ +/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ import { SvelteElement as SvelteElement$, append as append$, diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt index 88cca4b98..042573b88 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt @@ -1,4 +1,4 @@ -/* src/Dummy.svelte generated by Svelte vXXX */ +/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent as SvelteComponent$, append as append$, @@ -77,4 +77,4 @@ class Dummy$ extends SvelteComponent$ { } } -export default Dummy$; \ No newline at end of file +export default Dummy$; diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt index 869a0ffac..a4b142341 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt @@ -1,4 +1,4 @@ -/* src/Dummy.svelte generated by Svelte vXXX */ +/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent, append, diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt index 09e9292ed..64eef35e5 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt @@ -1,4 +1,4 @@ -/* src/Dummy.svelte generated by Svelte vXXX */ +/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent, append, 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) { From 0f44a8754b20897e3708fb12aa9d9db8385bc077 Mon Sep 17 00:00:00 2001 From: dominikg Date: Fri, 28 Jul 2023 13:35:43 +0200 Subject: [PATCH 2/8] chore: add changeset --- .changeset/grumpy-trains-do.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/grumpy-trains-do.md 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) From 62847df1939432b1d6b70c82d6b85bdfe110d6a7 Mon Sep 17 00:00:00 2001 From: dominikg Date: Fri, 28 Jul 2023 18:58:04 +0200 Subject: [PATCH 3/8] fix: normalize snapshots for difference in windows compiler comment output --- .../import-queries/__tests__/import-queries.spec.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..93c9d4341 100644 --- a/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts +++ b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts @@ -1,12 +1,14 @@ import { browserLogs, fetchFromPage, getText, isBuild, testDir } from '~utils'; -import { createServer, ViteDevServer } from 'vite'; +import { createServer, normalizePath, ViteDevServer } from 'vite'; import { VERSION } from 'svelte/compiler'; +import path from 'path'; 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(`/* ${normalizePath(testDir)}`, `/* ${path.basename(testDir)}`) // remove abs path from compiler comment + .replace(/generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)?/g, 'generated by Svelte vXXX') // remove svelte version from compiler comment .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 } From bf9a2da3c2d3a940a0118bbff39b69af0cd15ee2 Mon Sep 17 00:00:00 2001 From: dominikg Date: Fri, 28 Jul 2023 19:42:42 +0200 Subject: [PATCH 4/8] fix: try harder to normalize comment --- .../__snapshots__/svelte-3/ssr-custom-element.txt | 2 +- .../__tests__/__snapshots__/svelte-3/ssr-script.txt | 4 ++-- .../__snapshots__/svelte-4/ssr-custom-element.txt | 2 +- .../__tests__/__snapshots__/svelte-4/ssr-script.txt | 2 +- .../import-queries/__tests__/import-queries.spec.ts | 9 +++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt index 8fe958865..468eebd24 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-custom-element.txt @@ -1,4 +1,4 @@ -/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ +/* src/Dummy.svelte generated by Svelte vXXX */ import { SvelteElement as SvelteElement$, append as append$, diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt index 042573b88..88cca4b98 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-3/ssr-script.txt @@ -1,4 +1,4 @@ -/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ +/* src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent as SvelteComponent$, append as append$, @@ -77,4 +77,4 @@ class Dummy$ extends SvelteComponent$ { } } -export default Dummy$; +export default Dummy$; \ No newline at end of file diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt index a4b142341..869a0ffac 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-custom-element.txt @@ -1,4 +1,4 @@ -/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ +/* src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent, append, diff --git a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt index 64eef35e5..09e9292ed 100644 --- a/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt +++ b/packages/e2e-tests/import-queries/__tests__/__snapshots__/svelte-4/ssr-script.txt @@ -1,4 +1,4 @@ -/* temp/serve/import-queries/src/Dummy.svelte generated by Svelte vXXX */ +/* src/Dummy.svelte generated by Svelte vXXX */ import { SvelteComponent, append, 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 93c9d4341..d2e6d23c9 100644 --- a/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts +++ b/packages/e2e-tests/import-queries/__tests__/import-queries.spec.ts @@ -1,13 +1,14 @@ import { browserLogs, fetchFromPage, getText, isBuild, testDir } from '~utils'; -import { createServer, normalizePath, ViteDevServer } from 'vite'; +import { createServer, ViteDevServer } from 'vite'; import { VERSION } from 'svelte/compiler'; -import path from 'path'; 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(`/* ${normalizePath(testDir)}`, `/* ${path.basename(testDir)}`) // remove abs path from compiler comment - .replace(/generated by Svelte v\d\.\d+\.\d+(?:-[a-z]+\.\d+)?/g, 'generated by Svelte vXXX') // remove svelte version from compiler comment + .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(/"total": *\d+\.\d+/g, '"total":0.123456789'); // svelte compile stats } From f48264cc8df59b25a324d66a3007202079afbba9 Mon Sep 17 00:00:00 2001 From: dominikg Date: Mon, 31 Jul 2023 20:06:02 +0200 Subject: [PATCH 5/8] test: add testcase for hermetic build output --- .../e2e-tests/kit-node/__tests__/kit.spec.ts | 16 +++++++++++++--- packages/e2e-tests/kit-node/vite.config.js | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts index 554ae7398..8ea545307 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,16 @@ 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) + ); + 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: { From 45a77acd4fab53f6e58473503de0236d2934c935 Mon Sep 17 00:00:00 2001 From: dominikg Date: Mon, 31 Jul 2023 21:00:45 +0200 Subject: [PATCH 6/8] chore: log files that are leaking --- packages/e2e-tests/kit-node/__tests__/kit.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts index 8ea545307..4f11875e9 100644 --- a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts +++ b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts @@ -113,7 +113,12 @@ describe('kit-node', () => { const leakingFiles = outputFiles.filter( (f) => !f.endsWith('.png') && readFileContent(f).includes(dir) ); - expect(leakingFiles).toEqual([]); + if (leakingFiles.length > 0) { + console.error( + `These build output files leak parent dir: "${dir}"\n\t${leakingFiles.join('\n\t')}` + ); + } + expect(leakingFiles).toBe([]); }); } From ee10ae4dfeeaa17561e1e208c1940dc0d520905b Mon Sep 17 00:00:00 2001 From: dominikg Date: Mon, 31 Jul 2023 21:08:11 +0200 Subject: [PATCH 7/8] fix: yeah, that was dumb --- packages/e2e-tests/kit-node/__tests__/kit.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts index 4f11875e9..7e264592e 100644 --- a/packages/e2e-tests/kit-node/__tests__/kit.spec.ts +++ b/packages/e2e-tests/kit-node/__tests__/kit.spec.ts @@ -118,7 +118,7 @@ describe('kit-node', () => { `These build output files leak parent dir: "${dir}"\n\t${leakingFiles.join('\n\t')}` ); } - expect(leakingFiles).toBe([]); + expect(leakingFiles).toEqual([]); }); } From cb6a6c9d05f1948b8061005d86d324b03181c94e Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 5 Aug 2023 16:58:19 +0200 Subject: [PATCH 8/8] fix: set NODE_ENV to prodution in build tests --- packages/e2e-tests/e2e-server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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);