Skip to content

Commit

Permalink
[fix] don't log warning if root is configured (#5330)
Browse files Browse the repository at this point in the history
* [fix] don't log warning if root is configured

* enforce root with improved check
  • Loading branch information
benmccann authored Jul 1, 2022
1 parent aae5c65 commit 45e1601
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-chicken-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] don't log warning if root is configured
44 changes: 29 additions & 15 deletions packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { get_aliases, resolve_entry } from './utils.js';

const cwd = process.cwd();

/** @type {Record<string, any>} */
const enforced_config = {
base: true,
build: {
Expand Down Expand Up @@ -87,15 +88,6 @@ function kit() {
name: 'vite-plugin-svelte-kit',

async config(config, { command }) {
const overridden = find_overridden_config(config, enforced_config);

if (overridden.length > 0) {
console.log(
colors.bold().red('The following Vite config options will be overridden by SvelteKit:')
);
console.log(overridden.map((key) => ` - ${key}`).join('\n'));
}

vite_user_config = config;
svelte_config = await load_config();

Expand Down Expand Up @@ -130,16 +122,19 @@ function kit() {
input[name] = resolved;
});

return get_default_config({
const result = get_default_config({
config: svelte_config,
input,
ssr: false,
outDir: `${paths.client_out_dir}/immutable`
});

warn_overridden_config(config, result);
return result;
}

// dev and preview config can be shared
return {
const result = {
base: '/',
build: {
rollupOptions: {
Expand All @@ -155,6 +150,7 @@ function kit() {
resolve: {
alias: get_aliases(svelte_config.kit)
},
root: cwd,
server: {
fs: {
allow: [
Expand All @@ -178,6 +174,8 @@ function kit() {
}
}
};
warn_overridden_config(config, result);
return result;
},

buildStart() {
Expand Down Expand Up @@ -332,17 +330,33 @@ function kit() {

/**
* @param {Record<string, any>} config
* @param {Record<string, any>} enforced_config
* @param {Record<string, any>} resolved_config
* @param {string} [path]
* @param {string[]} [out] used locally to compute the return value
*/
function find_overridden_config(config, enforced_config, path = '', out = []) {
function warn_overridden_config(config, resolved_config, path = '', out = []) {
const overridden = find_overridden_config(config, resolved_config, path, out);
if (overridden.length > 0) {
console.log(
colors.bold().red('The following Vite config options will be overridden by SvelteKit:')
);
console.log(overridden.map((key) => ` - ${key}`).join('\n'));
}
}

/**
* @param {Record<string, any>} config
* @param {Record<string, any>} resolved_config
* @param {string} path
* @param {string[]} out used locally to compute the return value
*/
function find_overridden_config(config, resolved_config, path, out) {
for (const key in enforced_config) {
if (key in config) {
if (enforced_config[key] === true) {
if (enforced_config[key] === true && config[key] !== resolved_config[key]) {
out.push(path + key);
} else {
find_overridden_config(config[key], enforced_config[key], path + key + '.', out);
find_overridden_config(config[key], resolved_config[key], path + key + '.', out);
}
}
}
Expand Down

0 comments on commit 45e1601

Please sign in to comment.