@e-mc/watch 0.9.9 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/filegroup/index.js +1 -2
- package/index.js +100 -76
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.10.1/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IFileManager, ModuleConstructor } from "./index";
|
|
@@ -73,6 +73,7 @@ interface WatchModule {
|
|
|
73
73
|
key?: string;
|
|
74
74
|
cert?: string;
|
|
75
75
|
passphrase?: string;
|
|
76
|
+
ciphers?: string;
|
|
76
77
|
version?: SecureVersion;
|
|
77
78
|
};
|
|
78
79
|
settings?: {
|
|
@@ -105,11 +106,11 @@ instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
|
|
|
105
106
|
|
|
106
107
|
## References
|
|
107
108
|
|
|
108
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
109
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
110
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
111
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
112
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
109
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/asset.d.ts
|
|
110
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/core.d.ts
|
|
111
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/filemanager.d.ts
|
|
112
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/settings.d.ts
|
|
113
|
+
- https://www.unpkg.com/@e-mc/types@0.10.1/lib/watch.d.ts
|
|
113
114
|
|
|
114
115
|
* https://www.npmjs.com/package/@types/ws
|
|
115
116
|
|
package/filegroup/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var _a, _b, _c, _d, _e, _f;
|
|
3
3
|
const util = require("util");
|
|
4
4
|
const ws = require("ws");
|
|
5
|
-
const types_1 = require("@e-mc/types");
|
|
6
5
|
const core_1 = require("@e-mc/core");
|
|
6
|
+
const types_1 = require("@e-mc/types");
|
|
7
7
|
const kServer = Symbol('server');
|
|
8
8
|
const kStarted = Symbol('started');
|
|
9
9
|
const kPaused = Symbol('paused');
|
|
@@ -207,5 +207,4 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
207
207
|
_a = kServer, _b = kStarted, _c = kPaused, _d = kEtag, _e = kLastModified, _f = kSockets;
|
|
208
208
|
FileGroup.CONNECTION_TIMEOUT = 10 * 60000;
|
|
209
209
|
FileGroup.CLIENT_SESSION = new Map();
|
|
210
|
-
|
|
211
210
|
module.exports = FileGroup;
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const https = require("https");
|
|
6
6
|
const ws = require("ws");
|
|
7
7
|
const pm = require("picomatch");
|
|
8
|
-
const util_1 = require("@e-mc/request/util");
|
|
9
|
-
const types_1 = require("@e-mc/types");
|
|
10
8
|
const core_1 = require("@e-mc/core");
|
|
11
9
|
const request_1 = require("@e-mc/request");
|
|
10
|
+
const types_1 = require("@e-mc/types");
|
|
11
|
+
const util_1 = require("@e-mc/request/util");
|
|
12
12
|
const filegroup_1 = require("@e-mc/watch/filegroup");
|
|
13
13
|
const kInterval = Symbol('interval');
|
|
14
14
|
const kPort = Symbol('port');
|
|
@@ -19,7 +19,7 @@ const kTlsCert = Symbol('tlsCert');
|
|
|
19
19
|
const kTlsVersion = Symbol('tlsVersion');
|
|
20
20
|
const kTlsPassphrase = Symbol('tlsPassphrase');
|
|
21
21
|
const kTlsConfig = Symbol('tlsConfig');
|
|
22
|
-
const
|
|
22
|
+
const kCiphers = Symbol('ciphers');
|
|
23
23
|
const HTTP_MAP = new Map();
|
|
24
24
|
const DISK_MAP = new Map();
|
|
25
25
|
const PORT_MAP = new Map();
|
|
@@ -65,10 +65,41 @@ function closeFileGroup(map) {
|
|
|
65
65
|
}
|
|
66
66
|
function closeServer(map) {
|
|
67
67
|
for (const [port, value] of map) {
|
|
68
|
-
value.close(err =>
|
|
68
|
+
value.close(err => {
|
|
69
|
+
if (err) {
|
|
70
|
+
Watch.writeFail([`Unable to shutdown ${map === PORT_MAP ? 'WS' : 'WSS'} server`, 'port: ' + port], err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
69
73
|
}
|
|
70
74
|
map.clear();
|
|
71
75
|
}
|
|
76
|
+
function wasAborted(result, current) {
|
|
77
|
+
if (result?.aborted && current.abortable) {
|
|
78
|
+
current.abort();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function fatalError(instance, map, target, err) {
|
|
82
|
+
const uri = target.value.uri;
|
|
83
|
+
map.delete(uri);
|
|
84
|
+
abortTimeout(target);
|
|
85
|
+
instance.writeFail(["Unable to watch file", uri], err, 16);
|
|
86
|
+
}
|
|
87
|
+
function getErrorMessage(item, status = 0) {
|
|
88
|
+
switch (status) {
|
|
89
|
+
case 1:
|
|
90
|
+
if ((0, types_1.existsFlag)(item.flags)) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
return "ETag not supported";
|
|
94
|
+
case 2:
|
|
95
|
+
return "Not permitted to read file";
|
|
96
|
+
case 3:
|
|
97
|
+
return "Resource already in use";
|
|
98
|
+
default:
|
|
99
|
+
return "Unknown";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const isMap = (value) => value ? value.size > 0 : false;
|
|
72
103
|
const formatDate = (value) => new Date(value).toLocaleString().replace(/\/20\d+, /, '@').replace(/:\d+ (AM|PM)$/, (...match) => match[1]);
|
|
73
104
|
class Watch extends core_1.Client {
|
|
74
105
|
constructor() {
|
|
@@ -85,8 +116,9 @@ class Watch extends core_1.Client {
|
|
|
85
116
|
this[_e] = '';
|
|
86
117
|
this[_f] = '';
|
|
87
118
|
this[_g] = '';
|
|
88
|
-
this[_h] =
|
|
119
|
+
this[_h] = '';
|
|
89
120
|
this[_j] = undefined;
|
|
121
|
+
this[_k] = undefined;
|
|
90
122
|
}
|
|
91
123
|
static createServer(port, secure, active) {
|
|
92
124
|
if (typeof secure === 'boolean') {
|
|
@@ -99,7 +131,7 @@ class Watch extends core_1.Client {
|
|
|
99
131
|
if (wss = SECURE_MAP.get(port.toString())) {
|
|
100
132
|
return wss;
|
|
101
133
|
}
|
|
102
|
-
const { ca, passphrase, version, config } = secure;
|
|
134
|
+
const { ca, passphrase, ciphers, version, config } = secure;
|
|
103
135
|
let { key, cert } = secure;
|
|
104
136
|
if (key && cert && (key = request_1.readTLSKey(key, true)) && (cert = request_1.readTLSKey(cert, true))) {
|
|
105
137
|
const server = https.createServer({
|
|
@@ -107,6 +139,7 @@ class Watch extends core_1.Client {
|
|
|
107
139
|
ca: ca && request_1.readCACert(ca, true) || undefined,
|
|
108
140
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
109
141
|
cert,
|
|
142
|
+
ciphers,
|
|
110
143
|
minVersion: version || config?.minVersion
|
|
111
144
|
});
|
|
112
145
|
server.listen(port);
|
|
@@ -117,7 +150,7 @@ class Watch extends core_1.Client {
|
|
|
117
150
|
}
|
|
118
151
|
}
|
|
119
152
|
else {
|
|
120
|
-
this.writeFail(
|
|
153
|
+
this.writeFail("TLS/SSL key and cert not found", (0, types_1.errorMessage)('ws', "Missing TLS/SSL credentials"));
|
|
121
154
|
}
|
|
122
155
|
}
|
|
123
156
|
else if (wss = PORT_MAP.get(port.toString())) {
|
|
@@ -144,14 +177,22 @@ class Watch extends core_1.Client {
|
|
|
144
177
|
socket.on('close', function () {
|
|
145
178
|
filegroup_1.CLIENT_SESSION.delete(this);
|
|
146
179
|
});
|
|
147
|
-
|
|
180
|
+
for (const client of this.clients) {
|
|
181
|
+
filegroup_1.checkTimeout(client);
|
|
182
|
+
}
|
|
148
183
|
});
|
|
149
184
|
wss.on('error', function (err) {
|
|
150
185
|
const data = JSON.stringify({ event: types_1.WATCH_EVENT.ERROR, errors: [err.message] });
|
|
151
|
-
|
|
186
|
+
for (const client of this.clients) {
|
|
187
|
+
if (filegroup_1.checkTimeout(client)) {
|
|
188
|
+
client.send(data);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
152
191
|
});
|
|
153
192
|
wss.on('close', function () {
|
|
154
|
-
|
|
193
|
+
for (const client of this.clients) {
|
|
194
|
+
client.terminate();
|
|
195
|
+
}
|
|
155
196
|
});
|
|
156
197
|
return wss;
|
|
157
198
|
}
|
|
@@ -184,7 +225,7 @@ class Watch extends core_1.Client {
|
|
|
184
225
|
return super.init(config);
|
|
185
226
|
}
|
|
186
227
|
start(assets, permission) {
|
|
187
|
-
var
|
|
228
|
+
var _l;
|
|
188
229
|
if (this.aborted) {
|
|
189
230
|
return;
|
|
190
231
|
}
|
|
@@ -197,7 +238,7 @@ class Watch extends core_1.Client {
|
|
|
197
238
|
if (!(0, types_1.ignoreFlag)(item.flags)) {
|
|
198
239
|
const { bundleId, uri, localUri } = item;
|
|
199
240
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
200
|
-
(destMap[
|
|
241
|
+
(destMap[_l = ':' + bundleId] || (destMap[_l] = [])).push(item);
|
|
201
242
|
}
|
|
202
243
|
else if (uri && localUri) {
|
|
203
244
|
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
@@ -247,21 +288,6 @@ class Watch extends core_1.Client {
|
|
|
247
288
|
if (!watch) {
|
|
248
289
|
continue;
|
|
249
290
|
}
|
|
250
|
-
const fatalError = (map, target, err) => {
|
|
251
|
-
const uri = target.value.uri;
|
|
252
|
-
map.delete(uri);
|
|
253
|
-
abortTimeout(target);
|
|
254
|
-
this.writeFail(["Unable to watch file", uri], err, 16);
|
|
255
|
-
};
|
|
256
|
-
const watchExpired = (map, target, message = 'Expired') => {
|
|
257
|
-
this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
|
|
258
|
-
const data = map.get(target.uri);
|
|
259
|
-
if (!data?.size) {
|
|
260
|
-
map.delete(target.uri);
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
return false;
|
|
264
|
-
};
|
|
265
291
|
let expires = 0, status = 0, wss = null, main, id, socketId, port, secure, hot, always, watched, message;
|
|
266
292
|
if (watch === true && settings) {
|
|
267
293
|
const { uri, localUri, mimeType } = item;
|
|
@@ -275,7 +301,7 @@ class Watch extends core_1.Client {
|
|
|
275
301
|
}
|
|
276
302
|
if (!watch && localUri && !(watch = settings[localUri])) {
|
|
277
303
|
for (const pattern in settings) {
|
|
278
|
-
if ((0, types_1.hasGlob)(pattern) && pm.isMatch(localUri, pattern, { nocase: PLATFORM_WIN32 }) && (watch = settings[pattern])) {
|
|
304
|
+
if ((0, types_1.hasGlob)(pattern) && pm.isMatch(localUri, pattern, { nocase: core_1.Client.PLATFORM_WIN32 }) && (watch = settings[pattern])) {
|
|
279
305
|
break;
|
|
280
306
|
}
|
|
281
307
|
}
|
|
@@ -310,7 +336,7 @@ class Watch extends core_1.Client {
|
|
|
310
336
|
const key = this[kTlsKey];
|
|
311
337
|
const cert = this[kTlsCert];
|
|
312
338
|
if (key && cert) {
|
|
313
|
-
wss = Watch.createServer(port || (port = this.securePort), { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], config: this[kTlsConfig] });
|
|
339
|
+
wss = Watch.createServer(port || (port = this.securePort), { ca: this[kCa], key, cert, passphrase: this[kTlsPassphrase], version: this[kTlsVersion], ciphers: this[kCiphers], config: this[kTlsConfig] });
|
|
314
340
|
}
|
|
315
341
|
secure = true;
|
|
316
342
|
}
|
|
@@ -318,7 +344,7 @@ class Watch extends core_1.Client {
|
|
|
318
344
|
wss = Watch.createServer(port || (port = this.port));
|
|
319
345
|
}
|
|
320
346
|
if (!wss) {
|
|
321
|
-
this.writeFail(
|
|
347
|
+
this.writeFail("Unable to create WebSocket server", (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
|
|
322
348
|
socketId = undefined;
|
|
323
349
|
port = undefined;
|
|
324
350
|
secure = undefined;
|
|
@@ -335,7 +361,7 @@ class Watch extends core_1.Client {
|
|
|
335
361
|
if (main) {
|
|
336
362
|
group.main = main;
|
|
337
363
|
}
|
|
338
|
-
else if (related.length) {
|
|
364
|
+
else if (related.length > 0) {
|
|
339
365
|
group.related = related;
|
|
340
366
|
}
|
|
341
367
|
if (bundleMain) {
|
|
@@ -358,8 +384,6 @@ class Watch extends core_1.Client {
|
|
|
358
384
|
}
|
|
359
385
|
const timeout = { interval, retries: 0, aborted: false };
|
|
360
386
|
const target = { value: group, timeout, watcher: null };
|
|
361
|
-
const isMap = (value) => value ? value.size > 0 : false;
|
|
362
|
-
const wasAborted = (result, current) => result?.aborted && current.abortable && current.abort();
|
|
363
387
|
const checkPreceding = (map) => {
|
|
364
388
|
const data = map.get(uri);
|
|
365
389
|
if (!data) {
|
|
@@ -402,7 +426,7 @@ class Watch extends core_1.Client {
|
|
|
402
426
|
}
|
|
403
427
|
wss.close();
|
|
404
428
|
}
|
|
405
|
-
message =
|
|
429
|
+
message = `Destination already watched (${(current.secure ? 'wss' : 'ws') + '://hostname:' + current.port})`;
|
|
406
430
|
return 3;
|
|
407
431
|
}
|
|
408
432
|
}
|
|
@@ -435,7 +459,7 @@ class Watch extends core_1.Client {
|
|
|
435
459
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
436
460
|
(function recurse() {
|
|
437
461
|
let client = null;
|
|
438
|
-
new Promise((resolve, reject) => {
|
|
462
|
+
void new Promise((resolve, reject) => {
|
|
439
463
|
client = request.open(uri, opts)
|
|
440
464
|
.on('response', res => {
|
|
441
465
|
if (group.aborted) {
|
|
@@ -466,7 +490,9 @@ class Watch extends core_1.Client {
|
|
|
466
490
|
if (etag !== value.etag) {
|
|
467
491
|
value.etag = etag;
|
|
468
492
|
if (value.started) {
|
|
469
|
-
this.modified(value).then(result =>
|
|
493
|
+
void this.modified(value).then(result => {
|
|
494
|
+
wasAborted(result, value);
|
|
495
|
+
});
|
|
470
496
|
}
|
|
471
497
|
}
|
|
472
498
|
}
|
|
@@ -475,14 +501,16 @@ class Watch extends core_1.Client {
|
|
|
475
501
|
if (lastModified !== value.lastModified) {
|
|
476
502
|
value.lastModified = lastModified;
|
|
477
503
|
if (value.started) {
|
|
478
|
-
this.modified(value).then(result =>
|
|
504
|
+
void this.modified(value).then(result => {
|
|
505
|
+
wasAborted(result, value);
|
|
506
|
+
});
|
|
479
507
|
}
|
|
480
508
|
}
|
|
481
509
|
}
|
|
482
510
|
}
|
|
483
511
|
if (aborted) {
|
|
484
512
|
map.delete(destUrl);
|
|
485
|
-
if (watchExpired(HTTP_MAP, value)) {
|
|
513
|
+
if (this.watchExpired(HTTP_MAP, value)) {
|
|
486
514
|
abortTimeout(target);
|
|
487
515
|
}
|
|
488
516
|
}
|
|
@@ -490,10 +518,10 @@ class Watch extends core_1.Client {
|
|
|
490
518
|
}
|
|
491
519
|
else {
|
|
492
520
|
if (isMap(map)) {
|
|
493
|
-
reject(valid ? (0, types_1.errorValue)("ETag not supported", uri) : (0, types_1.errorMessage)(statusCode,
|
|
521
|
+
reject(valid ? (0, types_1.errorValue)("ETag not supported", uri) : (0, types_1.errorMessage)(statusCode, "Invalid HTTP request", uri));
|
|
494
522
|
return;
|
|
495
523
|
}
|
|
496
|
-
watchExpired(HTTP_MAP, group);
|
|
524
|
+
this.watchExpired(HTTP_MAP, group);
|
|
497
525
|
abortTimeout(target);
|
|
498
526
|
}
|
|
499
527
|
client?.destroy();
|
|
@@ -508,7 +536,7 @@ class Watch extends core_1.Client {
|
|
|
508
536
|
})
|
|
509
537
|
.on('timeout', () => {
|
|
510
538
|
if (!timeout.aborted && ++timeout.retries > 10) {
|
|
511
|
-
reject((0, types_1.errorMessage)(408,
|
|
539
|
+
reject((0, types_1.errorMessage)(408, "HTTP request timeout"));
|
|
512
540
|
return;
|
|
513
541
|
}
|
|
514
542
|
resolve();
|
|
@@ -530,7 +558,7 @@ class Watch extends core_1.Client {
|
|
|
530
558
|
}
|
|
531
559
|
})
|
|
532
560
|
.catch((err) => {
|
|
533
|
-
fatalError(HTTP_MAP, target, err);
|
|
561
|
+
fatalError(this, HTTP_MAP, target, err);
|
|
534
562
|
client?.destroy();
|
|
535
563
|
});
|
|
536
564
|
}).call(this);
|
|
@@ -543,7 +571,7 @@ class Watch extends core_1.Client {
|
|
|
543
571
|
let ptime = 0;
|
|
544
572
|
target.watcher = fs.watch(uri, (event, filename) => {
|
|
545
573
|
if (this.aborted || group.aborted) {
|
|
546
|
-
fatalError(DISK_MAP, target, (0, types_1.createAbortError)());
|
|
574
|
+
fatalError(this, DISK_MAP, target, (0, types_1.createAbortError)());
|
|
547
575
|
return;
|
|
548
576
|
}
|
|
549
577
|
const map = DISK_MAP.get(uri);
|
|
@@ -557,7 +585,7 @@ class Watch extends core_1.Client {
|
|
|
557
585
|
const value = input.value;
|
|
558
586
|
if (value.expired) {
|
|
559
587
|
map.delete(key);
|
|
560
|
-
if (watchExpired(DISK_MAP, value)) {
|
|
588
|
+
if (this.watchExpired(DISK_MAP, value)) {
|
|
561
589
|
abortTimeout(target);
|
|
562
590
|
}
|
|
563
591
|
}
|
|
@@ -568,7 +596,9 @@ class Watch extends core_1.Client {
|
|
|
568
596
|
}
|
|
569
597
|
}
|
|
570
598
|
else if (value.started) {
|
|
571
|
-
this.modified(value).then(result =>
|
|
599
|
+
void this.modified(value).then(result => {
|
|
600
|
+
wasAborted(result, value);
|
|
601
|
+
});
|
|
572
602
|
}
|
|
573
603
|
}
|
|
574
604
|
ptime = mtime + types_1.THRESHOLD.WATCH_CHANGE;
|
|
@@ -581,7 +611,7 @@ class Watch extends core_1.Client {
|
|
|
581
611
|
}
|
|
582
612
|
case 'rename':
|
|
583
613
|
map?.clear();
|
|
584
|
-
watchExpired(DISK_MAP, group, event === 'rename' ? 'File renamed: ' + filename : undefined);
|
|
614
|
+
this.watchExpired(DISK_MAP, group, event === 'rename' ? 'File renamed: ' + filename : undefined);
|
|
585
615
|
abortTimeout(target);
|
|
586
616
|
break;
|
|
587
617
|
}
|
|
@@ -610,36 +640,17 @@ class Watch extends core_1.Client {
|
|
|
610
640
|
else {
|
|
611
641
|
continue;
|
|
612
642
|
}
|
|
613
|
-
if (status
|
|
614
|
-
if (!message) {
|
|
615
|
-
switch (status) {
|
|
616
|
-
case 1:
|
|
617
|
-
if ((0, types_1.existsFlag)(item.flags)) {
|
|
618
|
-
continue;
|
|
619
|
-
}
|
|
620
|
-
message = 'ETag unavailable';
|
|
621
|
-
break;
|
|
622
|
-
case 2:
|
|
623
|
-
message = 'No read permission';
|
|
624
|
-
break;
|
|
625
|
-
case 3:
|
|
626
|
-
message = 'Server already in use';
|
|
627
|
-
break;
|
|
628
|
-
default:
|
|
629
|
-
message = "Unknown";
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
643
|
+
if (status === 0) {
|
|
636
644
|
this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
|
|
637
645
|
}
|
|
646
|
+
else if (message || (message = getErrorMessage(item, status))) {
|
|
647
|
+
this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
|
|
648
|
+
}
|
|
638
649
|
}
|
|
639
650
|
}
|
|
640
651
|
}
|
|
641
652
|
async modified(watch) {
|
|
642
|
-
this.formatMessage(16, 'WATCH',
|
|
653
|
+
this.formatMessage(16, 'WATCH', "File modified", watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
643
654
|
const { host, assets } = this;
|
|
644
655
|
let items, sanitize = false;
|
|
645
656
|
if (watch.main) {
|
|
@@ -648,7 +659,7 @@ class Watch extends core_1.Client {
|
|
|
648
659
|
}
|
|
649
660
|
else {
|
|
650
661
|
items = [];
|
|
651
|
-
if (assets.length) {
|
|
662
|
+
if (assets.length > 0) {
|
|
652
663
|
for (const item of watch.assets) {
|
|
653
664
|
const asset = assets.find(other => item.id && item.id === other.id);
|
|
654
665
|
if (!asset) {
|
|
@@ -669,7 +680,9 @@ class Watch extends core_1.Client {
|
|
|
669
680
|
}
|
|
670
681
|
}
|
|
671
682
|
if (!sanitize) {
|
|
672
|
-
|
|
683
|
+
for (const item of items) {
|
|
684
|
+
item.flags |= 2;
|
|
685
|
+
}
|
|
673
686
|
}
|
|
674
687
|
watch.captured = false;
|
|
675
688
|
try {
|
|
@@ -719,7 +732,7 @@ class Watch extends core_1.Client {
|
|
|
719
732
|
this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
|
|
720
733
|
}
|
|
721
734
|
}
|
|
722
|
-
configureServer({ ca, key, cert, passphrase, version, config }) {
|
|
735
|
+
configureServer({ ca, key, cert, passphrase, version, ciphers, config }) {
|
|
723
736
|
if (!(0, types_1.isString)(key) || !(0, types_1.isString)(cert)) {
|
|
724
737
|
return false;
|
|
725
738
|
}
|
|
@@ -735,6 +748,9 @@ class Watch extends core_1.Client {
|
|
|
735
748
|
if ((0, types_1.isString)(passphrase)) {
|
|
736
749
|
this[kTlsPassphrase] = passphrase;
|
|
737
750
|
}
|
|
751
|
+
if ((0, types_1.isString)(ciphers)) {
|
|
752
|
+
this[kCiphers] = ciphers;
|
|
753
|
+
}
|
|
738
754
|
if (!(0, types_1.isPlainObject)(config)) {
|
|
739
755
|
config = undefined;
|
|
740
756
|
}
|
|
@@ -777,6 +793,15 @@ class Watch extends core_1.Client {
|
|
|
777
793
|
willAbort(value) {
|
|
778
794
|
return this.host ? this.host.willAbort(value) : value === "(watch)";
|
|
779
795
|
}
|
|
796
|
+
watchExpired(map, target, message = "Expired") {
|
|
797
|
+
this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
|
|
798
|
+
const data = map.get(target.uri);
|
|
799
|
+
if (!data?.size) {
|
|
800
|
+
map.delete(target.uri);
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
780
805
|
set host(value) {
|
|
781
806
|
super.host = value;
|
|
782
807
|
if ((0, types_1.isArray)(value?.assets)) {
|
|
@@ -822,7 +847,6 @@ class Watch extends core_1.Client {
|
|
|
822
847
|
return this[kSecurePort];
|
|
823
848
|
}
|
|
824
849
|
}
|
|
825
|
-
_a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e =
|
|
850
|
+
_a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kCiphers, _f = kTlsKey, _g = kTlsCert, _h = kTlsPassphrase, _j = kTlsVersion, _k = kTlsConfig;
|
|
826
851
|
Watch.PROCESS_TIMEOUT = 5 * 1000;
|
|
827
|
-
|
|
828
852
|
module.exports = Watch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/watch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Watch constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.
|
|
24
|
-
"@e-mc/request": "0.
|
|
25
|
-
"@e-mc/types": "0.
|
|
23
|
+
"@e-mc/core": "0.10.1",
|
|
24
|
+
"@e-mc/request": "0.10.1",
|
|
25
|
+
"@e-mc/types": "0.10.1",
|
|
26
26
|
"picomatch": "^4.0.2",
|
|
27
27
|
"ws": "^8.18.0"
|
|
28
28
|
}
|