( targetPath: string, rootDirectory: string, )
| 114 | * @returns The relative path from rootDirectory to targetPath. |
| 115 | */ |
| 116 | export function makeRelative( |
| 117 | targetPath: string, |
| 118 | rootDirectory: string, |
| 119 | ): string { |
| 120 | const resolvedTargetPath = path.resolve(targetPath); |
| 121 | const resolvedRootDirectory = path.resolve(rootDirectory); |
| 122 | |
| 123 | const relativePath = path.relative(resolvedRootDirectory, resolvedTargetPath); |
| 124 | |
| 125 | // If the paths are the same, path.relative returns '', return '.' instead |
| 126 | return relativePath || '.'; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Escapes special characters in a file path like macOS terminal does. |
no outgoing calls
no test coverage detected