Skip to content

Commit f9e4632

Browse files
authored
fix(api): rename idFilter to filter to avoid confusion (#1199)
1 parent cf5a6be commit f9e4632

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

.changeset/ninety-squids-lead.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+
fix(api): add `api.filter` and deprecate `api.idFilter` to avoid confusing `filter.id = idFilter.id` assignments when used as hybrid filter in other plugins

docs/advanced-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function mySvelteTransform() {
1919
configResolved(c) {
2020
// optional, use the exact same id filter as vite-plugin-svelte itself
2121
const svelteIdFilter = c.plugins.find((p) => p.name === 'vite-plugin-svelte:config').api
22-
.idFilter;
22+
.filter.id;
2323
plugin.transform.filter.id = svelteIdFilter;
2424
},
2525
transform: {

packages/vite-plugin-svelte/src/plugins/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function compile(api) {
2020
name: 'vite-plugin-svelte:compile',
2121
configResolved() {
2222
//@ts-expect-error defined below but filter not in type
23-
plugin.transform.filter = api.idFilter;
23+
plugin.transform.filter = api.filter;
2424
options = api.options;
2525
compileSvelte = api.compileSvelte;
2626
},

packages/vite-plugin-svelte/src/plugins/configure.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export function configure(api, inlineOptions) {
7171
api.options.stats = new VitePluginSvelteStats();
7272
}
7373

74-
api.idFilter = buildIdFilter(options);
75-
74+
api.filter = buildIdFilter(options);
75+
api.idFilter = api.filter;
7676
api.idParser = buildIdParser(options);
7777
api.compileSvelte = createCompileSvelte();
7878
log.debug('resolved options', api.options, 'config');

packages/vite-plugin-svelte/src/plugins/hot-update.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export function hotUpdate(api) {
3434
plugin.transform.filter = {
3535
id: {
3636
// reinclude virtual styles to get their output
37-
include: [...api.idFilter.id.include, SVELTE_VIRTUAL_STYLE_ID_REGEX],
37+
include: [...api.filter.id.include, SVELTE_VIRTUAL_STYLE_ID_REGEX],
3838
exclude: [
3939
// ignore files in node_modules, we don't hot update them
4040
/\/node_modules\//,
4141
// remove style exclusion
42-
...api.idFilter.id.exclude.filter((filter) => filter !== SVELTE_VIRTUAL_STYLE_ID_REGEX)
42+
...api.filter.id.exclude.filter((filter) => filter !== SVELTE_VIRTUAL_STYLE_ID_REGEX)
4343
]
4444
}
4545
};

packages/vite-plugin-svelte/src/plugins/load-custom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function loadCustom(api) {
1515
enforce: 'pre', // must come before vites own asset handling or custom extensions like .svg won't work
1616
configResolved() {
1717
//@ts-expect-error load defined below but filter not in type
18-
plugin.load.filter = api.idFilter;
18+
plugin.load.filter = api.filter;
1919
},
2020

2121
load: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function preprocess(api) {
3232
enforce: 'pre',
3333
configResolved(c) {
3434
//@ts-expect-error defined below but filter not in type
35-
plugin.transform.filter = api.idFilter;
35+
plugin.transform.filter = api.filter;
3636
options = api.options;
3737
if (arraify(options.preprocess).length > 0) {
3838
preprocessSvelte = createPreprocessSvelte(options, c);

packages/vite-plugin-svelte/src/types/plugin-api.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import type { CompileSvelte } from './compile.d.ts';
44

55
export interface PluginAPI {
66
options: ResolvedOptions;
7-
idFilter: IdFilter;
7+
filter: IdFilter;
88
idParser: IdParser;
99
compileSvelte: CompileSvelte;
10+
/**
11+
* @deprecated use 'filter' instead
12+
* // TODO remove in next major
13+
*/
14+
idFilter: IdFilter;
1015
}

0 commit comments

Comments
 (0)