@@ -23,7 +23,12 @@ const { getValidatedPath } = require('internal/fs/utils');
23
23
const { kFSWatchStart, StatWatcher } = require ( 'internal/fs/watchers' ) ;
24
24
const { kEmptyObject } = require ( 'internal/util' ) ;
25
25
const { 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' ) ;
27
32
28
33
let internalSync ;
29
34
let internalPromises ;
@@ -45,7 +50,7 @@ async function traverse(dir, files = new SafeMap(), symbolicLinks = new SafeSet(
45
50
const subdirectories = [ ] ;
46
51
47
52
for await ( const file of filenames ) {
48
- const f = path . join ( dir , file . name ) ;
53
+ const f = pathJoin ( dir , file . name ) ;
49
54
50
55
files . set ( f , file ) ;
51
56
@@ -67,7 +72,7 @@ class FSWatcher extends EventEmitter {
67
72
#closed = false ;
68
73
#files = new SafeMap ( ) ;
69
74
#symbolicFiles = new SafeSet ( ) ;
70
- #rootPath = path . resolve ( ) ;
75
+ #rootPath = pathResolve ( ) ;
71
76
#watchingFile = false ;
72
77
73
78
constructor ( options = kEmptyObject ) {
@@ -140,10 +145,10 @@ class FSWatcher extends EventEmitter {
140
145
break ;
141
146
}
142
147
143
- const f = path . join ( folder , file . name ) ;
148
+ const f = pathJoin ( folder , file . name ) ;
144
149
145
150
if ( ! this . #files. has ( f ) ) {
146
- this . emit ( 'change' , 'rename' , path . relative ( this . #rootPath, f ) ) ;
151
+ this . emit ( 'change' , 'rename' , pathRelative ( this . #rootPath, f ) ) ;
147
152
148
153
if ( file . isSymbolicLink ( ) ) {
149
154
this . #symbolicFiles. add ( f ) ;
@@ -186,23 +191,23 @@ class FSWatcher extends EventEmitter {
186
191
if ( currentStats . birthtimeMs === 0 && previousStats . birthtimeMs !== 0 ) {
187
192
// The file is now deleted
188
193
this . #files. delete ( file ) ;
189
- this . emit ( 'change' , 'rename' , path . relative ( this . #rootPath, file ) ) ;
194
+ this . emit ( 'change' , 'rename' , pathRelative ( this . #rootPath, file ) ) ;
190
195
this . #unwatchFiles( file ) ;
191
196
} else if ( file === this . #rootPath && this . #watchingFile) {
192
197
// 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 ) ) ;
194
199
} else if ( this . #symbolicFiles. has ( file ) ) {
195
200
// Stats from watchFile does not return correct value for currentStats.isSymbolicLink()
196
201
// 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 ) ) ;
198
203
} else if ( currentStats . isDirectory ( ) ) {
199
204
this . #watchFolder( file ) ;
200
205
}
201
206
} ) ;
202
207
}
203
208
204
209
[ kFSWatchStart ] ( filename ) {
205
- filename = path . resolve ( getValidatedPath ( filename ) ) ;
210
+ filename = pathResolve ( getValidatedPath ( filename ) ) ;
206
211
207
212
try {
208
213
const file = lazyLoadFsSync ( ) . statSync ( filename ) ;
0 commit comments