@e-mc/watch 0.8.7 → 0.8.8
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 +3 -7
- package/README.md +8 -8
- package/filegroup/index.js +2 -1
- package/index.js +17 -13
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
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
|
|
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @e-mc/watch
|
|
2
2
|
|
|
3
3
|
* NodeJS 14
|
|
4
|
-
*
|
|
4
|
+
* ES2019
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/index.d.ts
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IFileManager, ModuleConstructor } from "./index";
|
|
@@ -57,12 +57,12 @@ interface WatchConstructor extends ModuleConstructor {
|
|
|
57
57
|
|
|
58
58
|
## References
|
|
59
59
|
|
|
60
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
61
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
62
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
63
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
64
|
-
- https://www.unpkg.com/@e-mc/types@0.8.
|
|
60
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/asset.d.ts
|
|
61
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/core.d.ts
|
|
62
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/filemanager.d.ts
|
|
63
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/settings.d.ts
|
|
64
|
+
- https://www.unpkg.com/@e-mc/types@0.8.8/lib/watch.d.ts
|
|
65
65
|
|
|
66
66
|
## LICENSE
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
MIT
|
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
|
@@ -82,7 +82,7 @@ class Watch extends core_1.Client {
|
|
|
82
82
|
ca: ca && request_1.default.readCACert(ca, true) || undefined,
|
|
83
83
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
84
84
|
cert,
|
|
85
|
-
minVersion: version || config
|
|
85
|
+
minVersion: version || (config === null || config === void 0 ? void 0 : config.minVersion)
|
|
86
86
|
});
|
|
87
87
|
server.listen(port);
|
|
88
88
|
wss = new ws.Server({ server });
|
|
@@ -182,6 +182,7 @@ class Watch extends core_1.Client {
|
|
|
182
182
|
}
|
|
183
183
|
start(assets, permission) {
|
|
184
184
|
var _k;
|
|
185
|
+
var _l;
|
|
185
186
|
if (this.aborted) {
|
|
186
187
|
return;
|
|
187
188
|
}
|
|
@@ -196,7 +197,7 @@ class Watch extends core_1.Client {
|
|
|
196
197
|
}
|
|
197
198
|
const { bundleId, uri, localUri } = item;
|
|
198
199
|
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
199
|
-
(destMap[
|
|
200
|
+
(destMap[_l = ':' + bundleId] || (destMap[_l] = [])).push(item);
|
|
200
201
|
}
|
|
201
202
|
else if (uri && localUri) {
|
|
202
203
|
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
@@ -221,7 +222,7 @@ class Watch extends core_1.Client {
|
|
|
221
222
|
for (let i = 0, length = items.length; i < length; ++i) {
|
|
222
223
|
const watch = items[i].watch;
|
|
223
224
|
if ((0, types_1.isObject)(watch)) {
|
|
224
|
-
watch.assets
|
|
225
|
+
(_k = watch.assets) === null || _k === void 0 ? void 0 : _k.forEach(other => {
|
|
225
226
|
if (items.includes(other)) {
|
|
226
227
|
return;
|
|
227
228
|
}
|
|
@@ -254,7 +255,7 @@ class Watch extends core_1.Client {
|
|
|
254
255
|
const watchExpired = (map, target, message = 'Expired') => {
|
|
255
256
|
this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
|
|
256
257
|
const data = map.get(target.uri);
|
|
257
|
-
if (!data
|
|
258
|
+
if (!(data === null || data === void 0 ? void 0 : data.size)) {
|
|
258
259
|
map.delete(target.uri);
|
|
259
260
|
return true;
|
|
260
261
|
}
|
|
@@ -328,6 +329,7 @@ class Watch extends core_1.Client {
|
|
|
328
329
|
}
|
|
329
330
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
330
331
|
const watching = (uri, esm) => {
|
|
332
|
+
var _k;
|
|
331
333
|
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
332
334
|
group.add(expires, socketId, id);
|
|
333
335
|
if (main) {
|
|
@@ -357,13 +359,14 @@ class Watch extends core_1.Client {
|
|
|
357
359
|
const timeout = { interval, retries: 0, aborted: false };
|
|
358
360
|
const target = { value: group, timeout, watcher: null };
|
|
359
361
|
const isMap = (value) => value ? value.size > 0 : false;
|
|
360
|
-
const wasAborted = (result, current) => result
|
|
362
|
+
const wasAborted = (result, current) => (result === null || result === void 0 ? void 0 : result.aborted) && current.abortable && current.abort();
|
|
361
363
|
const checkPreceding = (map) => {
|
|
364
|
+
var _k;
|
|
362
365
|
const data = map.get(uri);
|
|
363
366
|
if (!data) {
|
|
364
367
|
return;
|
|
365
368
|
}
|
|
366
|
-
const current = data.get(dest)
|
|
369
|
+
const current = (_k = data.get(dest)) === null || _k === void 0 ? void 0 : _k.value;
|
|
367
370
|
if (current && !current.expired) {
|
|
368
371
|
let reset;
|
|
369
372
|
if (id) {
|
|
@@ -428,7 +431,7 @@ class Watch extends core_1.Client {
|
|
|
428
431
|
return status;
|
|
429
432
|
}
|
|
430
433
|
const url = group.url || (group.url = new URL(uri));
|
|
431
|
-
const request = this.host
|
|
434
|
+
const request = ((_k = this.host) === null || _k === void 0 ? void 0 : _k.Request) || new request_1.default();
|
|
432
435
|
const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
|
|
433
436
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
434
437
|
(function recurse() {
|
|
@@ -448,7 +451,7 @@ class Watch extends core_1.Client {
|
|
|
448
451
|
const map = HTTP_MAP.get(uri);
|
|
449
452
|
const etag = res.headers.etag;
|
|
450
453
|
const lastModified = res.headers['last-modified'];
|
|
451
|
-
if (valid && map
|
|
454
|
+
if (valid && (map === null || map === void 0 ? void 0 : map.size) && (etag || lastModified)) {
|
|
452
455
|
for (const [destUrl, input] of map) {
|
|
453
456
|
const value = input.value;
|
|
454
457
|
if (value.paused) {
|
|
@@ -531,7 +534,7 @@ class Watch extends core_1.Client {
|
|
|
531
534
|
})
|
|
532
535
|
.catch(err => {
|
|
533
536
|
fatalError(HTTP_MAP, target, err);
|
|
534
|
-
client
|
|
537
|
+
client === null || client === void 0 ? void 0 : client.destroy();
|
|
535
538
|
});
|
|
536
539
|
}).call(this);
|
|
537
540
|
HTTP_MAP.set(uri, new Map([[dest, target]]));
|
|
@@ -642,6 +645,7 @@ class Watch extends core_1.Client {
|
|
|
642
645
|
}
|
|
643
646
|
}
|
|
644
647
|
async modified(watch) {
|
|
648
|
+
var _k, _l, _m, _o;
|
|
645
649
|
this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
646
650
|
const { host, assets } = this;
|
|
647
651
|
let items, sanitize = false;
|
|
@@ -676,7 +680,7 @@ class Watch extends core_1.Client {
|
|
|
676
680
|
}
|
|
677
681
|
watch.captured = false;
|
|
678
682
|
try {
|
|
679
|
-
const manager = this.whenModified
|
|
683
|
+
const manager = (_k = this.whenModified) === null || _k === void 0 ? void 0 : _k.call(this, items, sanitize);
|
|
680
684
|
for (const callback of this.extensions) {
|
|
681
685
|
try {
|
|
682
686
|
const listener = callback(watch, items);
|
|
@@ -698,7 +702,7 @@ class Watch extends core_1.Client {
|
|
|
698
702
|
if (host && watch.document) {
|
|
699
703
|
for (const { instance } of host.Document) {
|
|
700
704
|
if (host.hasDocument(instance, watch.document)) {
|
|
701
|
-
const result = instance.watchInit
|
|
705
|
+
const result = (_l = instance.watchInit) === null || _l === void 0 ? void 0 : _l.call(instance, watch, items, sanitize);
|
|
702
706
|
if (result) {
|
|
703
707
|
if ((0, types_1.isArray)(result.using)) {
|
|
704
708
|
manager.using(...result.using);
|
|
@@ -710,7 +714,7 @@ class Watch extends core_1.Client {
|
|
|
710
714
|
}
|
|
711
715
|
}
|
|
712
716
|
}
|
|
713
|
-
const listener = instance.watchModified
|
|
717
|
+
const listener = (_m = instance.watchModified) === null || _m === void 0 ? void 0 : _m.call(instance, watch, items);
|
|
714
718
|
if (typeof listener === 'function') {
|
|
715
719
|
manager.on('end', listener);
|
|
716
720
|
}
|
|
@@ -720,7 +724,7 @@ class Watch extends core_1.Client {
|
|
|
720
724
|
return await manager.start();
|
|
721
725
|
}
|
|
722
726
|
catch (err) {
|
|
723
|
-
this.writeFail(["Unknown", watch.url
|
|
727
|
+
this.writeFail(["Unknown", ((_o = watch.url) === null || _o === void 0 ? void 0 : _o.pathname) || path.basename(watch.uri)], err);
|
|
724
728
|
}
|
|
725
729
|
}
|
|
726
730
|
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.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"description": "Watch constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.8.
|
|
24
|
-
"@e-mc/request": "0.8.
|
|
25
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/core": "0.8.8",
|
|
24
|
+
"@e-mc/request": "0.8.8",
|
|
25
|
+
"@e-mc/types": "0.8.8",
|
|
26
26
|
"picomatch": "^3.0.1",
|
|
27
27
|
"ws": "^8.16.0"
|
|
28
28
|
}
|