@@ -2981,6 +2981,21 @@ var ts;
29812981})(ts || (ts = {}));
29822982var ts;
29832983(function (ts) {
2984+ function getNodeMajorVersion() {
2985+ if (typeof process === "undefined") {
2986+ return undefined;
2987+ }
2988+ var version = process.version;
2989+ if (!version) {
2990+ return undefined;
2991+ }
2992+ var dot = version.indexOf(".");
2993+ if (dot === -1) {
2994+ return undefined;
2995+ }
2996+ return parseInt(version.substring(1, dot));
2997+ }
2998+ ts.getNodeMajorVersion = getNodeMajorVersion;
29842999 ts.sys = (function () {
29853000 function getWScriptSystem() {
29863001 var fso = new ActiveXObject("Scripting.FileSystemObject");
@@ -3171,9 +3186,8 @@ var ts;
31713186 }
31723187 }
31733188 var watchedFileSet = createWatchedFileSet();
3174- function isNode4OrLater() {
3175- return parseInt(process.version.charAt(1)) >= 4;
3176- }
3189+ var nodeVersion = getNodeMajorVersion();
3190+ var isNode4OrLater = nodeVersion >= 4;
31773191 function isFileSystemCaseSensitive() {
31783192 if (platform === "win32" || platform === "win64") {
31793193 return false;
@@ -3312,10 +3326,10 @@ var ts;
33123326 },
33133327 watchDirectory: function (directoryName, callback, recursive) {
33143328 var options;
3315- if (!directoryExists(directoryName) || (isUNCPath(directoryName) && process.platform === "win32") ) {
3329+ if (!directoryExists(directoryName)) {
33163330 return noOpFileWatcher;
33173331 }
3318- if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) {
3332+ if (isNode4OrLater && (process.platform === "win32" || process.platform === "darwin")) {
33193333 options = { persistent: true, recursive: !!recursive };
33203334 }
33213335 else {
@@ -3327,9 +3341,6 @@ var ts;
33273341 }
33283342 ;
33293343 });
3330- function isUNCPath(s) {
3331- return s.length > 2 && s.charCodeAt(0) === 47 && s.charCodeAt(1) === 47;
3332- }
33333344 },
33343345 resolvePath: function (path) {
33353346 return _path.resolve(path);
@@ -74540,7 +74551,72 @@ var ts;
7454074551 writeMessage(pending.shift());
7454174552 }
7454274553 }
74554+ function extractWatchDirectoryCacheKey(path, currentDriveKey) {
74555+ path = ts.normalizeSlashes(path);
74556+ if (isUNCPath(path)) {
74557+ var firstSlash = path.indexOf(ts.directorySeparator, 2);
74558+ return firstSlash !== -1 ? path.substring(0, firstSlash).toLowerCase() : path;
74559+ }
74560+ var rootLength = ts.getRootLength(path);
74561+ if (rootLength === 0) {
74562+ return currentDriveKey;
74563+ }
74564+ if (path.charCodeAt(1) === 58 && path.charCodeAt(2) === 47) {
74565+ return path.charAt(0).toLowerCase();
74566+ }
74567+ if (path.charCodeAt(0) === 47 && path.charCodeAt(1) !== 47) {
74568+ return currentDriveKey;
74569+ }
74570+ return undefined;
74571+ }
74572+ function isUNCPath(s) {
74573+ return s.length > 2 && s.charCodeAt(0) === 47 && s.charCodeAt(1) === 47;
74574+ }
7454374575 var sys = ts.sys;
74576+ var useWatchGuard = process.platform === "win32" && ts.getNodeMajorVersion() >= 4;
74577+ if (useWatchGuard) {
74578+ var currentDrive_1 = extractWatchDirectoryCacheKey(sys.resolvePath(sys.getCurrentDirectory()), undefined);
74579+ var statusCache_1 = ts.createMap();
74580+ var originalWatchDirectory_1 = sys.watchDirectory;
74581+ sys.watchDirectory = function (path, callback, recursive) {
74582+ var cacheKey = extractWatchDirectoryCacheKey(path, currentDrive_1);
74583+ var status = cacheKey && statusCache_1.get(cacheKey);
74584+ if (status === undefined) {
74585+ if (logger.hasLevel(server.LogLevel.verbose)) {
74586+ logger.info(cacheKey + " for path " + path + " not found in cache...");
74587+ }
74588+ try {
74589+ var args = [ts.combinePaths(__dirname, "watchGuard.js"), path];
74590+ if (logger.hasLevel(server.LogLevel.verbose)) {
74591+ logger.info("Starting " + process.execPath + " with args " + JSON.stringify(args));
74592+ }
74593+ childProcess.execFileSync(process.execPath, args, { stdio: "ignore", env: { "ELECTRON_RUN_AS_NODE": "1" } });
74594+ status = true;
74595+ if (logger.hasLevel(server.LogLevel.verbose)) {
74596+ logger.info("WatchGuard for path " + path + " returned: OK");
74597+ }
74598+ }
74599+ catch (e) {
74600+ status = false;
74601+ if (logger.hasLevel(server.LogLevel.verbose)) {
74602+ logger.info("WatchGuard for path " + path + " returned: " + e.message);
74603+ }
74604+ }
74605+ if (cacheKey) {
74606+ statusCache_1.set(cacheKey, status);
74607+ }
74608+ }
74609+ else if (logger.hasLevel(server.LogLevel.verbose)) {
74610+ logger.info("watchDirectory for " + path + " uses cached drive information.");
74611+ }
74612+ if (status) {
74613+ return originalWatchDirectory_1.call(sys, path, callback, recursive);
74614+ }
74615+ else {
74616+ return { close: function () { } };
74617+ }
74618+ };
74619+ }
7454474620 sys.write = function (s) { return writeMessage(new Buffer(s, "utf8")); };
7454574621 sys.watchFile = function (fileName, callback) {
7454674622 var watchedFile = pollingWatchedFileSet.addFile(fileName, callback);
0 commit comments