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

fix: add .js extension for relative import/exports in declarations #134

Merged
merged 4 commits into from
Mar 10, 2023

Conversation

danielroe
Copy link
Member

Context: nuxt/nuxt#18426

Currently with Node16-style module resolution, the following will not be recognised by TS within a declaration file (imagine we have index.d.ts and other.d.ts):

export * from './other'

In order for this to be understood, it needs to have the JS file extension equivalent of the other dts file, which would be .js. (.mjs would be the equivalent for a .d.mts file).

Despite the fact that no .js file exists, TS understands the following to mean what we want:

export * from './other.js'

This PR adds support for a new flag (addRelativeDeclarationExtensions) which enables the addition of this extension within the outputted files. I've tested this within the Nuxt codebase both with and without Node16 style module resolution but it would benefit from broader testing as well, which is why I'm opening the PR for feedback at this point.

Remaining upstream todo would be to detect type import/exports within https://github.com/unjs/mlly.

@danielroe danielroe requested a review from pi0 March 7, 2023 17:39
@danielroe danielroe self-assigned this Mar 7, 2023
@codecov
Copy link

codecov bot commented Mar 7, 2023

Codecov Report

Merging #134 (3ae5952) into main (d512a61) will increase coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
+ Coverage   96.09%   96.32%   +0.22%     
==========================================
  Files           8        8              
  Lines         487      517      +30     
  Branches       98      100       +2     
==========================================
+ Hits          468      498      +30     
  Misses         19       19              
Impacted Files Coverage Δ
src/make.ts 90.07% <100.00%> (+0.36%) ⬆️
src/utils/dts.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@danielroe danielroe marked this pull request as ready for review March 8, 2023 10:03
@danielroe
Copy link
Member Author

@pi0 Might be worth merging #110 first; I'm happy to update this PR subsequently as it's not that complex.

@pi0 pi0 merged commit 65d055f into main Mar 10, 2023
@pi0
Copy link
Member

pi0 commented Mar 10, 2023

Let's quickly move forward for this. Looking for mlly PR for type support. Also 110 probably needs extra care for possible breaking changes.

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.

None yet

2 participants