Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-squids-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

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
2 changes: 1 addition & 1 deletion docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function mySvelteTransform() {
configResolved(c) {
// optional, use the exact same id filter as vite-plugin-svelte itself
const svelteIdFilter = c.plugins.find((p) => p.name === 'vite-plugin-svelte:config').api
.idFilter;
.filter.id;
plugin.transform.filter.id = svelteIdFilter;
},
transform: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/plugins/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function compile(api) {
name: 'vite-plugin-svelte:compile',
configResolved() {
//@ts-expect-error defined below but filter not in type
plugin.transform.filter = api.idFilter;
plugin.transform.filter = api.filter;
options = api.options;
compileSvelte = api.compileSvelte;
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-svelte/src/plugins/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export function configure(api, inlineOptions) {
api.options.stats = new VitePluginSvelteStats();
}

api.idFilter = buildIdFilter(options);

api.filter = buildIdFilter(options);
api.idFilter = api.filter;
api.idParser = buildIdParser(options);
api.compileSvelte = createCompileSvelte();
log.debug('resolved options', api.options, 'config');
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-svelte/src/plugins/hot-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export function hotUpdate(api) {
plugin.transform.filter = {
id: {
// reinclude virtual styles to get their output
include: [...api.idFilter.id.include, SVELTE_VIRTUAL_STYLE_ID_REGEX],
include: [...api.filter.id.include, SVELTE_VIRTUAL_STYLE_ID_REGEX],
exclude: [
// ignore files in node_modules, we don't hot update them
/\/node_modules\//,
// remove style exclusion
...api.idFilter.id.exclude.filter((filter) => filter !== SVELTE_VIRTUAL_STYLE_ID_REGEX)
...api.filter.id.exclude.filter((filter) => filter !== SVELTE_VIRTUAL_STYLE_ID_REGEX)
]
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/plugins/load-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function loadCustom(api) {
enforce: 'pre', // must come before vites own asset handling or custom extensions like .svg won't work
configResolved() {
//@ts-expect-error load defined below but filter not in type
plugin.load.filter = api.idFilter;
plugin.load.filter = api.filter;
},

load: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/plugins/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function preprocess(api) {
enforce: 'pre',
configResolved(c) {
//@ts-expect-error defined below but filter not in type
plugin.transform.filter = api.idFilter;
plugin.transform.filter = api.filter;
options = api.options;
if (arraify(options.preprocess).length > 0) {
preprocessSvelte = createPreprocessSvelte(options, c);
Expand Down
7 changes: 6 additions & 1 deletion packages/vite-plugin-svelte/src/types/plugin-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type { CompileSvelte } from './compile.d.ts';

export interface PluginAPI {
options: ResolvedOptions;
idFilter: IdFilter;
filter: IdFilter;
idParser: IdParser;
compileSvelte: CompileSvelte;
/**
* @deprecated use 'filter' instead
* // TODO remove in next major
*/
idFilter: IdFilter;
}
Loading