pax_global_header00006660000000000000000000000064135203313010014501gustar00rootroot0000000000000052 comment=91440c5a1615354fb9419354650937c434eb9f49 clean-stack-2.2.0/000077500000000000000000000000001352033130100136675ustar00rootroot00000000000000clean-stack-2.2.0/.editorconfig000066400000000000000000000002571352033130100163500ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 clean-stack-2.2.0/.gitattributes000066400000000000000000000000231352033130100165550ustar00rootroot00000000000000* text=auto eol=lf clean-stack-2.2.0/.gitignore000066400000000000000000000000271352033130100156560ustar00rootroot00000000000000node_modules yarn.lock clean-stack-2.2.0/.npmrc000066400000000000000000000000231352033130100150020ustar00rootroot00000000000000package-lock=false clean-stack-2.2.0/.travis.yml000066400000000000000000000000751352033130100160020ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' - '6' clean-stack-2.2.0/index.d.ts000066400000000000000000000022351352033130100155720ustar00rootroot00000000000000declare namespace cleanStack { interface Options { /** Prettify the file paths in the stack: `/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `~/dev/clean-stack/unicorn.js:2:15` @default false */ readonly pretty?: boolean; } } /** Clean up error stack traces. Removes the mostly unhelpful internal Node.js entries. @param stack - The `stack` property of an `Error`. @example ``` import cleanStack = require('clean-stack'); const error = new Error('Missing unicorn'); console.log(error.stack); // Error: Missing unicorn // at Object. (/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. (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) ``` */ declare function cleanStack( stack: string, options?: cleanStack.Options ): string; export = cleanStack; clean-stack-2.2.0/index.js000066400000000000000000000020371352033130100153360ustar00rootroot00000000000000'use strict'; const os = require('os'); const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir(); module.exports = (stack, options) => { options = Object.assign({pretty: false}, options); return stack.replace(/\\/g, '/') .split('\n') .filter(line => { const pathMatches = line.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(line => line.trim() !== '') .map(line => { if (options.pretty) { return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); } return line; }) .join('\n'); }; clean-stack-2.2.0/index.test-d.ts000066400000000000000000000003611352033130100165450ustar00rootroot00000000000000import {expectType} from 'tsd'; import cleanStack = require('.'); const error = new Error('Missing unicorn'); if (error.stack) { expectType(cleanStack(error.stack)); expectType(cleanStack(error.stack, {pretty: true})); } clean-stack-2.2.0/license000066400000000000000000000021251352033130100152340ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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. clean-stack-2.2.0/package.json000066400000000000000000000011331352033130100161530ustar00rootroot00000000000000{ "name": "clean-stack", "version": "2.2.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": ">=6" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "clean", "stack", "trace", "traces", "error", "err", "electron" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.7.2", "xo": "^0.24.0" }, "browser": { "os": false } } clean-stack-2.2.0/readme.md000066400000000000000000000030301352033130100154420ustar00rootroot00000000000000# clean-stack [![Build Status](https://travis-ci.org/sindresorhus/clean-stack.svg?branch=master)](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 clean-stack ``` ## Usage ```js const cleanStack = require('clean-stack'); const error = new Error('Missing unicorn'); console.log(error.stack); /* Error: Missing unicorn at Object. (/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. (/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`
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) clean-stack-2.2.0/test.js000066400000000000000000000146451352033130100152160ustar00rootroot00000000000000import os from 'os'; import test from 'ava'; import cleanStack from '.'; test('default', t => { const pre = 'Error: foo\n at Test.fn (/Users/sindresorhus/dev/clean-stack/test.js:6:15)'; const stack = `${pre}\n at handleMessage (internal/child_process.js:695:10)\n at Pipe.channel.onread (internal/child_process.js:440:11)\n at process.emit (events.js:172:7)`; t.is(cleanStack(stack), pre); }); test('default #2', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n 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)`; t.is(cleanStack(stack), pre); }); test('directly executed node script', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n 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) at node.js:968:3`; t.is(cleanStack(stack), pre); }); test('internal child_process', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at internal/child_process.js:696:12`; t.is(cleanStack(stack), pre); }); test('internal next_tick', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9)`; t.is(cleanStack(stack), pre); }); test('internal various modules', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n at emitOne (events.js:101:20) at process.emit (events.js:188:7) at process._fatalException (bootstrap_node.js:300:26)`; t.is(cleanStack(stack), pre); }); test('babel-polyfill', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n at run (/Users/sindresorhus/dev/clean-stack/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:87:22) at /Users/sindresorhus/dev/clean-stack/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:100:28`; t.is(cleanStack(stack), pre); }); test('pirates', t => { const pre = 'Error: foo\n at Object. (/Users/sindresorhus/dev/clean-stack/unicorn.js:4:7)'; const stack = `${pre}\n at Module._compile (/Users/zavr/dev/clean-stack/node_modules/pirates/lib/index.js:83:24) at Object.newLoader [as .js] (/Users/zavr/dev/clean-stack/node_modules/pirates/lib/index.js:88:7)`; t.is(cleanStack(stack), pre); }); test('works on Windows', t => { const expected = 'Error: foo\n at Test.fn (/Users/sindresorhus/dev/clean-stack/test.js:6:15)'; const stack = `Error: foo\n at Test.fn (\\Users\\sindresorhus\\dev\\clean-stack\\test.js:6:15)\n at handleMessage (internal\\child_process.js:695:10)\n at Pipe.channel.onread (internal\\child_process.js:440:11)\n at process.emit (events.js:172:7)`; t.is(cleanStack(stack), expected); }); test('works with Electron stack traces - dev app', t => { const expected = `Error: foo at Object. (/Users/sindresorhus/dev/electron-unhandled/fixture-rejection.js:17:16) at Object. (/Users/sindresorhus/dev/electron-unhandled/fixture-rejection.js:19:3)`; const stack = `Error: foo at Object. (/Users/sindresorhus/dev/electron-unhandled/fixture-rejection.js:17:16) at Object. (/Users/sindresorhus/dev/electron-unhandled/fixture-rejection.js:19:3) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at loadApplicationPackage (/Users/sindresorhus/dev/electron-unhandled/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:283:12) at Object. (/Users/sindresorhus/dev/electron-unhandled/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:325:5) at Object. (/Users/sindresorhus/dev/electron-unhandled/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar/main.js:361:3)`; t.is(cleanStack(stack), expected); }); test('works with Electron stack traces - built app', t => { const expected = `Error: foo at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/app/dist/main/index.js:107:16) at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/app/dist/main/index.js:568:3)`; const stack = `Error: foo at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/app/dist/main/index.js:107:16) at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/app/dist/main/index.js:568:3) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/electron.asar/browser/init.js:171:8) at Object. (/Users/sindresorhus/dev/forks/kap/dist/mac/Kap.app/Contents/Resources/electron.asar/browser/init.js:173:3) at Module._compile (module.js:571:32)`; t.is(cleanStack(stack), expected); }); test('pretty option', t => { const stack = `Error: foo\n at Test.fn (${os.homedir()}/dev/clean-stack/test.js:6:15)\n at handleMessage (internal/child_process.js:695:10)\n at Pipe.channel.onread (internal/child_process.js:440:11)\n at process.emit (events.js:172:7)`; const expected = 'Error: foo\n at Test.fn (~/dev/clean-stack/test.js:6:15)'; t.is(cleanStack(stack, {pretty: true}), expected); });