Skip to content

Commit 54d3bb5

Browse files
authored
feat(warnings): hide warnings in node_modules by default (#989)
* feat(warnings): hide warnings in node_modules by default * chore: update types
1 parent 19cfe33 commit 54d3bb5

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

.changeset/spotty-garlics-search.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': minor
3+
---
4+
5+
feat(warnings): change default loglevel of warnings originating from files in node_modules to debug. To see them call `DEBUG:vite-plugin-svelte:node-modules-onwarn pnpm build`.

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

+4
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

+14-2
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
/**

packages/vite-plugin-svelte/types/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ declare module '@sveltejs/vite-plugin-svelte' {
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 @@ declare module '@sveltejs/vite-plugin-svelte' {
145148
* }
146149
* }
147150
* ```
151+
*
148152
*/
149153
onwarn?: (warning: Warning, defaultHandler: (warning: Warning) => void) => void;
150154
/**

packages/vite-plugin-svelte/types/index.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
null,
2323
null
2424
],
25-
"mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8EZC,qBAAqBA;;;;;;;;;;;;;iBCtKtBC,MAAMA;iBCTNC,cAAcA;iBCgBRC,gBAAgBA"
25+
"mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkFZC,qBAAqBA;;;;;;;;;;;;;iBC1KtBC,MAAMA;iBCTNC,cAAcA;iBCgBRC,gBAAgBA"
2626
}

0 commit comments

Comments
 (0)