typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
109 stars 51 forks source link

Fix support for gts extensions remaining in emitted declarations #648

Closed NullVoxPopuli closed 10 months ago

NullVoxPopuli commented 10 months ago

Resolves: https://github.com/typed-ember/glint/issues/628


Given imports of:

// index.ts
import { Greeting } from './greeting.gts';
import { greeter } from './greeter.ts';

emitted declarations created via glint --declaration contain:

// index.d.ts
import { Greeting } from './greeting.gts';
import { greeter } from './greeter.ts';

This is incorrect, as in order to make greeting.gts and greeter.ts valid imports in declarations, the following declaration files would need to exist:

- ./index.d.ts <- the entrypoint (pictured above)
- ./greeting.gts.d.ts
- ./greeter.d.ts <- tsc has built in logic for this

A goal is not just have Glint support gjs/gts imports, but have the emitted output of glint --declarations be compatible with tsc.

So, to do that, for .gjs and .gts imports, we'll need to include .gjs and .gts in the name of the emitted assets.

the old approach So one way to deal with this is to, when transforming the files, chop off the extensions entirely so that the generated `index.d.ts` would contain: ```ts // index.d.ts import { Greeting } from './greeting'; import { greeter } from './greeter'; ``` which means that, the currently emitted `.d.ts`-only files would resolve... _if_ the resolving code is changed to support iterating over all possible file extensions -- which could lead to slower declaration building.
background using the learnings from work on the rollup plugins, it was _much_ easier to work with all the different files with explicit extensions in the imports. Resolving got _way_ easier, because the extensions were just right there in the import, and correct to what matched on disk. Unlike how TS has totally make extensions imports a nightmare for some projects, extension usage on `@embroider/addon-dev` _makes sense_ (specifying the author format, and it's compiled away in the resulting js). ----------- I think it'd be easier and less code to emit `basename().d.ts` for every import, than to - remove the extension from all imports - add resolving code everywhere to re-find the files (which would def be a breaking change without a flag to opt in to this behavior)

Support for resolving gts-extensioned files was added in: https://github.com/typed-ember/glint/pull/621 This PR finishes that work by making sure emitted declarations can resolve other declarations.

NullVoxPopuli commented 10 months ago

Gonna close because I don't have a solution in mind.

Demo: https://stackblitz.com/edit/stackblitz-starters-cj9ass?file=README.md

Additional Context: https://discord.com/channels/480462759797063690/568935504288940056/1171853131521470534