MCPcopy Index your code
hub / github.com/nodejs/node / matchFiles

Function matchFiles

test/fixtures/snapshot/typescript.js:20648–20708  ·  view source on GitHub ↗

@param path directory of the tsconfig.json

(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath)

Source from the content-addressed store, hash-verified

20646 ts.getRegexFromPattern = getRegexFromPattern;
20647 /** @param path directory of the tsconfig.json */
20648 function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath) {
20649 path = ts.normalizePath(path);
20650 currentDirectory = ts.normalizePath(currentDirectory);
20651 var patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
20652 var includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map(function (pattern) { return getRegexFromPattern(pattern, useCaseSensitiveFileNames); });
20653 var includeDirectoryRegex = patterns.includeDirectoryPattern && getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames);
20654 var excludeRegex = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames);
20655 // Associate an array of results with each include regex. This keeps results in order of the "include" order.
20656 // If there are no "includes", then just put everything in results[0].
20657 var results = includeFileRegexes ? includeFileRegexes.map(function () { return []; }) : [[]];
20658 var visited = new ts.Map();
20659 var toCanonical = ts.createGetCanonicalFileName(useCaseSensitiveFileNames);
20660 for (var _i = 0, _a = patterns.basePaths; _i < _a.length; _i++) {
20661 var basePath = _a[_i];
20662 visitDirectory(basePath, ts.combinePaths(currentDirectory, basePath), depth);
20663 }
20664 return ts.flatten(results);
20665 function visitDirectory(path, absolutePath, depth) {
20666 var canonicalPath = toCanonical(realpath(absolutePath));
20667 if (visited.has(canonicalPath))
20668 return;
20669 visited.set(canonicalPath, true);
20670 var _a = getFileSystemEntries(path), files = _a.files, directories = _a.directories;
20671 var _loop_1 = function (current) {
20672 var name = ts.combinePaths(path, current);
20673 var absoluteName = ts.combinePaths(absolutePath, current);
20674 if (extensions && !ts.fileExtensionIsOneOf(name, extensions))
20675 return "continue";
20676 if (excludeRegex && excludeRegex.test(absoluteName))
20677 return "continue";
20678 if (!includeFileRegexes) {
20679 results[0].push(name);
20680 }
20681 else {
20682 var includeIndex = ts.findIndex(includeFileRegexes, function (re) { return re.test(absoluteName); });
20683 if (includeIndex !== -1) {
20684 results[includeIndex].push(name);
20685 }
20686 }
20687 };
20688 for (var _i = 0, _b = ts.sort(files, ts.compareStringsCaseSensitive); _i < _b.length; _i++) {
20689 var current = _b[_i];
20690 _loop_1(current);
20691 }
20692 if (depth !== undefined) {
20693 depth--;
20694 if (depth === 0) {
20695 return;
20696 }
20697 }
20698 for (var _c = 0, _d = ts.sort(directories, ts.compareStringsCaseSensitive); _c < _d.length; _c++) {
20699 var current = _d[_c];
20700 var name = ts.combinePaths(path, current);
20701 var absoluteName = ts.combinePaths(absolutePath, current);
20702 if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
20703 (!excludeRegex || !excludeRegex.test(absoluteName))) {
20704 visitDirectory(name, absoluteName, depth);
20705 }

Callers

nothing calls this directly

Calls 4

getFileMatcherPatternsFunction · 0.85
getRegexFromPatternFunction · 0.85
visitDirectoryFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected