diff --git a/.prettierrc.js b/.prettierrc.js index 81cdfcd4d..384f65f42 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -20,7 +20,7 @@ module.exports = { } }, { - files: ['**/package.json', '**/README.md', 'docs/**/*.md'], + files: ['**/package.json', '**/README.md', 'docs/**/*.md', '.changeset/pre.json'], options: { useTabs: false, tabWidth: 2 diff --git a/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts b/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts deleted file mode 100644 index 1617d626f..000000000 --- a/packages/e2e-tests/vite-ssr/__tests__/vite-ssr.spec.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { - editFileAndWaitForHmrComplete, - getColor, - getEl, - getText, - isBuild, - untilMatches, - page, - e2eServer, - browserLogs, - fetchPageText -} from '~utils'; - -test('/', async () => { - expect(await page.textContent('h1')).toMatch('Hello svelte world'); // after hydration - - const html = await fetchPageText(); - expect(html).toMatch('Hello world'); // before hydration - if (isBuild) { - // TODO expect preload links - } -}); - -test('css', async () => { - if (isBuild) { - expect(await getColor('h1')).toBe('green'); - } else { - // During dev, the CSS is loaded from async chunk and we may have to wait - // when the test runs concurrently. - await untilMatches(() => getColor('h1'), 'green', 'h1 has color green'); - } -}); - -test('loaded esm only package', async () => { - expect(await page.textContent('#esm')).toMatch('esm'); - expect(browserLogs).toContain('esm'); - expect(e2eServer.logs.server.out).toContain('esm'); -}); - -test('asset', async () => { - // should have no 404s - browserLogs.forEach((msg) => { - expect(msg).not.toMatch('404'); - }); - const img = await page.$('img'); - expect(await img.getAttribute('src')).toMatch( - isBuild ? /\/assets\/logo-\w{8}\.png/ : '/src/assets/logo.png' - ); -}); - -if (!isBuild) { - describe('hmr', () => { - const updateApp = editFileAndWaitForHmrComplete.bind(null, 'src/App.svelte'); - test('should render additional html', async () => { - expect(await getEl('#hmr-test')).toBe(null); - await updateApp((content) => - content.replace( - '', - '
foo
\n' - ) - ); - await untilMatches(() => getText('#hmr-test'), 'foo', '#hmr-test contains text foo'); - }); - test('should apply style update', async () => { - expect(await getColor('h1')).toBe('green'); - await updateApp((content) => content.replace('color: green', 'color: red')); - await untilMatches(() => getColor('h1'), 'red', 'h1 has color red'); - }); - test('should not preserve state of updated props', async () => { - expect(await getText('#foo')).toBe('foo'); - await updateApp((content) => content.replace("foo = 'foo'", "foo = 'bar'")); - await untilMatches(() => getText('#foo'), 'bar', '#foo contains text bar'); - }); - }); -} diff --git a/packages/e2e-tests/vite-ssr/index.html b/packages/e2e-tests/vite-ssr/index.html deleted file mode 100644 index 7ef3ed135..000000000 --- a/packages/e2e-tests/vite-ssr/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - Svelte App - - - -
- - - diff --git a/packages/e2e-tests/vite-ssr/package.json b/packages/e2e-tests/vite-ssr/package.json deleted file mode 100644 index bb3f3b5a8..000000000 --- a/packages/e2e-tests/vite-ssr/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "e2e-tests-vite-ssr", - "private": true, - "version": "0.0.0", - "scripts": { - "dev": "node server", - "build": "pnpm build:client && pnpm build:server", - "build:client": "vite build --ssrManifest --outDir dist/client", - "build:server": "vite build --ssr src/entry-server.mjs --outDir dist/server", - "preview": "cross-env NODE_ENV=production node server", - "debug": "node --inspect-brk server" - }, - "devDependencies": { - "@sveltejs/vite-plugin-svelte": "workspace:^", - "compression": "^1.7.4", - "cross-env": "^7.0.3", - "e2e-test-dep-esm-only": "file:../_test_dependencies/esm-only", - "express": "^4.18.2", - "serve-static": "^1.15.0", - "svelte": "^4.2.0", - "vite": "^5.0.0-beta.1" - } -} diff --git a/packages/e2e-tests/vite-ssr/server.js b/packages/e2e-tests/vite-ssr/server.js deleted file mode 100644 index ef3192368..000000000 --- a/packages/e2e-tests/vite-ssr/server.js +++ /dev/null @@ -1,111 +0,0 @@ -// @ts-check -const fs = require('node:fs'); -const path = require('node:path'); -const express = require('express'); - -let port = 3000; -const args = process.argv.slice(2); -const portArgPos = args.indexOf('--port') + 1; -if (portArgPos > 0) { - port = parseInt(args[portArgPos], 10); -} - -async function createServer(root = process.cwd(), isProd = process.env.NODE_ENV === 'production') { - const resolve = (p) => path.resolve(__dirname, p); - - const indexProd = isProd ? fs.readFileSync(resolve('dist/client/index.html'), 'utf-8') : ''; - - const manifest = isProd - ? // @ts-ignore - // eslint-disable-next-line n/no-missing-require - require('./dist/client/ssr-manifest.json') - : {}; - - const app = express(); - - /** - * @type {import('vite').ViteDevServer} - */ - let vite; - if (!isProd) { - const inlineCfg = { - root, - appType: 'custom', - server: { - middlewareMode: true, - port, - strictPort: true, - hmr: { - port: port + 25000 - } - } - }; - // @ts-ignore - vite = await require('vite').createServer(inlineCfg); - // use vite's connect instance as middleware - app.use(vite.middlewares); - } else { - app.use(require('compression')()); - app.use( - require('serve-static')(resolve('dist/client'), { - index: false - }) - ); - } - - app.use('*', async (req, res) => { - try { - const url = req.originalUrl; - - let template, render; - if (!isProd) { - // always read fresh template in dev - template = fs.readFileSync(resolve('index.html'), 'utf-8'); - template = await vite.transformIndexHtml(url, template); - render = (await vite.ssrLoadModule('/src/entry-server.mjs')).render; - } else { - template = indexProd; - // @ts-ignore - // eslint-disable-next-line n/no-missing-require - render = require('./dist/server/entry-server.js').render; - } - const rendered = await render(req.originalUrl, manifest); - const appHtml = rendered.html; - const headElements = rendered.head || ''; - // TODO what do we do with rendered.css here. find out if emitCss was used and vite took care of it - const html = template - .replace('', headElements) - .replace('', appHtml); - - res.status(200).set({ 'Content-Type': 'text/html' }).end(html); - } catch (e) { - vite && vite.ssrFixStacktrace(e); - console.log(e.stack); - res.status(500).end(e.stack); - } - }); - - return { app, vite }; -} - -createServer().then(({ app }) => { - const server = app.listen(port, () => { - console.log('http://localhost:' + port); - }); - const exitProcess = async () => { - process.off('SIGTERM', exitProcess); - process.off('SIGINT', exitProcess); - process.stdin.off('end', exitProcess); - try { - await server.close(() => { - console.log('ssr server closed'); - }); - } finally { - // eslint-disable-next-line n/no-process-exit - process.exit(0); - } - }; - process.once('SIGTERM', exitProcess); - process.once('SIGINT', exitProcess); - process.stdin.on('end', exitProcess); -}); diff --git a/packages/e2e-tests/vite-ssr/src/App.svelte b/packages/e2e-tests/vite-ssr/src/App.svelte deleted file mode 100644 index 999941b80..000000000 --- a/packages/e2e-tests/vite-ssr/src/App.svelte +++ /dev/null @@ -1,30 +0,0 @@ - - -

Hello {world}

-

Open App.svelte in your editor and change something to see HMR in action

- -logo -
{foo}
-
{esm()}
- - - - - - - diff --git a/packages/e2e-tests/vite-ssr/src/assets/logo.png b/packages/e2e-tests/vite-ssr/src/assets/logo.png deleted file mode 100644 index 7e6f5eb5a..000000000 Binary files a/packages/e2e-tests/vite-ssr/src/assets/logo.png and /dev/null differ diff --git a/packages/e2e-tests/vite-ssr/src/components/Foo.svelte b/packages/e2e-tests/vite-ssr/src/components/Foo.svelte deleted file mode 100644 index a7d0e54c3..000000000 --- a/packages/e2e-tests/vite-ssr/src/components/Foo.svelte +++ /dev/null @@ -1,12 +0,0 @@ - - -
Foo bar={bar}
- - - diff --git a/packages/e2e-tests/vite-ssr/src/entry-client.mjs b/packages/e2e-tests/vite-ssr/src/entry-client.mjs deleted file mode 100644 index 6d665988d..000000000 --- a/packages/e2e-tests/vite-ssr/src/entry-client.mjs +++ /dev/null @@ -1,14 +0,0 @@ -import App from './App.svelte'; - -import { esm } from 'e2e-test-dep-esm-only'; -console.log(esm()); - -const app = new App({ - target: document.getElementById('svelte'), - hydrate: true, - props: { - world: 'svelte world' - } -}); - -export default app; diff --git a/packages/e2e-tests/vite-ssr/src/entry-server.mjs b/packages/e2e-tests/vite-ssr/src/entry-server.mjs deleted file mode 100644 index ff2ce25a3..000000000 --- a/packages/e2e-tests/vite-ssr/src/entry-server.mjs +++ /dev/null @@ -1,10 +0,0 @@ -import App from './App.svelte'; - -import { esm } from 'e2e-test-dep-esm-only'; -console.log(esm()); - -export async function render(url, manifest) { - return App.render({ - name: 'world' - }); -} diff --git a/packages/e2e-tests/vite-ssr/vite.config.js b/packages/e2e-tests/vite-ssr/vite.config.js deleted file mode 100644 index b0696aac2..000000000 --- a/packages/e2e-tests/vite-ssr/vite.config.js +++ /dev/null @@ -1,30 +0,0 @@ -const { defineConfig } = require('vite'); - -module.exports = defineConfig(async ({ command, mode }) => { - const { svelte } = await import('@sveltejs/vite-plugin-svelte'); - return { - plugins: [ - svelte({ - compilerOptions: { - hydratable: true /* required for clientside hydration */ - } - }) - ], - ssr: { - format: 'cjs' - }, - build: { - target: 'esnext', - minify: false, - assetsInlineLimit: 0 - }, - server: { - watch: { - // During tests we edit the files too fast and sometimes chokidar - // misses change events, so enforce polling for consistency - usePolling: true, - interval: 100 - } - } - }; -});