Skip to content

Commit ce47f34

Browse files
authored
chore!: rename to source-mapper (#35)
* chore: rename to source-mapper * chore: fix linter warnings * chore: fix pkg BREAKING CHANGE: import StackConverter is now import SourceMapper
1 parent d4b2c5d commit ce47f34

10 files changed

Lines changed: 317 additions & 259 deletions

File tree

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
</a>
1212
</div>
1313

14-
# 🥞 stack-converter
15-
`stack-converter` is a utility for translating function names, file names and line numbers in uglified JavaScript Error stack frames to the corresponding values in the original source. `stack-converter` is distributed as both a package and a library and is used by the [BugSplat](https://www.bugsplat.com) backend to deliver crash reporting as a service for JavaScript and TypeScript applications.
14+
# 🗺️ source-mapper
15+
`source-mapper` is a utility for translating function names, file names and line numbers in uglified JavaScript Error stack frames to the corresponding values in the original source. `source-mapper` is distributed as both a package and a library and is used by the [BugSplat](https://www.bugsplat.com) backend to deliver crash reporting as a service for JavaScript and TypeScript applications.
1616

17-
The following is an example JavaScript Error stack converted to its TypeScript equivalent using `stack-converter`:
17+
The following is an example JavaScript Error stack converted to its TypeScript equivalent using `source-mapper`:
1818

1919
```
2020
Error: BugSplat rocks!
21-
at crash (/Users/bobby/Desktop/bugsplat/stack-converter/dist/bin/cmd.js:16:11)
22-
at /Users/bobby/Desktop/bugsplat/stack-converter/dist/bin/cmd.js:6:9
23-
at Object.<anonymous> (/Users/bobby/Desktop/bugsplat/stack-converter/dist/bin/cmd.js:14:3)
21+
at crash (/Users/bobby/Desktop/bugsplat/source-mapper/dist/bin/cmd.js:16:11)
22+
at /Users/bobby/Desktop/bugsplat/source-mapper/dist/bin/cmd.js:6:9
23+
at Object.<anonymous> (/Users/bobby/Desktop/bugsplat/source-mapper/dist/bin/cmd.js:14:3)
2424
```
2525

2626
```
@@ -31,49 +31,54 @@ Error: BugSplat rocks!
3131
```
3232

3333
## 🖥 Command Line
34+
<<<<<<< HEAD
3435

3536
1. Install this package globally `npm i -g @bugsplat/stack-converter`
3637
2. Run `stack-converter -h` to see the latest usage information:
3738

39+
=======
40+
1. Install this package globally `npm i -g @bugsplat/source-mapper`
41+
2. Run `source-mapper -h` to see the latest usage information:
42+
>>>>>>> 0431171 (chore: rename to source-mapper)
3843
```bash
39-
bobby@BugSplat % ~ % stack-converter -h
44+
bobby@BugSplat % ~ % source-mapper -h
4045

41-
@bugsplat/stack-converter contains a command line utility and set of libraries to help you demangle JavaScript stack frames.
46+
@bugsplat/source-mapper contains a command line utility and set of libraries to help you demangle JavaScript stack frames.
4247

43-
stack-converter command line usage:
48+
source-mapper command line usage:
4449

45-
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
50+
source-mapper [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
4651

4752
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to the current directory
4853
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to the value in the clipboard
4954

5055
❤️ support@bugsplat.com
5156
```
5257

53-
3. Run `stack-converter` and optionally specify a path to a directory containing .js.map files, path to a single .js.map file, and a path to a .txt file containing a stringified JavaScript Error. If no options are provided `stack-converter` will default to looking in the current directory for source maps and attempt to read the stringified JavaScript error stack from the system clipboard.
58+
3. Run `source-mapper` and optionally specify a path to a directory containing .js.map files, path to a single .js.map file, and a path to a .txt file containing a stringified JavaScript Error. If no options are provided `source-mapper` will default to looking in the current directory for source maps and attempt to read the stringified JavaScript error stack from the system clipboard.
5459

5560
## 🧩 API
5661

57-
1. Install this package locally `npm i @bugsplat/stack-converter`
58-
2. Import `StackConverter` from `@bugsplat/stack-converter`
62+
1. Install this package locally `npm i @bugsplat/source-mapper`
63+
2. Import `SourceMapper` from `@bugsplat/source-mapper`
5964

6065
```ts
61-
import { StackConverter } from '@bugsplat/stack-converter';
66+
import { SourceMapper } from '@bugsplat/source-mapper';
6267
```
6368

64-
3. Create a new instance of `StackConverter` passing it an array of paths to source map files. You can also await the static factory function `createFromDirectory(directory: string): Promise<StackConverter>` which takes a path to a directory and creates a new StackConverter with an array of source map file paths it finds in the specified directory
69+
3. Create a new instance of `SourceMapper` passing it an array of paths to source map files. You can also await the static factory function `createFromDirectory(directory: string): Promise<SourceMapper>` which takes a path to a directory and creates a new SourceMapper with an array of source map file paths it finds in the specified directory
6570

6671
```ts
67-
const converter = new StackConverter(sourceMapFilePaths);
72+
const mapper = new SourceMapper(sourceMapFilePaths);
6873
```
6974

7075
```ts
71-
const converter = await StackConverter.createFromDirectory(directory);
76+
const mapper = await SourceMapper.createFromDirectory(directory);
7277
```
7378

7479
4. Await the call to convert passing it the stack property from a JavaScript Error object
7580
```ts
76-
const result = await converter.convert(error.stack);
81+
const result = await mapper.convert(error.stack);
7782
```
7883

7984
Thanks for using BugSplat!

bin/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import clipboard from 'clipboardy';
33
import { Stats } from 'fs';
44
import * as fs from 'fs/promises';
5-
import { StackConverter } from '../lib/stack-converter';
5+
import { SourceMapper } from '../lib/source-mapper';
66

77
const helpAndExit = () => {
88
const help = `
9-
@bugsplat/stack-converter contains a command line utility and set of libraries to help you demangle JavaScript stack frames.
9+
@bugsplat/source-mapper contains a command line utility and set of libraries to help you demangle JavaScript stack frames.
1010
11-
stack-converter command line usage:
11+
source-mapper command line usage:
1212
13-
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
13+
source-mapper [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
1414
1515
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to the current directory
1616
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to the value in the clipboard
@@ -67,7 +67,7 @@ const helpAndExit = () => {
6767
throw new Error('Stack contents are empty');
6868
}
6969

70-
const converter = sourceMapStat.isDirectory() ? await StackConverter.createFromDirectory(sourceMapPath) : new StackConverter([sourceMapPath]);
70+
const converter = sourceMapStat.isDirectory() ? await SourceMapper.createFromDirectory(sourceMapPath) : new SourceMapper([sourceMapPath]);
7171
const { error, stack } = await converter.convert(stackFileContents);
7272
if (error) {
7373
throw new Error(error);

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { StackConverter } from './stack-converter';
1+
export { SourceMapper as SourceMapper } from './source-mapper';
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@ import * as stackTraceParser from 'stacktrace-parser';
77
/**
88
* A class for converting stacktraces, mangled by transpiling, back to match the originating files.
99
* Usage:
10-
* const converter = new StackConverter(['a-sourceMap-file.js.sourceMap']);
10+
* const converter = new SourceMapper(['a-sourceMap-file.js.sourceMap']);
1111
* const mangledStack = '....';
1212
* const newStack = await converter.convert(managedStack);
1313
*/
14-
export class StackConverter {
14+
export class SourceMapper {
1515
private static readonly INDENT: string = ' ';
1616

1717
/**
18-
* Create a StackConverter by passing an array of paths to source map files
18+
* Create a SourceMapper by passing an array of paths to source map files
1919
*
2020
* @param sourceMapFilePaths - an array of paths to source map files for converting stacks
2121
* @throws - throws if no sourceMapFilePaths are provided
2222
*/
2323
constructor(private sourceMapFilePaths: Array<string>) {
2424
if (!sourceMapFilePaths?.length) {
25-
throw new Error('Could not create StackConverter: no source map file paths were provided!');
25+
throw new Error('Could not create SourceMapper: no source map file paths were provided!');
2626
}
2727
}
2828

2929
/**
30-
* Convenience method for creating a StackConverter from a directory containing source map files
30+
* Convenience method for creating a SourceMapper from a directory containing source map files
3131
*
3232
* @param directory - path to directory containing source map files
3333
* @throws - throws if no source map files exist in dir
34-
* @returns - promise that resolves to a new StackConverter
34+
* @returns - promise that resolves to a new SourceMapper
3535
*/
36-
static async createFromDirectory(directory: string): Promise<StackConverter> {
36+
static async createFromDirectory(directory: string): Promise<SourceMapper> {
3737
try {
3838
await fs.lstat(directory);
3939
} catch(error) {
40-
throw new Error(`Could not create StackConverter: ${directory} does not exist or is inaccessible!`);
40+
throw new Error(`Could not create SourceMapper: ${directory} does not exist or is inaccessible!`);
4141
}
4242

4343
const files = await fs.readdir(directory);
4444
const sourceMapFilePaths = files
4545
.filter(file => file.endsWith('.map'))
4646
.map(file => path.join(directory, file));
47-
return new StackConverter(sourceMapFilePaths);
47+
return new SourceMapper(sourceMapFilePaths);
4848
}
4949

5050
/**
@@ -67,22 +67,22 @@ export class StackConverter {
6767
const sourceMaps: { [filename: string]: SourceMapConsumer } = {};
6868
const sourceMapErrors: { [filename: string]: boolean } = {};
6969

70-
const errorLine = StackConverter.getChromiumErrorLineOrEmpty(stack);
70+
const errorLine = SourceMapper.getChromiumErrorLineOrEmpty(stack);
7171
if (errorLine) {
7272
buff.push(errorLine);
7373
}
7474

7575
for (const frame of stackFrames) {
7676
const { file, methodName, lineNumber, column } = frame;
7777
if (file in sourceMapErrors) {
78-
const comment = StackConverter.errorLoadingSourceMapComment('previous error');
79-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
78+
const comment = SourceMapper.errorLoadingSourceMapComment('previous error');
79+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column, comment));
8080
continue;
8181
}
8282

8383
if (!lineNumber && !column) {
8484
// handle case where <anonymous> is returned as file with no lineNumber or column
85-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column));
85+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column));
8686
continue;
8787
}
8888

@@ -94,25 +94,25 @@ export class StackConverter {
9494

9595
if (!mapFile) {
9696
set(sourceMapErrors, file, true);
97-
const comment = StackConverter.errorLoadingSourceMapComment('source map not found');
98-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
97+
const comment = SourceMapper.errorLoadingSourceMapComment('source map not found');
98+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column, comment));
9999
continue;
100100
}
101101

102102
try {
103103
if (!lineNumber || (lineNumber < 1)) {
104104
const funcName = methodName || '';
105-
buff.push(`${StackConverter.INDENT}at ${funcName}`);
105+
buff.push(`${SourceMapper.INDENT}at ${funcName}`);
106106
continue;
107107
}
108108

109109
let sourceMapConsumer: SourceMapConsumer = get(sourceMaps, mapFile);
110110
if (!sourceMapConsumer) {
111-
const { sourceMap, error } = await StackConverter.sourceMapFromFile(mapFile);
111+
const { sourceMap, error } = await SourceMapper.sourceMapFromFile(mapFile);
112112
if (!sourceMap || error) {
113113
set(sourceMapErrors, file, true);
114-
const comment = StackConverter.errorLoadingSourceMapComment(error);
115-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
114+
const comment = SourceMapper.errorLoadingSourceMapComment(error);
115+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column, comment));
116116
continue;
117117
}
118118
sourceMaps[mapFile] = sourceMap;
@@ -121,15 +121,15 @@ export class StackConverter {
121121

122122
const originalPosition = sourceMapConsumer.originalPositionFor({ line: lineNumber, column });
123123
if (!originalPosition || !originalPosition.line) {
124-
const comment = StackConverter.couldNotConvertStackFrameComment('original position not found');
125-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
124+
const comment = SourceMapper.couldNotConvertStackFrameComment('original position not found');
125+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column, comment));
126126
continue;
127127
}
128128
const name = originalPosition.name || methodName;
129-
buff.push(StackConverter.frameLine(name, originalPosition.source, originalPosition.line, originalPosition.column));
129+
buff.push(SourceMapper.frameLine(name, originalPosition.source, originalPosition.line, originalPosition.column));
130130
} catch (error) {
131-
const comment = StackConverter.couldNotConvertStackFrameComment((error as Error).message);
132-
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
131+
const comment = SourceMapper.couldNotConvertStackFrameComment((error as Error).message);
132+
buff.push(SourceMapper.frameLine(methodName, file, lineNumber, column, comment));
133133
}
134134
}
135135
return { stack: buff.join('\n') };
@@ -146,10 +146,10 @@ export class StackConverter {
146146
private static frameLine(methodName: string, file: string, line: number, column: number, comment?: string): string {
147147
const method = methodName || '<unknown>';
148148
if (!line && !column) {
149-
return `${StackConverter.INDENT}at ${method} (${file})` + (comment ? ' ***' + comment : '');
149+
return `${SourceMapper.INDENT}at ${method} (${file})` + (comment ? ' ***' + comment : '');
150150
}
151151

152-
return `${StackConverter.INDENT}at ${method} (${file}:${line}:${column})` + (comment ? ' ***' + comment : '');
152+
return `${SourceMapper.INDENT}at ${method} (${file}:${line}:${column})` + (comment ? ' ***' + comment : '');
153153
}
154154

155155
private static getChromiumErrorLineOrEmpty(stack: string): string {

0 commit comments

Comments
 (0)