diff options
Diffstat (limited to 'node_modules/clean-stack')
-rw-r--r-- | node_modules/clean-stack/index.js | 38 | ||||
-rw-r--r-- | node_modules/clean-stack/license | 21 | ||||
-rw-r--r-- | node_modules/clean-stack/package.json | 34 | ||||
-rw-r--r-- | node_modules/clean-stack/readme.md | 75 |
4 files changed, 168 insertions, 0 deletions
diff --git a/node_modules/clean-stack/index.js b/node_modules/clean-stack/index.js new file mode 100644 index 000000000..10aca5e7e --- /dev/null +++ b/node_modules/clean-stack/index.js @@ -0,0 +1,38 @@ +'use strict'; +const os = require('os'); + +const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; +const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/babel-polyfill\/.*)?\w+)\.js:\d+:\d+)|native)/; +const homeDir = os.homedir(); + +module.exports = (stack, options) => { + options = Object.assign({pretty: false}, options); + + return stack.replace(/\\/g, '/') + .split('\n') + .filter(x => { + const pathMatches = x.match(extractPathRegex); + if (pathMatches === null || !pathMatches[1]) { + return true; + } + + const match = pathMatches[1]; + + // Electron + if (match.includes('.app/Contents/Resources/electron.asar') || + match.includes('.app/Contents/Resources/default_app.asar')) { + return false; + } + + return !pathRegex.test(match); + }) + .filter(x => x.trim() !== '') + .map(x => { + if (options.pretty) { + return x.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); + } + + return x; + }) + .join('\n'); +}; diff --git a/node_modules/clean-stack/license b/node_modules/clean-stack/license new file mode 100644 index 000000000..654d0bfe9 --- /dev/null +++ b/node_modules/clean-stack/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/clean-stack/package.json b/node_modules/clean-stack/package.json new file mode 100644 index 000000000..6968c6704 --- /dev/null +++ b/node_modules/clean-stack/package.json @@ -0,0 +1,34 @@ +{ + "name": "clean-stack", + "version": "1.3.0", + "description": "Clean up error stack traces", + "license": "MIT", + "repository": "sindresorhus/clean-stack", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "clean", + "stack", + "trace", + "traces", + "error", + "err", + "electron" + ], + "devDependencies": { + "ava": "*", + "xo": "*" + } +} diff --git a/node_modules/clean-stack/readme.md b/node_modules/clean-stack/readme.md new file mode 100644 index 000000000..0c2252191 --- /dev/null +++ b/node_modules/clean-stack/readme.md @@ -0,0 +1,75 @@ +# clean-stack [](https://travis-ci.org/sindresorhus/clean-stack) + +> Clean up error stack traces + +Removes the mostly unhelpful internal Node.js entries. + +Also works in Electron. + + +## Install + +``` +$ npm install --save clean-stack +``` + + +## Usage + +```js +const cleanStack = require('clean-stack'); +const error = new Error('Missing unicorn'); + +console.log(error.stack); +/* +Error: Missing unicorn + at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) + at Module._compile (module.js:409:26) + at Object.Module._extensions..js (module.js:416:10) + at Module.load (module.js:343:32) + at Function.Module._load (module.js:300:12) + at Function.Module.runMain (module.js:441:10) + at startup (node.js:139:18) +*/ + +console.log(cleanStack(error.stack)); +/* +Error: Missing unicorn + at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) +*/ +``` + + +## API + +### cleanStack(stack, [options]) + +#### stack + +Type: `string` + +The `stack` property of an `Error`. + +#### options + +Type: `Object` + +##### pretty + +Type: `boolean`<br> +Default: `false` + +Prettify the file paths in the stack: + +`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `~/dev/clean-stack/unicorn.js:2:15` + + +## Related + +- [extrack-stack](https://github.com/sindresorhus/extract-stack) - Extract the actual stack of an error +- [stack-utils](https://github.com/tapjs/stack-utils) - Captures and cleans stack traces + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) |