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

Use .ts extension in relative source imports #591

Merged
merged 8 commits into from
Dec 30, 2024
Merged

Use .ts extension in relative source imports #591

merged 8 commits into from
Dec 30, 2024

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Nov 29, 2024

This change adopts the --rewriteRelativeImportExtensions option introduced in Typescript 5.7, and changes all relative paths to use the .ts extension.

Due to rollup/plugins#1820, a post-compilation transform is required to get the CLI tool to work right.

An ESLint rule is added to ensure that the .ts extension is always there; this may be of interest to others as well:

yaml/eslint.config.mjs

Lines 41 to 51 in 18e6112

'no-restricted-imports': [
'error',
{
patterns: [
{
regex: '^\\..*(?<!\\.ts)$',
message: 'Relative imports must use .ts extension.'
}
]
}
],

Together with explicit type on imports & exports, this change fixes #301 and makes the library work directly in Deno. A really simple Deno smoke test is included. It would be nice to get the full test suite to run on Deno as well, as discussed in #301 (comment)

Ping @justinmchase & @jeff-hykin: Would you have time to see if this works as expected?

@jeff-hykin
Copy link

Yeah thanks for the ping! If I remeber once I'm at my PC I'll try it out

@eemeli
Copy link
Owner Author

eemeli commented Nov 29, 2024

Also needed to add an afterDeclarations transform to drop the .ts extensions from the imports in the .d.ts files, in order to retain compatibility with older TS versions.

@eemeli
Copy link
Owner Author

eemeli commented Dec 9, 2024

@jeff-hykin Any time for a trial run yet?

I'm looking here for feedback from some actual Deno user to confirm that this does indeed provide a fix for #301, before just presuming so on my own initiative.

@justinmchase
Copy link

justinmchase commented Dec 14, 2024

Looks like its working to me, I cloned the repo, checked out the branch and wrote a little script.

test script

image

terminal results

image

@justinmchase
Copy link

Also, worth mentioning, but Deno has made a new package repo https://jsr.io which may be worth targeting instead of / in addition to deno land.

It's not much different in terms of what you publish, just done with a github action.

Here is a pretty minimal example repo I created for reference: https://github.com/justinmchase/type/blob/main/.github/workflows/publish.yml

@eemeli eemeli merged commit 2c55723 into main Dec 30, 2024
16 checks passed
@eemeli eemeli deleted the import-ts branch December 30, 2024 10:13
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.

Error loading in Deno
3 participants