Skip to content

Commit 6abf2c6

Browse files
authored
feat: support experimental.async and dynamicCompileOptions for Svelte modules (#1176)
* feat: support experimental.async and dynamicCompileOptions when compiling Svelte modules * fix: check if it exists before using * wip: add svelte version check for async and use it in kit-node test * fix: split async test into separate project, adapt tests when running in baseline svelte version * try to fix missing tsconfig bug that doesnt happen locally * fix: run sync script before testing too * dedupe dependencies * bump svelte&kit, update kit-async setup * switch kit-async to jsconfig.json
1 parent 55951de commit 6abf2c6

File tree

53 files changed

+691
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+691
-361
lines changed

.changeset/huge-ideas-nail.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': minor
3+
---
4+
5+
feat: add support for the new experimental.async option and apply dynamicCompileOptions when compiling Svelte modules

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ jobs:
4949
cache-dependency-path: '**/pnpm-lock.yaml'
5050
- name: install
5151
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
52+
- name: sync
53+
run: pnpm -r sync # required to ensure sveltekit test project have tsconfig.json which may be required by the checks below
5254
- name: format
5355
run: pnpm check:format
5456
- name: lint
@@ -77,21 +79,26 @@ jobs:
7779
node: [22]
7880
os: [ubuntu-latest, macos-latest, windows-latest]
7981
vite: ['current']
82+
svelte: ['current']
8083
include:
8184
- node: 20
8285
os: ubuntu-latest
8386
vite: 'current'
87+
svelte: 'current'
8488
- node: 24
8589
os: ubuntu-latest
8690
vite: 'current'
87-
# baseline test lowest vite and node version
91+
svelte: 'current'
92+
# baseline test lowest svelte, vite and node version
8893
- node: 20.19
8994
os: ubuntu-latest
9095
vite: 'baseline'
96+
svelte: 'baseline'
9197
# future test with rolldown-vite
9298
- node: 24
9399
os: ubuntu-latest
94100
vite: 'rolldown-vite'
101+
svelte: 'current'
95102
steps:
96103
- uses: actions/checkout@v4
97104
- uses: actions/setup-node@v4
@@ -115,6 +122,11 @@ jobs:
115122
run: |
116123
pnpm update -r --no-save [email protected]
117124
pnpm ls vite
125+
- name: downgrade svelte to baseline
126+
if: matrix.svelte == 'baseline'
127+
run: |
128+
pnpm update -r --no-save [email protected]
129+
pnpm ls svelte
118130
- name: update vite to rolldown-vite
119131
if: matrix.vite == 'rolldown-vite'
120132
run: |
@@ -134,7 +146,7 @@ jobs:
134146
- uses: actions/upload-artifact@v4
135147
if: failure()
136148
with:
137-
name: test-failure-${{github.run_id}}-${{ matrix.os }}-${{ matrix.node }}-${{ matrix.vite }}
149+
name: test-failure-${{github.run_id}}-os_${{ matrix.os }}-node_${{ matrix.node }}-vite_${{ matrix.vite }}-svelte_${{matrix.svelte}}
138150
path: |
139151
test-temp.tar
140152
pnpm-debug.log

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@eslint/js": "^9.31.0",
2929
"@stylistic/eslint-plugin-js": "^4.4.1",
3030
"@sveltejs/eslint-config": "^8.2.0",
31-
"@sveltejs/kit": "^2.22.5",
31+
"@sveltejs/kit": "^2.23.0",
3232
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
3333
"@types/fs-extra": "^11.0.4",
3434
"@types/node": "^22.16.3",
@@ -51,7 +51,7 @@
5151
"prettier": "^3.6.2",
5252
"prettier-plugin-svelte": "^3.4.0",
5353
"publint": "^0.3.12",
54-
"svelte": "^5.35.6",
54+
"svelte": "^5.36.1",
5555
"svelte-eslint-parser": "^1.2.0",
5656
"typescript": "^5.8.3",
5757
"typescript-eslint": "^8.36.0",

packages/e2e-tests/_test_dependencies/svelte-api-only/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
},
1616
"type": "module",
1717
"dependencies": {
18-
"svelte": "^5.35.6"
18+
"svelte": "^5.0.0"
1919
}
2020
}

packages/e2e-tests/autoprefixer-browerslist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"autoprefixer": "^10.4.21",
1616
"postcss": "^8.5.6",
1717
"postcss-load-config": "^6.0.1",
18-
"svelte": "^5.35.6",
18+
"svelte": "^5.36.1",
1919
"svelte-preprocess": "^6.0.3",
2020
"vite": "^7.0.4"
2121
},

