From b4f62b7afd36fd11cba3f722c818629154aa2ddc Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Wed, 20 Nov 2024 12:51:44 -0300 Subject: [PATCH] Fix watcher emit name and while condition Signed-off-by: Marcos Candeia --- src/emulation/watchers.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/emulation/watchers.ts b/src/emulation/watchers.ts index 861a4987..8b1618ff 100644 --- a/src/emulation/watchers.ts +++ b/src/emulation/watchers.ts @@ -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'; /** @@ -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); }