@@ -25,14 +25,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
26
26
exports . PathScurry = exports . Path = exports . PathScurryDarwin = exports . PathScurryPosix = exports . PathScurryWin32 = exports . PathScurryBase = exports . PathPosix = exports . PathWin32 = exports . PathBase = exports . ChildrenCache = exports . ResolveCache = void 0 ;
27
27
const lru_cache_1 = require ( "lru-cache" ) ;
28
- const path_1 = require ( "path" ) ;
29
- const url_1 = require ( "url" ) ;
30
- const actualFS = __importStar ( require ( "fs" ) ) ;
28
+ const node_path_1 = require ( "node:path" ) ;
29
+ const node_url_1 = require ( "node:url" ) ;
31
30
const fs_1 = require ( "fs" ) ;
31
+ const actualFS = __importStar ( require ( "node:fs" ) ) ;
32
32
const realpathSync = fs_1 . realpathSync . native ;
33
33
// TODO: test perf of fs/promises realpath vs realpathCB,
34
34
// since the promises one uses realpath.native
35
- const promises_1 = require ( "fs/promises" ) ;
35
+ const promises_1 = require ( "node: fs/promises" ) ;
36
36
const minipass_1 = require ( "minipass" ) ;
37
37
const defaultFS = {
38
38
lstatSync : fs_1 . lstatSync ,
@@ -48,8 +48,8 @@ const defaultFS = {
48
48
} ,
49
49
} ;
50
50
// if they just gave us require('fs') then use our default
51
- const fsFromOption = ( fsOption ) => ! fsOption || fsOption === defaultFS || fsOption === actualFS
52
- ? defaultFS
51
+ const fsFromOption = ( fsOption ) => ! fsOption || fsOption === defaultFS || fsOption === actualFS ?
52
+ defaultFS
53
53
: {
54
54
...defaultFS ,
55
55
...fsOption ,
@@ -90,20 +90,13 @@ const ENOREADLINK = 0b0001_0000_0000;
90
90
const ENOREALPATH = 0b0010_0000_0000 ;
91
91
const ENOCHILD = ENOTDIR | ENOENT | ENOREALPATH ;
92
92
const TYPEMASK = 0b0011_1111_1111 ;
93
- const entToType = ( s ) => s . isFile ( )
94
- ? IFREG
95
- : s . isDirectory ( )
96
- ? IFDIR
97
- : s . isSymbolicLink ( )
98
- ? IFLNK
99
- : s . isCharacterDevice ( )
100
- ? IFCHR
101
- : s . isBlockDevice ( )
102
- ? IFBLK
103
- : s . isSocket ( )
104
- ? IFSOCK
105
- : s . isFIFO ( )
106
- ? IFIFO
93
+ const entToType = ( s ) => s . isFile ( ) ? IFREG
94
+ : s . isDirectory ( ) ? IFDIR
95
+ : s . isSymbolicLink ( ) ? IFLNK
96
+ : s . isCharacterDevice ( ) ? IFCHR
97
+ : s . isBlockDevice ( ) ? IFBLK
98
+ : s . isSocket ( ) ? IFSOCK
99
+ : s . isFIFO ( ) ? IFIFO
107
100
: UNKNOWN ;
108
101
// normalize unicode path names
109
102
const normalizeCache = new Map ( ) ;
@@ -207,6 +200,11 @@ class PathBase {
207
200
* @internal
208
201
*/
209
202
nocase ;
203
+ /**
204
+ * boolean indicating that this path is the current working directory
205
+ * of the PathScurry collection that contains it.
206
+ */
207
+ isCWD = false ;
210
208
// potential default fs override
211
209
#fs;
212
210
// Stats fields
@@ -294,14 +292,20 @@ class PathBase {
294
292
#realpath;
295
293
/**
296
294
* This property is for compatibility with the Dirent class as of
297
- * Node v20, where Dirent['path'] refers to the path of the directory
298
- * that was passed to readdir. So, somewhat counterintuitively, this
299
- * property refers to the *parent* path, not the path object itself.
300
- * For root entries, it's the path to the entry itself.
295
+ * Node v20, where Dirent['parentPath'] refers to the path of the
296
+ * directory that was passed to readdir. For root entries, it's the path
297
+ * to the entry itself.
301
298
*/
302
- get path ( ) {
299
+ get parentPath ( ) {
303
300
return ( this . parent || this ) . fullpath ( ) ;
304
301
}
302
+ /**
303
+ * Deprecated alias for Dirent['parentPath'] Somewhat counterintuitively,
304
+ * this property refers to the *parent* path, not the path object itself.
305
+ */
306
+ get path ( ) {
307
+ return this . parentPath ;
308
+ }
305
309
/**
306
310
* Do not create new Path objects directly. They should always be accessed
307
311
* via the PathScurry class or other methods on the Path class.
@@ -355,8 +359,8 @@ class PathBase {
355
359
const rootPath = this . getRootString ( path ) ;
356
360
const dir = path . substring ( rootPath . length ) ;
357
361
const dirParts = dir . split ( this . splitSep ) ;
358
- const result = rootPath
359
- ? this . getRoot ( rootPath ) . #resolveParts( dirParts )
362
+ const result = rootPath ?
363
+ this . getRoot ( rootPath ) . #resolveParts( dirParts )
360
364
: this . #resolveParts( dirParts ) ;
361
365
return result ;
362
366
}
@@ -407,9 +411,7 @@ class PathBase {
407
411
}
408
412
// find the child
409
413
const children = this . children ( ) ;
410
- const name = this . nocase
411
- ? normalizeNocase ( pathPart )
412
- : normalize ( pathPart ) ;
414
+ const name = this . nocase ? normalizeNocase ( pathPart ) : normalize ( pathPart ) ;
413
415
for ( const p of children ) {
414
416
if ( p . #matchName === name ) {
415
417
return p ;
@@ -419,9 +421,7 @@ class PathBase {
419
421
// actually exist. If we know the parent isn't a dir, then
420
422
// in fact it CAN'T exist.
421
423
const s = this . parent ? this . sep : '' ;
422
- const fullpath = this . #fullpath
423
- ? this . #fullpath + s + pathPart
424
- : undefined ;
424
+ const fullpath = this . #fullpath ? this . #fullpath + s + pathPart : undefined ;
425
425
const pchild = this . newChild ( pathPart , UNKNOWN , {
426
426
...opts ,
427
427
parent : this ,
@@ -440,6 +440,8 @@ class PathBase {
440
440
* the cwd, then this ends up being equivalent to the fullpath()
441
441
*/
442
442
relative ( ) {
443
+ if ( this . isCWD )
444
+ return '' ;
443
445
if ( this . #relative !== undefined ) {
444
446
return this . #relative;
445
447
}
@@ -460,6 +462,8 @@ class PathBase {
460
462
relativePosix ( ) {
461
463
if ( this . sep === '/' )
462
464
return this . relative ( ) ;
465
+ if ( this . isCWD )
466
+ return '' ;
463
467
if ( this . #relativePosix !== undefined )
464
468
return this . #relativePosix;
465
469
const name = this . name ;
@@ -525,23 +529,15 @@ class PathBase {
525
529
return this [ `is${ type } ` ] ( ) ;
526
530
}
527
531
getType ( ) {
528
- return this . isUnknown ( )
529
- ? 'Unknown'
530
- : this . isDirectory ( )
531
- ? 'Directory'
532
- : this . isFile ( )
533
- ? 'File'
534
- : this . isSymbolicLink ( )
535
- ? 'SymbolicLink'
536
- : this . isFIFO ( )
537
- ? 'FIFO'
538
- : this . isCharacterDevice ( )
539
- ? 'CharacterDevice'
540
- : this . isBlockDevice ( )
541
- ? 'BlockDevice'
542
- : /* c8 ignore start */ this . isSocket ( )
543
- ? 'Socket'
544
- : 'Unknown' ;
532
+ return ( this . isUnknown ( ) ? 'Unknown'
533
+ : this . isDirectory ( ) ? 'Directory'
534
+ : this . isFile ( ) ? 'File'
535
+ : this . isSymbolicLink ( ) ? 'SymbolicLink'
536
+ : this . isFIFO ( ) ? 'FIFO'
537
+ : this . isCharacterDevice ( ) ? 'CharacterDevice'
538
+ : this . isBlockDevice ( ) ? 'BlockDevice'
539
+ : /* c8 ignore start */ this . isSocket ( ) ? 'Socket'
540
+ : 'Unknown' ) ;
545
541
/* c8 ignore stop */
546
542
}
547
543
/**
@@ -675,8 +671,8 @@ class PathBase {
675
671
* directly.
676
672
*/
677
673
isNamed ( n ) {
678
- return ! this . nocase
679
- ? this . #matchName === normalize ( n )
674
+ return ! this . nocase ?
675
+ this . #matchName === normalize ( n )
680
676
: this . #matchName === normalizeNocase ( n ) ;
681
677
}
682
678
/**
@@ -732,7 +728,7 @@ class PathBase {
732
728
/* c8 ignore stop */
733
729
try {
734
730
const read = this . #fs. readlinkSync ( this . fullpath ( ) ) ;
735
- const linkTarget = ( this . parent . realpathSync ( ) ) ?. resolve ( read ) ;
731
+ const linkTarget = this . parent . realpathSync ( ) ?. resolve ( read ) ;
736
732
if ( linkTarget ) {
737
733
return ( this . #linkTarget = linkTarget ) ;
738
734
}
@@ -853,9 +849,7 @@ class PathBase {
853
849
#readdirMaybePromoteChild( e , c ) {
854
850
for ( let p = c . provisional ; p < c . length ; p ++ ) {
855
851
const pchild = c [ p ] ;
856
- const name = this . nocase
857
- ? normalizeNocase ( e . name )
858
- : normalize ( e . name ) ;
852
+ const name = this . nocase ? normalizeNocase ( e . name ) : normalize ( e . name ) ;
859
853
if ( name !== pchild . #matchName) {
860
854
continue ;
861
855
}
@@ -1154,6 +1148,8 @@ class PathBase {
1154
1148
[ setAsCwd ] ( oldCwd ) {
1155
1149
if ( oldCwd === this )
1156
1150
return ;
1151
+ oldCwd . isCWD = false ;
1152
+ this . isCWD = true ;
1157
1153
const changed = new Set ( [ ] ) ;
1158
1154
let rp = [ ] ;
1159
1155
let p = this ;
@@ -1208,7 +1204,7 @@ class PathWin32 extends PathBase {
1208
1204
* @internal
1209
1205
*/
1210
1206
getRootString ( path ) {
1211
- return path_1 . win32 . parse ( path ) . root ;
1207
+ return node_path_1 . win32 . parse ( path ) . root ;
1212
1208
}
1213
1209
/**
1214
1210
* @internal
@@ -1330,7 +1326,7 @@ class PathScurryBase {
1330
1326
constructor ( cwd = process . cwd ( ) , pathImpl , sep , { nocase, childrenCacheSize = 16 * 1024 , fs = defaultFS , } = { } ) {
1331
1327
this . #fs = fsFromOption ( fs ) ;
1332
1328
if ( cwd instanceof URL || cwd . startsWith ( 'file://' ) ) {
1333
- cwd = ( 0 , url_1 . fileURLToPath ) ( cwd ) ;
1329
+ cwd = ( 0 , node_url_1 . fileURLToPath ) ( cwd ) ;
1334
1330
}
1335
1331
// resolve and split root, and then add to the store.
1336
1332
// this is the only time we call path.resolve()
@@ -1919,7 +1915,7 @@ class PathScurryWin32 extends PathScurryBase {
1919
1915
sep = '\\' ;
1920
1916
constructor ( cwd = process . cwd ( ) , opts = { } ) {
1921
1917
const { nocase = true } = opts ;
1922
- super ( cwd , path_1 . win32 , '\\' , { ...opts , nocase } ) ;
1918
+ super ( cwd , node_path_1 . win32 , '\\' , { ...opts , nocase } ) ;
1923
1919
this . nocase = nocase ;
1924
1920
for ( let p = this . cwd ; p ; p = p . parent ) {
1925
1921
p . nocase = this . nocase ;
@@ -1932,7 +1928,7 @@ class PathScurryWin32 extends PathScurryBase {
1932
1928
// if the path starts with a single separator, it's not a UNC, and we'll
1933
1929
// just get separator as the root, and driveFromUNC will return \
1934
1930
// In that case, mount \ on the root from the cwd.
1935
- return path_1 . win32 . parse ( dir ) . root . toUpperCase ( ) ;
1931
+ return node_path_1 . win32 . parse ( dir ) . root . toUpperCase ( ) ;
1936
1932
}
1937
1933
/**
1938
1934
* @internal
@@ -1962,7 +1958,7 @@ class PathScurryPosix extends PathScurryBase {
1962
1958
sep = '/' ;
1963
1959
constructor ( cwd = process . cwd ( ) , opts = { } ) {
1964
1960
const { nocase = false } = opts ;
1965
- super ( cwd , path_1 . posix , '/' , { ...opts , nocase } ) ;
1961
+ super ( cwd , node_path_1 . posix , '/' , { ...opts , nocase } ) ;
1966
1962
this . nocase = nocase ;
1967
1963
}
1968
1964
/**
@@ -2012,9 +2008,7 @@ exports.Path = process.platform === 'win32' ? PathWin32 : PathPosix;
2012
2008
* {@link PathScurryWin32} on Windows systems, {@link PathScurryDarwin} on
2013
2009
* Darwin (macOS) systems, {@link PathScurryPosix} on all others.
2014
2010
*/
2015
- exports . PathScurry = process . platform === 'win32'
2016
- ? PathScurryWin32
2017
- : process . platform === 'darwin'
2018
- ? PathScurryDarwin
2011
+ exports . PathScurry = process . platform === 'win32' ? PathScurryWin32
2012
+ : process . platform === 'darwin' ? PathScurryDarwin
2019
2013
: PathScurryPosix ;
2020
2014
//# sourceMappingURL=index.js.map
0 commit comments