@@ -774,14 +774,14 @@ async function runMochaWatchJSONAsync(args, opts, change) {
774774let lastTouchedTime = Date . now ( ) ;
775775
776776/**
777- * Synchronously touch a file with a fresh, strictly-increasing mtime.
778- * Creates the file and all its parent directories if necessary.
777+ * Synchronously touch a file, creating it and all its parent directories
778+ * if necessary.
779+ * One call is one change as far as a file watcher is concerned.
779780 *
780- * Every touch gets its own mtime so that each one registers as a change on
781- * every file-watcher backend; repeatedly setting an identical mtime is
782- * invisible to polling watchers. Note that watchers may still coalesce
783- * repeated touches of the same file made in very quick succession --
784- * space them out in time.
781+ * An existing file gets a fresh, significantly-increasing mtime
782+ * since repeatedly setting an identical mtime is invisible to polling watchers.
783+ * The timestamp increases significantly so watchers don't coalesce changes.
784+ * A new file is only created: its timestamp is irrelevant.
785785 *
786786 * @param {string } filepath - Path to file
787787 */
@@ -791,10 +791,12 @@ function touchFile(filepath) {
791791 const touchTime = new Date ( lastTouchedTime ) ;
792792 try {
793793 fs . utimesSync ( filepath , touchTime , touchTime ) ;
794- } catch {
794+ } catch ( err ) {
795+ if ( err . code !== "ENOENT" ) {
796+ throw err ;
797+ }
795798 const fd = fs . openSync ( filepath , "a" ) ;
796799 fs . closeSync ( fd ) ;
797- fs . utimesSync ( filepath , touchTime , touchTime ) ;
798800 }
799801}
800802
0 commit comments