Skip to content

Commit d746d85

Browse files
committed
fix: reduce logging for deprecations
1 parent 37019aa commit d746d85

File tree

7 files changed

+41
-10
lines changed

7 files changed

+41
-10
lines changed

.changeset/cuddly-bars-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
reduce deprecation logging to info and allow disabling it with a flat

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ interface ExperimentalOptions {
173173
*/
174174
disableSvelteResolveWarnings?: boolean;
175175

176+
/**
177+
* disable api.sveltePreprocess info
178+
*
179+
* @default false
180+
*/
181+
disableApiSveltePreprocessWarnings?: boolean;
182+
176183
compileModule?: CompileModuleOptions;
177184
}
178185

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const SVELTE_EXPORT_CONDITIONS = ['svelte'];
2626
export const FAQ_LINK_MISSING_EXPORTS_CONDITION =
2727
'https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition';
2828

29+
export const LINK_TRANSFORM_WITH_PLUGIN =
30+
'https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/advanced-usage.md#transform-svelte-files-with-vite-plugins';
31+
2932
export const DEFAULT_SVELTE_EXT = ['.svelte'];
3033
export const DEFAULT_SVELTE_MODULE_INFIX = ['.svelte.'];
3134
export const DEFAULT_SVELTE_MODULE_EXT = ['.js', '.ts'];

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,12 @@ async function buildExtraConfigForDependencies(options, config) {
461461
}
462462
});
463463
if (
464+
!options.isBuild &&
464465
!options.experimental?.disableSvelteResolveWarnings &&
465466
packagesWithoutSvelteExportsCondition?.size > 0
466467
) {
467-
log.warn(
468-
`WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.\n\n${[
468+
log.info.once(
469+
`The following packages have a svelte field in their package.json but no exports condition for svelte.\n\n${[
469470
...packagesWithoutSvelteExportsCondition
470471
].join('\n')}\n\nPlease see ${FAQ_LINK_MISSING_EXPORTS_CONDITION} for details.`
471472
);

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { log } from './log.js';
22
import { normalizePath } from 'vite';
3+
import { LINK_TRANSFORM_WITH_PLUGIN } from './constants.js';
34

45
/**
56
* @param {import('../types/options.d.ts').ResolvedOptions} options
@@ -15,17 +16,24 @@ function buildExtraPreprocessors(options, config) {
1516
/** @type {import('svelte/compiler').PreprocessorGroup[]} */
1617
const appendPreprocessors = [];
1718

18-
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p.api?.sveltePreprocess);
19-
if (pluginsWithPreprocessorsDeprecated.length > 0) {
20-
log.warn(
21-
`The following plugins use the deprecated 'plugin.api.sveltePreprocess' field. Please contact their maintainers and ask them to use a vite plugin transform instead: ${pluginsWithPreprocessorsDeprecated
19+
/** @type {import('vite').Plugin[]} */
20+
const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
21+
22+
if (
23+
!options.isBuild &&
24+
!options.experimental?.disableApiSveltePreprocessWarnings &&
25+
pluginsWithPreprocessors.length > 0
26+
) {
27+
log.info.once(
28+
`The following plugins use the deprecated 'plugin.api.sveltePreprocess' field: ${pluginsWithPreprocessors
2229
.map((p) => p.name)
23-
.join(', ')}`
30+
.join(', ')}
31+
Please contact their maintainers and ask them to use a vite plugin transform instead.
32+
See ${LINK_TRANSFORM_WITH_PLUGIN} for more information.
33+
`.replace(/\t+/g, '\t')
2434
);
2535
}
2636
/** @type {import('vite').Plugin[]} */
27-
const pluginsWithPreprocessors = config.plugins.filter((p) => p?.api?.sveltePreprocess);
28-
/** @type {import('vite').Plugin[]} */
2937
const ignored = [];
3038
/** @type {import('vite').Plugin[]} */
3139
const included = [];

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ declare module '@sveltejs/vite-plugin-svelte' {
173173
*/
174174
disableSvelteResolveWarnings?: boolean;
175175

176+
/**
177+
* disable api.sveltePreprocess info
178+
*
179+
* @default false
180+
*/
181+
disableApiSveltePreprocessWarnings?: boolean;
182+
176183
compileModule?: CompileModuleOptions;
177184
}
178185

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
null,
2727
null
2828
],
29-
"mappings": ";;;;aAIYA,OAAOA;;WAETC,mBAAmBA;;;;;;;;;;;kBAWZC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAiDnBC,mBAAmBA;;;;;;;;;;;;;;;;WAgBnBC,oBAAoBA;;;;;;;;;;;;;;;MAezBC,SAASA;;kBAEGC,qBAAqBA;;;;;;;;;;;;;;;;;;iBChLtBC,MAAMA;iBCMNC,cAAcA;iBCFRC,gBAAgBA",
29+
"mappings": ";;;;aAIYA,OAAOA;;WAETC,mBAAmBA;;;;;;;;;;;kBAWZC,aAAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAgGbC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAiDnBC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;WAuBnBC,oBAAoBA;;;;;;;;;;;;;;;MAezBC,SAASA;;kBAEGC,qBAAqBA;;;;;;;;;;;;;;;;;;iBCvLtBC,MAAMA;iBCMNC,cAAcA;iBCFRC,gBAAgBA",
3030
"ignoreList": []
3131
}

0 commit comments

Comments
 (0)