Skip to content

Commit

Permalink
module: use kNodeModulesRE to detect node_modules
Browse files Browse the repository at this point in the history
This is faster and more consistent with other places using the
regular expression to detect node_modules.

PR-URL: nodejs#55243
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]>
  • Loading branch information
joyeecheung committed Feb 5, 2025
1 parent 78a4e05 commit 534c432
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const {
RegExpPrototypeExec,
decodeURIComponent,
} = primordials;
const { kEmptyObject } = require('internal/util');
const {
kEmptyObject,
} = require('internal/util');

const { defaultGetFormat } = require('internal/modules/esm/get_format');
const { validateAttributes, emitImportAssertionWarning } = require('internal/modules/esm/assert');
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ function spliceOne(list, index) {

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

function isUnderNodeModules(filename) {
return filename && (RegExpPrototypeExec(kNodeModulesRE, filename) !== null);
}

let getStructuredStackImpl;

function lazyGetStructuredStack() {
Expand Down Expand Up @@ -524,7 +528,7 @@ function isInsideNodeModules() {
) {
continue;
}
return RegExpPrototypeExec(kNodeModulesRE, filename) !== null;
return isUnderNodeModules(filename);
}
}
return false;
Expand Down Expand Up @@ -913,6 +917,7 @@ module.exports = {
isArrayBufferDetached,
isError,
isInsideNodeModules,
isUnderNodeModules,
join,
lazyDOMException,
lazyDOMExceptionClass,
Expand Down

0 comments on commit 534c432

Please sign in to comment.