Skip to content

Commit f9cd5a9

Browse files
committed
feat(warnings): hide warnings in node_modules by default
1 parent 38fd166 commit f9cd5a9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/vite-plugin-svelte/src/public.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ export interface SvelteConfig {
136136
/**
137137
* Handles warning emitted from the Svelte compiler
138138
*
139+
* warnings emitted for files in node_modules are logged at the debug level, to see them run
140+
* `DEBUG=vite-plugin-svelte:node-modules-onwarn pnpm build`
141+
*
139142
* @example
140143
* ```
141144
* (warning, defaultHandler) => {
@@ -145,6 +148,7 @@ export interface SvelteConfig {
145148
* }
146149
* }
147150
* ```
151+
*
148152
*/
149153
onwarn?: (warning: Warning, defaultHandler: (warning: Warning) => void) => void;
150154
/**

packages/vite-plugin-svelte/src/utils/log.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,26 @@ function buildExtraWarnings(warnings, isBuild) {
226226
* @param {import('svelte/compiler').Warning} w
227227
*/
228228
function warnDev(w) {
229-
if (log.info.enabled) log.info(buildExtendedLogMessage(w));
229+
if (w.filename?.includes('node_modules')) {
230+
if (isDebugNamespaceEnabled('node-modules-onwarn')) {
231+
log.debug(buildExtendedLogMessage(w), undefined, 'node-modules-onwarn');
232+
}
233+
} else if (log.info.enabled) {
234+
log.info(buildExtendedLogMessage(w));
235+
}
230236
}
231237

232238
/**
233239
* @param {import('svelte/compiler').Warning & {frame?: string}} w
234240
*/
235241
function warnBuild(w) {
236-
if (log.warn.enabled) log.warn(buildExtendedLogMessage(w), w.frame);
242+
if (w.filename?.includes('node_modules')) {
243+
if (isDebugNamespaceEnabled('node-modules-onwarn')) {
244+
log.debug(buildExtendedLogMessage(w), w.frame, 'node-modules-onwarn');
245+
}
246+
} else if (log.warn.enabled) {
247+
log.warn(buildExtendedLogMessage(w), w.frame);
248+
}
237249
}
238250

239251
/**

0 commit comments

Comments
 (0)