Skip to content

Commit 47e8a9f

Browse files
authored
fix: reduce logging for deprecations (#1158)
* fix: reduce logging for deprecations * fix wording
1 parent 072f214 commit 47e8a9f

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 flag

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 deprecation warnings
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,4 +1,5 @@
11
import { log } from './log.js';
2+
import { LINK_TRANSFORM_WITH_PLUGIN } from './constants.js';
23

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

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