| 538 | const isWindows = process.platform === 'win32' |
| 539 | |
| 540 | export function replaceRoot(string: string, root: string) { |
| 541 | const schemaRoot = root.startsWith('file://') ? root : pathToFileURL(root).toString() |
| 542 | if (!root.endsWith('/') && !isWindows) { |
| 543 | root += '?/' |
| 544 | } |
| 545 | if (!isWindows) { |
| 546 | return string |
| 547 | .replace(new RegExp(schemaRoot, 'g'), '<urlRoot>') |
| 548 | .replace(new RegExp(root, 'g'), '<root>/') |
| 549 | } |
| 550 | let unixRoot = root.replace(/\\/g, '/') |
| 551 | let win32Root = root.replaceAll('/', '\\\\') |
| 552 | if (!root.endsWith('/') && !root.endsWith('\\')) { |
| 553 | unixRoot += '?/' |
| 554 | win32Root += '?\\\\' |
| 555 | } |
| 556 | |
| 557 | return string |
| 558 | .replace(new RegExp(schemaRoot, 'gi'), '<urlRoot>') |
| 559 | .replace(new RegExp(unixRoot, 'gi'), '<root>/') |
| 560 | .replace(new RegExp(win32Root, 'gi'), '<root>/') |
| 561 | } |
| 562 | |
| 563 | export const ts = String.raw |
| 564 | |