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 <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> 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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy