Skip to content

Commit 763b906

Browse files
committed
fix: update glob dependency and improve file search logic in FileSystem class
1 parent 10f59fb commit 763b906

File tree

5 files changed

+430
-409
lines changed

5 files changed

+430
-409
lines changed

packages/cli/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,20 @@
6565
"chalk": "^4.1.1",
6666
"commander": "^11.1.0",
6767
"esbuild-loader": "^4.0.3",
68-
"glob": "^7.1.7",
68+
"glob": "^11",
6969
"jest": "^29.7.0",
7070
"js-yaml": "^4.1.0",
7171
"log-symbols": "^4.0.0",
7272
"shx": "^0.3.4",
7373
"source-map-support": "^0.5.21",
7474
"ts-jest": "^29.1.1",
75-
"ts-loader": "^9.3.1",
76-
"ts-node": "^10.4.0",
75+
"ts-loader": "^9.5",
76+
"ts-node": "^10.9.0",
7777
"tsconfig-paths-webpack-plugin": "^3.5.2",
7878
"typescript": "5.1.6",
79-
"webpack": "^5.88.2",
80-
"webpack-cli": "^5.1.4",
81-
"webpack-glob-entry": "^2.1.1",
82-
"webpack-merge": "^5.9.0",
83-
"webpack-node-externals": "^3.0.0"
79+
"webpack": "^5.97",
80+
"webpack-cli": "^6.0",
81+
"webpack-merge": "^6.0"
8482
},
8583
"publisher": "curlybracket",
8684
"gitHead": "f16fa9dcbf7ef17328047ecb07ab4a7e6a94140a"

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"dependencies": {
5353
"@vlocode/util": "workspace:*",
5454
"chalk": "^4.1.1",
55+
"glob": "^11",
5556
"globby": "^11.0.4",
5657
"luxon": "^3.4.4",
5758
"memfs": "^3.2.2",

packages/core/src/fs/fileSystem.ts

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { spreadAsync } from '@vlocode/util';
22
import { minimatch, MinimatchOptions } from 'minimatch'
3+
import { Glob } from 'glob'
34

45
export interface StatsOptions {
56
/**
@@ -33,7 +34,7 @@ export interface FindOptions extends WriteOptions {
3334
/**
3435
* Single or multiple Working directories to use when searching. If not specified the current working directory is used.
3536
*/
36-
cwd?: string | string[];
37+
cwd?: string | string[];
3738
/**
3839
* Glob patterns of natches to exclude from the search
3940
*/
@@ -58,7 +59,7 @@ export interface FindOptions extends WriteOptions {
5859
noCase?: boolean;
5960
}
6061

61-
type GlobPatterns = string | string[] | RegExp | RegExp[];
62+
type GlobPatterns = string | string[];
6263

6364
export enum FindType {
6465
file = 1,
@@ -185,55 +186,33 @@ export abstract class FileSystem {
185186
* }
186187
* ```
187188
*/
188-
public async *find(globPatterns: GlobPatterns, options?: FindOptions): AsyncGenerator<string> {
189-
const inputCwd = options?.cwd;
190-
if (Array.isArray(inputCwd)) {
191-
// When multiple cwd's are specified, search each of them
192-
for (const cwd of inputCwd) {
193-
yield* this.find(globPatterns, { ...options, cwd: this.normalizeSeparators(cwd) });
194-
}
195-
return;
196-
}
189+
public async *find(patterns: GlobPatterns, options?: FindOptions): AsyncGenerator<string> {
190+
const globs = (Array.isArray(patterns) ? patterns : [ patterns ]).flatMap(
191+
pattern => (options?.cwd && Array.isArray(options.cwd) ? options.cwd : [ options?.cwd ]).map(
192+
(cwd: string | undefined) => new Glob(pattern, {
193+
cwd,
194+
withFileTypes: true,
195+
windowsPathsNoEscape: true,
196+
dotRelative: true,
197+
ignore: options?.exclude,
198+
noext: true,
199+
nodir: options?.findType === FindType.file,
200+
maxDepth: options?.depth,
201+
nocase: options?.noCase
202+
})
203+
)
204+
);
197205

198-
const cwd = this.normalizeSeparators(inputCwd ?? process.cwd());
199-
const patterns = this.compilePatterns(globPatterns);
200-
const excludePatterns = options?.exclude ? this.compilePatterns(options?.exclude) : undefined;
201-
const findType = typeof options?.findType === 'string'
202-
? (options?.findType === 'directory' ? FindType.directory : FindType.file)
203-
: (options?.findType ?? FindType.file | FindType.directory);
204-
const depth = options?.depth;
205206
let limit = options?.limit;
206207

207-
for (const info of await this.readDirectory(cwd)) {
208-
const path = `${cwd}/${info.name}`;
209-
210-
// Exclude according to exclude patterns
211-
if (excludePatterns?.some(pattern => pattern.test(info.name) || pattern.test(path))) {
212-
continue;
213-
}
214-
215-
if (info.isDirectory()) {
216-
// Match directory
217-
if (findType & FindType.directory) {
218-
if (patterns.some(pattern => pattern.test(info.name) || pattern.test(path))) {
219-
yield path;
220-
if (limit && --limit <= 0) {
221-
return;
222-
}
223-
}
224-
}
225-
226-
if (depth === undefined || depth > 0) {
227-
// Search sub directories when depth is not specified or when depth is not yet reached
228-
yield* this.find(patterns, { ...options, cwd: path, depth: depth && depth - 1, limit });
229-
}
230-
} else if (info.isFile() && findType & FindType.file) {
231-
// Match files?
232-
if (patterns.some(pattern => pattern.test(info.name) || pattern.test(path))) {
233-
yield path;
234-
if (limit && --limit <= 0) {
235-
return;
236-
}
208+
for (const glob of globs) {
209+
for await (const file of glob) {
210+
if (options?.findType === FindType.directory && !file.isDirectory()) {
211+
continue;
212+
}
213+
yield this.normalizeSeparators(file.fullpath());
214+
if (limit !== undefined && --limit === 0) {
215+
return;
237216
}
238217
}
239218
}
@@ -242,7 +221,7 @@ export abstract class FileSystem {
242221
private compilePatterns(patterns: GlobPatterns, options?: MinimatchOptions): RegExp[] {
243222
return (Array.isArray(patterns) ? patterns : [ patterns ]).map(pattern => {
244223
if (typeof pattern === 'string') {
245-
const compiled = minimatch.makeRe(pattern, options);
224+
const compiled = minimatch.makeRe(this.normalizeSeparators(pattern), options);
246225
if (!compiled) {
247226
throw new Error(`Invalid glob pattern: ${pattern}`);
248227
}

packages/vscode-extension/package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,6 @@
15161516
"@types/luxon": "^3.3.0",
15171517
"@types/node": "^20.4.2",
15181518
"@types/vscode": "^1.70.0",
1519-
"@types/webpack": "^5.28.1",
1520-
"@types/webpack-merge": "^4.1.5",
15211519
"@vlocode/core": "workspace:*",
15221520
"@vlocode/omniscript": "workspace:*",
15231521
"@vlocode/salesforce": "workspace:*",
@@ -1542,17 +1540,15 @@
15421540
"shx": "^0.3.4",
15431541
"source-map-support": "^0.5.21",
15441542
"ts-jest": "^29.1.1",
1545-
"ts-loader": "^9.4.0",
1546-
"ts-node": "^10.4.0",
1543+
"ts-loader": "^9.5",
1544+
"ts-node": "^10.9.0",
15471545
"tsconfig-paths-webpack-plugin": "^3.5.2",
15481546
"type-fest": "^2.12.2",
15491547
"typescript": "5.1.6",
15501548
"vlocity": "1.14.18",
15511549
"vscode-languageclient": "^8.1.0",
1552-
"webpack": "^5.88.2",
1553-
"webpack-cli": "^5.1.4",
1554-
"webpack-glob-entry": "^2.1.1",
1555-
"webpack-merge": "^5.9.0",
1556-
"webpack-node-externals": "^3.0.0"
1550+
"webpack": "^5.97",
1551+
"webpack-cli": "^6.0",
1552+
"webpack-merge": "^6.0"
15571553
}
15581554
}

0 commit comments

Comments
 (0)