Skip to content

Commit 26499a1

Browse files
committed
lib: move glob from path to internal/fs/glob
1 parent 4e2bdf6 commit 26499a1

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

lib/internal/fs/glob.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,23 @@ class Glob {
650650
}
651651
}
652652

653+
function glob(path, pattern, windows) {
654+
validateString(path, 'path');
655+
validateString(pattern, 'pattern');
656+
return lazyMinimatch().minimatch(path, pattern, {
657+
kEmptyObject,
658+
nocase: isMacOS || isWindows,
659+
windowsPathsNoEscape: true,
660+
nonegate: true,
661+
nocomment: true,
662+
optimizationLevel: 2,
663+
platform: windows ? 'win32' : 'posix',
664+
nocaseMagicOnly: true,
665+
});
666+
}
667+
653668
module.exports = {
654669
__proto__: null,
655670
Glob,
671+
glob,
656672
};

lib/internal/test_runner/coverage.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const {
2525
readFileSync,
2626
rmSync,
2727
} = require('fs');
28-
const { setupCoverageHooks, isWindows, isMacOS } = require('internal/util');
28+
const { setupCoverageHooks } = require('internal/util');
2929
const { tmpdir } = require('os');
3030
const { join, resolve, relative } = require('path');
3131
const { fileURLToPath } = require('internal/url');
@@ -36,31 +36,14 @@ const {
3636
ERR_SOURCE_MAP_MISSING_SOURCE,
3737
},
3838
} = require('internal/errors');
39+
const { glob } = require('internal/fs/glob');
40+
3941
const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/;
4042
const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4143
const kLineEndingRegex = /\r?\n$/u;
4244
const kLineSplitRegex = /(?<=\r?\n)/u;
4345
const kStatusRegex = /\/\* node:coverage (?<status>enable|disable) \*\//;
4446

45-
let minimatch;
46-
function lazyMinimatch() {
47-
minimatch ??= require('internal/deps/minimatch/index');
48-
return minimatch;
49-
}
50-
51-
function glob(path, pattern, windows) {
52-
return lazyMinimatch().minimatch(path, pattern, {
53-
__proto__: null,
54-
nocase: isMacOS || isWindows,
55-
windowsPathsNoEscape: true,
56-
nonegate: true,
57-
nocomment: true,
58-
optimizationLevel: 2,
59-
platform: windows ? 'win32' : 'posix',
60-
nocaseMagicOnly: true,
61-
});
62-
}
63-
6447
class CoverageLine {
6548
constructor(line, startOffset, src, length = src?.length) {
6649
const newlineLength = src == null ? 0 :

lib/path.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ const {
5252
} = require('internal/validators');
5353

5454
const {
55-
getLazy,
5655
emitExperimentalWarning,
5756
isWindows,
58-
isMacOS,
57+
getLazy,
5958
} = require('internal/util');
6059

61-
const lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index'));
60+
const lazyGlob = getLazy(() => require('internal/fs/glob').glob);
6261

6362
function isPathSeparator(code) {
6463
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
@@ -164,22 +163,6 @@ function _format(sep, pathObject) {
164163
return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
165164
}
166165

167-
function glob(path, pattern, windows) {
168-
emitExperimentalWarning('glob');
169-
validateString(path, 'path');
170-
validateString(pattern, 'pattern');
171-
return lazyMinimatch().minimatch(path, pattern, {
172-
__proto__: null,
173-
nocase: isMacOS || isWindows,
174-
windowsPathsNoEscape: true,
175-
nonegate: true,
176-
nocomment: true,
177-
optimizationLevel: 2,
178-
platform: windows ? 'win32' : 'posix',
179-
nocaseMagicOnly: true,
180-
});
181-
}
182-
183166
const win32 = {
184167
/**
185168
* path.resolve([from ...], to)
@@ -1140,7 +1123,10 @@ const win32 = {
11401123
},
11411124

11421125
matchesGlob(path, pattern) {
1143-
return glob(path, pattern, true);
1126+
emitExperimentalWarning('glob');
1127+
const test = lazyGlob()
1128+
process._rawDebug(test);
1129+
return lazyGlob()(path, pattern, true);
11441130
},
11451131

11461132
sep: '\\',
@@ -1616,7 +1602,8 @@ const posix = {
16161602
},
16171603

16181604
matchesGlob(path, pattern) {
1619-
return glob(path, pattern, false);
1605+
emitExperimentalWarning('glob');
1606+
return lazyGlob()(path, pattern, false);
16201607
},
16211608

16221609
sep: '/',

0 commit comments

Comments
 (0)