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

declarationMap option in svelte-package #7793

Open
DetachHead opened this issue Nov 24, 2022 · 5 comments · May be fixed by #8843 or #11527
Open

declarationMap option in svelte-package #7793

DetachHead opened this issue Nov 24, 2022 · 5 comments · May be fixed by #8843 or #11527
Labels
feature request New feature or request p3-edge-case SvelteKit cannot be used in an uncommon way pkg:svelte-package Issues related to svelte-package
Milestone

Comments

@DetachHead
Copy link

Describe the problem

tsc has a declarationMap compiler option, which is useful for libraries that distribute their source code along with the compiled .js/.d.ts files as it allows IDEs to navigate to the source code when ctrl+clicking imported symbols. see https://www.typescriptlang.org/tsconfig#declarationMap

Describe the proposed solution

a declarationMap option for svelte-package

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

@benmccann benmccann added the pkg:svelte-package Issues related to svelte-package label Nov 24, 2022
@dummdidumm
Copy link
Member

What's the use case for distributing your source code along the compiled js/dts files? Where in the wild does that happen already?

@DetachHead
Copy link
Author

It doesn't happen in the wild very much unfortunately because no one even knows about this feature. But it's so much more useful to be able to go to a function's source code than its type declaration or its compiled js. I'm sure if more people knew about it, it would be more common. I do it with all my packages

@dummdidumm dummdidumm added the p3-edge-case SvelteKit cannot be used in an uncommon way label Nov 25, 2022
@dummdidumm dummdidumm added this to the post-1.0 milestone Nov 25, 2022
@benmccann benmccann added the feature request New feature or request label Jan 20, 2023
@benmccann benmccann added the ready to implement please submit PRs for these issues! label Jan 28, 2023
@dummdidumm dummdidumm removed the ready to implement please submit PRs for these issues! label Jan 31, 2023
@dummdidumm
Copy link
Member

Dug into this. Turning in declarationMap in the tsconfig.json is enough to create the d.ts.map files, so I don't think we need an extra option here. The URL inside that mapping file is problematic though:

  • For Svelte files, it points to a .svelte.ts file, but that should be a .svelte.ts file. The relative path also goes up one directory too far (should be ../src/ instead of ../../src/)
  • In general, it's a relative path pointing to the source, which isn't available if you only publish the contents of package

The first one is a proper bug on our side which needs fixing. The second one is a general TypeScript problem, that behavior is not configurable (there's an open issue on the TS tracker for it). The question is if we somehow smooth over it by copying over the sources, too, if we detect that the user wants this, or if it's in the hands of the developer to do the right thing there (not publishing the package directory, rather the whole project and configure the main package.json manually correctly).
I'm leaning towards first fixing the bug on our side and document the behavior.

dummdidumm added a commit that referenced this issue Feb 1, 2023
@dummdidumm dummdidumm linked a pull request Feb 1, 2023 that will close this issue
5 tasks
@mamidenn
Copy link

The use case we are facing is in a monorepo where packages are referencing each other via package.json (not tsconfig.json references). We want developers to be able to navigate to the sources of packages within the monorepo. Enabling declaration map creation is easily done via tsconfig but due to the relative source path in the generated maps going up one directory too far (as the typescript transpiling happens inside a temp directory) "Go to Source Definition" cannot find the actual source. Fixing the paths manually by removing the first ../ fixes that.

#8843 was addressing exactly that issue but was closed in favor of another PR which did not actually fix anything described in this issue.

@JanNitschke JanNitschke linked a pull request Jan 5, 2024 that will close this issue
5 tasks
@asjir
Copy link

asjir commented Mar 15, 2024

I really wish either #8843 or #11527 would get merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request p3-edge-case SvelteKit cannot be used in an uncommon way pkg:svelte-package Issues related to svelte-package
Projects
None yet
5 participants