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

feat: using source maps for better stack traces #2975

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from

Conversation

pkerschbaum
Copy link

In the section about I’m writing a library, regarding sourceMap: true and declarationMap: true, the docs currently state:

These are only useful if the library also ships its source (.ts) files.

IMO source maps for the output JavaScript files can also be useful for better stack traces.
I added a sentence for that and removed the hint quoted above (because for better stack traces the source maps alone are sufficient; the source files don't need to be distributed also).

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind mentioning this, but the current wording seems to be pretty repetitive; it's three sentences that say "By shipping ...".

@pkerschbaum pkerschbaum force-pushed the feat/add-source-maps-hint-regarding-stack-traces branch from de7dcc8 to 3f8aa58 Compare October 8, 2024 09:38
@pkerschbaum pkerschbaum force-pushed the feat/add-source-maps-hint-regarding-stack-traces branch from 3f8aa58 to 3915aeb Compare October 8, 2024 09:56
@pkerschbaum
Copy link
Author

@jakebailey I improved the text a little bit!

- **`sourceMap: true`** and **`declarationMap: true`** emit source maps for the output JavaScript and type declaration files, respectively. These are only useful if the library also ships its source (`.ts`) files. By shipping source maps and source files, consumers of the library will be able to debug the library code somewhat more easily. By shipping declaration maps and source files, consumers will be able to see the original TypeScript sources when they run Go To Definition on imports from the libraries. Both of these represent a tradeoff between developer experience and library size, so it’s up to you whether to include them.
- **`sourceMap: true`** emits source maps for the output JavaScript files. By shipping source maps, when consumers of the library execute the code with source maps enabled (e.g. via [`node --enable-source-maps`](https://nodejs.org/docs/latest-v18.x/api/cli.html#--enable-source-maps)), stack traces of errors will point to the original source TypeScript files (instead of the emitted output JavaScript files). When the source files are also shipped with the library, source maps allow consumers of the library to debug the library code somewhat more easily.
- **`declarationMap: true`** emits source maps for the output type declaration files. By shipping declaration maps and source files, consumers will be able to see the original TypeScript sources when they run Go To Definition on imports from the libraries.
- Note that **`sourceMap: true`** and **`declarationMap: true`** represent a tradeoff between developer experience and library size, so it’s up to you whether to include them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern here has been for each bullet to be about a specific compiler option, but this one is clarifying the previous lines. I'm not sure how to do better, though.

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.

2 participants