Skip to content

Commit

Permalink
Filter out namespaced internal modules
Browse files Browse the repository at this point in the history
Fixes: #54
Refs: nodejs/node#35498

PR-URL: #55
Credit: @richardlau
Close: #55
Reviewed-by: @isaacs
  • Loading branch information
richardlau authored and isaacs committed Nov 13, 2020
1 parent b3c146e commit ec0a544
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const natives = [].concat(
require('module').builtinModules,
'bootstrap_node',
'node',
).map(n => new RegExp(`(?:\\(${n}\\.js:\\d+:\\d+\\)$|^\\s*at ${n}\\.js:\\d+:\\d+$)`));
).map(n => new RegExp(`(?:\\((?:node:)?${n}(?:\\.js)?:\\d+:\\d+\\)$|^\\s*at (?:node:)?${n}(?:\\.js)?:\\d+:\\d+$)`));

natives.push(
/\(internal\/[^:]+:\d+:\d+\)$/,
/\s*at internal\/[^:]+:\d+:\d+$/,
/\((?:node:)?internal\/[^:]+:\d+:\d+\)$/,
/\s*at (?:node:)?internal\/[^:]+:\d+:\d+$/,
/\/\.node-spawn-wrap-\w+-\w+\/node:\d+:\d+\)?$/
);

Expand Down
42 changes: 42 additions & 0 deletions test/internals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

const t = require('tap');
const StackUtils = require('../');

const utils = require('./_utils');

const stackUtils = new StackUtils({ cwd: '/home/user' });

t.test('removes namespaced internal modules', t => {
const stack = utils.join([
'at Test.<anonymous> (test/test.js:99:5)',
'at TapWrap.runInAsyncScope (node:async_hooks:193:9)',
'at Object.<anonymous> (test/test.js:94:3)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
'at Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at Module._compile (node:internal/modules/cjs/loader:1083:30)',
'at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)',
'at Module.load (node:internal/modules/cjs/loader:948:32)',
'at Function.Module._load (node:internal/modules/cjs/loader:789:14)',
'at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)',
'at node:internal/main/run_main_module:17:47'
]);
const expectedStack = utils.join([
'Test.<anonymous> (test/test.js:99:5)',
'Object.<anonymous> (test/test.js:94:3)',
'Module.replacementCompile (node_modules/append-transform/index.js:58:13)',
'Object.<anonymous> (node_modules/append-transform/index.js:62:4)',
])
t.plan(1);
t.is(stackUtils.clean(stack), expectedStack);
});

0 comments on commit ec0a544

Please sign in to comment.