Skip to content

Commit

Permalink
fix: update packages (#34)
Browse files Browse the repository at this point in the history
* fix: typo in usage

* fix: help tweaks

* fix: update packages

* fix: downgrade clipboardy for pkg
  • Loading branch information
bobbyg603 authored Nov 13, 2023
1 parent 3e63660 commit d4b2c5d
Show file tree
Hide file tree
Showing 9 changed files with 3,443 additions and 1,811 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ coverage
.eslintrc.js
babel.config.js
jest.config.js
.idea
.idea
spec
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = {
'jsdoc/check-values': 1,
'jsdoc/empty-tags': 1,
'jsdoc/implements-on-classes': 1,
'jsdoc/newline-after-description': 1,
'jsdoc/no-undefined-types': 1,
'jsdoc/require-jsdoc': 1,
'jsdoc/require-param': 1,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/node_modules/
/build/
/dist/
/pkg/

js/*.map
js/ts.js
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,46 @@ Error: BugSplat rocks!
```

## 🖥 Command Line

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

```bash
bobby@BugSplat % ~ % stack-converter -h

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

stack-converter command line usage:

stack-converter [ [ "/source-map-directory" OR "/source.map.js" ] [ "/stack-trace.txt" ] ]
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]

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

❤️ support@bugsplat.com
```
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.

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.

## 🧩 API

1. Install this package locally `npm i @bugsplat/stack-converter`
2. Import `StackConverter` from `@bugsplat/stack-converter`

```ts
import { StackConverter } from '@bugsplat/stack-converter';
```

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

```ts
const converter = new StackConverter(sourceMapFilePaths);
```

```ts
const converter = await StackConverter.createFromDirectory(directory);
```

4. Await the call to convert passing it the stack property from a JavaScript Error object
```ts
const result = await converter.convert(error.stack);
Expand Down
25 changes: 13 additions & 12 deletions bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env node
import * as clipboardy from 'clipboardy';
import clipboard from 'clipboardy';
import { Stats } from 'fs';
import * as fs from 'fs/promises';
import { StackConverter } from '../lib/stack-converter';
Expand All @@ -10,16 +10,16 @@ const helpAndExit = () => {
stack-converter command line usage:
stack-converter [ [ "/source-map-directory" OR "/source.map.js" ] [ "/stack-trace.txt" ] ]
stack-converter [ [ "/source-map-directory" OR "/source.js.map" ] [ "/stack-trace.txt" ] ]
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to current directory
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to value in clipboard
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to the current directory
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to the value in the clipboard
❤️ support@bugsplat.com
`;

console.log(help);
process.exit(1);
process.exit(0);
};

(async () => {
Expand All @@ -29,6 +29,7 @@ const helpAndExit = () => {
|| process.argv.some(arg => arg === '/h')
|| process.argv.some(arg => arg === '-help')
|| process.argv.some(arg => arg === '/help')
|| process.argv.some(arg => arg === '--help')
) {
helpAndExit();
}
Expand All @@ -41,24 +42,24 @@ const helpAndExit = () => {
let sourceMapStat: Stats;
try {
sourceMapStat = await fs.lstat(sourceMapPath);
} catch {
throw new Error(`Source map path ${sourceMapPath} does not exist`);
} catch (cause) {
throw new Error(`Source map path ${sourceMapPath} does not exist`, { cause });
}

let stackFileContents;
const stackFilePath = process.argv[3];
if (!stackFilePath) {
stackFileContents = await clipboardy.read();
stackFileContents = await clipboard.read();
} else {
try {
await fs.lstat(stackFilePath);
} catch {
throw new Error(`Stack file path ${stackFilePath} does not exist`);
} catch (cause) {
throw new Error(`Stack file path ${stackFilePath} does not exist`, { cause });
}
try {
stackFileContents = await fs.readFile(stackFilePath, 'utf-8');
} catch {
throw new Error(`Could not read contents of ${stackFilePath}`);
} catch (cause) {
throw new Error(`Could not read contents of ${stackFilePath}`, { cause });
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/stack-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export class StackConverter {
}
const name = originalPosition.name || methodName;
buff.push(StackConverter.frameLine(name, originalPosition.source, originalPosition.line, originalPosition.column));
} catch (err) {
const comment = StackConverter.couldNotConvertStackFrameComment(err.message);
} catch (error) {
const comment = StackConverter.couldNotConvertStackFrameComment((error as Error).message);
buff.push(StackConverter.frameLine(methodName, file, lineNumber, column, comment));
}
}
Expand Down
Loading

0 comments on commit d4b2c5d

Please sign in to comment.