| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5a95852 commit ec9c0b5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -754,6 +754,7 @@ async function createChokidarWatcher( | |||
| 754 | 754 | ): Promise<BuildWatcher> { | |
| 755 | 755 | const chokidar = chokidarModule ?? (await import('chokidar')); | |
| 756 | 756 | const watchedFiles = new Set<string>(); | |
| 757 | + const fileStats = new Map<string, { mtimeMs: number; size: number }>(); | ||
| 757 | 758 | ||
| 758 | 759 | let queue: WatcherQueue; | |
| 759 | 760 | if (options?.polling) { | |
@@ -813,16 +814,36 @@ async function createChokidarWatcher( | |||
| 813 | 814 | return; | |
| 814 | 815 | } | |
| 815 | 816 | ||
| 816 | - if (type !== 'removed') { | ||
| 817 | - const stat = fs.statSync(rawPath, { throwIfNoEntry: false }); | ||
| 818 | - // Ignore historical events from before watcher initialization, but allow a 1000 ms window | ||
| 819 | - // to account for coarse filesystem timestamp resolution (e.g., ext4/overlayfs integer second | ||
| 820 | - // mtime truncation on Linux) where files modified during startup may have truncated .000 ms mtimes. | ||
| 821 | - if (stat && stat.mtimeMs < initTime - 1000) { | ||
| 822 | - return; | ||
| 823 | - } | ||
| 817 | + if (type === 'removed') { | ||
| 818 | + fileStats.delete(lookupKey); | ||
| 819 | + queue.addChange(type, rawPath); | ||
| 820 | + | ||
| 821 | + return; | ||
| 822 | + } | ||
| 823 | + | ||
| 824 | + const stat = fs.statSync(rawPath, { throwIfNoEntry: false }); | ||
| 825 | + if (!stat) { | ||
| 826 | + return; | ||
| 824 | 827 | } | |
| 825 | 828 | ||
| 829 | + // Ignore historical events from before watcher initialization, but allow a 1000 ms window | ||
| 830 | + // to account for coarse filesystem timestamp resolution (e.g., ext4/overlayfs integer second | ||
| 831 | + // mtime truncation on Linux) where files modified during startup may have truncated .000 ms mtimes. | ||
| 832 | + if (stat.mtimeMs < initTime - 1000) { | ||
| 833 | + return; | ||
| 834 | + } | ||
| 835 | + | ||
| 836 | + const previousStat = fileStats.get(lookupKey); | ||
| 837 | + if ( | ||
| 838 | + type === 'modified' && | ||
| 839 | + previousStat && | ||
| 840 | + previousStat.mtimeMs === stat.mtimeMs && | ||
| 841 | + previousStat.size === stat.size | ||
| 842 | + ) { | ||
| 843 | + return; | ||
| 844 | + } | ||
| 845 | + | ||
| 846 | + fileStats.set(lookupKey, { mtimeMs: stat.mtimeMs, size: stat.size }); | ||
| 826 | 847 | queue.addChange(type, rawPath); | |
| 827 | 848 | }; | |
| 828 | 849 | ||
@@ -835,8 +856,23 @@ async function createChokidarWatcher( | |||
| 835 | 856 | return this; | |
| 836 | 857 | }, | |
| 837 | 858 | ||
| 838 | - next() { | ||
| 839 | - return queue.next(); | ||
| 859 | + async next() { | ||
| 860 | + const result = await queue.next(); | ||
| 861 | + if (result.value) { | ||
| 862 | + const files = [...result.value.added, ...result.value.modified]; | ||
| 863 | + await Promise.all( | ||
| 864 | + files.map(async (file) => { | ||
| 865 | + const stat = await fs.promises.stat(file).catch(() => undefined); | ||
| 866 | + if (stat?.isFile()) { | ||
| 867 | + const posixPath = toPosixPathNormalized(file); | ||
| 868 | + const lookupKey = toLookupKey(posixPath, isCaseSensitive); | ||
| 869 | + fileStats.set(lookupKey, { mtimeMs: stat.mtimeMs, size: stat.size }); | ||
| 870 | + } | ||
| 871 | + }), | ||
| 872 | + ); | ||
| 873 | + } | ||
| 874 | + | ||
| 875 | + return result; | ||
| 840 | 876 | }, | |
| 841 | 877 | ||
| 842 | 878 | add(paths) { | |
@@ -875,6 +911,7 @@ async function createChokidarWatcher( | |||
| 875 | 911 | const lookupKey = toLookupKey(posixPath, isCaseSensitive); | |
| 876 | 912 | if (watchedFiles.has(lookupKey)) { | |
| 877 | 913 | watchedFiles.delete(lookupKey); | |
| 914 | + fileStats.delete(lookupKey); | ||
| 878 | 915 | ||
| 879 | 916 | // When the last watched file in a package is removed, unwatch the package directory. | |
| 880 | 917 | const { isPackage, unwatchPkgDir } = nodeModulesManager.removePackageFile( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments