Skip to content

Commit

Permalink
fix: only apply infix filter to basename (#920)
Browse files Browse the repository at this point in the history
* fix: only apply infix filter to basename

* Update packages/vite-plugin-svelte/src/utils/id.js

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
Rich-Harris and dummdidumm authored May 27, 2024
1 parent 2157d16 commit bc8026f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-eagles-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

fix: only apply infix filter to basename
14 changes: 10 additions & 4 deletions packages/vite-plugin-svelte/src/utils/id.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createFilter, normalizePath } from 'vite';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { log } from './log.js';
import { DEFAULT_SVELTE_MODULE_EXT, DEFAULT_SVELTE_MODULE_INFIX } from './constants.js';

Expand Down Expand Up @@ -179,10 +180,15 @@ function buildFilter(include, exclude, extensions) {
*/
function buildModuleFilter(include, exclude, infixes, extensions) {
const rollupFilter = createFilter(include, exclude);
return (filename) =>
rollupFilter(filename) &&
infixes.some((infix) => filename.includes(infix)) &&
extensions.some((ext) => filename.endsWith(ext));
return (filename) => {
const basename = path.basename(filename);

return (
rollupFilter(filename) &&
infixes.some((infix) => basename.includes(infix)) &&
extensions.some((ext) => basename.endsWith(ext))
);
};
}

/**
Expand Down

0 comments on commit bc8026f

Please sign in to comment.