From 61b37bab2a4eb36bc497d405eeb1cf6d100eddf7 Mon Sep 17 00:00:00 2001 From: zodern Date: Fri, 27 Aug 2021 16:43:03 -0500 Subject: [PATCH] Disable native file watching during meteor create --- tools/cli/commands.js | 2 ++ tools/fs/safe-watcher.ts | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/cli/commands.js b/tools/cli/commands.js index 848848cfaa..3bfaf564b0 100644 --- a/tools/cli/commands.js +++ b/tools/cli/commands.js @@ -17,6 +17,7 @@ var release = require('../packaging/release.js'); const { Profile } = require("../tool-env/profile"); +import { disableNativeWatcher } from '../fs/safe-watcher'; import { ensureDevBundleDependencies } from '../cordova/index.js'; import { CordovaRunner } from '../cordova/runner.js'; import { iOSRunTarget, AndroidRunTarget } from '../cordova/run-targets.js'; @@ -533,6 +534,7 @@ main.registerCommand({ }, catalogRefresh: new catalog.Refresh.Never() }, function (options) { + disableNativeWatcher(); // Creating a package is much easier than creating an app, so if that's what // we are doing, do that first. (For example, we don't springboard to the diff --git a/tools/fs/safe-watcher.ts b/tools/fs/safe-watcher.ts index 12c658a363..62b129d9c3 100644 --- a/tools/fs/safe-watcher.ts +++ b/tools/fs/safe-watcher.ts @@ -10,12 +10,6 @@ import { const watchLibrary = require("pathwatcher"); -// Set METEOR_WATCH_FORCE_POLLING environment variable to a truthy value to -// force the use of files.watchFile instead of watchLibrary.watch. -var WATCHER_ENABLED = ! JSON.parse( - process.env.METEOR_WATCH_FORCE_POLLING || "false" -); - // Default to prioritizing changed files, but disable that behavior (and // thus prioritize all files equally) if METEOR_WATCH_PRIORITIZE_CHANGED // is explicitly set to a string that parses to a falsy value. @@ -40,6 +34,12 @@ const WATCHER_CLEANUP_DELAY_MS = 30000; // to deduplicate files by ino. const DEDUPLICATE_BY_INO = process.platform !== "win32"; +// Set METEOR_WATCH_FORCE_POLLING environment variable to a truthy value to +// force the use of files.watchFile instead of watchLibrary.watch. +let watcherEnabled = ! JSON.parse( + process.env.METEOR_WATCH_FORCE_POLLING || "false" +); + const entriesByIno = new Map; @@ -132,7 +132,7 @@ function startNewWatcher(absPath: string): Entry { return NO_WATCHER_POLLING_INTERVAL; } - if (WATCHER_ENABLED || PRIORITIZE_CHANGED) { + if (watcherEnabled || PRIORITIZE_CHANGED) { // As long as native file watching is enabled (even if it doesn't // work correctly) and the developer hasn't explicitly opted out of // the file watching priority system, poll unchanged files at a @@ -350,7 +350,7 @@ function statWatch( } function watchLibraryWatch(absPath: string, callback: EntryCallback) { - if (WATCHER_ENABLED) { + if (watcherEnabled) { try { return watchLibrary.watch(convertToOSPath(absPath), callback); } catch (e) { @@ -410,3 +410,10 @@ export const watch = Profile( } as SafeWatcher; } ); + +// On Windows, pathwatcher can sometimes cause Meteor to get stuck. If we +// don't need native watching for a command, we can disable it. +// This is a temporary fix until pathwatcher is fixed or we replace it. +export function disableNativeWatcher () { + watcherEnabled = false; +}