Skip to content

Commit d4b2c5d

Browse files
authored
fix: update packages (#34)
* fix: typo in usage * fix: help tweaks * fix: update packages * fix: downgrade clipboardy for pkg
1 parent 3e63660 commit d4b2c5d

9 files changed

Lines changed: 3443 additions & 1811 deletions

File tree

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ coverage
44
.eslintrc.js
55
babel.config.js
66
jest.config.js
7-
.idea
7+
.idea
8+
spec

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module.exports = {
2222
'jsdoc/check-values': 1,
2323
'jsdoc/empty-tags': 1,
2424
'jsdoc/implements-on-classes': 1,
25-
'jsdoc/newline-after-description': 1,
2625
'jsdoc/no-undefined-types': 1,
2726
'jsdoc/require-jsdoc': 1,
2827
'jsdoc/require-param': 1,

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/node_modules/
33
/build/
44
/dist/
5+
/pkg/
56

67
js/*.map
78
js/ts.js

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,46 @@ Error: BugSplat rocks!
3131
```
3232

3333
## 🖥 Command Line
34+
3435
1. Install this package globally `npm i -g @bugsplat/stack-converter`
3536
2. Run `stack-converter -h` to see the latest usage information:
37+
3638
```bash
3739
bobby@BugSplat % ~ % stack-converter -h
3840

3941
@bugsplat/stack-converter contains a command line utility and set of libraries to help you demangle JavaScript stack frames.
4042

4143
stack-converter command line usage:
4244

43-
stack-converter [ [ "/source-map-directory" OR "/source.map.js" ] [ "/stack-trace.txt" ] ]
45+
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
4446

45-
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to current directory
46-
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to value in clipboard
47+
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to the current directory
48+
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to the value in the clipboard
4749

4850
❤️ support@bugsplat.com
4951
```
50-
3. Run `stack-converter` and optionally specify a path to a directory containing .map files, path to a single .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.
52+
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.
5154

5255
## 🧩 API
56+
5357
1. Install this package locally `npm i @bugsplat/stack-converter`
5458
2. Import `StackConverter` from `@bugsplat/stack-converter`
59+
5560
```ts
5661
import { StackConverter } from '@bugsplat/stack-converter';
5762
```
63+
5864
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
65+
5966
```ts
6067
const converter = new StackConverter(sourceMapFilePaths);
6168
```
69+
6270
```ts
6371
const converter = await StackConverter.createFromDirectory(directory);
6472
```
73+
6574
4. Await the call to convert passing it the stack property from a JavaScript Error object
6675
```ts
6776
const result = await converter.convert(error.stack);

bin/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env node
2-
import * as clipboardy from 'clipboardy';
2+
import clipboard from 'clipboardy';
33
import { Stats } from 'fs';
44
import * as fs from 'fs/promises';
55
import { StackConverter } from '../lib/stack-converter';
@@ -10,16 +10,16 @@ const helpAndExit = () => {
1010
1111
stack-converter command line usage:
1212
13-
stack-converter [ [ "/source-map-directory" OR "/source.map.js" ] [ "/stack-trace.txt" ] ]
13+
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
1414
15-
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to current directory
16-
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to value in clipboard
15+
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to the current directory
16+
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to the value in the clipboard
1717
1818
❤️ support@bugsplat.com
1919
`;
2020

2121
console.log(help);
22-
process.exit(1);
22+
process.exit(0);
2323
};
2424

2525
(async () => {
@@ -29,6 +29,7 @@ const helpAndExit = () => {
2929
|| process.argv.some(arg => arg === '/h')
3030
|| process.argv.some(arg => arg === '-help')
3131
|| process.argv.some(arg => arg === '/help')
32+
|| process.argv.some(arg => arg === '--help')
3233
) {
3334
helpAndExit();
3435
}
@@ -41,24 +42,24 @@ const helpAndExit = () => {
4142
let sourceMapStat: Stats;
4243
try {
4344
sourceMapStat = await fs.lstat(sourceMapPath);
44-
} catch {
45-
throw new Error(`Source map path ${sourceMapPath} does not exist`);
45+
} catch (cause) {
46+
throw new Error(`Source map path ${sourceMapPath} does not exist`, { cause });
4647
}
4748

4849
let stackFileContents;
4950
const stackFilePath = process.argv[3];
5051
if (!stackFilePath) {
51-
stackFileContents = await clipboardy.read();
52+
stackFileContents = await clipboard.read();
5253
} else {
5354
try {
5455
await fs.lstat(stackFilePath);
55-
} catch {
56-
throw new Error(`Stack file path ${stackFilePath} does not exist`);
56+
} catch (cause) {
57+
throw new Error(`Stack file path ${stackFilePath} does not exist`, { cause });
5758
}
5859
try {
5960
stackFileContents = await fs.readFile(stackFilePath, 'utf-8');
60-
} catch {
61-
throw new Error(`Could not read contents of ${stackFilePath}`);
61+
} catch (cause) {
62+
throw new Error(`Could not read contents of ${stackFilePath}`, { cause });
6263
}
6364
}
6465

lib/stack-converter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export class StackConverter {
127127
}
128128
const name = originalPosition.name || methodName;
129129
buff.push(StackConverter.frameLine(name, originalPosition.source, originalPosition.line, originalPosition.column));
130-
} catch (err) {
131-
const comment = StackConverter.couldNotConvertStackFrameComment(err.message);
130+
} catch (error) {
131+
const comment = StackConverter.couldNotConvertStackFrameComment((error as Error).message);
132132
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
133133
}
134134
}

0 commit comments

Comments
 (0)