-
-
Notifications
You must be signed in to change notification settings - Fork 81
Description
Followup to #944 #952 and #984
Currently, the default config generated by sv cli uses this function:
dynamicCompileOptions: ({ filename }) =>
filename.includes('node_modules') ? undefined : { runes: true }This currently just checks for the existence of node_modules in the filename path for determining if the compiler should use runes mode.
As a result:
- It does not respect any existing
<svelte:options runes={false}>in.sveltefiles- edit: corrected, see comments
- It unintentionally forces runes mode for generated files in the
.svelte-kitfolder- edit: partially incorrect due to (1) being incorrect
- It unintentionally skips a path like
src/lib/leafnode_modules, or all paths if the username happens to benode_modules
A more complete solution could be instead to scope the changes to the src folder, and also skip .svelte files that contain <svelte:options as a "I know what I'm doing" hint.
Example function:
import { extname, join, relative } from 'node:path';
const srcDir = join(import.meta.dirname, 'src');
/** @type {import('@sveltejs/vite-plugin-svelte').PluginOptions['dynamicCompileOptions']} */
const dynamicCompileOptions = ({ filename, code }) => {
const isOutOfSrc = relative(srcDir, filename).startsWith('..');
// .svelte.ts and .svelte.js definitely require runes mode
const isSFCWithOptionDeclared =
extname(filename) === 'svelte' && code.includes('<svelte:options');
return isOutOfSrc || isSFCWithOptionDeclared ? undefined : { runes: true };
};However, I think sv cli is not the right place to apply this anyway, because if e.g. we want to update the function, that requires all users with generated configs to manually change their config; it is an inherently fragile execution of the concept.
Even the function I provided would be fragile against the user configuring a custom kit.files.src path.