(path: string)
| 55 | * For example: "/path/to/*.txt" returns "/path/to" |
| 56 | */ |
| 57 | export function getGlobBaseDirectory(path: string): string { |
| 58 | const globMatch = path.match(GLOB_PATTERN_REGEX) |
| 59 | if (!globMatch || globMatch.index === undefined) { |
| 60 | return path |
| 61 | } |
| 62 | |
| 63 | // Get everything before the first glob character |
| 64 | const beforeGlob = path.substring(0, globMatch.index) |
| 65 | |
| 66 | // Find the last directory separator |
| 67 | const lastSepIndex = |
| 68 | getPlatform() === 'windows' |
| 69 | ? Math.max(beforeGlob.lastIndexOf('/'), beforeGlob.lastIndexOf('\\')) |
| 70 | : beforeGlob.lastIndexOf('/') |
| 71 | if (lastSepIndex === -1) return '.' |
| 72 | |
| 73 | return beforeGlob.substring(0, lastSepIndex) || '/' |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Expands tilde (~) at the start of a path to the user's home directory. |
no test coverage detected