diff --git a/index.js b/index.js index c0f6acf..48c7645 100644 --- a/index.js +++ b/index.js @@ -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+\)?$/ ); diff --git a/test/internals.js b/test/internals.js new file mode 100644 index 0000000..25dbceb --- /dev/null +++ b/test/internals.js @@ -0,0 +1,43 @@ + ',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. (test/test.js:99:5)', + 'at TapWrap.runInAsyncScope (node:async_hooks:193:9)', + 'at TapWrap.runInAsyncScope (node:async_hooks:193:9)', + 'at Object. (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. (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. (test/test.js:99:5)', + 'Object. (test/test.js:94:3)', + 'Module.replacementCompile (node_modules/append-transform/index.js:58:13)', + 'Object. (node_modules/append-transform/index.js:62:4)', + ]) + t.plan(1); + t.is(stackUtils.clean(stack), expectedStack); +});