Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Svelte module resolution tweaks #2481

Merged
merged 10 commits into from
Aug 30, 2024
Merged

Conversation

dummdidumm
Copy link
Member

This is essentially #2478 minus the exports map changes: Svelte files are now resolved by intercepting checks for .d.svelte.ts instead of .svelte.ts. As a consequence, we can handle sibling foo.svelte / foo.svelte.ts files and importing both. When doing import Foo from './foo.svelte this now resolves to the Svelte file (prio to #2463 it would resovle to the .svelte.ts file), and doing import Foo from './foo.svelte.js will resolve to the TS file.

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
@dummdidumm dummdidumm merged commit a3a7a91 into master Aug 30, 2024
3 checks passed
@dummdidumm dummdidumm deleted the svelte-resolution-tweaks branch August 30, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant