1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.makeWatchRun = void 0;
|
4 | const path = require("path");
|
5 | const constants = require("./constants");
|
6 | const servicesHost_1 = require("./servicesHost");
|
7 | const utils_1 = require("./utils");
|
8 |
|
9 |
|
10 |
|
11 | function makeWatchRun(instance, loader) {
|
12 |
|
13 | const lastTimes = new Map();
|
14 | const startTime = 0;
|
15 |
|
16 | const loaderIndex = loader.loaderIndex;
|
17 | return (compiler, callback) => {
|
18 | var _a, _b;
|
19 | (_b = (_a = instance.servicesHost) === null || _a === void 0 ? void 0 : _a.clearCache) === null || _b === void 0 ? void 0 : _b.call(_a);
|
20 | const promises = [];
|
21 | if (instance.loaderOptions.transpileOnly) {
|
22 | instance.reportTranspileErrors = true;
|
23 | }
|
24 | else {
|
25 | const times = compiler.fileTimestamps;
|
26 | for (const [filePath, date] of times) {
|
27 | const key = instance.filePathKeyMapper(filePath);
|
28 | const lastTime = lastTimes.get(key) || startTime;
|
29 | if (date <= lastTime) {
|
30 | continue;
|
31 | }
|
32 | lastTimes.set(key, date);
|
33 | promises.push(updateFile(instance, key, filePath, loader, loaderIndex));
|
34 | }
|
35 |
|
36 |
|
37 | for (const [key, { fileName }] of instance.files.entries()) {
|
38 | if (fileName.match(constants.dtsDtsxOrDtsDtsxMapRegex) !== null &&
|
39 | fileName.match(constants.nodeModules) === null) {
|
40 | promises.push(updateFile(instance, key, fileName, loader, loaderIndex));
|
41 | }
|
42 | }
|
43 | }
|
44 |
|
45 | if (instance.solutionBuilderHost) {
|
46 | for (const { fileName, } of instance.solutionBuilderHost.watchedFiles.values()) {
|
47 | instance.solutionBuilderHost.updateSolutionBuilderInputFile(fileName);
|
48 | }
|
49 | instance.solutionBuilderHost.clearCache();
|
50 | }
|
51 | Promise.all(promises)
|
52 | .then(() => callback())
|
53 | .catch(err => callback(err));
|
54 | };
|
55 | }
|
56 | exports.makeWatchRun = makeWatchRun;
|
57 | function updateFile(instance, key, filePath, loader, loaderIndex) {
|
58 | return new Promise((resolve, reject) => {
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | if (loaderIndex + 1 < loader.loaders.length &&
|
64 | instance.rootFileNames.has(path.normalize(filePath))) {
|
65 | let request = `!!${path.resolve(__dirname, 'stringify-loader.js')}!`;
|
66 | for (let i = loaderIndex + 1; i < loader.loaders.length; ++i) {
|
67 | request += loader.loaders[i].request + '!';
|
68 | }
|
69 | request += filePath;
|
70 | loader.loadModule(request, (err, source) => {
|
71 | if (err) {
|
72 | reject(err);
|
73 | }
|
74 | else {
|
75 | const text = JSON.parse(source);
|
76 | servicesHost_1.updateFileWithText(instance, key, filePath, () => text);
|
77 | resolve();
|
78 | }
|
79 | });
|
80 | }
|
81 | else {
|
82 | servicesHost_1.updateFileWithText(instance, key, filePath, nFilePath => utils_1.fsReadFile(nFilePath) || '');
|
83 | resolve();
|
84 | }
|
85 | });
|
86 | }
|
87 |
|
\ | No newline at end of file |