packages/e2e-tests/configfile-custom/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"devDependencies": {
1414
"@sveltejs/vite-plugin-svelte": "workspace:^",
15-
"svelte": "^5.35.6",
15+
"svelte": "^5.36.1",
1616
"vite": "^7.0.4"
1717
},
1818
"type": "module"

packages/e2e-tests/configfile-esm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"devDependencies": {
1414
"@sveltejs/vite-plugin-svelte": "workspace:^",
15-
"svelte": "^5.35.6",
15+
"svelte": "^5.36.1",
1616
"svelte-preprocess": "^6.0.3",
1717
"vite": "^7.0.4"
1818
},

packages/e2e-tests/css-dev-sourcemap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"devDependencies": {
1212
"@sveltejs/vite-plugin-svelte": "workspace:^",
1313
"sass": "^1.89.2",
14-
"svelte": "^5.35.6",
14+
"svelte": "^5.36.1",
1515
"vite": "^7.0.4"
1616
}
1717
}
Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1-
import { browserLogs, findAssetFile, getColor, getEl, getText, isBuild } from '~utils';
1+
import {
2+
browserLogs,
3+
findAssetFile,
4+
getColor,
5+
getEl,
6+
getText,
7+
IS_SVELTE_BASELINE,
8+
isBuild
9+
} from '~utils';
210
import { expect } from 'vitest';
311

4-
test('should not have failed requests', async () => {
5-
browserLogs.forEach((msg) => {
6-
expect(msg).not.toMatch('404');
12+
// support for treeshaking css was added after 5.0.0
13+
describe.skipIf(IS_SVELTE_BASELINE)('css-treeshake', () => {
14+
test('should not have failed requests', async () => {
15+
browserLogs.forEach((msg) => {
16+
expect(msg).not.toMatch('404');
17+
});
718
});
8-
});
9-
10-
test('should apply css from used components', async () => {
11-
expect(await getText('#app')).toBe('App');
12-
expect(await getColor('#app')).toBe('blue');
13-
expect(await getText('#a')).toBe('A');
14-
expect(await getColor('#a')).toBe('red');
15-
});
16-
17-
test('should apply css from unused components that contain global styles', async () => {
18-
expect(await getEl('head style[src]'));
19-
expect(await getColor('#test')).toBe('green'); // from B.svelte
20-
});
2119

22-
test('should not render unused components', async () => {
23-
expect(await getEl('#b')).toBeNull();
24-
expect(await getEl('#c')).toBeNull();
25-
});
20+
test('should apply css from used components', async () => {
21+
expect(await getText('#app')).toBe('App');
22+
expect(await getColor('#app')).toBe('blue');
23+
expect(await getText('#a')).toBe('A');
24+
expect(await getColor('#a')).toBe('red');
25+
});
2626

27-
if (isBuild) {
28-
test('should include unscoped global styles from unused components', async () => {
29-
const cssOutput = findAssetFile(/index-.*\.css/);
30-
expect(cssOutput).toContain('#test{color:green}'); // from B.svelte
27+
test('should apply css from unused components that contain global styles', async () => {
28+
expect(await getEl('head style[src]'));
29+
expect(await getColor('#test')).toBe('green'); // from B.svelte
3130
});
32-
test('should not include scoped styles from unused components', async () => {
33-
const cssOutput = findAssetFile(/index-.*\.css/);
34-
// from C.svelte
35-
expect(cssOutput).not.toContain('.unused');
31+
32+
test('should not render unused components', async () => {
33+
expect(await getEl('#b')).toBeNull();
34+
expect(await getEl('#c')).toBeNull();
3635
});
37-
}
36+
37+
if (isBuild) {
38+
test('should include unscoped global styles from unused components', async () => {
39+
const cssOutput = findAssetFile(/index-.*\.css/);
40+
expect(cssOutput).toContain('#test{color:green}'); // from B.svelte
41+
});
42+
test('should not include scoped styles from unused components', async () => {
43+
const cssOutput = findAssetFile(/index-.*\.css/);
44+
// from C.svelte
45+
expect(cssOutput).not.toContain('.unused');
46+
});
47+
}
48+
});

packages/e2e-tests/css-treeshake/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"devDependencies": {
1212
"@sveltejs/vite-plugin-svelte": "workspace:^",
1313
"sass": "^1.89.2",
14-
"svelte": "^5.35.6",
14+
"svelte": "^5.36.1",
1515
"vite": "^7.0.4"
1616
}
1717
}

0 commit comments

Comments
 (0)