forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsys.js
More file actions
1460 lines (1460 loc) · 70.6 KB
/
sys.js
File metadata and controls
1460 lines (1460 loc) · 70.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setSys = exports.sys = exports.patchWriteFileEnsuringDirectory = exports.createSystemWatchFunctions = exports.setSysLog = exports.sysLog = exports.ignoredPaths = exports.getFileWatcherEventKind = exports.unchangedPollThresholds = exports.getModifiedTime = exports.missingFileModifiedTime = exports.PollingInterval = exports.FileWatcherEventKind = exports.setStackTraceLimit = exports.generateDjb2Hash = void 0;
var ts_1 = require("./_namespaces/ts");
/**
* djb2 hashing algorithm
* http://www.cse.yorku.ca/~oz/hash.html
*
* @internal
*/
function generateDjb2Hash(data) {
var acc = 5381;
for (var i = 0; i < data.length; i++) {
acc = ((acc << 5) + acc) + data.charCodeAt(i);
}
return acc.toString();
}
exports.generateDjb2Hash = generateDjb2Hash;
/**
* Set a high stack trace limit to provide more information in case of an error.
* Called for command-line and server use cases.
* Not called if TypeScript is used as a library.
*
* @internal
*/
function setStackTraceLimit() {
if (Error.stackTraceLimit < 100) { // Also tests that we won't set the property if it doesn't exist.
Error.stackTraceLimit = 100;
}
}
exports.setStackTraceLimit = setStackTraceLimit;
var FileWatcherEventKind;
(function (FileWatcherEventKind) {
FileWatcherEventKind[FileWatcherEventKind["Created"] = 0] = "Created";
FileWatcherEventKind[FileWatcherEventKind["Changed"] = 1] = "Changed";
FileWatcherEventKind[FileWatcherEventKind["Deleted"] = 2] = "Deleted";
})(FileWatcherEventKind || (exports.FileWatcherEventKind = FileWatcherEventKind = {}));
/** @internal */
var PollingInterval;
(function (PollingInterval) {
PollingInterval[PollingInterval["High"] = 2000] = "High";
PollingInterval[PollingInterval["Medium"] = 500] = "Medium";
PollingInterval[PollingInterval["Low"] = 250] = "Low";
})(PollingInterval || (exports.PollingInterval = PollingInterval = {}));
/** @internal */
exports.missingFileModifiedTime = new Date(0); // Any subsequent modification will occur after this time
/** @internal */
function getModifiedTime(host, fileName) {
return host.getModifiedTime(fileName) || exports.missingFileModifiedTime;
}
exports.getModifiedTime = getModifiedTime;
function createPollingIntervalBasedLevels(levels) {
var _a;
return _a = {},
_a[PollingInterval.Low] = levels.Low,
_a[PollingInterval.Medium] = levels.Medium,
_a[PollingInterval.High] = levels.High,
_a;
}
var defaultChunkLevels = { Low: 32, Medium: 64, High: 256 };
var pollingChunkSize = createPollingIntervalBasedLevels(defaultChunkLevels);
/** @internal */
exports.unchangedPollThresholds = createPollingIntervalBasedLevels(defaultChunkLevels);
function setCustomPollingValues(system) {
if (!system.getEnvironmentVariable) {
return;
}
var pollingIntervalChanged = setCustomLevels("TSC_WATCH_POLLINGINTERVAL", PollingInterval);
pollingChunkSize = getCustomPollingBasedLevels("TSC_WATCH_POLLINGCHUNKSIZE", defaultChunkLevels) || pollingChunkSize;
exports.unchangedPollThresholds = getCustomPollingBasedLevels("TSC_WATCH_UNCHANGEDPOLLTHRESHOLDS", defaultChunkLevels) || exports.unchangedPollThresholds;
function getLevel(envVar, level) {
return system.getEnvironmentVariable("".concat(envVar, "_").concat(level.toUpperCase()));
}
function getCustomLevels(baseVariable) {
var customLevels;
setCustomLevel("Low");
setCustomLevel("Medium");
setCustomLevel("High");
return customLevels;
function setCustomLevel(level) {
var customLevel = getLevel(baseVariable, level);
if (customLevel) {
(customLevels || (customLevels = {}))[level] = Number(customLevel);
}
}
}
function setCustomLevels(baseVariable, levels) {
var customLevels = getCustomLevels(baseVariable);
if (customLevels) {
setLevel("Low");
setLevel("Medium");
setLevel("High");
return true;
}
return false;
function setLevel(level) {
levels[level] = customLevels[level] || levels[level];
}
}
function getCustomPollingBasedLevels(baseVariable, defaultLevels) {
var customLevels = getCustomLevels(baseVariable);
return (pollingIntervalChanged || customLevels) &&
createPollingIntervalBasedLevels(customLevels ? __assign(__assign({}, defaultLevels), customLevels) : defaultLevels);
}
}
function pollWatchedFileQueue(host, queue, pollIndex, chunkSize, callbackOnWatchFileStat) {
var definedValueCopyToIndex = pollIndex;
// Max visit would be all elements of the queue
for (var canVisit = queue.length; chunkSize && canVisit; nextPollIndex(), canVisit--) {
var watchedFile = queue[pollIndex];
if (!watchedFile) {
continue;
}
else if (watchedFile.isClosed) {
queue[pollIndex] = undefined;
continue;
}
// Only files polled count towards chunkSize
chunkSize--;
var fileChanged = onWatchedFileStat(watchedFile, getModifiedTime(host, watchedFile.fileName));
if (watchedFile.isClosed) {
// Closed watcher as part of callback
queue[pollIndex] = undefined;
continue;
}
callbackOnWatchFileStat === null || callbackOnWatchFileStat === void 0 ? void 0 : callbackOnWatchFileStat(watchedFile, pollIndex, fileChanged);
// Defragment the queue while we are at it
if (queue[pollIndex]) {
// Copy this file to the non hole location
if (definedValueCopyToIndex < pollIndex) {
queue[definedValueCopyToIndex] = watchedFile;
queue[pollIndex] = undefined;
}
definedValueCopyToIndex++;
}
}
// Return next poll index
return pollIndex;
function nextPollIndex() {
pollIndex++;
if (pollIndex === queue.length) {
if (definedValueCopyToIndex < pollIndex) {
// There are holes from definedValueCopyToIndex to end of queue, change queue size
queue.length = definedValueCopyToIndex;
}
pollIndex = 0;
definedValueCopyToIndex = 0;
}
}
}
function createDynamicPriorityPollingWatchFile(host) {
var watchedFiles = [];
var changedFilesInLastPoll = [];
var lowPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.Low);
var mediumPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.Medium);
var highPollingIntervalQueue = createPollingIntervalQueue(PollingInterval.High);
return watchFile;
function watchFile(fileName, callback, defaultPollingInterval) {
var file = {
fileName: fileName,
callback: callback,
unchangedPolls: 0,
mtime: getModifiedTime(host, fileName)
};
watchedFiles.push(file);
addToPollingIntervalQueue(file, defaultPollingInterval);
return {
close: function () {
file.isClosed = true;
// Remove from watchedFiles
(0, ts_1.unorderedRemoveItem)(watchedFiles, file);
// Do not update polling interval queue since that will happen as part of polling
}
};
}
function createPollingIntervalQueue(pollingInterval) {
var queue = [];
queue.pollingInterval = pollingInterval;
queue.pollIndex = 0;
queue.pollScheduled = false;
return queue;
}
function pollPollingIntervalQueue(_timeoutType, queue) {
queue.pollIndex = pollQueue(queue, queue.pollingInterval, queue.pollIndex, pollingChunkSize[queue.pollingInterval]);
// Set the next polling index and timeout
if (queue.length) {
scheduleNextPoll(queue.pollingInterval);
}
else {
ts_1.Debug.assert(queue.pollIndex === 0);
queue.pollScheduled = false;
}
}
function pollLowPollingIntervalQueue(_timeoutType, queue) {
// Always poll complete list of changedFilesInLastPoll
pollQueue(changedFilesInLastPoll, PollingInterval.Low, /*pollIndex*/ 0, changedFilesInLastPoll.length);
// Finally do the actual polling of the queue
pollPollingIntervalQueue(_timeoutType, queue);
// Schedule poll if there are files in changedFilesInLastPoll but no files in the actual queue
// as pollPollingIntervalQueue wont schedule for next poll
if (!queue.pollScheduled && changedFilesInLastPoll.length) {
scheduleNextPoll(PollingInterval.Low);
}
}
function pollQueue(queue, pollingInterval, pollIndex, chunkSize) {
return pollWatchedFileQueue(host, queue, pollIndex, chunkSize, onWatchFileStat);
function onWatchFileStat(watchedFile, pollIndex, fileChanged) {
if (fileChanged) {
watchedFile.unchangedPolls = 0;
// Changed files go to changedFilesInLastPoll queue
if (queue !== changedFilesInLastPoll) {
queue[pollIndex] = undefined;
addChangedFileToLowPollingIntervalQueue(watchedFile);
}
}
else if (watchedFile.unchangedPolls !== exports.unchangedPollThresholds[pollingInterval]) {
watchedFile.unchangedPolls++;
}
else if (queue === changedFilesInLastPoll) {
// Restart unchangedPollCount for unchanged file and move to low polling interval queue
watchedFile.unchangedPolls = 1;
queue[pollIndex] = undefined;
addToPollingIntervalQueue(watchedFile, PollingInterval.Low);
}
else if (pollingInterval !== PollingInterval.High) {
watchedFile.unchangedPolls++;
queue[pollIndex] = undefined;
addToPollingIntervalQueue(watchedFile, pollingInterval === PollingInterval.Low ? PollingInterval.Medium : PollingInterval.High);
}
}
}
function pollingIntervalQueue(pollingInterval) {
switch (pollingInterval) {
case PollingInterval.Low:
return lowPollingIntervalQueue;
case PollingInterval.Medium:
return mediumPollingIntervalQueue;
case PollingInterval.High:
return highPollingIntervalQueue;
}
}
function addToPollingIntervalQueue(file, pollingInterval) {
pollingIntervalQueue(pollingInterval).push(file);
scheduleNextPollIfNotAlreadyScheduled(pollingInterval);
}
function addChangedFileToLowPollingIntervalQueue(file) {
changedFilesInLastPoll.push(file);
scheduleNextPollIfNotAlreadyScheduled(PollingInterval.Low);
}
function scheduleNextPollIfNotAlreadyScheduled(pollingInterval) {
if (!pollingIntervalQueue(pollingInterval).pollScheduled) {
scheduleNextPoll(pollingInterval);
}
}
function scheduleNextPoll(pollingInterval) {
pollingIntervalQueue(pollingInterval).pollScheduled = host.setTimeout(pollingInterval === PollingInterval.Low ? pollLowPollingIntervalQueue : pollPollingIntervalQueue, pollingInterval, pollingInterval === PollingInterval.Low ? "pollLowPollingIntervalQueue" : "pollPollingIntervalQueue", pollingIntervalQueue(pollingInterval));
}
}
function createUseFsEventsOnParentDirectoryWatchFile(fsWatch, useCaseSensitiveFileNames) {
// One file can have multiple watchers
var fileWatcherCallbacks = (0, ts_1.createMultiMap)();
var dirWatchers = new Map();
var toCanonicalName = (0, ts_1.createGetCanonicalFileName)(useCaseSensitiveFileNames);
return nonPollingWatchFile;
function nonPollingWatchFile(fileName, callback, _pollingInterval, fallbackOptions) {
var filePath = toCanonicalName(fileName);
fileWatcherCallbacks.add(filePath, callback);
var dirPath = (0, ts_1.getDirectoryPath)(filePath) || ".";
var watcher = dirWatchers.get(dirPath) ||
createDirectoryWatcher((0, ts_1.getDirectoryPath)(fileName) || ".", dirPath, fallbackOptions);
watcher.referenceCount++;
return {
close: function () {
if (watcher.referenceCount === 1) {
watcher.close();
dirWatchers.delete(dirPath);
}
else {
watcher.referenceCount--;
}
fileWatcherCallbacks.remove(filePath, callback);
}
};
}
function createDirectoryWatcher(dirName, dirPath, fallbackOptions) {
var watcher = fsWatch(dirName, 1 /* FileSystemEntryKind.Directory */, function (_eventName, relativeFileName, modifiedTime) {
// When files are deleted from disk, the triggered "rename" event would have a relativefileName of "undefined"
if (!(0, ts_1.isString)(relativeFileName))
return;
var fileName = (0, ts_1.getNormalizedAbsolutePath)(relativeFileName, dirName);
// Some applications save a working file via rename operations
var callbacks = fileName && fileWatcherCallbacks.get(toCanonicalName(fileName));
if (callbacks) {
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
var fileCallback = callbacks_1[_i];
fileCallback(fileName, FileWatcherEventKind.Changed, modifiedTime);
}
}
},
/*recursive*/ false, PollingInterval.Medium, fallbackOptions);
watcher.referenceCount = 0;
dirWatchers.set(dirPath, watcher);
return watcher;
}
}
function createFixedChunkSizePollingWatchFile(host) {
var watchedFiles = [];
var pollIndex = 0;
var pollScheduled;
return watchFile;
function watchFile(fileName, callback) {
var file = {
fileName: fileName,
callback: callback,
mtime: getModifiedTime(host, fileName)
};
watchedFiles.push(file);
scheduleNextPoll();
return {
close: function () {
file.isClosed = true;
(0, ts_1.unorderedRemoveItem)(watchedFiles, file);
}
};
}
function pollQueue() {
pollScheduled = undefined;
pollIndex = pollWatchedFileQueue(host, watchedFiles, pollIndex, pollingChunkSize[PollingInterval.Low]);
scheduleNextPoll();
}
function scheduleNextPoll() {
if (!watchedFiles.length || pollScheduled)
return;
pollScheduled = host.setTimeout(pollQueue, PollingInterval.High, "pollQueue");
}
}
function createSingleWatcherPerName(cache, useCaseSensitiveFileNames, name, callback, createWatcher) {
var toCanonicalFileName = (0, ts_1.createGetCanonicalFileName)(useCaseSensitiveFileNames);
var path = toCanonicalFileName(name);
var existing = cache.get(path);
if (existing) {
existing.callbacks.push(callback);
}
else {
cache.set(path, {
watcher: createWatcher((
// Cant infer types correctly so lets satisfy checker
function (param1, param2, param3) { var _a; return (_a = cache.get(path)) === null || _a === void 0 ? void 0 : _a.callbacks.slice().forEach(function (cb) { return cb(param1, param2, param3); }); })),
callbacks: [callback]
});
}
return {
close: function () {
var watcher = cache.get(path);
// Watcher is not expected to be undefined, but if it is normally its because
// exception was thrown somewhere else and watch state is not what it should be
if (!watcher)
return;
if (!(0, ts_1.orderedRemoveItem)(watcher.callbacks, callback) || watcher.callbacks.length)
return;
cache.delete(path);
(0, ts_1.closeFileWatcherOf)(watcher);
}
};
}
/**
* Returns true if file status changed
*/
function onWatchedFileStat(watchedFile, modifiedTime) {
var oldTime = watchedFile.mtime.getTime();
var newTime = modifiedTime.getTime();
if (oldTime !== newTime) {
watchedFile.mtime = modifiedTime;
// Pass modified times so tsc --build can use it
watchedFile.callback(watchedFile.fileName, getFileWatcherEventKind(oldTime, newTime), modifiedTime);
return true;
}
return false;
}
/** @internal */
function getFileWatcherEventKind(oldTime, newTime) {
return oldTime === 0
? FileWatcherEventKind.Created
: newTime === 0
? FileWatcherEventKind.Deleted
: FileWatcherEventKind.Changed;
}
exports.getFileWatcherEventKind = getFileWatcherEventKind;
/** @internal */
exports.ignoredPaths = ["/node_modules/.", "/.git", "/.#"];
var curSysLog = ts_1.noop;
/** @internal */
function sysLog(s) {
return curSysLog(s);
}
exports.sysLog = sysLog;
/** @internal */
function setSysLog(logger) {
curSysLog = logger;
}
exports.setSysLog = setSysLog;
/**
* Watch the directory recursively using host provided method to watch child directories
* that means if this is recursive watcher, watch the children directories as well
* (eg on OS that dont support recursive watch using fs.watch use fs.watchFile)
*/
function createDirectoryWatcherSupportingRecursive(_a) {
var watchDirectory = _a.watchDirectory, useCaseSensitiveFileNames = _a.useCaseSensitiveFileNames, getCurrentDirectory = _a.getCurrentDirectory, getAccessibleSortedChildDirectories = _a.getAccessibleSortedChildDirectories, fileSystemEntryExists = _a.fileSystemEntryExists, realpath = _a.realpath, setTimeout = _a.setTimeout, clearTimeout = _a.clearTimeout;
var cache = new Map();
var callbackCache = (0, ts_1.createMultiMap)();
var cacheToUpdateChildWatches = new Map();
var timerToUpdateChildWatches;
var filePathComparer = (0, ts_1.getStringComparer)(!useCaseSensitiveFileNames);
var toCanonicalFilePath = (0, ts_1.createGetCanonicalFileName)(useCaseSensitiveFileNames);
return function (dirName, callback, recursive, options) { return recursive ?
createDirectoryWatcher(dirName, options, callback) :
watchDirectory(dirName, callback, recursive, options); };
/**
* Create the directory watcher for the dirPath.
*/
function createDirectoryWatcher(dirName, options, callback) {
var dirPath = toCanonicalFilePath(dirName);
var directoryWatcher = cache.get(dirPath);
if (directoryWatcher) {
directoryWatcher.refCount++;
}
else {
directoryWatcher = {
watcher: watchDirectory(dirName, function (fileName) {
if (isIgnoredPath(fileName, options))
return;
if (options === null || options === void 0 ? void 0 : options.synchronousWatchDirectory) {
// Call the actual callback
invokeCallbacks(dirPath, fileName);
// Iterate through existing children and update the watches if needed
updateChildWatches(dirName, dirPath, options);
}
else {
nonSyncUpdateChildWatches(dirName, dirPath, fileName, options);
}
}, /*recursive*/ false, options),
refCount: 1,
childWatches: ts_1.emptyArray
};
cache.set(dirPath, directoryWatcher);
updateChildWatches(dirName, dirPath, options);
}
var callbackToAdd = callback && { dirName: dirName, callback: callback };
if (callbackToAdd) {
callbackCache.add(dirPath, callbackToAdd);
}
return {
dirName: dirName,
close: function () {
var directoryWatcher = ts_1.Debug.checkDefined(cache.get(dirPath));
if (callbackToAdd)
callbackCache.remove(dirPath, callbackToAdd);
directoryWatcher.refCount--;
if (directoryWatcher.refCount)
return;
cache.delete(dirPath);
(0, ts_1.closeFileWatcherOf)(directoryWatcher);
directoryWatcher.childWatches.forEach(ts_1.closeFileWatcher);
}
};
}
function invokeCallbacks(dirPath, fileNameOrInvokeMap, fileNames) {
var fileName;
var invokeMap;
if ((0, ts_1.isString)(fileNameOrInvokeMap)) {
fileName = fileNameOrInvokeMap;
}
else {
invokeMap = fileNameOrInvokeMap;
}
// Call the actual callback
callbackCache.forEach(function (callbacks, rootDirName) {
var _a;
if (invokeMap && invokeMap.get(rootDirName) === true)
return;
if (rootDirName === dirPath || ((0, ts_1.startsWith)(dirPath, rootDirName) && dirPath[rootDirName.length] === ts_1.directorySeparator)) {
if (invokeMap) {
if (fileNames) {
var existing = invokeMap.get(rootDirName);
if (existing) {
(_a = existing).push.apply(_a, fileNames);
}
else {
invokeMap.set(rootDirName, fileNames.slice());
}
}
else {
invokeMap.set(rootDirName, true);
}
}
else {
callbacks.forEach(function (_a) {
var callback = _a.callback;
return callback(fileName);
});
}
}
});
}
function nonSyncUpdateChildWatches(dirName, dirPath, fileName, options) {
// Iterate through existing children and update the watches if needed
var parentWatcher = cache.get(dirPath);
if (parentWatcher && fileSystemEntryExists(dirName, 1 /* FileSystemEntryKind.Directory */)) {
// Schedule the update and postpone invoke for callbacks
scheduleUpdateChildWatches(dirName, dirPath, fileName, options);
return;
}
// Call the actual callbacks and remove child watches
invokeCallbacks(dirPath, fileName);
removeChildWatches(parentWatcher);
}
function scheduleUpdateChildWatches(dirName, dirPath, fileName, options) {
var existing = cacheToUpdateChildWatches.get(dirPath);
if (existing) {
existing.fileNames.push(fileName);
}
else {
cacheToUpdateChildWatches.set(dirPath, { dirName: dirName, options: options, fileNames: [fileName] });
}
if (timerToUpdateChildWatches) {
clearTimeout(timerToUpdateChildWatches);
timerToUpdateChildWatches = undefined;
}
timerToUpdateChildWatches = setTimeout(onTimerToUpdateChildWatches, 1000, "timerToUpdateChildWatches");
}
function onTimerToUpdateChildWatches() {
timerToUpdateChildWatches = undefined;
sysLog("sysLog:: onTimerToUpdateChildWatches:: ".concat(cacheToUpdateChildWatches.size));
var start = (0, ts_1.timestamp)();
var invokeMap = new Map();
while (!timerToUpdateChildWatches && cacheToUpdateChildWatches.size) {
var result = cacheToUpdateChildWatches.entries().next();
ts_1.Debug.assert(!result.done);
var _a = result.value, dirPath = _a[0], _b = _a[1], dirName = _b.dirName, options = _b.options, fileNames = _b.fileNames;
cacheToUpdateChildWatches.delete(dirPath);
// Because the child refresh is fresh, we would need to invalidate whole root directory being watched
// to ensure that all the changes are reflected at this time
var hasChanges = updateChildWatches(dirName, dirPath, options);
invokeCallbacks(dirPath, invokeMap, hasChanges ? undefined : fileNames);
}
sysLog("sysLog:: invokingWatchers:: Elapsed:: ".concat((0, ts_1.timestamp)() - start, "ms:: ").concat(cacheToUpdateChildWatches.size));
callbackCache.forEach(function (callbacks, rootDirName) {
var existing = invokeMap.get(rootDirName);
if (existing) {
callbacks.forEach(function (_a) {
var callback = _a.callback, dirName = _a.dirName;
if ((0, ts_1.isArray)(existing)) {
existing.forEach(callback);
}
else {
callback(dirName);
}
});
}
});
var elapsed = (0, ts_1.timestamp)() - start;
sysLog("sysLog:: Elapsed:: ".concat(elapsed, "ms:: onTimerToUpdateChildWatches:: ").concat(cacheToUpdateChildWatches.size, " ").concat(timerToUpdateChildWatches));
}
function removeChildWatches(parentWatcher) {
if (!parentWatcher)
return;
var existingChildWatches = parentWatcher.childWatches;
parentWatcher.childWatches = ts_1.emptyArray;
for (var _i = 0, existingChildWatches_1 = existingChildWatches; _i < existingChildWatches_1.length; _i++) {
var childWatcher = existingChildWatches_1[_i];
childWatcher.close();
removeChildWatches(cache.get(toCanonicalFilePath(childWatcher.dirName)));
}
}
function updateChildWatches(parentDir, parentDirPath, options) {
// Iterate through existing children and update the watches if needed
var parentWatcher = cache.get(parentDirPath);
if (!parentWatcher)
return false;
var newChildWatches;
var hasChanges = (0, ts_1.enumerateInsertsAndDeletes)(fileSystemEntryExists(parentDir, 1 /* FileSystemEntryKind.Directory */) ? (0, ts_1.mapDefined)(getAccessibleSortedChildDirectories(parentDir), function (child) {
var childFullName = (0, ts_1.getNormalizedAbsolutePath)(child, parentDir);
// Filter our the symbolic link directories since those arent included in recursive watch
// which is same behaviour when recursive: true is passed to fs.watch
return !isIgnoredPath(childFullName, options) && filePathComparer(childFullName, (0, ts_1.normalizePath)(realpath(childFullName))) === 0 /* Comparison.EqualTo */ ? childFullName : undefined;
}) : ts_1.emptyArray, parentWatcher.childWatches, function (child, childWatcher) { return filePathComparer(child, childWatcher.dirName); }, createAndAddChildDirectoryWatcher, ts_1.closeFileWatcher, addChildDirectoryWatcher);
parentWatcher.childWatches = newChildWatches || ts_1.emptyArray;
return hasChanges;
/**
* Create new childDirectoryWatcher and add it to the new ChildDirectoryWatcher list
*/
function createAndAddChildDirectoryWatcher(childName) {
var result = createDirectoryWatcher(childName, options);
addChildDirectoryWatcher(result);
}
/**
* Add child directory watcher to the new ChildDirectoryWatcher list
*/
function addChildDirectoryWatcher(childWatcher) {
(newChildWatches || (newChildWatches = [])).push(childWatcher);
}
}
function isIgnoredPath(path, options) {
return (0, ts_1.some)(exports.ignoredPaths, function (searchPath) { return isInPath(path, searchPath); }) ||
isIgnoredByWatchOptions(path, options, useCaseSensitiveFileNames, getCurrentDirectory);
}
function isInPath(path, searchPath) {
if ((0, ts_1.stringContains)(path, searchPath))
return true;
if (useCaseSensitiveFileNames)
return false;
return (0, ts_1.stringContains)(toCanonicalFilePath(path), searchPath);
}
}
function createFileWatcherCallback(callback) {
return function (_fileName, eventKind, modifiedTime) { return callback(eventKind === FileWatcherEventKind.Changed ? "change" : "rename", "", modifiedTime); };
}
function createFsWatchCallbackForFileWatcherCallback(fileName, callback, getModifiedTime) {
return function (eventName, _relativeFileName, modifiedTime) {
if (eventName === "rename") {
// Check time stamps rather than file system entry checks
modifiedTime || (modifiedTime = getModifiedTime(fileName) || exports.missingFileModifiedTime);
callback(fileName, modifiedTime !== exports.missingFileModifiedTime ? FileWatcherEventKind.Created : FileWatcherEventKind.Deleted, modifiedTime);
}
else {
// Change
callback(fileName, FileWatcherEventKind.Changed, modifiedTime);
}
};
}
function isIgnoredByWatchOptions(pathToCheck, options, useCaseSensitiveFileNames, getCurrentDirectory) {
return ((options === null || options === void 0 ? void 0 : options.excludeDirectories) || (options === null || options === void 0 ? void 0 : options.excludeFiles)) && ((0, ts_1.matchesExclude)(pathToCheck, options === null || options === void 0 ? void 0 : options.excludeFiles, useCaseSensitiveFileNames, getCurrentDirectory()) ||
(0, ts_1.matchesExclude)(pathToCheck, options === null || options === void 0 ? void 0 : options.excludeDirectories, useCaseSensitiveFileNames, getCurrentDirectory()));
}
function createFsWatchCallbackForDirectoryWatcherCallback(directoryName, callback, options, useCaseSensitiveFileNames, getCurrentDirectory) {
return function (eventName, relativeFileName) {
// In watchDirectory we only care about adding and removing files (when event name is
// "rename"); changes made within files are handled by corresponding fileWatchers (when
// event name is "change")
if (eventName === "rename") {
// When deleting a file, the passed baseFileName is null
var fileName = !relativeFileName ? directoryName : (0, ts_1.normalizePath)((0, ts_1.combinePaths)(directoryName, relativeFileName));
if (!relativeFileName || !isIgnoredByWatchOptions(fileName, options, useCaseSensitiveFileNames, getCurrentDirectory)) {
callback(fileName);
}
}
};
}
/** @internal */
function createSystemWatchFunctions(_a) {
var pollingWatchFileWorker = _a.pollingWatchFileWorker, getModifiedTime = _a.getModifiedTime, setTimeout = _a.setTimeout, clearTimeout = _a.clearTimeout, fsWatchWorker = _a.fsWatchWorker, fileSystemEntryExists = _a.fileSystemEntryExists, useCaseSensitiveFileNames = _a.useCaseSensitiveFileNames, getCurrentDirectory = _a.getCurrentDirectory, fsSupportsRecursiveFsWatch = _a.fsSupportsRecursiveFsWatch, getAccessibleSortedChildDirectories = _a.getAccessibleSortedChildDirectories, realpath = _a.realpath, tscWatchFile = _a.tscWatchFile, useNonPollingWatchers = _a.useNonPollingWatchers, tscWatchDirectory = _a.tscWatchDirectory, inodeWatching = _a.inodeWatching, sysLog = _a.sysLog;
var pollingWatches = new Map();
var fsWatches = new Map();
var fsWatchesRecursive = new Map();
var dynamicPollingWatchFile;
var fixedChunkSizePollingWatchFile;
var nonPollingWatchFile;
var hostRecursiveDirectoryWatcher;
var hitSystemWatcherLimit = false;
return {
watchFile: watchFile,
watchDirectory: watchDirectory
};
function watchFile(fileName, callback, pollingInterval, options) {
options = updateOptionsForWatchFile(options, useNonPollingWatchers);
var watchFileKind = ts_1.Debug.checkDefined(options.watchFile);
switch (watchFileKind) {
case ts_1.WatchFileKind.FixedPollingInterval:
return pollingWatchFile(fileName, callback, PollingInterval.Low, /*options*/ undefined);
case ts_1.WatchFileKind.PriorityPollingInterval:
return pollingWatchFile(fileName, callback, pollingInterval, /*options*/ undefined);
case ts_1.WatchFileKind.DynamicPriorityPolling:
return ensureDynamicPollingWatchFile()(fileName, callback, pollingInterval, /*options*/ undefined);
case ts_1.WatchFileKind.FixedChunkSizePolling:
return ensureFixedChunkSizePollingWatchFile()(fileName, callback, /* pollingInterval */ undefined, /*options*/ undefined);
case ts_1.WatchFileKind.UseFsEvents:
return fsWatch(fileName, 0 /* FileSystemEntryKind.File */, createFsWatchCallbackForFileWatcherCallback(fileName, callback, getModifiedTime),
/*recursive*/ false, pollingInterval, (0, ts_1.getFallbackOptions)(options));
case ts_1.WatchFileKind.UseFsEventsOnParentDirectory:
if (!nonPollingWatchFile) {
nonPollingWatchFile = createUseFsEventsOnParentDirectoryWatchFile(fsWatch, useCaseSensitiveFileNames);
}
return nonPollingWatchFile(fileName, callback, pollingInterval, (0, ts_1.getFallbackOptions)(options));
default:
ts_1.Debug.assertNever(watchFileKind);
}
}
function ensureDynamicPollingWatchFile() {
return dynamicPollingWatchFile || (dynamicPollingWatchFile = createDynamicPriorityPollingWatchFile({ getModifiedTime: getModifiedTime, setTimeout: setTimeout }));
}
function ensureFixedChunkSizePollingWatchFile() {
return fixedChunkSizePollingWatchFile || (fixedChunkSizePollingWatchFile = createFixedChunkSizePollingWatchFile({ getModifiedTime: getModifiedTime, setTimeout: setTimeout }));
}
function updateOptionsForWatchFile(options, useNonPollingWatchers) {
if (options && options.watchFile !== undefined)
return options;
switch (tscWatchFile) {
case "PriorityPollingInterval":
// Use polling interval based on priority when create watch using host.watchFile
return { watchFile: ts_1.WatchFileKind.PriorityPollingInterval };
case "DynamicPriorityPolling":
// Use polling interval but change the interval depending on file changes and their default polling interval
return { watchFile: ts_1.WatchFileKind.DynamicPriorityPolling };
case "UseFsEvents":
// Use notifications from FS to watch with falling back to fs.watchFile
return generateWatchFileOptions(ts_1.WatchFileKind.UseFsEvents, ts_1.PollingWatchKind.PriorityInterval, options);
case "UseFsEventsWithFallbackDynamicPolling":
// Use notifications from FS to watch with falling back to dynamic watch file
return generateWatchFileOptions(ts_1.WatchFileKind.UseFsEvents, ts_1.PollingWatchKind.DynamicPriority, options);
case "UseFsEventsOnParentDirectory":
useNonPollingWatchers = true;
// fall through
default:
return useNonPollingWatchers ?
// Use notifications from FS to watch with falling back to fs.watchFile
generateWatchFileOptions(ts_1.WatchFileKind.UseFsEventsOnParentDirectory, ts_1.PollingWatchKind.PriorityInterval, options) :
// Default to using fs events
{ watchFile: ts_1.WatchFileKind.UseFsEvents };
}
}
function generateWatchFileOptions(watchFile, fallbackPolling, options) {
var defaultFallbackPolling = options === null || options === void 0 ? void 0 : options.fallbackPolling;
return {
watchFile: watchFile,
fallbackPolling: defaultFallbackPolling === undefined ?
fallbackPolling :
defaultFallbackPolling
};
}
function watchDirectory(directoryName, callback, recursive, options) {
if (fsSupportsRecursiveFsWatch) {
return fsWatch(directoryName, 1 /* FileSystemEntryKind.Directory */, createFsWatchCallbackForDirectoryWatcherCallback(directoryName, callback, options, useCaseSensitiveFileNames, getCurrentDirectory), recursive, PollingInterval.Medium, (0, ts_1.getFallbackOptions)(options));
}
if (!hostRecursiveDirectoryWatcher) {
hostRecursiveDirectoryWatcher = createDirectoryWatcherSupportingRecursive({
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
getCurrentDirectory: getCurrentDirectory,
fileSystemEntryExists: fileSystemEntryExists,
getAccessibleSortedChildDirectories: getAccessibleSortedChildDirectories,
watchDirectory: nonRecursiveWatchDirectory,
realpath: realpath,
setTimeout: setTimeout,
clearTimeout: clearTimeout
});
}
return hostRecursiveDirectoryWatcher(directoryName, callback, recursive, options);
}
function nonRecursiveWatchDirectory(directoryName, callback, recursive, options) {
ts_1.Debug.assert(!recursive);
var watchDirectoryOptions = updateOptionsForWatchDirectory(options);
var watchDirectoryKind = ts_1.Debug.checkDefined(watchDirectoryOptions.watchDirectory);
switch (watchDirectoryKind) {
case ts_1.WatchDirectoryKind.FixedPollingInterval:
return pollingWatchFile(directoryName, function () { return callback(directoryName); }, PollingInterval.Medium,
/*options*/ undefined);
case ts_1.WatchDirectoryKind.DynamicPriorityPolling:
return ensureDynamicPollingWatchFile()(directoryName, function () { return callback(directoryName); }, PollingInterval.Medium,
/*options*/ undefined);
case ts_1.WatchDirectoryKind.FixedChunkSizePolling:
return ensureFixedChunkSizePollingWatchFile()(directoryName, function () { return callback(directoryName); },
/* pollingInterval */ undefined,
/*options*/ undefined);
case ts_1.WatchDirectoryKind.UseFsEvents:
return fsWatch(directoryName, 1 /* FileSystemEntryKind.Directory */, createFsWatchCallbackForDirectoryWatcherCallback(directoryName, callback, options, useCaseSensitiveFileNames, getCurrentDirectory), recursive, PollingInterval.Medium, (0, ts_1.getFallbackOptions)(watchDirectoryOptions));
default:
ts_1.Debug.assertNever(watchDirectoryKind);
}
}
function updateOptionsForWatchDirectory(options) {
if (options && options.watchDirectory !== undefined)
return options;
switch (tscWatchDirectory) {
case "RecursiveDirectoryUsingFsWatchFile":
// Use polling interval based on priority when create watch using host.watchFile
return { watchDirectory: ts_1.WatchDirectoryKind.FixedPollingInterval };
case "RecursiveDirectoryUsingDynamicPriorityPolling":
// Use polling interval but change the interval depending on file changes and their default polling interval
return { watchDirectory: ts_1.WatchDirectoryKind.DynamicPriorityPolling };
default:
var defaultFallbackPolling = options === null || options === void 0 ? void 0 : options.fallbackPolling;
return {
watchDirectory: ts_1.WatchDirectoryKind.UseFsEvents,
fallbackPolling: defaultFallbackPolling !== undefined ?
defaultFallbackPolling :
undefined
};
}
}
function pollingWatchFile(fileName, callback, pollingInterval, options) {
return createSingleWatcherPerName(pollingWatches, useCaseSensitiveFileNames, fileName, callback, function (cb) { return pollingWatchFileWorker(fileName, cb, pollingInterval, options); });
}
function fsWatch(fileOrDirectory, entryKind, callback, recursive, fallbackPollingInterval, fallbackOptions) {
return createSingleWatcherPerName(recursive ? fsWatchesRecursive : fsWatches, useCaseSensitiveFileNames, fileOrDirectory, callback, function (cb) { return fsWatchHandlingExistenceOnHost(fileOrDirectory, entryKind, cb, recursive, fallbackPollingInterval, fallbackOptions); });
}
function fsWatchHandlingExistenceOnHost(fileOrDirectory, entryKind, callback, recursive, fallbackPollingInterval, fallbackOptions) {
var lastDirectoryPartWithDirectorySeparator;
var lastDirectoryPart;
if (inodeWatching) {
lastDirectoryPartWithDirectorySeparator = fileOrDirectory.substring(fileOrDirectory.lastIndexOf(ts_1.directorySeparator));
lastDirectoryPart = lastDirectoryPartWithDirectorySeparator.slice(ts_1.directorySeparator.length);
}
/** Watcher for the file system entry depending on whether it is missing or present */
var watcher = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
watchMissingFileSystemEntry() :
watchPresentFileSystemEntry();
return {
close: function () {
// Close the watcher (either existing file system entry watcher or missing file system entry watcher)
if (watcher) {
watcher.close();
watcher = undefined;
}
}
};
function updateWatcher(createWatcher) {
// If watcher is not closed, update it
if (watcher) {
sysLog("sysLog:: ".concat(fileOrDirectory, ":: Changing watcher to ").concat(createWatcher === watchPresentFileSystemEntry ? "Present" : "Missing", "FileSystemEntryWatcher"));
watcher.close();
watcher = createWatcher();
}
}
/**
* Watch the file or directory that is currently present
* and when the watched file or directory is deleted, switch to missing file system entry watcher
*/
function watchPresentFileSystemEntry() {
if (hitSystemWatcherLimit) {
sysLog("sysLog:: ".concat(fileOrDirectory, ":: Defaulting to watchFile"));
return watchPresentFileSystemEntryWithFsWatchFile();
}
try {
var presentWatcher = fsWatchWorker(fileOrDirectory, recursive, inodeWatching ?
callbackChangingToMissingFileSystemEntry :
callback);
// Watch the missing file or directory or error
presentWatcher.on("error", function () {
callback("rename", "");
updateWatcher(watchMissingFileSystemEntry);
});
return presentWatcher;
}
catch (e) {
// Catch the exception and use polling instead
// Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point
// so instead of throwing error, use fs.watchFile
hitSystemWatcherLimit || (hitSystemWatcherLimit = e.code === "ENOSPC");
sysLog("sysLog:: ".concat(fileOrDirectory, ":: Changing to watchFile"));
return watchPresentFileSystemEntryWithFsWatchFile();
}
}
function callbackChangingToMissingFileSystemEntry(event, relativeName) {
// In some scenarios, file save operation fires event with fileName.ext~ instead of fileName.ext
// To ensure we see the file going missing and coming back up (file delete and then recreated)
// and watches being updated correctly we are calling back with fileName.ext as well as fileName.ext~
// The worst is we have fired event that was not needed but we wont miss any changes
// especially in cases where file goes missing and watches wrong inode
var originalRelativeName;
if (relativeName && (0, ts_1.endsWith)(relativeName, "~")) {
originalRelativeName = relativeName;
relativeName = relativeName.slice(0, relativeName.length - 1);
}
// because relativeName is not guaranteed to be correct we need to check on each rename with few combinations
// Eg on ubuntu while watching app/node_modules the relativeName is "node_modules" which is neither relative nor full path
if (event === "rename" &&
(!relativeName ||
relativeName === lastDirectoryPart ||
(0, ts_1.endsWith)(relativeName, lastDirectoryPartWithDirectorySeparator))) {
var modifiedTime = getModifiedTime(fileOrDirectory) || exports.missingFileModifiedTime;
if (originalRelativeName)
callback(event, originalRelativeName, modifiedTime);
callback(event, relativeName, modifiedTime);
if (inodeWatching) {
// If this was rename event, inode has changed means we need to update watcher
updateWatcher(modifiedTime === exports.missingFileModifiedTime ? watchMissingFileSystemEntry : watchPresentFileSystemEntry);
}
else if (modifiedTime === exports.missingFileModifiedTime) {
updateWatcher(watchMissingFileSystemEntry);
}
}
else {
if (originalRelativeName)
callback(event, originalRelativeName);
callback(event, relativeName);
}
}
/**
* Watch the file or directory using fs.watchFile since fs.watch threw exception
* Eg. on linux the number of watches are limited and one could easily exhaust watches and the exception ENOSPC is thrown when creating watcher at that point
*/
function watchPresentFileSystemEntryWithFsWatchFile() {
return watchFile(fileOrDirectory, createFileWatcherCallback(callback), fallbackPollingInterval, fallbackOptions);
}
/**
* Watch the file or directory that is missing
* and switch to existing file or directory when the missing filesystem entry is created
*/
function watchMissingFileSystemEntry() {
return watchFile(fileOrDirectory, function (_fileName, eventKind, modifiedTime) {
if (eventKind === FileWatcherEventKind.Created) {
modifiedTime || (modifiedTime = getModifiedTime(fileOrDirectory) || exports.missingFileModifiedTime);
if (modifiedTime !== exports.missingFileModifiedTime) {
callback("rename", "", modifiedTime);
// Call the callback for current file or directory
// For now it could be callback for the inner directory creation,
// but just return current directory, better than current no-op
updateWatcher(watchPresentFileSystemEntry);
}
}
}, fallbackPollingInterval, fallbackOptions);
}
}
}
exports.createSystemWatchFunctions = createSystemWatchFunctions;
/**
* patch writefile to create folder before writing the file
*
* @internal
*/
function patchWriteFileEnsuringDirectory(sys) {
// patch writefile to create folder before writing the file
var originalWriteFile = sys.writeFile;
sys.writeFile = function (path, data, writeBom) {
return (0, ts_1.writeFileEnsuringDirectories)(path, data, !!writeBom, function (path, data, writeByteOrderMark) { return originalWriteFile.call(sys, path, data, writeByteOrderMark); }, function (path) { return sys.createDirectory(path); }, function (path) { return sys.directoryExists(path); });
};
}
exports.patchWriteFileEnsuringDirectory = patchWriteFileEnsuringDirectory;
// TODO: GH#18217 this is used as if it's certainly defined in many places.
exports.sys = (function () {
// NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual
// byte order mark from the specified encoding. Using any other byte order mark does
// not actually work.
var byteOrderMarkIndicator = "\uFEFF";
function getNodeSystem() {
var _a;
var nativePattern = /^native |^\([^)]+\)$|^(internal[\\/]|[a-zA-Z0-9_\s]+(\.js)?$)/;
var _fs = require("fs");
var _path = require("path");
var _os = require("os");
// crypto can be absent on reduced node installations
var _crypto;
try {
_crypto = require("crypto");
}
catch (_b) {
_crypto = undefined;
}
var activeSession;
var profilePath = "./profile.cpuprofile";
var Buffer = require("buffer").Buffer;
var isLinuxOrMacOs = process.platform === "linux" || process.platform === "darwin";
var platform = _os.platform();
var useCaseSensitiveFileNames = isFileSystemCaseSensitive();
var fsRealpath = !!_fs.realpathSync.native ? process.platform === "win32" ? fsRealPathHandlingLongPath : _fs.realpathSync.native : _fs.realpathSync;
// If our filename is "sys.js", then we are executing unbundled on the raw tsc output.
// In that case, simulate a faked path in the directory where a bundle would normally
// appear (e.g. the directory containing lib.*.d.ts files).
//
// Note that if we ever emit as files like cjs/mjs, this check will be wrong.
var executingFilePath = __filename.endsWith("sys.js") ? _path.join(_path.dirname(__dirname), "__fake__.js") : __filename;
var fsSupportsRecursiveFsWatch = process.platform === "win32" || process.platform === "darwin";
var getCurrentDirectory = (0, ts_1.memoize)(function () { return process.cwd(); });
var watchFile = (_a = createSystemWatchFunctions({
pollingWatchFileWorker: fsWatchFileWorker,
getModifiedTime: getModifiedTime,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
fsWatchWorker: fsWatchWorker,
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
getCurrentDirectory: getCurrentDirectory,
fileSystemEntryExists: fileSystemEntryExists,
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
fsSupportsRecursiveFsWatch: fsSupportsRecursiveFsWatch,
getAccessibleSortedChildDirectories: function (path) { return getAccessibleFileSystemEntries(path).directories; },
realpath: realpath,
tscWatchFile: process.env.TSC_WATCHFILE,
useNonPollingWatchers: !!process.env.TSC_NONPOLLING_WATCHER,
tscWatchDirectory: process.env.TSC_WATCHDIRECTORY,
inodeWatching: isLinuxOrMacOs,
sysLog: sysLog,
}), _a.watchFile), watchDirectory = _a.watchDirectory;
var nodeSystem = {
args: process.argv.slice(2),
newLine: _os.EOL,
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
write: function (s) {
process.stdout.write(s);
},