| 65 | } |
| 66 | |
| 67 | interface FileTree { |
| 68 | [key: string]: FileTree | true; |
| 69 | } |
| 70 | |
| 71 | function createFileTree(fileList: string[]): FileTree { |
| 72 | const fileTree: FileTree = Object.create(null); |
| 73 | for (const filePath of fileList) { |
| 74 | const parts = filePath.split(/[\\/]/).filter(Boolean); |
| 75 | let current = fileTree; |
| 76 | for (const part of parts) { |
| 77 | const next = current[part] ?? (current[part] = Object.create(null) as FileTree); |
| 78 | if (next === true) throw new Error(`Invalid file tree path: ${filePath}`); |
| 79 | current = next; |
| 80 | } |
| 81 | current._f_ = true; |
| 82 | } |