Skip to content

Commit cf8701c

Browse files
joyeecheungmarco-ippolito
authored andcommitted
module: use kNodeModulesRE to detect node_modules
This is faster and more consistent with other places using the regular expression to detect node_modules. PR-URL: #55243 Backport-PR-URL: #56927 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Refs: #52697
1 parent 64ce95b commit cf8701c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/internal/modules/esm/load.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const {
55
RegExpPrototypeExec,
66
decodeURIComponent,
77
} = primordials;
8-
const { kEmptyObject } = require('internal/util');
8+
const {
9+
kEmptyObject,
10+
} = require('internal/util');
911

1012
const { defaultGetFormat } = require('internal/modules/esm/get_format');
1113
const { validateAttributes, emitImportAssertionWarning } = require('internal/modules/esm/assert');

lib/internal/util.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@ function spliceOne(list, index) {
477477

478478
const kNodeModulesRE = /^(?:.*)[\\/]node_modules[\\/]/;
479479

480+
function isUnderNodeModules(filename) {
481+
return filename && (RegExpPrototypeExec(kNodeModulesRE, filename) !== null);
482+
}
483+
480484
let getStructuredStackImpl;
481485

482486
function lazyGetStructuredStack() {
@@ -524,7 +528,7 @@ function isInsideNodeModules() {
524528
) {
525529
continue;
526530
}
527-
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
531+
return isUnderNodeModules(filename);
528532
}
529533
}
530534
return false;
@@ -913,6 +917,7 @@ module.exports = {
913917
isArrayBufferDetached,
914918
isError,
915919
isInsideNodeModules,
920+
isUnderNodeModules,
916921
join,
917922
lazyDOMException,
918923
lazyDOMExceptionClass,

0 commit comments

Comments
 (0)