Use `dynamicCompileOptions` instead of `compilerOptions.runes` for `create`

Open Beginner friendly
#1,466 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
nodejs, typescript
Domain
cli, tooling

Research direction

Search the scaffolder's templates for the sveltekit({ compilerOptions: { runes: ... } }) block, which is the only code the payload names. Replace it with the dynamicCompileOptions form from the issue, and check whether the optional node:path sep change should also be made. Done when the generated project still forces runes for app code but not for node_modules, which you can confirm by scaffolding a project and inspecting its svelte.config.js.

Written by the indexing model from the issue text.

Description

As I was experimenting with the project scaffolder, I noticed I could steal that compilerOptions.runes trick to make sure runes are enforced in Svelte Changelog.

But while copying it and reading the docs, I noticed they mention Vite users (SvelteKit) should prefer dynamicCompileOptions. dynamicCompileOptions docs also provide an (outdated but) explicit example for that kind of check.

As a result, the template should probably be changed:

			sveltekit({
				// Force runes mode for the project, except for libraries. Can be removed in Svelte 6.
-				compilerOptions: {
-					runes: ({ filename }) =>
-						filename.split(/[/\\]/).includes('node_modules') ? undefined : true
+				dynamicCompileOptions: ({ filename, compileOptions }) => {
+					if (!filename.split(/[/\\]/).includes('node_modules') && !compileOptions.runes) {
+						return { runes: true };
+					}
				},
				adapter: adapter()
			})

Additionally, Node (and Bun) environments can take advantage of "node:path".sep instead of a (non-precompiled) regex, improving performance:

+import { sep } from 'node:path';

...
-					if (!filename.split(/[/\\]/).includes('node_modules') && !compileOptions.runes) {
+					if (!filename.split(sep).includes('node_modules') && !compileOptions.runes) {
...
Dominant language
TypeScript
Stars
513
Forks
110
Avg merge
5d 1h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sveltejs/cli

All issues in sveltejs/cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.