diff --git a/.changeset/spotty-garlics-search.md b/.changeset/spotty-garlics-search.md new file mode 100644 index 000000000..3fdbd17de --- /dev/null +++ b/.changeset/spotty-garlics-search.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': minor +--- + +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`. diff --git a/packages/vite-plugin-svelte/src/public.d.ts b/packages/vite-plugin-svelte/src/public.d.ts index 0278d2770..ee9c89c86 100644 --- a/packages/vite-plugin-svelte/src/public.d.ts +++ b/packages/vite-plugin-svelte/src/public.d.ts @@ -136,6 +136,9 @@ export interface SvelteConfig { /** * Handles warning emitted from the Svelte compiler * + * warnings emitted for files in node_modules are logged at the debug level, to see them run + * `DEBUG=vite-plugin-svelte:node-modules-onwarn pnpm build` + * * @example * ``` * (warning, defaultHandler) => { @@ -145,6 +148,7 @@ export interface SvelteConfig { * } * } * ``` + * */ onwarn?: (warning: Warning, defaultHandler: (warning: Warning) => void) => void; /** diff --git a/packages/vite-plugin-svelte/src/utils/log.js b/packages/vite-plugin-svelte/src/utils/log.js index 4bb15c1a5..9769ead7f 100644 --- a/packages/vite-plugin-svelte/src/utils/log.js +++ b/packages/vite-plugin-svelte/src/utils/log.js @@ -226,14 +226,26 @@ function buildExtraWarnings(warnings, isBuild) { * @param {import('svelte/compiler').Warning} w */ function warnDev(w) { - if (log.info.enabled) log.info(buildExtendedLogMessage(w)); + if (w.filename?.includes('node_modules')) { + if (isDebugNamespaceEnabled('node-modules-onwarn')) { + log.debug(buildExtendedLogMessage(w), undefined, 'node-modules-onwarn'); + } + } else if (log.info.enabled) { + log.info(buildExtendedLogMessage(w)); + } } /** * @param {import('svelte/compiler').Warning & {frame?: string}} w */ function warnBuild(w) { - if (log.warn.enabled) log.warn(buildExtendedLogMessage(w), w.frame); + if (w.filename?.includes('node_modules')) { + if (isDebugNamespaceEnabled('node-modules-onwarn')) { + log.debug(buildExtendedLogMessage(w), w.frame, 'node-modules-onwarn'); + } + } else if (log.warn.enabled) { + log.warn(buildExtendedLogMessage(w), w.frame); + } } /** diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts index f2c3838be..5d6c1fa9b 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -136,6 +136,9 @@ declare module '@sveltejs/vite-plugin-svelte' { /** * Handles warning emitted from the Svelte compiler * + * warnings emitted for files in node_modules are logged at the debug level, to see them run + * `DEBUG=vite-plugin-svelte:node-modules-onwarn pnpm build` + * * @example * ``` * (warning, defaultHandler) => { @@ -145,6 +148,7 @@ declare module '@sveltejs/vite-plugin-svelte' { * } * } * ``` + * */ onwarn?: (warning: Warning, defaultHandler: (warning: Warning) => void) => void; /** diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map index b01db05a6..f45ed2c62 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts.map +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -22,5 +22,5 @@ null, null ], - "mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA8EZC,qBAAqBA;;;;;;;;;;;;;iBCtKtBC,MAAMA;iBCTNC,cAAcA;iBCgBRC,gBAAgBA" + "mappings": ";;;;aAIYA,OAAOA;;;;;;;;;;;;;kBAaFC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAkFZC,qBAAqBA;;;;;;;;;;;;;iBC1KtBC,MAAMA;iBCTNC,cAAcA;iBCgBRC,gBAAgBA" } \ No newline at end of file