fix: Svelte module resolution tweaks#2481
Merged
dummdidumm merged 10 commits intomasterfrom Aug 30, 2024
Merged
Conversation
This change allows people to write export maps using only a `svelte` condition (and no `types` condition) and still have the types for their components resolved (i.e. the import is found) as long as they use TypeScript (i.e. have lang="ts" attribute) inside it. This should help people using monorepo setups with strong typings and not wanting to provide d.ts files alongside. This is achieved doing three adjustments: - add `customConditions: ['svelte']` to the compiler options, so that TypeScript's resolution algorithm takes it into account - ensure that Svelte files have a module kind of ESM, so that TypeScript's resolution algorithm goes into the right branches - deal with `.d.svelte.ts` files in the context of an exports map, because that's what TypeScript will try to resolve this to in the end This is also related to #1056 insofar that we align with TypeScript for this new capability: We don't resolve the file if it's a component not using TypeScript (i.e. not having the lang="ts" tag), similar to how TypeScript does not resolve .js files within node_modules
…ke `./foo.svelte` make .svelte query before .svelte.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is essentially #2478 minus the exports map changes: Svelte files are now resolved by intercepting checks for
.d.svelte.tsinstead of.svelte.ts. As a consequence, we can handle siblingfoo.svelte/foo.svelte.tsfiles and importing both. When doingimport Foo from './foo.sveltethis now resolves to the Svelte file (prio to #2463 it would resovle to the.svelte.tsfile), and doingimport Foo from './foo.svelte.jswill resolve to the TS file.