(files: Map<string, string>, pattern: string)
| 221 | * Returns matching file keys and virtual directory prefixes. |
| 222 | */ |
| 223 | export function glob(files: Map<string, string>, pattern: string): string[] { |
| 224 | const result = new Set<string>() |
| 225 | |
| 226 | const directories = new Set<string>() |
| 227 | for (const filePath of files.keys()) { |
| 228 | if (filePath.endsWith('/.folder')) { |
| 229 | directories.add(filePath.slice(0, -'/.folder'.length)) |
| 230 | continue |
| 231 | } |
| 232 | const parts = filePath.split('/') |
| 233 | for (let i = 1; i < parts.length; i++) { |
| 234 | directories.add(parts.slice(0, i).join('/')) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | for (const filePath of files.keys()) { |
| 239 | if (filePath.endsWith('/.folder')) continue |
| 240 | if (micromatch.isMatch(filePath, pattern, VFS_GLOB_OPTIONS)) { |
| 241 | result.add(filePath) |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | for (const dir of directories) { |
| 246 | if (micromatch.isMatch(dir, pattern, VFS_GLOB_OPTIONS)) { |
| 247 | result.add(dir) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return Array.from(result).sort() |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Read a VFS file's content, optionally with offset and limit. |
no test coverage detected