-
Notifications
You must be signed in to change notification settings - Fork 507
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
sources
paths are incorrect in declarationMap files (*.d.ts.map) emitted by tsdx
#479
Comments
Since I reviewed #465 / #468, this definitely does seem related to them, as well as #135 . Based on the comments in #135, it sounds like adding A potentially relevant note is that there is this function in the codebase Lines 104 to 112 in 4f6de10
Type definitions originally get generated by rpts2 in dist/src/ and are then moved to dist/ by TSDX.
I suspect that if TSDX uses, internally as a default, As they're generated in This comment is also still relevant, that |
Potentially related to ezolenko/rollup-plugin-typescript2#136 , which goes over why rpts2's type definitions output structure mirrors that of your source structure |
Looked into it a bit more and there's very little code in rpts2 around Something else potentially related is that, in your case, you have specified an |
@agilgur5 - To verify your notes above, I hacked That said, setting tsdx/src/createRollupConfig.ts Lines 156 to 158 in 77bc303
If my tsconfig has no BTW, while stepping through tsdx code to investigate this problem, I discovered two additional problems with tsconfig parsing: #483 (comments and other extended JSON features are not handled the same as tsc does) and #484 ( I just updated the repro repo for this issue (https://github.com/justingrant/ts-declaration-map-repro) to remove problematic JSON that triggered #483 these issues, to avoid complicating reproes of this issue. I also removed |
Thanks for checking this! So #468 will create a workaround for this bug. I think we can try adding
Per my comments there, let's not mix The above
Great finds! Will follow-up in those.
Should probably make this a separate branch as it's a more specific problem. |
Agreed. My
That sounds like a good solution.
The current master branch of https://github.com/justingrant/ts-declaration-map-repro has no
Given the explanation above, would a new branch still be helpful? I'm happy to add another branch but I'm not sure what should be in it. Could you clarify what other repro(s) you think would be useful in this repo? |
Or rather, not yet you didn't 😅😅😅 See #468 (comment) for some of the other problems around
Yea that change is fine and I agree I don't think it necessarily needs a repro either. Though repros are always helpful so a maintainer doesn't need to, like, create the code themselves. This case is also a bit unique as it's a silent error, so you'd only notice when things are different from expected.
Ok, gotcha. I think the original case is easier to understand the root cause, but that makes sense.
I think this is fine as at least I've already grasped it and will probably be the one to PR a fix. Thanks for the clarification around the changes! |
@agilgur5 - All sounds good. I had one question about your proposed fix: (from your comment in #468)
Once that fix is in place, will |
Yup, it would have to be. I'm actually working on that right now and stuck on some failing tests here. Running into an issue where even with |
Figured out that the problem was that #468 changed the Can do some internal deprecation of code to workaround this, but super not ideal 😕 |
Just noticed your repro also has |
This comment has been minimized.
This comment has been minimized.
@ibraelillo this issue is already tagged as "workaround available" because there is already one available as is written here and in the related issues, it is setting your I also already added a PR to do that by default in #488 that is linked above but have not merged it because it is actually an upstream issue and the change is a bit breaking if anyone is using a Rollup plugin that operates on declarations with TSDX (c.f. #80 ), but otherwise safe to use as a workaround. And I had already filed the upstream issue ezolenko/rollup-plugin-typescript2#204 linked above and then made an upstream PR myself linked above ezolenko/rollup-plugin-typescript2#221 . I've been quite busy at work so unfortunately I haven't been able to put in much OSS time, but that was actually my top priority to get into for v0.13.x (now I've waited too long to release v0.14 as a result). The maintainer did not provide much support there either so some bugs have caused it to stall. |
This comment has been minimized.
This comment has been minimized.
@agilgur5 I've done this workaround because of the fix you proposed was not working for me. I'm working with several libraries created with tsdx on a large monorepo and they all present the same issue, actually fixed for me at least with this workaround. I've passed two days browsing and trying any kind of fixes and only that one worked well on every library we have in the monorepo without any further modification. I'm still pending results on this topic, if any other solution comes to light. |
@ibraelillo well I'm not sure why it doesn't work for you, #488 has tests included and they pass. If something doesn't work, would need a minimal reproduction to ascertain anything. Though to be clear, the real fix and real issue is upstream and not here and that's where attention should be focused. |
There's a winding web of issues here that are difficult to follow while attempting to ascertain who/how/if there is a fix for this. Shouldn't this be fixed by default without needing to use (or add) |
@paynecodes my comment above summarizes it, but here's a longer form version of that:
|
@agilgur5 Thank you for your insightful reponse! If only more people know about declarationMap, I don't think think they would want to work without it. At least not in a monorepo context ;) |
Just updated my PR upstream in ezolenko/rollup-plugin-typescript2#221, think I've solved the problem now. Summarized a lot of the work and debugging I did in the comments there (ezolenko/rollup-plugin-typescript2#221 (comment)) |
Current Behavior
When using the
declarationMap
option in tsconfig.json, thesources
array in declaration map files does not contain correct relative paths. Repro steps:git clone https://github.com/justingrant/ts-declaration-map-repro.git
cd ts-declaration-map-repro
yarn
yarn run with-tsc
- this will simply runtsc
against this repo../dist/index.d.ts.map
. It will begin with:{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"]
. Note the correct relative path to index.tsxyarn run with-tsdx
which usestdsx
instead oftsc
but uses the same TS config../dist/index.d.ts.map
again. Here's what you'll see:{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.tsx"]
. Note that the path to index.tsx is incorrectly relative to the project root, not relative todist
.Expected behavior
Correct relative path to index.tsx (
../src/index.tsx
) in the map file'ssources
array.Suggested solution(s)
I'm assuming that there's a way to configure rollup-plugin-typescript2 so that declaration maps are emitted with the correct paths.
Additional context
Note that only declaration map files are affected. Relative paths in regular sourcemap files works fine.
I'm not sure if this is a problem with tsdx or rollup-plugin-typescript2. But I didn't see any mention of this problem in rollup-plugin-typescript2's issue list, so I figured that tsdx may be the culprit because it's the new kid on the block. I'm assuming (perhaps naively) that if the problem was in rollup-plugin-typescript2 that it would have been reported in its GitHub issues already.
At first I thought that this problem was related to #465, but I think that issue is solely about how to handle the
declarationDir
config setting which I'm not using at all. Instead, I'm relying on the sameoutDir
folder for both transpiled output and for declaration output.This issue may be a dupe of #135, but I'm not sure, because #135 has a much more complex config. But the problem does look similar: in both issues the relative path to the source files is missing in declaration maps emitted by tsdx.
BTW, great library! Glad you're building this.
Your environment
The text was updated successfully, but these errors were encountered: