(
file: string,
mappings?:
| Record<string, string>
| Array<{ find: string | RegExp; replacement: string }>,
)
| 201 | * ``` |
| 202 | */ |
| 203 | export function getMappingFilePath( |
| 204 | file: string, |
| 205 | mappings?: |
| 206 | | Record<string, string> |
| 207 | | Array<{ find: string | RegExp; replacement: string }>, |
| 208 | ): string { |
| 209 | if (!mappings) { |
| 210 | return file; |
| 211 | } |
| 212 | if (Array.isArray(mappings)) { |
| 213 | for (let i = 0; i < mappings.length; i++) { |
| 214 | let find = mappings[i].find; |
| 215 | let replacement = mappings[i].replacement; |
| 216 | if (typeof find === 'string') { |
| 217 | const realFilePath = replaceFileWithString(file, find, replacement); |
| 218 | if (realFilePath) { |
| 219 | return realFilePath; |
| 220 | } |
| 221 | } else if (find instanceof RegExp) { |
| 222 | const realFilePath = replaceFileWithRegExp(file, find, replacement); |
| 223 | if (realFilePath) { |
| 224 | return realFilePath; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } else { |
| 229 | for (let find in mappings) { |
| 230 | const replacement = mappings[find]; |
| 231 | const realFilePath = replaceFileWithString(file, find, replacement); |
| 232 | if (realFilePath) { |
| 233 | return realFilePath; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | return file; |
| 238 | } |
| 239 | |
| 240 | function replaceFileWithString( |
| 241 | file: string, |
no test coverage detected