Skip to content

Commit 45e1601

Browse files
authored
[fix] don't log warning if root is configured (#5330)
* [fix] don't log warning if root is configured * enforce root with improved check
1 parent aae5c65 commit 45e1601

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

.changeset/quick-chicken-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] don't log warning if root is configured

packages/kit/src/vite/index.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { get_aliases, resolve_entry } from './utils.js';
1818

1919
const cwd = process.cwd();
2020

21+
/** @type {Record<string, any>} */
2122
const enforced_config = {
2223
base: true,
2324
build: {
@@ -87,15 +88,6 @@ function kit() {
8788
name: 'vite-plugin-svelte-kit',
8889

8990
async config(config, { command }) {
90-
const overridden = find_overridden_config(config, enforced_config);
91-
92-
if (overridden.length > 0) {
93-
console.log(
94-
colors.bold().red('The following Vite config options will be overridden by SvelteKit:')
95-
);
96-
console.log(overridden.map((key) => ` - ${key}`).join('\n'));
97-
}
98-
9991
vite_user_config = config;
10092
svelte_config = await load_config();
10193

@@ -130,16 +122,19 @@ function kit() {
130122
input[name] = resolved;
131123
});
132124

133-
return get_default_config({
125+
const result = get_default_config({
134126
config: svelte_config,
135127
input,
136128
ssr: false,
137129
outDir: `${paths.client_out_dir}/immutable`
138130
});
131+
132+
warn_overridden_config(config, result);
133+
return result;
139134
}
140135

141136
// dev and preview config can be shared
142-
return {
137+
const result = {
143138
base: '/',
144139
build: {
145140
rollupOptions: {
@@ -155,6 +150,7 @@ function kit() {
155150
resolve: {
156151
alias: get_aliases(svelte_config.kit)
157152
},
153+
root: cwd,
158154
server: {
159155
fs: {
160156
allow: [
@@ -178,6 +174,8 @@ function kit() {
178174
}
179175
}
180176
};
177+
warn_overridden_config(config, result);
178+
return result;
181179
},
182180

183181
buildStart() {
@@ -332,17 +330,33 @@ function kit() {
332330

333331
/**
334332
* @param {Record<string, any>} config
335-
* @param {Record<string, any>} enforced_config
333+
* @param {Record<string, any>} resolved_config
336334
* @param {string} [path]
337335
* @param {string[]} [out] used locally to compute the return value
338336
*/
339-
function find_overridden_config(config, enforced_config, path = '', out = []) {
337+
function warn_overridden_config(config, resolved_config, path = '', out = []) {
338+
const overridden = find_overridden_config(config, resolved_config, path, out);
339+
if (overridden.length > 0) {
340+
console.log(
341+
colors.bold().red('The following Vite config options will be overridden by SvelteKit:')
342+
);
343+
console.log(overridden.map((key) => ` - ${key}`).join('\n'));
344+
}
345+
}
346+
347+
/**
348+
* @param {Record<string, any>} config
349+
* @param {Record<string, any>} resolved_config
350+
* @param {string} path
351+
* @param {string[]} out used locally to compute the return value
352+
*/
353+
function find_overridden_config(config, resolved_config, path, out) {
340354
for (const key in enforced_config) {
341355
if (key in config) {
342-
if (enforced_config[key] === true) {
356+
if (enforced_config[key] === true && config[key] !== resolved_config[key]) {
343357
out.push(path + key);
344358
} else {
345-
find_overridden_config(config[key], enforced_config[key], path + key + '.', out);
359+
find_overridden_config(config[key], resolved_config[key], path + key + '.', out);
346360
}
347361
}
348362
}

0 commit comments

Comments
 (0)