Skip to content

Commit 4542e68

Browse files
breaking: stop re-exporting vitePreprocess (#11297)
--------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Simon Holthausen <[email protected]>
1 parent 4f71ea1 commit 4542e68

File tree

15 files changed

+162
-382
lines changed

15 files changed

+162
-382
lines changed

.changeset/nine-moles-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': major
3+
---
4+
5+
breaking: stop re-exporting vitePreprocess

documentation/docs/60-appendix/20-integrations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Preprocessors transform your `.svelte` files before passing them to the compiler
88

99
### `vitePreprocess`
1010

11-
`vite-plugin-svelte` offers a [`vitePreprocess`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md) feature which utilizes Vite for preprocessing. It is capable of handling the language flavors Vite handles: TypeScript, PostCSS, SCSS, Less, Stylus, and SugarSS. For convenience, it is re-exported from the `@sveltejs/kit/vite` package. If you set your project up with TypeScript it will be included by default:
11+
`vite-plugin-svelte` offers a [`vitePreprocess`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md) feature which utilizes Vite for preprocessing. It is capable of handling the language flavors Vite handles: TypeScript, PostCSS, SCSS, Less, Stylus, and SugarSS. If you set your project up with TypeScript it will be included by default:
1212

1313
```js
1414
// svelte.config.js
15-
import { vitePreprocess } from '@sveltejs/kit/vite';
15+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
1616

1717
export default {
1818
preprocess: [vitePreprocess()]

documentation/docs/60-appendix/30-migrating-to-sveltekit-2.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ If a form contains an `<input type="file">` but does not have an `enctype="multi
127127

128128
Previously, the generated `tsconfig.json` was trying its best to still produce a somewhat valid config when your `tsconfig.json` included `paths` or `baseUrl`. In SvelteKit 2, the validation is more strict and will warn when you use either `paths` or `baseUrl` in your `tsconfig.json`. These settings are used to generate path aliases and you should use [the `alias` config](configuration#alias) option in your `svelte.config.js` instead, to also create a corresponding alias for the bundler.
129129

130+
## `vitePreprocess` is no longer exported from `@sveltejs/kit/vite`
131+
132+
Since `@sveltejs/vite-plugin-svelte` is now a peer dependency, SvelteKit 2 no longer re-exports `vitePreprocess`. You should import it directly from `@svelte/vite-plugin-svelte`.
133+
130134
## Updated dependency requirements
131135

132136
SvelteKit 2 requires Node `18.13` or higher, and the following minimum dependency versions:

packages/create-svelte/shared/+default+checkjs/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import { vitePreprocess } from '@sveltejs/kit/vite';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {

packages/create-svelte/shared/+default+typescript/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import { vitePreprocess } from '@sveltejs/kit/vite';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {

packages/create-svelte/shared/+typescript/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import { vitePreprocess } from '@sveltejs/kit/vite';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {

packages/create-svelte/templates/default/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@neoconfetti/svelte": "^1.0.0",
1212
"@sveltejs/adapter-auto": "workspace:*",
1313
"@sveltejs/kit": "workspace:*",
14+
"@sveltejs/vite-plugin-svelte": "^3.0.0",
1415
"svelte": "^4.2.8",
1516
"typescript": "^5.3.3",
1617
"vite": "^5.0.8"

packages/create-svelte/templates/default/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import { vitePreprocess } from '@sveltejs/kit/vite';
2+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
// This config is ignored and replaced with one of the configs in the shared folder when a project is created.
55

packages/kit/src/exports/vite/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ import {
3737
sveltekit_paths
3838
} from './module_ids.js';
3939

40-
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
41-
4240
const cwd = process.cwd();
4341

4442
/** @type {import('./types.js').EnforcedConfig} */

packages/kit/types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,6 @@ declare module '@sveltejs/kit/node/polyfills' {
18371837
}
18381838

18391839
declare module '@sveltejs/kit/vite' {
1840-
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
18411840
/**
18421841
* Returns the SvelteKit Vite plugins.
18431842
* */

packages/migrate/migrations/sveltekit-2/migrate.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,47 @@ export function update_svelte_config() {
8787
*/
8888
export function update_svelte_config_content(code) {
8989
const regex = /\s*dangerZone:\s*{[^}]*},?/g;
90-
return code.replace(regex, '');
90+
const result = code.replace(regex, '');
91+
if (result !== code) {
92+
log_migration(
93+
'Removed `dangerZone` from svelte.config.js: https://kit.svelte.dev/docs/v2-migration-guide#server-fetches-are-not-trackable-anymore'
94+
);
95+
}
96+
97+
const project = new Project({ useInMemoryFileSystem: true });
98+
const source = project.createSourceFile('svelte.ts', result);
99+
100+
const namedImport = get_import(source, '@sveltejs/kit/vite', 'vitePreprocess');
101+
if (!namedImport) return result;
102+
103+
const logger = log_on_ts_modification(
104+
source,
105+
'Changed `vitePreprocess` import: https://kit.svelte.dev/docs/v2-migration-guide#vitepreprocess-is-no-longer-exported-from-sveltejs-kit-vite'
106+
);
107+
108+
if (namedImport.getParent().getParent().getNamedImports().length === 1) {
109+
namedImport
110+
.getParent()
111+
.getParent()
112+
.getParent()
113+
.setModuleSpecifier('@sveltejs/vite-plugin-svelte');
114+
} else {
115+
namedImport.remove();
116+
const vps = source.getImportDeclaration(
117+
(i) => i.getModuleSpecifierValue() === '@sveltejs/vite-plugin-svelte'
118+
);
119+
if (vps) {
120+
vps.addNamedImport('vitePreprocess');
121+
} else {
122+
source.addImportDeclaration({
123+
moduleSpecifier: '@sveltejs/vite-plugin-svelte',
124+
namedImports: ['vitePreprocess']
125+
});
126+
}
127+
}
128+
129+
logger();
130+
return source.getFullText();
91131
}
92132

93133
/**
@@ -231,6 +271,11 @@ function replace_resolve_path(source) {
231271
const namedImport = get_import(source, '@sveltejs/kit', 'resolvePath');
232272
if (!namedImport) return;
233273

274+
const logger = log_on_ts_modification(
275+
source,
276+
'Replaced `resolvePath` with `resolveRoute`: https://kit.svelte.dev/docs/v2-migration-guide#resolvePath-has-been-removed'
277+
);
278+
234279
for (const id of namedImport.getNameNode().findReferencesAsNodes()) {
235280
id.replaceWithText('resolveRoute');
236281
}
@@ -251,6 +296,8 @@ function replace_resolve_path(source) {
251296
namedImports: ['resolveRoute']
252297
});
253298
}
299+
300+
logger();
254301
}
255302

256303
/**

packages/migrate/migrations/sveltekit-2/svelte-config-samples.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,85 @@ export default {
4242
}
4343
};
4444
```
45+
46+
## Replaces vitePreprocess import (1)
47+
48+
```js before
49+
import adapter from '@sveltejs/adapter-auto';
50+
import { vitePreprocess } from '@sveltejs/kit/vite';
51+
52+
/** @type {import('@sveltejs/kit').Config} */
53+
const config = {
54+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
55+
// for more information about preprocessors
56+
preprocess: vitePreprocess(),
57+
58+
kit: {
59+
adapter: adapter()
60+
}
61+
};
62+
63+
export default config;
64+
```
65+
66+
```js after
67+
import adapter from '@sveltejs/adapter-auto';
68+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
69+
70+
/** @type {import('@sveltejs/kit').Config} */
71+
const config = {
72+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
73+
// for more information about preprocessors
74+
preprocess: vitePreprocess(),
75+
76+
kit: {
77+
adapter: adapter()
78+
}
79+
};
80+
81+
export default config;
82+
```
83+
84+
## Replaces vitePreprocess import (2)
85+
86+
```js before
87+
import adapter from '@sveltejs/adapter-auto';
88+
import { vitePreprocess, foo } from '@sveltejs/kit/vite';
89+
90+
export default {
91+
preprocess: vitePreprocess()
92+
};
93+
```
94+
95+
<!-- prettier-ignore -->
96+
```js after
97+
import adapter from '@sveltejs/adapter-auto';
98+
import { foo } from '@sveltejs/kit/vite';
99+
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
100+
101+
export default {
102+
preprocess: vitePreprocess()
103+
};
104+
```
105+
106+
## Replaces vitePreprocess import (3)
107+
108+
```js before
109+
import adapter from '@sveltejs/adapter-auto';
110+
import { vitePreprocess, foo } from '@sveltejs/kit/vite';
111+
import { a } from '@sveltejs/vite-plugin-svelte';
112+
113+
export default {
114+
preprocess: vitePreprocess()
115+
};
116+
```
117+
118+
```js after
119+
import adapter from '@sveltejs/adapter-auto';
120+
import { foo } from '@sveltejs/kit/vite';
121+
import { a, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
122+
123+
export default {
124+
preprocess: vitePreprocess()
125+
};
126+
```

packages/package/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"svelte2tsx": "~0.6.27"
1919
},
2020
"devDependencies": {
21+
"@sveltejs/vite-plugin-svelte": "^3.0.1",
2122
"@types/node": "^18.19.3",
2223
"@types/semver": "^7.5.6",
2324
"svelte": "^4.2.8",

packages/package/test/fixtures/resolve-alias/svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { vitePreprocess } from '../../../../kit/src/exports/vite/index.js';
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
22
import { fileURLToPath } from 'node:url';
33
import path from 'node:path';
44

0 commit comments

Comments
 (0)