1
1
import fs from 'node:fs' ;
2
2
import path from 'node:path' ;
3
3
4
- import { svelte } from '@sveltejs/vite-plugin-svelte ' ;
4
+ import * as imr from 'import-meta-resolve ' ;
5
5
import colors from 'kleur' ;
6
- import * as vite from 'vite' ;
7
6
8
7
import { copy , mkdirp , posixify , read , resolve_entry , rimraf } from '../../utils/filesystem.js' ;
9
8
import { create_static_module , create_dynamic_module } from '../../core/env.js' ;
@@ -34,6 +33,7 @@ import {
34
33
sveltekit_environment ,
35
34
sveltekit_paths
36
35
} from './module_ids.js' ;
36
+ import { pathToFileURL } from 'node:url' ;
37
37
38
38
const cwd = process . cwd ( ) ;
39
39
@@ -122,6 +122,17 @@ const warning_preprocessor = {
122
122
}
123
123
} ;
124
124
125
+ /**
126
+ * Resolve a dependency relative to the current working directory,
127
+ * rather than relative to this package
128
+ * @param {string } dependency
129
+ */
130
+ async function resolve_peer_dependency ( dependency ) {
131
+ // @ts -expect-error the types are wrong
132
+ const resolved = await imr . resolve ( dependency , pathToFileURL ( process . cwd ( ) + '/dummy.js' ) ) ;
133
+ return import ( resolved ) ;
134
+ }
135
+
125
136
/**
126
137
* Returns the SvelteKit Vite plugins.
127
138
* @returns {Promise<import('vite').Plugin[]> }
@@ -153,7 +164,9 @@ export async function sveltekit() {
153
164
...svelte_config . vitePlugin
154
165
} ;
155
166
156
- return [ ...svelte ( vite_plugin_svelte_options ) , ...kit ( { svelte_config } ) ] ;
167
+ const { svelte } = await resolve_peer_dependency ( '@sveltejs/vite-plugin-svelte' ) ;
168
+
169
+ return [ ...svelte ( vite_plugin_svelte_options ) , ...( await kit ( { svelte_config } ) ) ] ;
157
170
}
158
171
159
172
// These variables live outside the `kit()` function because it is re-invoked by each Vite build
@@ -174,9 +187,11 @@ let manifest_data;
174
187
* - https://rollupjs.org/guide/en/#output-generation-hooks
175
188
*
176
189
* @param {{ svelte_config: import('types').ValidatedConfig } } options
177
- * @return {import('vite').Plugin[] }
190
+ * @return {Promise< import('vite').Plugin[]> }
178
191
*/
179
- function kit ( { svelte_config } ) {
192
+ async function kit ( { svelte_config } ) {
193
+ const vite = await resolve_peer_dependency ( 'vite' ) ;
194
+
180
195
const { kit } = svelte_config ;
181
196
const out = `${ kit . outDir } /output` ;
182
197
0 commit comments