An open API service indexing awesome lists of open source software.

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.

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
)
```