@@ -69,6 +69,10 @@ export class FileSystemPaths {
69
69
}
70
70
}
71
71
72
+ // Where to fine executables.
73
+ //
74
+ // In particular this class provides all the tools needed to find
75
+ // executables, including through an environment variable.
72
76
export class Executables {
73
77
constructor (
74
78
public readonly delimiter : string ,
@@ -91,10 +95,12 @@ export class Executables {
91
95
}
92
96
}
93
97
98
+ // The dependencies FileSystemPathUtils has on node's path module.
94
99
interface IRawPaths {
95
100
relative ( relpath : string , rootpath : string ) : string ;
96
101
}
97
102
103
+ // A collection of high-level utilities related to filesystem paths.
98
104
export class FileSystemPathUtils {
99
105
constructor (
100
106
public readonly home : string ,
@@ -119,12 +125,16 @@ export class FileSystemPathUtils {
119
125
) ;
120
126
}
121
127
128
+ // Return true if the two paths are equivalent on the current
129
+ // filesystem and false otherwise. On Windows this is significant.
130
+ // On non-Windows the filenames must always be exactly the same.
122
131
public arePathsSame ( path1 : string , path2 : string ) : boolean {
123
132
path1 = this . paths . normCase ( path1 ) ;
124
133
path2 = this . paths . normCase ( path2 ) ;
125
134
return path1 === path2 ;
126
135
}
127
136
137
+ // Return the canonicalized absolute filename.
128
138
public async getRealPath ( filename : string ) : Promise < string > {
129
139
try {
130
140
return await fs . realpath ( filename ) ;
@@ -134,13 +144,14 @@ export class FileSystemPathUtils {
134
144
}
135
145
}
136
146
137
- public getDisplayName ( pathValue : string , cwd ?: string ) : string {
138
- if ( cwd && pathValue . startsWith ( cwd ) ) {
139
- return `.${ this . paths . sep } ${ this . raw . relative ( cwd , pathValue ) } ` ;
140
- } else if ( pathValue . startsWith ( this . home ) ) {
141
- return `~${ this . paths . sep } ${ this . raw . relative ( this . home , pathValue ) } ` ;
147
+ // Return the clean (displayable) form of the given filename.
148
+ public getDisplayName ( filename : string , cwd ?: string ) : string {
149
+ if ( cwd && filename . startsWith ( cwd ) ) {
150
+ return `.${ this . paths . sep } ${ this . raw . relative ( cwd , filename ) } ` ;
151
+ } else if ( filename . startsWith ( this . home ) ) {
152
+ return `~${ this . paths . sep } ${ this . raw . relative ( this . home , filename ) } ` ;
142
153
} else {
143
- return pathValue ;
154
+ return filename ;
144
155
}
145
156
}
146
157
}
0 commit comments