@@ -25,14 +25,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
2525Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2626exports . PathScurry = exports . Path = exports . PathScurryDarwin = exports . PathScurryPosix = exports . PathScurryWin32 = exports . PathScurryBase = exports . PathPosix = exports . PathWin32 = exports . PathBase = exports . ChildrenCache = exports . ResolveCache = void 0 ;
2727const 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" ) ;
3130const fs_1 = require ( "fs" ) ;
31+ const actualFS = __importStar ( require ( "node:fs" ) ) ;
3232const realpathSync = fs_1 . realpathSync . native ;
3333// TODO: test perf of fs/promises realpath vs realpathCB,
3434// since the promises one uses realpath.native
35- const promises_1 = require ( "fs/promises" ) ;
35+ const promises_1 = require ( "node: fs/promises" ) ;
3636const minipass_1 = require ( "minipass" ) ;
3737const defaultFS = {
3838 lstatSync : fs_1 . lstatSync ,
@@ -48,8 +48,8 @@ const defaultFS = {
4848 } ,
4949} ;
5050// 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
5353 : {
5454 ...defaultFS ,
5555 ...fsOption ,
@@ -90,20 +90,13 @@ const ENOREADLINK = 0b0001_0000_0000;
9090const ENOREALPATH = 0b0010_0000_0000 ;
9191const ENOCHILD = ENOTDIR | ENOENT | ENOREALPATH ;
9292const 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
107100 : UNKNOWN ;
108101// normalize unicode path names
109102const normalizeCache = new Map ( ) ;
@@ -207,6 +200,11 @@ class PathBase {
207200 * @internal
208201 */
209202 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 ;
210208 // potential default fs override
211209 #fs;
212210 // Stats fields
@@ -294,14 +292,20 @@ class PathBase {
294292 #realpath;
295293 /**
296294 * 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.
301298 */
302- get path ( ) {
299+ get parentPath ( ) {
303300 return ( this . parent || this ) . fullpath ( ) ;
304301 }
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+ }
305309 /**
306310 * Do not create new Path objects directly. They should always be accessed
307311 * via the PathScurry class or other methods on the Path class.
@@ -355,8 +359,8 @@ class PathBase {
355359 const rootPath = this . getRootString ( path ) ;
356360 const dir = path . substring ( rootPath . length ) ;
357361 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 )
360364 : this . #resolveParts( dirParts ) ;
361365 return result ;
362366 }
@@ -407,9 +411,7 @@ class PathBase {
407411 }
408412 // find the child
409413 const children = this . children ( ) ;
410- const name = this . nocase
411- ? normalizeNocase ( pathPart )
412- : normalize ( pathPart ) ;
414+ const name = this . nocase ? normalizeNocase ( pathPart ) : normalize ( pathPart ) ;
413415 for ( const p of children ) {
414416 if ( p . #matchName === name ) {
415417 return p ;
@@ -419,9 +421,7 @@ class PathBase {
419421 // actually exist. If we know the parent isn't a dir, then
420422 // in fact it CAN'T exist.
421423 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 ;
425425 const pchild = this . newChild ( pathPart , UNKNOWN , {
426426 ...opts ,
427427 parent : this ,
@@ -440,6 +440,8 @@ class PathBase {
440440 * the cwd, then this ends up being equivalent to the fullpath()
441441 */
442442 relative ( ) {
443+ if ( this . isCWD )
444+ return '' ;
443445 if ( this . #relative !== undefined ) {
444446 return this . #relative;
445447 }
@@ -460,6 +462,8 @@ class PathBase {
460462 relativePosix ( ) {
461463 if ( this . sep === '/' )
462464 return this . relative ( ) ;
465+ if ( this . isCWD )
466+ return '' ;
463467 if ( this . #relativePosix !== undefined )
464468 return this . #relativePosix;
465469 const name = this . name ;
@@ -525,23 +529,15 @@ class PathBase {
525529 return this [ `is${ type } ` ] ( ) ;
526530 }
527531 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' ) ;
545541 /* c8 ignore stop */
546542 }
547543 /**
@@ -675,8 +671,8 @@ class PathBase {
675671 * directly.
676672 */
677673 isNamed ( n ) {
678- return ! this . nocase
679- ? this . #matchName === normalize ( n )
674+ return ! this . nocase ?
675+ this . #matchName === normalize ( n )
680676 : this . #matchName === normalizeNocase ( n ) ;
681677 }
682678 /**
@@ -732,7 +728,7 @@ class PathBase {
732728 /* c8 ignore stop */
733729 try {
734730 const read = this . #fs. readlinkSync ( this . fullpath ( ) ) ;
735- const linkTarget = ( this . parent . realpathSync ( ) ) ?. resolve ( read ) ;
731+ const linkTarget = this . parent . realpathSync ( ) ?. resolve ( read ) ;
736732 if ( linkTarget ) {
737733 return ( this . #linkTarget = linkTarget ) ;
738734 }
@@ -853,9 +849,7 @@ class PathBase {
853849 #readdirMaybePromoteChild( e , c ) {
854850 for ( let p = c . provisional ; p < c . length ; p ++ ) {
855851 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 ) ;
859853 if ( name !== pchild . #matchName) {
860854 continue ;
861855 }
@@ -1154,6 +1148,8 @@ class PathBase {
11541148 [ setAsCwd ] ( oldCwd ) {
11551149 if ( oldCwd === this )
11561150 return ;
1151+ oldCwd . isCWD = false ;
1152+ this . isCWD = true ;
11571153 const changed = new Set ( [ ] ) ;
11581154 let rp = [ ] ;
11591155 let p = this ;
@@ -1208,7 +1204,7 @@ class PathWin32 extends PathBase {
12081204 * @internal
12091205 */
12101206 getRootString ( path ) {
1211- return path_1 . win32 . parse ( path ) . root ;
1207+ return node_path_1 . win32 . parse ( path ) . root ;
12121208 }
12131209 /**
12141210 * @internal
@@ -1330,7 +1326,7 @@ class PathScurryBase {
13301326 constructor ( cwd = process . cwd ( ) , pathImpl , sep , { nocase, childrenCacheSize = 16 * 1024 , fs = defaultFS , } = { } ) {
13311327 this . #fs = fsFromOption ( fs ) ;
13321328 if ( cwd instanceof URL || cwd . startsWith ( 'file://' ) ) {
1333- cwd = ( 0 , url_1 . fileURLToPath ) ( cwd ) ;
1329+ cwd = ( 0 , node_url_1 . fileURLToPath ) ( cwd ) ;
13341330 }
13351331 // resolve and split root, and then add to the store.
13361332 // this is the only time we call path.resolve()
@@ -1919,7 +1915,7 @@ class PathScurryWin32 extends PathScurryBase {
19191915 sep = '\\' ;
19201916 constructor ( cwd = process . cwd ( ) , opts = { } ) {
19211917 const { nocase = true } = opts ;
1922- super ( cwd , path_1 . win32 , '\\' , { ...opts , nocase } ) ;
1918+ super ( cwd , node_path_1 . win32 , '\\' , { ...opts , nocase } ) ;
19231919 this . nocase = nocase ;
19241920 for ( let p = this . cwd ; p ; p = p . parent ) {
19251921 p . nocase = this . nocase ;
@@ -1932,7 +1928,7 @@ class PathScurryWin32 extends PathScurryBase {
19321928 // if the path starts with a single separator, it's not a UNC, and we'll
19331929 // just get separator as the root, and driveFromUNC will return \
19341930 // 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 ( ) ;
19361932 }
19371933 /**
19381934 * @internal
@@ -1962,7 +1958,7 @@ class PathScurryPosix extends PathScurryBase {
19621958 sep = '/' ;
19631959 constructor ( cwd = process . cwd ( ) , opts = { } ) {
19641960 const { nocase = false } = opts ;
1965- super ( cwd , path_1 . posix , '/' , { ...opts , nocase } ) ;
1961+ super ( cwd , node_path_1 . posix , '/' , { ...opts , nocase } ) ;
19661962 this . nocase = nocase ;
19671963 }
19681964 /**
@@ -2012,9 +2008,7 @@ exports.Path = process.platform === 'win32' ? PathWin32 : PathPosix;
20122008 * {@link PathScurryWin32} on Windows systems, {@link PathScurryDarwin} on
20132009 * Darwin (macOS) systems, {@link PathScurryPosix} on all others.
20142010 */
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
20192013 : PathScurryPosix ;
20202014//# sourceMappingURL=index.js.map
0 commit comments