diff --git a/lib/internal/fs/glob.js b/lib/internal/fs/glob.js index 0f4939f7e1ba0d..87cf2937408728 100644 --- a/lib/internal/fs/glob.js +++ b/lib/internal/fs/glob.js @@ -650,7 +650,23 @@ class Glob { } } +function glob(path, pattern, windows) { + validateString(path, 'path'); + validateString(pattern, 'pattern'); + return lazyMinimatch().minimatch(path, pattern, { + kEmptyObject, + nocase: isMacOS || isWindows, + windowsPathsNoEscape: true, + nonegate: true, + nocomment: true, + optimizationLevel: 2, + platform: windows ? 'win32' : 'posix', + nocaseMagicOnly: true, + }); +} + module.exports = { __proto__: null, Glob, + glob, }; diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index f4a9efac8e8447..c8163386f069cd 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -25,7 +25,7 @@ const { readFileSync, rmSync, } = require('fs'); -const { setupCoverageHooks, isWindows, isMacOS } = require('internal/util'); +const { setupCoverageHooks } = require('internal/util'); const { tmpdir } = require('os'); const { join, resolve, relative } = require('path'); const { fileURLToPath } = require('internal/url'); @@ -36,31 +36,14 @@ const { ERR_SOURCE_MAP_MISSING_SOURCE, }, } = require('internal/errors'); +const { glob } = require('internal/fs/glob'); + const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/; const kIgnoreRegex = /\/\* node:coverage ignore next (?\d+ )?\*\//; const kLineEndingRegex = /\r?\n$/u; const kLineSplitRegex = /(?<=\r?\n)/u; const kStatusRegex = /\/\* node:coverage (?enable|disable) \*\//; -let minimatch; -function lazyMinimatch() { - minimatch ??= require('internal/deps/minimatch/index'); - return minimatch; -} - -function glob(path, pattern, windows) { - return lazyMinimatch().minimatch(path, pattern, { - __proto__: null, - nocase: isMacOS || isWindows, - windowsPathsNoEscape: true, - nonegate: true, - nocomment: true, - optimizationLevel: 2, - platform: windows ? 'win32' : 'posix', - nocaseMagicOnly: true, - }); -} - class CoverageLine { constructor(line, startOffset, src, length = src?.length) { const newlineLength = src == null ? 0 : diff --git a/lib/path.js b/lib/path.js index 40161c45e2a911..bf364fb8e112e8 100644 --- a/lib/path.js +++ b/lib/path.js @@ -52,13 +52,12 @@ const { } = require('internal/validators'); const { - getLazy, emitExperimentalWarning, isWindows, - isMacOS, + getLazy, } = require('internal/util'); -const lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index')); +const lazyGlob = getLazy(() => require('internal/fs/glob')).glob; function isPathSeparator(code) { return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH; @@ -164,22 +163,6 @@ function _format(sep, pathObject) { return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`; } -function glob(path, pattern, windows) { - emitExperimentalWarning('glob'); - validateString(path, 'path'); - validateString(pattern, 'pattern'); - return lazyMinimatch().minimatch(path, pattern, { - __proto__: null, - nocase: isMacOS || isWindows, - windowsPathsNoEscape: true, - nonegate: true, - nocomment: true, - optimizationLevel: 2, - platform: windows ? 'win32' : 'posix', - nocaseMagicOnly: true, - }); -} - const win32 = { /** * path.resolve([from ...], to) @@ -1140,7 +1123,8 @@ const win32 = { }, matchesGlob(path, pattern) { - return glob(path, pattern, true); + emitExperimentalWarning('glob'); + return lazyGlob()(path, pattern, true); }, sep: '\\', @@ -1616,7 +1600,8 @@ const posix = { }, matchesGlob(path, pattern) { - return glob(path, pattern, false); + emitExperimentalWarning('glob'); + return lazyGlob()(path, pattern, false); }, sep: '/',