@e-mc/watch 0.6.2 → 0.6.4
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/README.md +1 -1
- package/filegroup/index.js +2 -1
- package/index.js +18 -14
- package/package.json +5 -5
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/README.md
CHANGED
package/filegroup/index.js
CHANGED
|
@@ -95,11 +95,12 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
95
95
|
return this.sockets.find(item => item.socketId === socketId);
|
|
96
96
|
}
|
|
97
97
|
send(event, data) {
|
|
98
|
+
var _g;
|
|
98
99
|
const server = this.server;
|
|
99
100
|
let result = false;
|
|
100
101
|
if (server && (data.socketId = this.socketId)) {
|
|
101
102
|
data.event = event;
|
|
102
|
-
data.always
|
|
103
|
+
(_g = data.always) !== null && _g !== void 0 ? _g : (data.always = this.always);
|
|
103
104
|
const value = data.value;
|
|
104
105
|
if (value && (util.types.isAnyArrayBuffer(value) || util.types.isArrayBufferView(value))) {
|
|
105
106
|
try {
|
package/index.js
CHANGED
|
@@ -88,7 +88,7 @@ class Watch extends core_1.Client {
|
|
|
88
88
|
ca: ca && request_1.default.readCACert(ca, true) || undefined,
|
|
89
89
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
90
90
|
cert,
|
|
91
|
-
minVersion: version || config
|
|
91
|
+
minVersion: version || (config === null || config === void 0 ? void 0 : config.minVersion)
|
|
92
92
|
});
|
|
93
93
|
server.listen(port);
|
|
94
94
|
wss = new ws.Server({ server });
|
|
@@ -191,14 +191,15 @@ class Watch extends core_1.Client {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
start(assets, permission) {
|
|
194
|
-
var _k;
|
|
194
|
+
var _k, _l, _m;
|
|
195
|
+
var _o;
|
|
195
196
|
if (this.aborted) {
|
|
196
197
|
return;
|
|
197
198
|
}
|
|
198
199
|
if (permission) {
|
|
199
200
|
this.permission = permission;
|
|
200
201
|
}
|
|
201
|
-
const username = this.host
|
|
202
|
+
const username = (_k = this.host) === null || _k === void 0 ? void 0 : _k.username;
|
|
202
203
|
const destMap = Object.create(null);
|
|
203
204
|
for (const item of assets) {
|
|
204
205
|
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
@@ -206,7 +207,7 @@ class Watch extends core_1.Client {
|
|
|
206
207
|
}
|
|
207
208
|
const { bundleId, uri, localUri } = item;
|
|
208
209
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
209
|
-
(destMap[
|
|
210
|
+
(destMap[_o = ':' + bundleId] || (destMap[_o] = [])).push(item);
|
|
210
211
|
}
|
|
211
212
|
else if (uri && localUri) {
|
|
212
213
|
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
@@ -231,7 +232,7 @@ class Watch extends core_1.Client {
|
|
|
231
232
|
for (let i = 0, length = items.length; i < length; ++i) {
|
|
232
233
|
const watch = items[i].watch;
|
|
233
234
|
if ((0, types_1.isObject)(watch)) {
|
|
234
|
-
watch.assets
|
|
235
|
+
(_l = watch.assets) === null || _l === void 0 ? void 0 : _l.forEach(other => {
|
|
235
236
|
if (items.includes(other)) {
|
|
236
237
|
return;
|
|
237
238
|
}
|
|
@@ -271,7 +272,7 @@ class Watch extends core_1.Client {
|
|
|
271
272
|
return false;
|
|
272
273
|
};
|
|
273
274
|
let expires = 0, status = 0, wss = null, main, id, socketId, port, secure, hot, always, watched, message, settings;
|
|
274
|
-
if (watch === true && username && (settings = this.settings.users
|
|
275
|
+
if (watch === true && username && (settings = (_m = this.settings.users) === null || _m === void 0 ? void 0 : _m[username])) {
|
|
275
276
|
const { uri, localUri, mimeType } = item;
|
|
276
277
|
watch = false;
|
|
277
278
|
if (uri && !(watch = settings[uri])) {
|
|
@@ -338,6 +339,7 @@ class Watch extends core_1.Client {
|
|
|
338
339
|
}
|
|
339
340
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
340
341
|
const watching = (uri, esm) => {
|
|
342
|
+
var _k;
|
|
341
343
|
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
342
344
|
group.add(expires, socketId, id);
|
|
343
345
|
if (main) {
|
|
@@ -367,13 +369,14 @@ class Watch extends core_1.Client {
|
|
|
367
369
|
const timeout = { interval, retries: 0, aborted: false };
|
|
368
370
|
const target = { value: group, timeout, watcher: null };
|
|
369
371
|
const isMap = (value) => value ? value.size > 0 : false;
|
|
370
|
-
const checkAborted = (result, current) => result
|
|
372
|
+
const checkAborted = (result, current) => (result === null || result === void 0 ? void 0 : result.aborted) && current.abortable && current.abort();
|
|
371
373
|
const checkPreceding = (map) => {
|
|
374
|
+
var _k;
|
|
372
375
|
const data = map[uri];
|
|
373
376
|
if (!data) {
|
|
374
377
|
return;
|
|
375
378
|
}
|
|
376
|
-
const current = data.get(dest)
|
|
379
|
+
const current = (_k = data.get(dest)) === null || _k === void 0 ? void 0 : _k.value;
|
|
377
380
|
if (current && !current.expired) {
|
|
378
381
|
let reset;
|
|
379
382
|
if (id) {
|
|
@@ -438,7 +441,7 @@ class Watch extends core_1.Client {
|
|
|
438
441
|
return status;
|
|
439
442
|
}
|
|
440
443
|
const url = group.url || (group.url = new URL(uri));
|
|
441
|
-
const request = this.host
|
|
444
|
+
const request = ((_k = this.host) === null || _k === void 0 ? void 0 : _k.Request) || new request_1.default();
|
|
442
445
|
const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
|
|
443
446
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
444
447
|
(function recurse() {
|
|
@@ -458,7 +461,7 @@ class Watch extends core_1.Client {
|
|
|
458
461
|
const map = HTTP_MAP[uri];
|
|
459
462
|
const etag = res.headers.etag;
|
|
460
463
|
const lastModified = res.headers['last-modified'];
|
|
461
|
-
if (valid && map
|
|
464
|
+
if (valid && (map === null || map === void 0 ? void 0 : map.size) && (etag || lastModified)) {
|
|
462
465
|
for (const [destUrl, input] of map) {
|
|
463
466
|
const value = input.value;
|
|
464
467
|
if (value.paused) {
|
|
@@ -654,6 +657,7 @@ class Watch extends core_1.Client {
|
|
|
654
657
|
}
|
|
655
658
|
}
|
|
656
659
|
async modified(watch) {
|
|
660
|
+
var _k, _l, _m, _o;
|
|
657
661
|
this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
658
662
|
const { host, assets } = this;
|
|
659
663
|
let items, sanitize = false;
|
|
@@ -688,7 +692,7 @@ class Watch extends core_1.Client {
|
|
|
688
692
|
}
|
|
689
693
|
watch.captured = false;
|
|
690
694
|
try {
|
|
691
|
-
const manager = this.whenModified
|
|
695
|
+
const manager = (_k = this.whenModified) === null || _k === void 0 ? void 0 : _k.call(this, items, sanitize);
|
|
692
696
|
for (const callback of this.extensions) {
|
|
693
697
|
try {
|
|
694
698
|
const listener = callback(watch, items);
|
|
@@ -710,7 +714,7 @@ class Watch extends core_1.Client {
|
|
|
710
714
|
if (host && watch.document) {
|
|
711
715
|
for (const { instance } of host.Document) {
|
|
712
716
|
if (host.hasDocument(instance, watch.document)) {
|
|
713
|
-
const result = instance.watchInit
|
|
717
|
+
const result = (_l = instance.watchInit) === null || _l === void 0 ? void 0 : _l.call(instance, watch, items, sanitize);
|
|
714
718
|
if (result) {
|
|
715
719
|
if ((0, types_1.isArray)(result.using)) {
|
|
716
720
|
manager.using(...result.using);
|
|
@@ -722,7 +726,7 @@ class Watch extends core_1.Client {
|
|
|
722
726
|
}
|
|
723
727
|
}
|
|
724
728
|
}
|
|
725
|
-
const listener = instance.watchModified
|
|
729
|
+
const listener = (_m = instance.watchModified) === null || _m === void 0 ? void 0 : _m.call(instance, watch, items);
|
|
726
730
|
if (typeof listener === 'function') {
|
|
727
731
|
manager.on('end', listener);
|
|
728
732
|
}
|
|
@@ -732,7 +736,7 @@ class Watch extends core_1.Client {
|
|
|
732
736
|
return await manager.start();
|
|
733
737
|
}
|
|
734
738
|
catch (err) {
|
|
735
|
-
this.writeFail(["Unknown", watch.url
|
|
739
|
+
this.writeFail(["Unknown", ((_o = watch.url) === null || _o === void 0 ? void 0 : _o.pathname) || path.basename(watch.uri)], err);
|
|
736
740
|
}
|
|
737
741
|
}
|
|
738
742
|
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.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Watch constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.6.
|
|
24
|
-
"@e-mc/request": "0.6.
|
|
25
|
-
"@e-mc/types": "0.6.
|
|
23
|
+
"@e-mc/core": "0.6.4",
|
|
24
|
+
"@e-mc/request": "0.6.4",
|
|
25
|
+
"@e-mc/types": "0.6.4",
|
|
26
26
|
"picomatch": "^2.3.1",
|
|
27
|
-
"ws": "^8.
|
|
27
|
+
"ws": "^8.17.0"
|
|
28
28
|
}
|
|
29
29
|
}
|