@e-mc/watch 0.7.2 → 0.7.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 +4 -8
- package/README.md +1 -1
- package/filegroup/index.js +2 -1
- package/index.js +20 -16
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Sukina
|
|
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
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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
|
@@ -91,7 +91,7 @@ class Watch extends core_1.Client {
|
|
|
91
91
|
ca: ca && request_1.default.readCACert(ca, true) || undefined,
|
|
92
92
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
93
93
|
cert,
|
|
94
|
-
minVersion: version || config
|
|
94
|
+
minVersion: version || (config === null || config === void 0 ? void 0 : config.minVersion)
|
|
95
95
|
});
|
|
96
96
|
server.listen(port);
|
|
97
97
|
wss = new ws.Server({ server });
|
|
@@ -190,14 +190,15 @@ class Watch extends core_1.Client {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
start(assets, permission) {
|
|
193
|
-
var _k;
|
|
193
|
+
var _k, _l, _m;
|
|
194
|
+
var _o;
|
|
194
195
|
if (this.aborted) {
|
|
195
196
|
return;
|
|
196
197
|
}
|
|
197
198
|
if (permission) {
|
|
198
199
|
this.permission = permission;
|
|
199
200
|
}
|
|
200
|
-
const username = this.host
|
|
201
|
+
const username = (_k = this.host) === null || _k === void 0 ? void 0 : _k.username;
|
|
201
202
|
const destMap = Object.create(null);
|
|
202
203
|
for (const item of assets) {
|
|
203
204
|
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
@@ -205,7 +206,7 @@ class Watch extends core_1.Client {
|
|
|
205
206
|
}
|
|
206
207
|
const { bundleId, uri, localUri } = item;
|
|
207
208
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
208
|
-
(destMap[
|
|
209
|
+
(destMap[_o = ':' + bundleId] || (destMap[_o] = [])).push(item);
|
|
209
210
|
}
|
|
210
211
|
else if (uri && localUri) {
|
|
211
212
|
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
@@ -230,7 +231,7 @@ class Watch extends core_1.Client {
|
|
|
230
231
|
for (let i = 0, length = items.length; i < length; ++i) {
|
|
231
232
|
const watch = items[i].watch;
|
|
232
233
|
if ((0, types_1.isObject)(watch)) {
|
|
233
|
-
watch.assets
|
|
234
|
+
(_l = watch.assets) === null || _l === void 0 ? void 0 : _l.forEach(other => {
|
|
234
235
|
if (items.includes(other)) {
|
|
235
236
|
return;
|
|
236
237
|
}
|
|
@@ -263,14 +264,14 @@ class Watch extends core_1.Client {
|
|
|
263
264
|
const watchExpired = (map, target, message = 'Expired') => {
|
|
264
265
|
this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
|
|
265
266
|
const data = map.get(target.uri);
|
|
266
|
-
if (!data
|
|
267
|
+
if (!(data === null || data === void 0 ? void 0 : data.size)) {
|
|
267
268
|
map.delete(target.uri);
|
|
268
269
|
return true;
|
|
269
270
|
}
|
|
270
271
|
return false;
|
|
271
272
|
};
|
|
272
273
|
let expires = 0, status = 0, wss = null, main, id, socketId, port, secure, hot, always, watched, message, settings;
|
|
273
|
-
if (watch === true && username && (settings = this.settings.users
|
|
274
|
+
if (watch === true && username && (settings = (_m = this.settings.users) === null || _m === void 0 ? void 0 : _m[username])) {
|
|
274
275
|
const { uri, localUri, mimeType } = item;
|
|
275
276
|
watch = false;
|
|
276
277
|
if (uri && !(watch = settings[uri])) {
|
|
@@ -337,6 +338,7 @@ class Watch extends core_1.Client {
|
|
|
337
338
|
}
|
|
338
339
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
339
340
|
const watching = (uri, esm) => {
|
|
341
|
+
var _k;
|
|
340
342
|
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
341
343
|
group.add(expires, socketId, id);
|
|
342
344
|
if (main) {
|
|
@@ -366,13 +368,14 @@ class Watch extends core_1.Client {
|
|
|
366
368
|
const timeout = { interval, retries: 0, aborted: false };
|
|
367
369
|
const target = { value: group, timeout, watcher: null };
|
|
368
370
|
const isMap = (value) => value ? value.size > 0 : false;
|
|
369
|
-
const checkAborted = (result, current) => result
|
|
371
|
+
const checkAborted = (result, current) => (result === null || result === void 0 ? void 0 : result.aborted) && current.abortable && current.abort();
|
|
370
372
|
const checkPreceding = (map) => {
|
|
373
|
+
var _k;
|
|
371
374
|
const data = map.get(uri);
|
|
372
375
|
if (!data) {
|
|
373
376
|
return;
|
|
374
377
|
}
|
|
375
|
-
const current = data.get(dest)
|
|
378
|
+
const current = (_k = data.get(dest)) === null || _k === void 0 ? void 0 : _k.value;
|
|
376
379
|
if (current && !current.expired) {
|
|
377
380
|
let reset;
|
|
378
381
|
if (id) {
|
|
@@ -437,7 +440,7 @@ class Watch extends core_1.Client {
|
|
|
437
440
|
return status;
|
|
438
441
|
}
|
|
439
442
|
const url = group.url || (group.url = new URL(uri));
|
|
440
|
-
const request = this.host
|
|
443
|
+
const request = ((_k = this.host) === null || _k === void 0 ? void 0 : _k.Request) || new request_1.default();
|
|
441
444
|
const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
|
|
442
445
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
443
446
|
(function recurse() {
|
|
@@ -457,7 +460,7 @@ class Watch extends core_1.Client {
|
|
|
457
460
|
const map = HTTP_MAP.get(uri);
|
|
458
461
|
const etag = res.headers.etag;
|
|
459
462
|
const lastModified = res.headers['last-modified'];
|
|
460
|
-
if (valid && map
|
|
463
|
+
if (valid && (map === null || map === void 0 ? void 0 : map.size) && (etag || lastModified)) {
|
|
461
464
|
for (const [destUrl, input] of map) {
|
|
462
465
|
const value = input.value;
|
|
463
466
|
if (value.paused) {
|
|
@@ -540,7 +543,7 @@ class Watch extends core_1.Client {
|
|
|
540
543
|
})
|
|
541
544
|
.catch(err => {
|
|
542
545
|
fatalError(HTTP_MAP, target, err);
|
|
543
|
-
client
|
|
546
|
+
client === null || client === void 0 ? void 0 : client.destroy();
|
|
544
547
|
});
|
|
545
548
|
}).call(this);
|
|
546
549
|
HTTP_MAP.set(uri, new Map([[dest, target]]));
|
|
@@ -651,6 +654,7 @@ class Watch extends core_1.Client {
|
|
|
651
654
|
}
|
|
652
655
|
}
|
|
653
656
|
async modified(watch) {
|
|
657
|
+
var _k, _l, _m, _o;
|
|
654
658
|
this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
655
659
|
const { host, assets } = this;
|
|
656
660
|
let items, sanitize = false;
|
|
@@ -685,7 +689,7 @@ class Watch extends core_1.Client {
|
|
|
685
689
|
}
|
|
686
690
|
watch.captured = false;
|
|
687
691
|
try {
|
|
688
|
-
const manager = this.whenModified
|
|
692
|
+
const manager = (_k = this.whenModified) === null || _k === void 0 ? void 0 : _k.call(this, items, sanitize);
|
|
689
693
|
for (const callback of this.extensions) {
|
|
690
694
|
try {
|
|
691
695
|
const listener = callback(watch, items);
|
|
@@ -707,7 +711,7 @@ class Watch extends core_1.Client {
|
|
|
707
711
|
if (host && watch.document) {
|
|
708
712
|
for (const { instance } of host.Document) {
|
|
709
713
|
if (host.hasDocument(instance, watch.document)) {
|
|
710
|
-
const result = instance.watchInit
|
|
714
|
+
const result = (_l = instance.watchInit) === null || _l === void 0 ? void 0 : _l.call(instance, watch, items, sanitize);
|
|
711
715
|
if (result) {
|
|
712
716
|
if ((0, types_1.isArray)(result.using)) {
|
|
713
717
|
manager.using(...result.using);
|
|
@@ -719,7 +723,7 @@ class Watch extends core_1.Client {
|
|
|
719
723
|
}
|
|
720
724
|
}
|
|
721
725
|
}
|
|
722
|
-
const listener = instance.watchModified
|
|
726
|
+
const listener = (_m = instance.watchModified) === null || _m === void 0 ? void 0 : _m.call(instance, watch, items);
|
|
723
727
|
if (typeof listener === 'function') {
|
|
724
728
|
manager.on('end', listener);
|
|
725
729
|
}
|
|
@@ -729,7 +733,7 @@ class Watch extends core_1.Client {
|
|
|
729
733
|
return await manager.start();
|
|
730
734
|
}
|
|
731
735
|
catch (err) {
|
|
732
|
-
this.writeFail(["Unknown", watch.url
|
|
736
|
+
this.writeFail(["Unknown", ((_o = watch.url) === null || _o === void 0 ? void 0 : _o.pathname) || path.basename(watch.uri)], err);
|
|
733
737
|
}
|
|
734
738
|
}
|
|
735
739
|
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.7.
|
|
3
|
+
"version": "0.7.4",
|
|
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.7.
|
|
24
|
-
"@e-mc/request": "0.7.
|
|
25
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/core": "0.7.4",
|
|
24
|
+
"@e-mc/request": "0.7.4",
|
|
25
|
+
"@e-mc/types": "0.7.4",
|
|
26
26
|
"picomatch": "^3.0.1",
|
|
27
27
|
"ws": "^8.16.0"
|
|
28
28
|
}
|