Skip to content

Commit

Permalink
Fix watcher emit name and while condition
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Nov 20, 2024
1 parent 14cd605 commit b4f62b7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/emulation/watchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as fs from 'node:fs';
import { ErrnoError } from '../error.js';
import { isStatsEqual, type Stats } from '../stats.js';
import { normalizePath } from '../utils.js';
import { dirname, basename } from './path.js';
import { dirname } from './path.js';
import { statSync } from './sync.js';

/**
Expand Down Expand Up @@ -175,19 +175,19 @@ export function emitChange(eventType: fs.WatchEventType, filename: string) {
// Notify watchers on the specific file
if (watchers.has(normalizedFilename)) {
for (const watcher of watchers.get(normalizedFilename)!) {
watcher.emit('change', eventType, basename(filename));
watcher.emit('change', eventType, filename.substring(normalizedFilename.length));
}
}

// Notify watchers on parent directories if they are watching recursively
let parent = dirname(normalizedFilename);
while (parent !== normalizedFilename && parent !== '/') {
do {
if (watchers.has(parent)) {
for (const watcher of watchers.get(parent)!) {
watcher.emit('change', eventType, basename(filename));
watcher.emit('change', eventType, filename.substring(parent.length));
}
}
normalizedFilename = parent;
parent = dirname(parent);
}
} while (parent !== normalizedFilename);
}

0 comments on commit b4f62b7

Please sign in to comment.