@volar/typescript 1.6.9 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchFiles = void 0;
4
+ const core_1 = require("./core");
5
+ const path_1 = require("./path");
6
+ // KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
7
+ // ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
8
+ // Reserved characters, forces escaping of any non-word (or digit), non-whitespace character.
9
+ // It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future
10
+ // proof.
11
+ const reservedCharacterPattern = /[^\w\s\/]/g;
12
+ const wildcardCharCodes = [42 /* CharacterCodes.asterisk */, 63 /* CharacterCodes.question */];
13
+ const commonPackageFolders = ["node_modules", "bower_components", "jspm_packages"];
14
+ const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
15
+ const filesMatcher = {
16
+ /**
17
+ * Matches any single directory segment unless it is the last segment and a .min.js file
18
+ * Breakdown:
19
+ * [^./] # matches everything up to the first . character (excluding directory separators)
20
+ * (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
21
+ */
22
+ singleAsteriskRegexFragment: "([^./]|(\\.(?!min\\.js$))?)*",
23
+ /**
24
+ * Regex for the ** wildcard. Matches any number of subdirectories. When used for including
25
+ * files or directories, does not match subdirectories that start with a . character
26
+ */
27
+ doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
28
+ replaceWildcardCharacter: match => replaceWildcardCharacter(match, filesMatcher.singleAsteriskRegexFragment)
29
+ };
30
+ const directoriesMatcher = {
31
+ singleAsteriskRegexFragment: "[^/]*",
32
+ /**
33
+ * Regex for the ** wildcard. Matches any number of subdirectories. When used for including
34
+ * files or directories, does not match subdirectories that start with a . character
35
+ */
36
+ doubleAsteriskRegexFragment: `(/${implicitExcludePathRegexPattern}[^/.][^/]*)*?`,
37
+ replaceWildcardCharacter: match => replaceWildcardCharacter(match, directoriesMatcher.singleAsteriskRegexFragment)
38
+ };
39
+ const excludeMatcher = {
40
+ singleAsteriskRegexFragment: "[^/]*",
41
+ doubleAsteriskRegexFragment: "(/.+?)?",
42
+ replaceWildcardCharacter: match => replaceWildcardCharacter(match, excludeMatcher.singleAsteriskRegexFragment)
43
+ };
44
+ const wildcardMatchers = {
45
+ files: filesMatcher,
46
+ directories: directoriesMatcher,
47
+ exclude: excludeMatcher
48
+ };
49
+ function getRegularExpressionForWildcard(specs, basePath, usage) {
50
+ const patterns = getRegularExpressionsForWildcards(specs, basePath, usage);
51
+ if (!patterns || !patterns.length) {
52
+ return undefined;
53
+ }
54
+ const pattern = patterns.map(pattern => `(${pattern})`).join("|");
55
+ // If excluding, match "foo/bar/baz...", but if including, only allow "foo".
56
+ const terminator = usage === "exclude" ? "($|/)" : "$";
57
+ return `^(${pattern})${terminator}`;
58
+ }
59
+ function getRegularExpressionsForWildcards(specs, basePath, usage) {
60
+ if (specs === undefined || specs.length === 0) {
61
+ return undefined;
62
+ }
63
+ return (0, core_1.flatMap)(specs, spec => spec && getSubPatternFromSpec(spec, basePath, usage, wildcardMatchers[usage]));
64
+ }
65
+ /**
66
+ * An "includes" path "foo" is implicitly a glob "foo/** /*" (without the space) if its last component has no extension,
67
+ * and does not contain any glob characters itself.
68
+ */
69
+ function isImplicitGlob(lastPathComponent) {
70
+ return !/[.*?]/.test(lastPathComponent);
71
+ }
72
+ function getSubPatternFromSpec(spec, basePath, usage, { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }) {
73
+ let subpattern = "";
74
+ let hasWrittenComponent = false;
75
+ const components = (0, path_1.getNormalizedPathComponents)(spec, basePath);
76
+ const lastComponent = (0, core_1.last)(components);
77
+ if (usage !== "exclude" && lastComponent === "**") {
78
+ return undefined;
79
+ }
80
+ // getNormalizedPathComponents includes the separator for the root component.
81
+ // We need to remove to create our regex correctly.
82
+ components[0] = (0, path_1.removeTrailingDirectorySeparator)(components[0]);
83
+ if (isImplicitGlob(lastComponent)) {
84
+ components.push("**", "*");
85
+ }
86
+ let optionalCount = 0;
87
+ for (let component of components) {
88
+ if (component === "**") {
89
+ subpattern += doubleAsteriskRegexFragment;
90
+ }
91
+ else {
92
+ if (usage === "directories") {
93
+ subpattern += "(";
94
+ optionalCount++;
95
+ }
96
+ if (hasWrittenComponent) {
97
+ subpattern += path_1.directorySeparator;
98
+ }
99
+ if (usage !== "exclude") {
100
+ let componentPattern = "";
101
+ // The * and ? wildcards should not match directories or files that start with . if they
102
+ // appear first in a component. Dotted directories and files can be included explicitly
103
+ // like so: **/.*/.*
104
+ if (component.charCodeAt(0) === 42 /* CharacterCodes.asterisk */) {
105
+ componentPattern += "([^./]" + singleAsteriskRegexFragment + ")?";
106
+ component = component.substr(1);
107
+ }
108
+ else if (component.charCodeAt(0) === 63 /* CharacterCodes.question */) {
109
+ componentPattern += "[^./]";
110
+ component = component.substr(1);
111
+ }
112
+ componentPattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
113
+ // Patterns should not include subfolders like node_modules unless they are
114
+ // explicitly included as part of the path.
115
+ //
116
+ // As an optimization, if the component pattern is the same as the component,
117
+ // then there definitely were no wildcard characters and we do not need to
118
+ // add the exclusion pattern.
119
+ if (componentPattern !== component) {
120
+ subpattern += implicitExcludePathRegexPattern;
121
+ }
122
+ subpattern += componentPattern;
123
+ }
124
+ else {
125
+ subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
126
+ }
127
+ }
128
+ hasWrittenComponent = true;
129
+ }
130
+ while (optionalCount > 0) {
131
+ subpattern += ")?";
132
+ optionalCount--;
133
+ }
134
+ return subpattern;
135
+ }
136
+ function replaceWildcardCharacter(match, singleAsteriskRegexFragment) {
137
+ return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
138
+ }
139
+ /** @param path directory of the tsconfig.json */
140
+ function getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory) {
141
+ path = (0, path_1.normalizePath)(path);
142
+ currentDirectory = (0, path_1.normalizePath)(currentDirectory);
143
+ const absolutePath = (0, path_1.combinePaths)(currentDirectory, path);
144
+ return {
145
+ includeFilePatterns: (0, core_1.map)(getRegularExpressionsForWildcards(includes, absolutePath, "files"), pattern => `^${pattern}$`),
146
+ includeFilePattern: getRegularExpressionForWildcard(includes, absolutePath, "files"),
147
+ includeDirectoryPattern: getRegularExpressionForWildcard(includes, absolutePath, "directories"),
148
+ excludePattern: getRegularExpressionForWildcard(excludes, absolutePath, "exclude"),
149
+ basePaths: getBasePaths(path, includes, useCaseSensitiveFileNames)
150
+ };
151
+ }
152
+ function getRegexFromPattern(pattern, useCaseSensitiveFileNames) {
153
+ return new RegExp(pattern, useCaseSensitiveFileNames ? "" : "i");
154
+ }
155
+ /** @param path directory of the tsconfig.json */
156
+ function matchFiles(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory, depth, getFileSystemEntries, realpath) {
157
+ path = (0, path_1.normalizePath)(path);
158
+ currentDirectory = (0, path_1.normalizePath)(currentDirectory);
159
+ const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
160
+ const includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map(pattern => getRegexFromPattern(pattern, useCaseSensitiveFileNames));
161
+ const includeDirectoryRegex = patterns.includeDirectoryPattern && getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames);
162
+ const excludeRegex = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames);
163
+ // Associate an array of results with each include regex. This keeps results in order of the "include" order.
164
+ // If there are no "includes", then just put everything in results[0].
165
+ const results = includeFileRegexes ? includeFileRegexes.map(() => []) : [[]];
166
+ const visited = new Map();
167
+ const toCanonical = (0, core_1.createGetCanonicalFileName)(useCaseSensitiveFileNames);
168
+ for (const basePath of patterns.basePaths) {
169
+ visitDirectory(basePath, (0, path_1.combinePaths)(currentDirectory, basePath), depth);
170
+ }
171
+ return (0, core_1.flatten)(results);
172
+ function visitDirectory(path, absolutePath, depth) {
173
+ const canonicalPath = toCanonical(realpath(absolutePath));
174
+ if (visited.has(canonicalPath))
175
+ return;
176
+ visited.set(canonicalPath, true);
177
+ const { files, directories } = getFileSystemEntries(path);
178
+ for (const current of (0, core_1.sort)(files, core_1.compareStringsCaseSensitive)) {
179
+ const name = (0, path_1.combinePaths)(path, current);
180
+ const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
181
+ if (extensions && !(0, path_1.fileExtensionIsOneOf)(name, extensions))
182
+ continue;
183
+ if (excludeRegex && excludeRegex.test(absoluteName))
184
+ continue;
185
+ if (!includeFileRegexes) {
186
+ results[0].push(name);
187
+ }
188
+ else {
189
+ const includeIndex = (0, core_1.findIndex)(includeFileRegexes, re => re.test(absoluteName));
190
+ if (includeIndex !== -1) {
191
+ results[includeIndex].push(name);
192
+ }
193
+ }
194
+ }
195
+ if (depth !== undefined) {
196
+ depth--;
197
+ if (depth === 0) {
198
+ return;
199
+ }
200
+ }
201
+ for (const current of (0, core_1.sort)(directories, core_1.compareStringsCaseSensitive)) {
202
+ const name = (0, path_1.combinePaths)(path, current);
203
+ const absoluteName = (0, path_1.combinePaths)(absolutePath, current);
204
+ if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&
205
+ (!excludeRegex || !excludeRegex.test(absoluteName))) {
206
+ visitDirectory(name, absoluteName, depth);
207
+ }
208
+ }
209
+ }
210
+ }
211
+ exports.matchFiles = matchFiles;
212
+ /**
213
+ * Computes the unique non-wildcard base paths amongst the provided include patterns.
214
+ */
215
+ function getBasePaths(path, includes, useCaseSensitiveFileNames) {
216
+ // Storage for our results in the form of literal paths (e.g. the paths as written by the user).
217
+ const basePaths = [path];
218
+ if (includes) {
219
+ // Storage for literal base paths amongst the include patterns.
220
+ const includeBasePaths = [];
221
+ for (const include of includes) {
222
+ // We also need to check the relative paths by converting them to absolute and normalizing
223
+ // in case they escape the base path (e.g "..\somedirectory")
224
+ const absolute = (0, path_1.isRootedDiskPath)(include) ? include : (0, path_1.normalizePath)((0, path_1.combinePaths)(path, include));
225
+ // Append the literal and canonical candidate base paths.
226
+ includeBasePaths.push(getIncludeBasePath(absolute));
227
+ }
228
+ // Sort the offsets array using either the literal or canonical path representations.
229
+ includeBasePaths.sort((0, core_1.getStringComparer)(!useCaseSensitiveFileNames));
230
+ // Iterate over each include base path and include unique base paths that are not a
231
+ // subpath of an existing base path
232
+ for (const includeBasePath of includeBasePaths) {
233
+ if ((0, core_1.every)(basePaths, basePath => !(0, path_1.containsPath)(basePath, includeBasePath, path, !useCaseSensitiveFileNames))) {
234
+ basePaths.push(includeBasePath);
235
+ }
236
+ }
237
+ }
238
+ return basePaths;
239
+ }
240
+ function getIncludeBasePath(absolute) {
241
+ const wildcardOffset = (0, core_1.indexOfAnyCharCode)(absolute, wildcardCharCodes);
242
+ if (wildcardOffset < 0) {
243
+ // No "*" or "?" in the path
244
+ return !(0, path_1.hasExtension)(absolute)
245
+ ? absolute
246
+ : (0, path_1.removeTrailingDirectorySeparator)((0, path_1.getDirectoryPath)(absolute));
247
+ }
248
+ return absolute.substring(0, absolute.lastIndexOf(path_1.directorySeparator, wildcardOffset));
249
+ }
250
+ //# sourceMappingURL=utilities.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/typescript",
3
- "version": "1.6.9",
3
+ "version": "1.7.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,7 +13,10 @@
13
13
  "directory": "packages/typescript"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-core": "1.6.9"
16
+ "@volar/language-core": "1.7.1"
17
17
  },
18
- "gitHead": "e676fa08e4186bd2f8cc14861ef65f8d8c855ea1"
18
+ "devDependencies": {
19
+ "@volar/language-service": "1.7.1"
20
+ },
21
+ "gitHead": "6d092d684c65ce43af8a401bc90d0b2769a2bf49"
19
22
  }