Skip to content

Commit

Permalink
fix: Defer warnings until after vite warning message (#5563)
Browse files Browse the repository at this point in the history
* feat: Overridden config warning AFTER server start

* fix: Make it easier to add other warnings later

* Changeset

* fix: gtm-nayan is smarter than I am

* Update packages/kit/src/vite/index.js

Co-authored-by: Bjorn Lu <[email protected]>

* fix: Remove unnecessary function replacement

* feat: gtm-nyan saves the day

* Update packages/kit/src/vite/index.js

Co-authored-by: Simon H <[email protected]>

* tweak implementation

* remove unused parameter

* oops

Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Simon H <[email protected]>
Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
4 people authored Jul 21, 2022
1 parent bfac97a commit 9aaa9a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-pans-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] vite dev no longer covers errors
24 changes: 19 additions & 5 deletions packages/kit/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ function kit() {
/** @type {import('types').BuildData} */
let build_data;

/** @type {string | undefined} */
let deferred_warning;

/**
* @type {{
* build_dir: string;
Expand Down Expand Up @@ -188,7 +191,8 @@ function kit() {

const new_config = vite_client_build_config();

warn_overridden_config(config, new_config);
const warning = warn_overridden_config(config, new_config);
if (warning) console.error(warning + '\n');

return new_config;
}
Expand Down Expand Up @@ -235,7 +239,8 @@ function kit() {
}
}
};
warn_overridden_config(config, result);

deferred_warning = warn_overridden_config(config, result);
return result;
},

Expand Down Expand Up @@ -373,6 +378,14 @@ function kit() {
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
*/
async configureServer(vite) {
// This method is called by Vite after clearing the screen.
// This patch ensures we can log any important messages afterwards for the user to see.
const print_urls = vite.printUrls;
vite.printUrls = function () {
print_urls.apply(this);
if (deferred_warning) console.error('\n' + deferred_warning);
};

return await dev(vite, vite_config, svelte_config);
},

Expand Down Expand Up @@ -422,11 +435,12 @@ function collect_output(bundle) {
*/
function warn_overridden_config(config, resolved_config) {
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);

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

Expand Down

0 comments on commit 9aaa9a7

Please sign in to comment.