clean-stack
Advanced tools
Comparing version 4.2.0 to 5.0.0
@@ -1,2 +0,2 @@ | ||
export interface Options { | ||
export type Options = { | ||
/** | ||
@@ -19,3 +19,3 @@ Prettify the file paths in the stack: | ||
readonly basePath?: string; | ||
} | ||
}; | ||
@@ -22,0 +22,0 @@ /** |
15
index.js
@@ -1,10 +0,9 @@ | ||
import os from 'os'; | ||
import escapeStringRegexp from 'escape-string-regexp'; | ||
import homeDirectory from '#home-directory'; | ||
const extractPathRegex = /\s+at.*[(\s](.*)\)?/; | ||
const pathRegex = /^(?:(?:(?:node|node:[\w/]+|(?:(?:node:)?internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)(?:\.js)?:\d+:\d+)|native)/; | ||
const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir().replace(/\\/g, '/'); | ||
export default function cleanStack(stack, {pretty = false, basePath} = {}) { | ||
const basePathRegex = basePath && new RegExp(`(at | \\()${escapeStringRegexp(basePath.replace(/\\/g, '/'))}`, 'g'); | ||
const basePathRegex = basePath && new RegExp(`(at | \\()(file://)?${escapeStringRegexp(basePath.replace(/\\/g, '/'))}/?`, 'g'); | ||
@@ -27,6 +26,6 @@ if (typeof stack !== 'string') { | ||
if ( | ||
match.includes('.app/Contents/Resources/electron.asar') || | ||
match.includes('.app/Contents/Resources/default_app.asar') || | ||
match.includes('node_modules/electron/dist/resources/electron.asar') || | ||
match.includes('node_modules/electron/dist/resources/default_app.asar') | ||
match.includes('.app/Contents/Resources/electron.asar') | ||
|| match.includes('.app/Contents/Resources/default_app.asar') | ||
|| match.includes('node_modules/electron/dist/resources/electron.asar') | ||
|| match.includes('node_modules/electron/dist/resources/default_app.asar') | ||
) { | ||
@@ -45,3 +44,3 @@ return false; | ||
if (pretty) { | ||
line = line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); | ||
line = line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDirectory, '~'))); | ||
} | ||
@@ -48,0 +47,0 @@ |
{ | ||
"name": "clean-stack", | ||
"version": "4.2.0", | ||
"version": "5.0.0", | ||
"description": "Clean up error stack traces", | ||
@@ -15,4 +15,11 @@ "license": "MIT", | ||
"exports": "./index.js", | ||
"imports": { | ||
"#home-directory": { | ||
"node": "./home-directory.js", | ||
"default": "./home-directory-browser.js" | ||
} | ||
}, | ||
"types": "./index.d.ts", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14.16" | ||
}, | ||
@@ -24,3 +31,5 @@ "scripts": { | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"home-directory.js", | ||
"home-directory-browser.js" | ||
], | ||
@@ -39,5 +48,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
"ava": "^4.3.3", | ||
"tsd": "^0.24.1", | ||
"xo": "^0.52.3" | ||
}, | ||
@@ -44,0 +53,0 @@ "browser": { |
@@ -11,5 +11,5 @@ # clean-stack | ||
```sh | ||
npm install clean-stack | ||
``` | ||
$ npm install clean-stack | ||
``` | ||
@@ -71,5 +71,5 @@ ## Usage | ||
Remove the given base path from stack trace file paths, effectively turning absolute paths into relative ones. | ||
Remove the given base path from stack trace file paths, effectively turning absolute paths into relative ones. It will also transform absolute file URLs into relative paths. | ||
Example with `'/Users/sindresorhus/dev/clean-stack/'` as `basePath`: | ||
Example with `'/Users/sindresorhus/dev/clean-stack'` as `basePath`: | ||
@@ -76,0 +76,0 @@ `/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `unicorn.js:2:15` |
7145
7
82