@bmp/highlight-stack
Advanced tools
Comparing version 0.0.2 to 0.1.0
47
index.js
@@ -10,5 +10,2 @@ /* | ||
// modules > native | ||
const p = require('path') | ||
// modules > 3rd party | ||
@@ -25,27 +22,33 @@ const chalk = require('chalk') | ||
module.exports = function (stack, html) { | ||
// eslint-disable-next-line no-useless-escape | ||
return stack && stack.replace(/\/[\/\w.-]+/g, (match) => { | ||
if (match.indexOf('node_modules') > -1) { | ||
return match | ||
} | ||
const cwd = process.cwd() + '/' | ||
const dir = p.dirname(process.cwd()) | ||
const index = match.indexOf(dir) | ||
const regexpNodeModules = new RegExp(`node_modules/([^:]+):(\\d+):(\\d+)`) | ||
const regexpLocal = new RegExp(`${cwd}([^:]+):(\\d+):(\\d+)`) | ||
if (index > -1) { | ||
const endIndex = index + dir.length | ||
return stack && stack | ||
.split('\n') | ||
.map(line => { | ||
if (line.includes('(internal/')) { | ||
return chalk.grey(line) | ||
} | ||
if (html) { | ||
return match.slice(0, endIndex) + match.slice(endIndex).bold() | ||
if (line.includes('node_modules')) { | ||
return line.replace(regexpNodeModules, (_, file, line, column) => { | ||
if (html) { | ||
return `${cwd}/${file.bold}:${line}:${column}` | ||
} | ||
return `${chalk.grey('node_modules/')}${chalk.blue(file)}:${chalk.blue.bold(line)}:${chalk.blue(column)}` | ||
}) | ||
} | ||
return match.slice(0, endIndex) + chalk.yellow(match.slice(endIndex)) | ||
} | ||
return line.replace(regexpLocal, (_, file, line, column) => { | ||
if (html) { | ||
return `${cwd}/${file.bold}:${line}:${column}` | ||
} | ||
if (html) { | ||
return match.bold() | ||
} | ||
return chalk.yellow(match) | ||
}) | ||
return `${chalk.grey(cwd)}${chalk.yellow(file)}:${chalk.yellow.bold(line)}:${chalk.yellow(column)}` | ||
}) | ||
}).join('\n') | ||
// eslint-disable-next-line no-useless-escape | ||
} |
{ | ||
"name": "@bmp/highlight-stack", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "highlights the name of local (not in node_modules) files in error stack", | ||
@@ -21,12 +21,12 @@ "main": "index.js", | ||
"dependencies": { | ||
"chalk": "^2.3.2" | ||
"chalk": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.19.1", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.10.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.0.1" | ||
"eslint": "^5.7.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^7.0.1", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0" | ||
} | ||
} |
3549
43
Updatedchalk@^2.4.1