@@ -236,7 +236,10 @@ async function createParcelWatcher(
236236 const queue = new WatcherQueue ( ) ;
237237
238238 const isCaseSensitive = isFileSystemCaseSensitive ( options ?. cwd ) ;
239- const rootDirPosix = toPosixPathNormalized ( options ?. cwd ?? process . cwd ( ) ) ;
239+ const rootDir = options ?. cwd ? path . resolve ( options . cwd ) : process . cwd ( ) ;
240+ const rootDirPosix = toPosixPathNormalized ( rootDir ) ;
241+ const realRootDir = fs . existsSync ( rootDir ) ? fs . realpathSync ( rootDir ) : rootDir ;
242+ const realRootDirPosix = toPosixPathNormalized ( realRootDir ) ;
240243 const rootDirLookupKey = toLookupKey ( rootDirPosix , isCaseSensitive ) ;
241244 const extraSubscriptions = new Map < string , ParcelWatcher . AsyncSubscription > ( ) ;
242245 const pendingSubscriptions = new Map < string , Promise < ParcelWatcher . AsyncSubscription > > ( ) ;
@@ -245,7 +248,11 @@ async function createParcelWatcher(
245248 const handleEvents = ( events : ParcelWatcher . Event [ ] ) => {
246249 const changes : { type : 'added' | 'modified' | 'removed' ; file : string } [ ] = [ ] ;
247250 for ( const event of events ) {
248- const posixPath = toPosixPathNormalized ( event . path ) ;
251+ let rawPath = toPosixPath ( event . path ) ;
252+ if ( realRootDirPosix !== rootDirPosix && rawPath . startsWith ( realRootDirPosix ) ) {
253+ rawPath = rootDirPosix + rawPath . slice ( realRootDirPosix . length ) ;
254+ }
255+ const posixPath = toPosixPathNormalized ( rawPath ) ;
249256 const lookupKey = toLookupKey ( posixPath , isCaseSensitive ) ;
250257 if ( ! isPathWatched ( lookupKey , watchedFiles ) ) {
251258 continue ;
@@ -419,7 +426,10 @@ async function createChokidarWatcher(
419426 const watchedFiles = new Set < string > ( ) ;
420427 const queue = new WatcherQueue ( ) ;
421428
422- const rootDir = options ?. cwd ?? process . cwd ( ) ;
429+ const rootDir = options ?. cwd ? path . resolve ( options . cwd ) : process . cwd ( ) ;
430+ const rootDirPosix = toPosixPathNormalized ( rootDir ) ;
431+ const realRootDir = fs . existsSync ( rootDir ) ? fs . realpathSync ( rootDir ) : rootDir ;
432+ const realRootDirPosix = toPosixPathNormalized ( realRootDir ) ;
423433 const isCaseSensitive = isFileSystemCaseSensitive ( rootDir ) ;
424434
425435 const watcher = chokidar . watch ( [ ] , {
@@ -431,7 +441,11 @@ async function createChokidarWatcher(
431441 } ) ;
432442
433443 const handleEvent = ( type : 'added' | 'modified' | 'removed' , rawPath : string ) => {
434- const posixPath = toPosixPathNormalized ( rawPath ) ;
444+ let normalizedPath = toPosixPath ( rawPath ) ;
445+ if ( realRootDirPosix !== rootDirPosix && normalizedPath . startsWith ( realRootDirPosix ) ) {
446+ normalizedPath = rootDirPosix + normalizedPath . slice ( realRootDirPosix . length ) ;
447+ }
448+ const posixPath = toPosixPathNormalized ( normalizedPath ) ;
435449 const lookupKey = toLookupKey ( posixPath , isCaseSensitive ) ;
436450 if ( ! isPathWatched ( lookupKey , watchedFiles ) ) {
437451 return ;
0 commit comments