Skip to content

Commit

Permalink
Add parentPath to PathBase
Browse files Browse the repository at this point in the history
PR-URL: #19
Credit: @mrginglymus
Close: #19
Reviewed-by: @isaacs
  • Loading branch information
mrginglymus authored and isaacs committed May 9, 2024
1 parent ea50966 commit a1241ff
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,22 @@ export abstract class PathBase implements Dirent {

/**
* This property is for compatibility with the Dirent class as of
* Node v20, where Dirent['path'] refers to the path of the directory
* that was passed to readdir. So, somewhat counterintuitively, this
* property refers to the *parent* path, not the path object itself.
* For root entries, it's the path to the entry itself.
* Node v20, where Dirent['parentPath'] refers to the path of the
* directory that was passed to readdir. For root entries, it's the path
* to the entry itself.
*/
get path(): string {
get parentPath(): string {
return (this.parent || this).fullpath()
}

/**
* Deprecated alias for Dirent['parentPath'] Somewhat counterintuitively,
* this property refers to the *parent* path, not the path object itself.
*/
get path(): string {
return this.parentPath
}

/**
* Do not create new Path objects directly. They should always be accessed
* via the PathScurry class or other methods on the Path class.
Expand Down

0 comments on commit a1241ff

Please sign in to comment.