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

chore: allow Vite 5 #817

Closed
wants to merge 12 commits into from
6 changes: 6 additions & 0 deletions .changeset/chilled-parents-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/vite-plugin-svelte-inspector': patch
'@sveltejs/vite-plugin-svelte': patch
---

chore: allow Vite 5
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ name: CI
on:
push:
branches:
- main
- v1
- v2
pull_request:
branches:
- main
- v1
- v2
env:
# we call `pnpm playwright install` instead
Expand Down Expand Up @@ -78,16 +74,28 @@ jobs:
node: [16]
os: [ubuntu-latest, macos-latest, windows-latest]
svelte: [4]
vite: [4]
include:
- node: 14
os: ubuntu-latest
svelte: 3
vite: 4
- node: 18
os: ubuntu-latest
svelte: 4
vite: 4
- node: 20
os: ubuntu-latest
svelte: 4
vite: 4
- node: 18
os: ubuntu-latest
svelte: 4
vite: 5
- node: 20
os: ubuntu-latest
svelte: 4
vite: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
Expand Down Expand Up @@ -120,6 +128,9 @@ jobs:
- name: install for node14 or svelte3
if: matrix.node == 14 || matrix.svelte == 3
run: pnpm install --no-frozen-lockfile --prefer-offline --ignore-scripts
- name: install vite 5
if: matrix.vite == 5
run: pnpm i -Dw vite@^5.0.3 && pnpm install --no-frozen-lockfile
- name: install playwright chromium
run: pnpm playwright install chromium
- name: run tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { browserLogs, fetchFromPage, getText, isBuild, testDir } from '~utils';
import { createServer, ViteDevServer } from 'vite';
import { VERSION } from 'svelte/compiler';
import { createServer, version as viteVersion, ViteDevServer } from 'vite';
import { VERSION as svelteVersion } 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
Expand All @@ -13,12 +13,13 @@ function normalizeSnapshot(result: string) {
.replace(/"total": *\d+\.\d+/g, '"total":0.123456789'); // svelte compile stats
}

const svelteMajor = VERSION.split('.', 1)[0];
const vite5 = viteVersion.startsWith('5');
const svelteMajor = svelteVersion.split('.', 1)[0];
function snapshotFilename(name: string) {
return `./__snapshots__/svelte-${svelteMajor}/${name}.txt`;
}

describe('raw', () => {
describe.skipIf(vite5)('raw', () => {
test('does not have failed requests', async () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404');
Expand Down Expand Up @@ -90,7 +91,7 @@ describe('raw', () => {

// vitest prints a warning about obsolete snapshots during build tests, ignore it, they are used in dev tests.
// always regenerate snapshots with `pnpm test:serve import-queries -u` and check the diffs if they are correct
describe.runIf(isBuild)('snapshots not obsolete warning', async () => {
describe.skipIf(vite5).runIf(isBuild)('snapshots not obsolete warning', async () => {
afterAll(() => {
console.log(
'Ignore the obsolete snapshot warnings for ssrLoadModule snapshots from vitest during test:build, they are used in test:serve'
Expand All @@ -101,7 +102,7 @@ describe.runIf(isBuild)('snapshots not obsolete warning', async () => {
});
});

describe.runIf(!isBuild)('direct', () => {
describe.skipIf(vite5).runIf(!isBuild)('direct', () => {
test('Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css', async () => {
const response = await fetchFromPage(
'src/Dummy.svelte?direct&svelte&type=style&sourcemap&lang.css',
Expand All @@ -128,7 +129,7 @@ describe.runIf(!isBuild)('direct', () => {
});
});

describe.runIf(!isBuild)('ssrLoadModule', () => {
describe.skipIf(vite5).runIf(!isBuild)('ssrLoadModule', () => {
let vite: ViteDevServer;
let ssrLoadDummy;
beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/kit-node/__tests__/kit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('kit-node', () => {
);
expectArrayEqual(
config.resolve.mainFields,
['svelte', 'module', 'jsnext:main', 'jsnext'],
['svelte', 'browser', 'module', 'jsnext:main', 'jsnext'],
benmccann marked this conversation as resolved.
Show resolved Hide resolved
`resolve.mainFields in ${filename}`
);
expectArrayEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte-inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"peerDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.2.0",
"svelte": "^3.54.0 || ^4.0.0",
"vite": "^4.0.0"
"vite": "^4.0.0 || ^5.0.0"
},
"devDependencies": {
"@types/debug": "^4.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"peerDependencies": {
"svelte": "^3.54.0 || ^4.0.0 || ^5.0.0-next.0",
"vite": "^4.0.0"
"vite": "^4.0.0 || ^5.0.3"
},
"devDependencies": {
"@types/debug": "^4.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isSvelte3 } from './svelte-version.js';

export const VITE_RESOLVE_MAIN_FIELDS = ['module', 'jsnext:main', 'jsnext'];
export const VITE_RESOLVE_MAIN_FIELDS = ['browser', 'module', 'jsnext:main', 'jsnext'];
benmccann marked this conversation as resolved.
Show resolved Hide resolved

export const SVELTE_RESOLVE_MAIN_FIELDS = ['svelte'];

Expand Down
Loading