@@ -23,7 +23,12 @@ const { getValidatedPath } = require('internal/fs/utils');
2323const { kFSWatchStart, StatWatcher } = require ( 'internal/fs/watchers' ) ;
2424const { kEmptyObject } = require ( 'internal/util' ) ;
2525const { validateBoolean, validateAbortSignal } = require ( 'internal/validators' ) ;
26- const path = require ( 'path' ) ;
26+ const {
27+ basename : pathBasename ,
28+ join : pathJoin ,
29+ relative : pathRelative ,
30+ resolve : pathResolve ,
31+ } = require ( 'path' ) ;
2732
2833let internalSync ;
2934let internalPromises ;
@@ -45,7 +50,7 @@ async function traverse(dir, files = new SafeMap(), symbolicLinks = new SafeSet(
4550 const subdirectories = [ ] ;
4651
4752 for await ( const file of filenames ) {
48- const f = path . join ( dir , file . name ) ;
53+ const f = pathJoin ( dir , file . name ) ;
4954
5055 files . set ( f , file ) ;
5156
@@ -67,7 +72,7 @@ class FSWatcher extends EventEmitter {
6772 #closed = false ;
6873 #files = new SafeMap ( ) ;
6974 #symbolicFiles = new SafeSet ( ) ;
70- #rootPath = path . resolve ( ) ;
75+ #rootPath = pathResolve ( ) ;
7176 #watchingFile = false ;
7277
7378 constructor ( options = kEmptyObject ) {
@@ -140,10 +145,10 @@ class FSWatcher extends EventEmitter {
140145 break ;
141146 }
142147
143- const f = path . join ( folder , file . name ) ;
148+ const f = pathJoin ( folder , file . name ) ;
144149
145150 if ( ! this . #files. has ( f ) ) {
146- this . emit ( 'change' , 'rename' , path . relative ( this . #rootPath, f ) ) ;
151+ this . emit ( 'change' , 'rename' , pathRelative ( this . #rootPath, f ) ) ;
147152
148153 if ( file . isSymbolicLink ( ) ) {
149154 this . #symbolicFiles. add ( f ) ;
@@ -186,23 +191,23 @@ class FSWatcher extends EventEmitter {
186191 if ( currentStats . birthtimeMs === 0 && previousStats . birthtimeMs !== 0 ) {
187192 // The file is now deleted
188193 this . #files. delete ( file ) ;
189- this . emit ( 'change' , 'rename' , path . relative ( this . #rootPath, file ) ) ;
194+ this . emit ( 'change' , 'rename' , pathRelative ( this . #rootPath, file ) ) ;
190195 this . #unwatchFiles( file ) ;
191196 } else if ( file === this . #rootPath && this . #watchingFile) {
192197 // This case will only be triggered when watching a file with fs.watch
193- this . emit ( 'change' , 'change' , path . basename ( file ) ) ;
198+ this . emit ( 'change' , 'change' , pathBasename ( file ) ) ;
194199 } else if ( this . #symbolicFiles. has ( file ) ) {
195200 // Stats from watchFile does not return correct value for currentStats.isSymbolicLink()
196201 // Since it is only valid when using fs.lstat(). Therefore, check the existing symbolic files.
197- this . emit ( 'change' , 'rename' , path . relative ( this . #rootPath, file ) ) ;
202+ this . emit ( 'change' , 'rename' , pathRelative ( this . #rootPath, file ) ) ;
198203 } else if ( currentStats . isDirectory ( ) ) {
199204 this . #watchFolder( file ) ;
200205 }
201206 } ) ;
202207 }
203208
204209 [ kFSWatchStart ] ( filename ) {
205- filename = path . resolve ( getValidatedPath ( filename ) ) ;
210+ filename = pathResolve ( getValidatedPath ( filename ) ) ;
206211
207212 try {
208213 const file = lazyLoadFsSync ( ) . statSync ( filename ) ;
0 commit comments