Skip to content

Allow more flexible glob matchers for runic js/ts modules #11536

Closed
@Hugos68

Description

@Hugos68

Describe the problem

When you want to write runic code outside .svelte files you require to use the .svelte.js or .svelte.ts extension. This is fine and benefits compile times.

The issue with this is that it can easily conflict with other libraries/frameworks that also utilize files extensions, in my case: Vitest.
Sveltekit by default through the npm create svelte CLI adds the following matchers:

export default defineConfig({
	plugins: [sveltekit()],
	test: {
		include: ['src/**/*.{test,spec}.{js,ts}']
	}
});

This means when you require runic code inside test files you need to first rename your test file to .test.svelte.ts and then add the matcher to the vite config. Not only is this tedious but VSCode extensions like Vitest also don't understand this extra file extension which hurts the DX quite a bit for writing runic code/tests.
(Yes, you need runes inside test files because you might test a module that receives some state)

Describe the proposed solution

The solution would be that the compiler uses a more flexible matcher for compiling js/ts files, of the top of my head I came up with: *.svelte.*{js,ts}.
Here are a couple of test cases that showcase the matches:

svelte-module.ts // ignored
module-svelte.ts // ignored
svelte.module.ts // ignored
module.svelte.ts // match
module.svelte.test.ts // match
module.test.svelte.ts // match

This allows for more flexible file names that don't degrade the experience with testing. I'm sure there are more frameworks/libraries that also utilize file extensions (potentially storybook) so I wouldn't say this is an edge case but a pretty common use case.

A bonus would be if when checking the Vitest option through the CLI scaffolds these matchers.

Importance

would make my life easier

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions