Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

watch-run.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const path = require("path");
  4. const constants = require("./constants");
  5. const utils_1 = require("./utils");
  6. /**
  7. * Make function which will manually update changed files
  8. */
  9. function makeWatchRun(instance) {
  10. // Called Before starting compilation after watch
  11. const lastTimes = new Map();
  12. const startTime = 0;
  13. return (compiler, callback) => {
  14. if (null === instance.modifiedFiles) {
  15. instance.modifiedFiles = new Map();
  16. }
  17. // startTime = startTime || watching.startTime;
  18. const times = compiler.fileTimestamps;
  19. for (const [filePath, date] of times) {
  20. if (date > (lastTimes.get(filePath) || startTime) &&
  21. filePath.match(constants.tsTsxJsJsxRegex) !== null) {
  22. continue;
  23. }
  24. lastTimes.set(filePath, date);
  25. updateFile(instance, filePath);
  26. }
  27. // On watch update add all known dts files expect the ones in node_modules
  28. // (skip @types/* and modules with typings)
  29. for (const filePath of instance.files.keys()) {
  30. if (filePath.match(constants.dtsDtsxOrDtsDtsxMapRegex) !== null &&
  31. filePath.match(constants.nodeModules) === null) {
  32. updateFile(instance, filePath);
  33. }
  34. }
  35. callback();
  36. };
  37. }
  38. exports.makeWatchRun = makeWatchRun;
  39. function updateFile(instance, filePath) {
  40. const nFilePath = path.normalize(filePath);
  41. const file = instance.files.get(nFilePath) || instance.otherFiles.get(nFilePath);
  42. if (file !== undefined) {
  43. file.text = utils_1.readFile(nFilePath) || '';
  44. file.version++;
  45. instance.version++;
  46. instance.modifiedFiles.set(nFilePath, file);
  47. if (instance.watchHost !== undefined) {
  48. instance.watchHost.invokeFileWatcher(nFilePath, instance.compiler.FileWatcherEventKind.Changed);
  49. }
  50. }
  51. }