( file: string, find: string, replacement: string, )
| 238 | } |
| 239 | |
| 240 | function replaceFileWithString( |
| 241 | file: string, |
| 242 | find: string, |
| 243 | replacement: string, |
| 244 | ): string | null { |
| 245 | find = handlePathWithSlash(find); |
| 246 | replacement = handlePathWithSlash(replacement); |
| 247 | if (file.startsWith(find)) { |
| 248 | const realFilePath = file.replace(find, replacement); |
| 249 | if (fs.existsSync(realFilePath)) { |
| 250 | return realFilePath; |
| 251 | } |
| 252 | } else { |
| 253 | find = `/node_modules/${find}`; |
| 254 | const index = file.indexOf(find); |
| 255 | if (index !== -1) { |
| 256 | const realFilePath = replacement + file.slice(index + find.length); |
| 257 | if (fs.existsSync(realFilePath)) { |
| 258 | return realFilePath; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | return null; |
| 263 | } |
| 264 | |
| 265 | function replaceFileWithRegExp( |
| 266 | file: string, |
no test coverage detected