-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
fix: Don't replace .d.ts paths #234
base: master
Are you sure you want to change the base?
Conversation
const dotIndex = base.indexOf('.'); | ||
const name = base.slice(0, dotIndex); | ||
const extension = base.slice(dotIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might wonder why I did this instead of just using the extension already given to me by parse
. This is because they consider xyz.d.ts
to have a name of xyz.d
and an extension of .ts
src/utils/trie.ts
Outdated
const extension = base.slice(dotIndex); | ||
|
||
const normalizedExtension = extension.replace( | ||
/^\.([mc])?ts(x)?$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a ^
which means the whole extension must be matched. This may need to have smarter logic.
Files to definitely exclude:
foo.d.css.ts
- The correct way of defining a declaration file forfoo.css
file. Cannot point to ajs
file.foo.css.d.ts
- A legacy way of defining afoo.css
file. Cannot point to ajs
file.foo.d.ts
- Declaration files for a JS file. This JS file could technically exist in repo but if it does the.d.ts
file should probably exist alongside. Also if you're doing this you probably should have a plain.ts
file instead.foo.xyz.ts
- I'm unsure why you'd write this but it would be broken by this regex change. Maybe some libraries make this common or some repos do this?
If you'd like me to look into a better way, I can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided I may as well push a fix for foo.xyz.ts
. See "Add explicit isDTS detection"
Context: I have an alias written as
"@utils": ["./src/utils/index.d.mts"]
and it was being changed to./src/utils/index.d.mjs
which broke resolution.I know it's obviously niche to be using tsc-alias on already written
.d.ts
files but I'm of course typing someone else's code so plain.ts
files don't make sense. I can see a few alternatives here:noRewritePaths
or something..d.mts
and.d.mjs
But I think this solution is pretty simple!