MCPcopy Create free account
hub / github.com/nodejs/node / getWildcardDirectories

Function getWildcardDirectories

test/fixtures/snapshot/typescript.js:42140–42190  ·  view source on GitHub ↗

* Gets directories in a set of include patterns that should be watched for changes.

(_a, path, useCaseSensitiveFileNames)

Source from the content-addressed store, hash-verified

42138 * Gets directories in a set of include patterns that should be watched for changes.
42139 */
42140 function getWildcardDirectories(_a, path, useCaseSensitiveFileNames) {
42141 var include = _a.validatedIncludeSpecs, exclude = _a.validatedExcludeSpecs;
42142 // We watch a directory recursively if it contains a wildcard anywhere in a directory segment
42143 // of the pattern:
42144 //
42145 // /a/b/**/d - Watch /a/b recursively to catch changes to any d in any subfolder recursively
42146 // /a/b/*/d - Watch /a/b recursively to catch any d in any immediate subfolder, even if a new subfolder is added
42147 // /a/b - Watch /a/b recursively to catch changes to anything in any recursive subfoler
42148 //
42149 // We watch a directory without recursion if it contains a wildcard in the file segment of
42150 // the pattern:
42151 //
42152 // /a/b/* - Watch /a/b directly to catch any new file
42153 // /a/b/a?z - Watch /a/b directly to catch any new file matching a?z
42154 var rawExcludeRegex = ts.getRegularExpressionForWildcard(exclude, path, "exclude");
42155 var excludeRegex = rawExcludeRegex && new RegExp(rawExcludeRegex, useCaseSensitiveFileNames ? "" : "i");
42156 var wildcardDirectories = {};
42157 if (include !== undefined) {
42158 var recursiveKeys = [];
42159 for (var _i = 0, include_1 = include; _i < include_1.length; _i++) {
42160 var file = include_1[_i];
42161 var spec = ts.normalizePath(ts.combinePaths(path, file));
42162 if (excludeRegex && excludeRegex.test(spec)) {
42163 continue;
42164 }
42165 var match = getWildcardDirectoryFromSpec(spec, useCaseSensitiveFileNames);
42166 if (match) {
42167 var key = match.key, flags = match.flags;
42168 var existingFlags = wildcardDirectories[key];
42169 if (existingFlags === undefined || existingFlags < flags) {
42170 wildcardDirectories[key] = flags;
42171 if (flags === 1 /* WatchDirectoryFlags.Recursive */) {
42172 recursiveKeys.push(key);
42173 }
42174 }
42175 }
42176 }
42177 // Remove any subpaths under an existing recursively watched directory.
42178 for (var key in wildcardDirectories) {
42179 if (ts.hasProperty(wildcardDirectories, key)) {
42180 for (var _b = 0, recursiveKeys_1 = recursiveKeys; _b < recursiveKeys_1.length; _b++) {
42181 var recursiveKey = recursiveKeys_1[_b];
42182 if (key !== recursiveKey && ts.containsPath(recursiveKey, key, path, !useCaseSensitiveFileNames)) {
42183 delete wildcardDirectories[key];
42184 }
42185 }
42186 }
42187 }
42188 }
42189 return wildcardDirectories;
42190 }
42191 function getWildcardDirectoryFromSpec(spec, useCaseSensitiveFileNames) {
42192 var match = wildcardDirectoryPattern.exec(spec);
42193 if (match) {

Callers 1

Calls 3

testMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected