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

Support import paths with .gts extensions #620

Closed
wants to merge 1 commit into from

Conversation

lukemelia
Copy link
Contributor

@lukemelia lukemelia commented Sep 19, 2023

Note that using imports with extensions requires TypeScript 5 and enabling the setting to support importing files with typescript extensions ("allowImportingTsExtensions").

Fixes #618

package.json Outdated Show resolved Hide resolved
@lukemelia lukemelia force-pushed the gts-imports branch 3 times, most recently from 3c5a721 to ec568f4 Compare September 19, 2023 23:06
@@ -28,7 +28,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did node change? was node 14 supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project's volta config specified 16 but CI was running as 14. This started being a problem when I added a dependency on @typescript-eslint/eslint-plugin to the ts-template-imports-app package, which requires node 16+

@@ -58,8 +58,15 @@ export default class DocumentCache {
);
}

private gtsAwareExtName(filename: string): string {
if (filename.endsWith('.gts.ts')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two extensions?
🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the extension that TypeScript tries if you import a .gts module since it has no intrinsic understanding of the .gts extension. We're intercepting it to map it to the actual file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth a comment in the source because it will definitely look weird to future readers.

);
let originalStart = node.getStart();
let originalLength = node.getEnd() - originalStart;
const printer = ts.createPrinter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to create a new printer each time this function is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Will improve that

const Bang: TOC<{ Args: { times: number } }> = <template>
{{repeat '!' @times}}
</template>

declare module '@glint/environment-ember-loose/registry' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this added? it's only needed for loose mode

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be a good idea to incorporate loose mode to make sure we have decent coverage for this scenario since in today's apps using .gts files, they will still have route templates.

return params[0].repeat(params[1]);
}

const repeatHelper = helper(repeat);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wrap in helper?

As of ember-source@4.5, we don't need helper, and can "just" export the functions (and change the signature to be a normal function as it once before it was moved in to this file)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Will fix.

@@ -0,0 +1,3 @@
<div class="main">
<Greeting @target="Earthling" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah loose mode here

@@ -4,7 +4,17 @@
"private": true,
"license": "MIT",
"scripts": {
"test": "glint"
"test": "npm-run-all test:*",
"test:typecheck": "glint",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why run both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I did this because the other test apps are running both of these.

Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some questions. thanks for working on this! this is a massive help!!

@lukemelia lukemelia force-pushed the gts-imports branch 3 times, most recently from ccd40c5 to 0967bb9 Compare September 20, 2023 16:02
@lukemelia
Copy link
Contributor Author

Updates made! Thanks for the feedback @NullVoxPopuli

Copy link
Contributor

@ef4 ef4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me.

@@ -58,8 +58,15 @@ export default class DocumentCache {
);
}

private gtsAwareExtName(filename: string): string {
if (filename.endsWith('.gts.ts')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth a comment in the source because it will definitely look weird to future readers.

Copy link
Member

@dfreeman dfreeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've been on vacation and disconnected this week, and I'm catching up on my phone on the train back now.

I'll dive deeper when I have computer access again, but please hold on merging this. I don't think the transform layer is likely the right place to be solving this, which would explain why it's been so painful.

@dfreeman
Copy link
Member

I've opened a PR with an alternative approach to this problem in #621

@lukemelia I want to apologize for the miscommunication on this and the time/effort it's cost you—it's 100% my fault. I'd had a separate conversation in Discord about what would need to happen to fix this, and then on #618 I got sidetracked by some of the meta-questions being asked and didn't focus properly on the fix you were suggesting there to realize that you hadn't been a part of or seen that original conversation.

Thank you very much for your work on this, and I'm sorry for pointing you in the wrong direction!

@lukemelia
Copy link
Contributor Author

No worries, @dfreeman. Thanks for resetting us onto the right path.

@lukemelia lukemelia closed this Sep 25, 2023
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.

Support import paths with .gts extensions
4 participants