@@ -2981,6 +2981,21 @@ var ts;
2981
2981
})(ts || (ts = {}));
2982
2982
var ts;
2983
2983
(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;
2984
2999
ts.sys = (function () {
2985
3000
function getWScriptSystem() {
2986
3001
var fso = new ActiveXObject("Scripting.FileSystemObject");
@@ -3171,9 +3186,8 @@ var ts;
3171
3186
}
3172
3187
}
3173
3188
var watchedFileSet = createWatchedFileSet();
3174
- function isNode4OrLater() {
3175
- return parseInt(process.version.charAt(1)) >= 4;
3176
- }
3189
+ var nodeVersion = getNodeMajorVersion();
3190
+ var isNode4OrLater = nodeVersion >= 4;
3177
3191
function isFileSystemCaseSensitive() {
3178
3192
if (platform === "win32" || platform === "win64") {
3179
3193
return false;
@@ -3312,10 +3326,10 @@ var ts;
3312
3326
},
3313
3327
watchDirectory: function (directoryName, callback, recursive) {
3314
3328
var options;
3315
- if (!directoryExists(directoryName) || (isUNCPath(directoryName) && process.platform === "win32") ) {
3329
+ if (!directoryExists(directoryName)) {
3316
3330
return noOpFileWatcher;
3317
3331
}
3318
- if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) {
3332
+ if (isNode4OrLater && (process.platform === "win32" || process.platform === "darwin")) {
3319
3333
options = { persistent: true, recursive: !!recursive };
3320
3334
}
3321
3335
else {
@@ -3327,9 +3341,6 @@ var ts;
3327
3341
}
3328
3342
;
3329
3343
});
3330
- function isUNCPath(s) {
3331
- return s.length > 2 && s.charCodeAt(0) === 47 && s.charCodeAt(1) === 47;
3332
- }
3333
3344
},
3334
3345
resolvePath: function (path) {
3335
3346
return _path.resolve(path);
@@ -74540,7 +74551,72 @@ var ts;
74540
74551
writeMessage(pending.shift());
74541
74552
}
74542
74553
}
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
+ }
74543
74575
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
+ }
74544
74620
sys.write = function (s) { return writeMessage(new Buffer(s, "utf8")); };
74545
74621
sys.watchFile = function (fileName, callback) {
74546
74622
var watchedFile = pollingWatchedFileSet.addFile(fileName, callback);
0 commit comments