https://github.com/alloc/resolve-stack-sources
Resolve source files in a stack trace using sourcemaps.
https://github.com/alloc/resolve-stack-sources
nodejs sourcemaps
Last synced: 8 months ago
JSON representation
Resolve source files in a stack trace using sourcemaps.
- Host: GitHub
- URL: https://github.com/alloc/resolve-stack-sources
- Owner: alloc
- License: mit
- Created: 2025-05-28T17:48:40.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-05-28T18:48:46.000Z (8 months ago)
- Last Synced: 2025-05-28T20:00:39.063Z (8 months ago)
- Topics: nodejs, sourcemaps
- Language: TypeScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# resolve-stack-sources
Rewrite a stack trace with source maps. This package was extracted from [wrangler](https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/) to be used by other frameworks.
```
pnpm add resolve-stack-sources
```
## Usage
```ts
import { getSourceMappedString } from 'resolve-stack-sources'
const sourceMappedStackTrace = getSourceMappedString(error.stack)
// => string
```
You may pass a custom `retrieveSourceMap` function to the `getSourceMappedString` function.
```ts
import { getSourceMappedString } from 'resolve-stack-sources'
function retrieveSourceMap(source: string) {
// The `source` is the path to the source file.
// You must return either null or a { url, map } object.
}
const sourceMappedStackTrace = getSourceMappedString(
error.stack,
retrieveSourceMap
)
```