Skip to content

Commit

Permalink
Normalize to unix style paths before filtering out "internals".
Browse files Browse the repository at this point in the history
This makes it a little easier to write regular expressions for internals by normalizing the array before applying the filter. This means your regular expression only needs to deal with forward slash separators

Fixes #9
  • Loading branch information
jamestalmage committed Jan 14, 2016
1 parent ac75d47 commit df98523
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ StackUtils.prototype.clean = function (stack) {
var lastNonAtLine = null;
var result = [];

stack.forEach(function (st1) {
var st = st1;
stack.forEach(function (st) {
st = st.replace(/\\/g, '/');
var isInternal = this._internals.some(function (internal) {
return internal.test(st);
});
Expand All @@ -59,9 +59,7 @@ StackUtils.prototype.clean = function (stack) {
}
}

st = st
.replace(/\\/g, '/')
.replace(this._cwd + '/', '');
st = st.replace(this._cwd + '/', '');

if (st) {
if (isAtLine) {
Expand Down
12 changes: 6 additions & 6 deletions test/long-stack-traces.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {join, fixtureDir} from './_utils';

function internals() {
return StackUtils.nodeInternals().concat([
/[\\\/]long-stack-traces\.js:[0-9]+:[0-9]+\)?$/,
/[\\\/]internal-error\.js:[0-9]+:[0-9]+\)?$/,
/[\\\/]internal-then\.js:[0-9]+:[0-9]+\)?$/,
/[\\\/]node_modules[\\\/]/,
/\/long-stack-traces\.js:[0-9]+:[0-9]+\)?$/,
/\/internal-error\.js:[0-9]+:[0-9]+\)?$/,
/\/internal-then\.js:[0-9]+:[0-9]+\)?$/,
/\/node_modules\//,
// TODO: Should any of these be default internals?
/[\\\/]\.node-spawn-wrap-\w+-\w+[\\\/]node:[0-9]+:[0-9]+\)?$/,
/internal[\\\/]module\.js:[0-9]+:[0-9]+\)?$/,
/\/\.node-spawn-wrap-\w+-\w+\/node:[0-9]+:[0-9]+\)?$/,
/internal\/module\.js:[0-9]+:[0-9]+\)?$/,
/node\.js:[0-9]+:[0-9]+\)?$/
]);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,6 @@ function internalStack() {
function internals() {
return StackUtils.nodeInternals().concat([
/test\.js:[0-9]+:[0-9]+\)?$/,
/[\\\/]node_modules[\\\/]/
/\/node_modules\//
]);
}

0 comments on commit df98523

Please sign in to comment.