@e-mc/watch 0.5.4 → 0.5.6
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/LICENSE +1 -1
- package/filegroup/index.js +2 -1
- package/index.js +17 -13
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/filegroup/index.js
CHANGED
|
@@ -89,11 +89,12 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
89
89
|
return this.sockets.find(item => item.socketId === socketId);
|
|
90
90
|
}
|
|
91
91
|
send(event, data) {
|
|
92
|
+
var _f;
|
|
92
93
|
const server = this.server;
|
|
93
94
|
let result = false;
|
|
94
95
|
if (server && (data.socketId = this.socketId)) {
|
|
95
96
|
data.event = event;
|
|
96
|
-
data.always
|
|
97
|
+
(_f = data.always) !== null && _f !== void 0 ? _f : (data.always = this.always);
|
|
97
98
|
const outgoing = JSON.stringify(data);
|
|
98
99
|
server.clients.forEach(client => {
|
|
99
100
|
if (FileGroup.checkTimeout(client)) {
|
package/index.js
CHANGED
|
@@ -62,7 +62,7 @@ class Watch extends core_1.Client {
|
|
|
62
62
|
ca: ca && request_1.default.readCACert(ca, true) || undefined,
|
|
63
63
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
64
64
|
cert,
|
|
65
|
-
minVersion: version || config
|
|
65
|
+
minVersion: version || (config === null || config === void 0 ? void 0 : config.minVersion)
|
|
66
66
|
});
|
|
67
67
|
server.listen(port);
|
|
68
68
|
wss = new ws.Server({ server });
|
|
@@ -176,7 +176,8 @@ class Watch extends core_1.Client {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
start(assets, permission) {
|
|
179
|
-
var _k;
|
|
179
|
+
var _k, _l;
|
|
180
|
+
var _m;
|
|
180
181
|
if (this.aborted) {
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
@@ -184,7 +185,7 @@ class Watch extends core_1.Client {
|
|
|
184
185
|
this.permission = permission;
|
|
185
186
|
}
|
|
186
187
|
const startTime = Date.now();
|
|
187
|
-
const username = this.host
|
|
188
|
+
const username = (_k = this.host) === null || _k === void 0 ? void 0 : _k.username;
|
|
188
189
|
const destMap = Object.create(null);
|
|
189
190
|
for (const item of assets) {
|
|
190
191
|
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
@@ -192,7 +193,7 @@ class Watch extends core_1.Client {
|
|
|
192
193
|
}
|
|
193
194
|
const { bundleId, uri, localUri } = item;
|
|
194
195
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
195
|
-
(destMap[
|
|
196
|
+
(destMap[_m = ':' + bundleId] || (destMap[_m] = [])).push(item);
|
|
196
197
|
}
|
|
197
198
|
else if (uri && localUri) {
|
|
198
199
|
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
@@ -255,7 +256,7 @@ class Watch extends core_1.Client {
|
|
|
255
256
|
return false;
|
|
256
257
|
};
|
|
257
258
|
let expires = 0, status = 0, wss, main, id, socketId, port, secure, hot, always, watched, message, settings;
|
|
258
|
-
if (watch === true && username && (settings = this.settings.users
|
|
259
|
+
if (watch === true && username && (settings = (_l = this.settings.users) === null || _l === void 0 ? void 0 : _l[username])) {
|
|
259
260
|
const { uri, localUri, mimeType } = item;
|
|
260
261
|
watch = false;
|
|
261
262
|
if (uri && !(watch = settings[uri])) {
|
|
@@ -315,6 +316,7 @@ class Watch extends core_1.Client {
|
|
|
315
316
|
}
|
|
316
317
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
317
318
|
const watching = (uri, esm) => {
|
|
319
|
+
var _k;
|
|
318
320
|
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
319
321
|
group.add(expires, socketId, id);
|
|
320
322
|
if (main) {
|
|
@@ -344,13 +346,14 @@ class Watch extends core_1.Client {
|
|
|
344
346
|
const timeout = { interval, retries: 0, aborted: false };
|
|
345
347
|
const target = { value: group, timeout, watcher: null };
|
|
346
348
|
const isMap = (value) => value ? value.size > 0 : false;
|
|
347
|
-
const checkAborted = (result, current) => result
|
|
349
|
+
const checkAborted = (result, current) => (result === null || result === void 0 ? void 0 : result.aborted) && current.abortable && current.abort();
|
|
348
350
|
const checkPreceding = (map) => {
|
|
351
|
+
var _k;
|
|
349
352
|
const data = map[uri];
|
|
350
353
|
if (!data) {
|
|
351
354
|
return;
|
|
352
355
|
}
|
|
353
|
-
const current = data.get(dest)
|
|
356
|
+
const current = (_k = data.get(dest)) === null || _k === void 0 ? void 0 : _k.value;
|
|
354
357
|
if (current && !current.expired) {
|
|
355
358
|
let reset;
|
|
356
359
|
if (id) {
|
|
@@ -415,7 +418,7 @@ class Watch extends core_1.Client {
|
|
|
415
418
|
return status;
|
|
416
419
|
}
|
|
417
420
|
const url = group.url || (group.url = new URL(uri));
|
|
418
|
-
const request = this.host
|
|
421
|
+
const request = ((_k = this.host) === null || _k === void 0 ? void 0 : _k.Request) || new request_1.default();
|
|
419
422
|
const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
|
|
420
423
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
421
424
|
(function recurse() {
|
|
@@ -435,7 +438,7 @@ class Watch extends core_1.Client {
|
|
|
435
438
|
const map = HTTP_MAP[uri];
|
|
436
439
|
const etag = res.headers.etag;
|
|
437
440
|
const lastModified = res.headers['last-modified'];
|
|
438
|
-
if (valid && map
|
|
441
|
+
if (valid && (map === null || map === void 0 ? void 0 : map.size) && (etag || lastModified)) {
|
|
439
442
|
for (const [destUrl, input] of map) {
|
|
440
443
|
const value = input.value;
|
|
441
444
|
if (value.paused) {
|
|
@@ -628,6 +631,7 @@ class Watch extends core_1.Client {
|
|
|
628
631
|
}
|
|
629
632
|
}
|
|
630
633
|
async modified(watch) {
|
|
634
|
+
var _k, _l, _m, _o;
|
|
631
635
|
this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
632
636
|
const { host, assets } = this;
|
|
633
637
|
let items, sanitize = false;
|
|
@@ -662,7 +666,7 @@ class Watch extends core_1.Client {
|
|
|
662
666
|
}
|
|
663
667
|
watch.captured = false;
|
|
664
668
|
try {
|
|
665
|
-
const manager = this.whenModified
|
|
669
|
+
const manager = (_k = this.whenModified) === null || _k === void 0 ? void 0 : _k.call(this, items, sanitize);
|
|
666
670
|
for (const callback of this.extensions) {
|
|
667
671
|
try {
|
|
668
672
|
const listener = callback(watch, items);
|
|
@@ -682,7 +686,7 @@ class Watch extends core_1.Client {
|
|
|
682
686
|
if (host && watch.document) {
|
|
683
687
|
for (const { instance } of host.Document) {
|
|
684
688
|
if (host.hasDocument(instance, watch.document)) {
|
|
685
|
-
const result = instance.watchInit
|
|
689
|
+
const result = (_l = instance.watchInit) === null || _l === void 0 ? void 0 : _l.call(instance, watch, items, sanitize);
|
|
686
690
|
if (result) {
|
|
687
691
|
if ((0, types_1.isArray)(result.using)) {
|
|
688
692
|
manager.using(...result.using);
|
|
@@ -694,7 +698,7 @@ class Watch extends core_1.Client {
|
|
|
694
698
|
}
|
|
695
699
|
}
|
|
696
700
|
}
|
|
697
|
-
const listener = instance.watchModified
|
|
701
|
+
const listener = (_m = instance.watchModified) === null || _m === void 0 ? void 0 : _m.call(instance, watch, items);
|
|
698
702
|
if (typeof listener === 'function') {
|
|
699
703
|
manager.on('end', listener);
|
|
700
704
|
}
|
|
@@ -705,7 +709,7 @@ class Watch extends core_1.Client {
|
|
|
705
709
|
}
|
|
706
710
|
}
|
|
707
711
|
catch (err) {
|
|
708
|
-
this.writeFail(["Unknown", watch.url
|
|
712
|
+
this.writeFail(["Unknown", ((_o = watch.url) === null || _o === void 0 ? void 0 : _o.pathname) || path.basename(watch.uri)], err);
|
|
709
713
|
}
|
|
710
714
|
}
|
|
711
715
|
configureServer({ ca, key, cert, passphrase, version, config }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/watch",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
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": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.5.
|
|
24
|
-
"@e-mc/request": "0.5.
|
|
25
|
-
"@e-mc/types": "0.5.
|
|
23
|
+
"@e-mc/core": "0.5.6",
|
|
24
|
+
"@e-mc/request": "0.5.6",
|
|
25
|
+
"@e-mc/types": "0.5.6",
|
|
26
26
|
"picomatch": "^2.3.1",
|
|
27
27
|
"ws": "^8.16.0"
|
|
28
28
|
}
|