typed-ember / glint

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

Support custom extensions with `allowImportingTsExtensions` #621

Closed dfreeman closed 1 year ago

dfreeman commented 1 year ago

This is an alternative approach to the one taken in #620, and fixes #618.

620 attempts to support import paths with an explicit .gts extension by rewriting those imports during transformation, but module resolution really shouldn't be a concern of the transform layer. For example:

TS has a hard-coded internal set of the extensions it considers to "be" TypeScript, and we work around this fact by presenting custom extensions like .gjs and .gts as .js and .ts files respectively. This is how such files get included during whole-project typechecking, and is also how extensionless imports of .gts and .gjs are resolved today.

This PR addresses #618 in the same manner as we handle custom extensions in general: by providing a custom hook for the compiler API to implement the behavior we want. In this instance, the hook is resolveModuleNameLiterals rather than the system-level readFile and friends, but the gist is the same: when a .gts file is imported, we intercept and rewrite the request to as though it had been for the corresponding .ts file.

lukemelia commented 1 year ago

Also, I tried this branch of glint against the project we are trying to convert to a v2 addon, which contains imports with .gts extensions, and it appears to build and typecheck successfully.

dfreeman commented 1 year ago

Should be available in @glint/core@1.2.0!

NullVoxPopuli commented 1 year ago

thanks! Already PR'd an update here: https://github.com/embroider-build/addon-blueprint/pull/206

bartocc commented 1 year ago

Things are moving fast, it's awesome 👏