Skip to content

Commit

Permalink
fix: padCwd and trimCwd were not working correctly with absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
joneff committed Jan 8, 2023
1 parent 706066e commit 2d5087f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,16 @@ export const logger = new Logger();
// #region cwd
export const CWD = process.cwd();
export function trimCwd(cwd: string, filePath: string) : string {
if ( path.isAbsolute(filePath) && !filePath.startsWith(cwd) ) {
return filePath;
}

return path.relative(cwd, filePath);
}
export function padCwd(cwd: string, filePath: string) : string {
if ( path.isAbsolute(filePath) && !filePath.startsWith(cwd) ) {
return filePath;
}
return path.resolve(cwd, filePath );
}
// #endregion
Expand Down

0 comments on commit 2d5087f

Please sign in to comment.