feat: resolve Svelte components using TS from exports map

#2478

Pull request

Draft
D
dummdidumm
Aug 28, 2024, 3:39 PM

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 no longer needed since the switch to using .d.svelte.ts as the "virtual file check" entry point
  • 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

As a side effect, this is a major version bump for language-tools and the typescript plugin, and consequently for svelte-check/vs code extension

Info

Assignees None
Reviewers None
Labels None
Milestone None