* Normalize paths across platforms. * Filters must be ran on all platforms to guard against false positives
(value: T)
| 108 | * Filters must be ran on all platforms to guard against false positives |
| 109 | */ |
| 110 | function normalizePaths<T>(value: T): T { |
| 111 | if (typeof value !== 'string') { |
| 112 | return value; |
| 113 | } |
| 114 | |
| 115 | const {cwd, tempDir, tempDirReal, homeDir, homeDirReal} = |
| 116 | getPathsForNormalization(); |
| 117 | |
| 118 | const homeRelativeToTemp = path.relative(tempDir, homeDir); |
| 119 | |
| 120 | const runner: ((val: string) => string)[] = [ |
| 121 | (val) => (val.includes('keepAnsi') ? val : stripAnsi(val)), |
| 122 | // Replace process.cwd with <PROJECT_ROOT> |
| 123 | (val) => val.split(cwd).join('<PROJECT_ROOT>'), |
| 124 | |
| 125 | // Replace temp directory with <TEMP_DIR> |
| 126 | (val) => val.split(tempDirReal).join('<TEMP_DIR>'), |
| 127 | (val) => val.split(tempDir).join('<TEMP_DIR>'), |
| 128 | |
| 129 | (val) => val.split(tempDirReal).join('<TEMP_DIR>'), |
| 130 | (val) => val.split(tempDir).join('<TEMP_DIR>'), |
| 131 | |
| 132 | // Replace home directory with <HOME_DIR> |
| 133 | (val) => val.split(homeDirReal).join('<HOME_DIR>'), |
| 134 | (val) => val.split(homeDir).join('<HOME_DIR>'), |
| 135 | |
| 136 | // Handle HOME_DIR nested inside TEMP_DIR |
| 137 | // This happens on windows GitHub actions runners |
| 138 | // tempDir: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp', |
| 139 | // homeDir: 'C:\\Users\\runneradmin', |
| 140 | (val) => |
| 141 | val |
| 142 | .split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`) |
| 143 | .join('<HOME_DIR>'), |
| 144 | |
| 145 | // replace /prefix___MKDTEMP_DIR___ABC123 with /prefix<MKDTEMP_DIR_STABLE> |
| 146 | // The random 6-char suffix of mkdtemp() is removed to make snapshots stable |
| 147 | (val) => { |
| 148 | const [before, after] = val.split('___MKDTEMP_DIR___'); |
| 149 | if (after) { |
| 150 | const afterSub = after.substring(6); |
| 151 | return [before, afterSub].join('<MKDTEMP_DIR_STABLE>'); |
| 152 | } |
| 153 | return before; |
| 154 | }, |
| 155 | |
| 156 | // Replace the Docusaurus version with a stub |
| 157 | (val) => val.split(version).join('<CURRENT_VERSION>'), |
| 158 | |
| 159 | // In case the CWD is escaped |
| 160 | (val) => val.split(escapePath(cwd)).join('<PROJECT_ROOT>'), |
| 161 | |
| 162 | // Remove win32 drive letters, C:\ -> \ |
| 163 | (val) => val.replace(/[a-zA-Z]:\\/g, '\\'), |
| 164 | |
| 165 | // Remove duplicate backslashes created from escapePath |
| 166 | (val) => val.replace(/\\\\/g, '\\'), |
| 167 |
no test coverage detected
searching dependent graphs…