@e-mc/watch 0.6.0 → 0.6.2
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 +7 -11
- package/README.md +5 -3
- package/filegroup/index.d.ts +5 -5
- package/filegroup/index.js +4 -4
- package/index.d.ts +4 -4
- package/index.js +36 -36
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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.
|
|
1
|
+
Copyright 2023 Ninja Scroll
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
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.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FileGroupConstructor } from '../../types/lib/watch';
|
|
2
|
-
import type { ExternalAsset } from '../../types/lib/asset';
|
|
3
|
-
|
|
4
|
-
declare const FileGroup: FileGroupConstructor<ExternalAsset>;
|
|
5
|
-
|
|
1
|
+
import type { FileGroupConstructor } from '../../types/lib/watch';
|
|
2
|
+
import type { ExternalAsset } from '../../types/lib/asset';
|
|
3
|
+
|
|
4
|
+
declare const FileGroup: FileGroupConstructor<ExternalAsset>;
|
|
5
|
+
|
|
6
6
|
export = FileGroup;
|
package/filegroup/index.js
CHANGED
|
@@ -3,8 +3,8 @@ var _a, _b, _c, _d, _e, _f;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const util = require("util");
|
|
5
5
|
const ws = require("ws");
|
|
6
|
-
const types_1 = require("
|
|
7
|
-
const core_1 = require("
|
|
6
|
+
const types_1 = require("@e-mc/types");
|
|
7
|
+
const core_1 = require("@e-mc/core");
|
|
8
8
|
const kServer = Symbol('server');
|
|
9
9
|
const kStarted = Symbol('started');
|
|
10
10
|
const kPaused = Symbol('paused');
|
|
@@ -151,7 +151,7 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
151
151
|
set related(value) {
|
|
152
152
|
this._related = value.map(item => {
|
|
153
153
|
item = FileGroup.cloneAsset(item);
|
|
154
|
-
item.flags = 1
|
|
154
|
+
item.flags = 1;
|
|
155
155
|
return item;
|
|
156
156
|
});
|
|
157
157
|
}
|
|
@@ -206,7 +206,7 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
_a = kServer, _b = kStarted, _c = kPaused, _d = kEtag, _e = kLastModified, _f = kSockets;
|
|
209
|
-
FileGroup.CONNECTION_TIMEOUT = 10 * 60000
|
|
209
|
+
FileGroup.CONNECTION_TIMEOUT = 10 * 60000;
|
|
210
210
|
FileGroup.CLIENT_SESSION = new Map();
|
|
211
211
|
exports.default = FileGroup;
|
|
212
212
|
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IFileManager, WatchConstructor } from '../types/lib';
|
|
2
|
-
|
|
3
|
-
declare const Watch: WatchConstructor<IFileManager>;
|
|
4
|
-
|
|
1
|
+
import type { IFileManager, WatchConstructor } from '../types/lib';
|
|
2
|
+
|
|
3
|
+
declare const Watch: WatchConstructor<IFileManager>;
|
|
4
|
+
|
|
5
5
|
export = Watch;
|
package/index.js
CHANGED
|
@@ -6,11 +6,11 @@ const fs = require("fs");
|
|
|
6
6
|
const https = require("https");
|
|
7
7
|
const ws = require("ws");
|
|
8
8
|
const pm = require("picomatch");
|
|
9
|
-
const util_1 = require("
|
|
10
|
-
const types_1 = require("
|
|
11
|
-
const core_1 = require("
|
|
12
|
-
const request_1 = require("
|
|
13
|
-
const filegroup_1 = require("
|
|
9
|
+
const util_1 = require("@e-mc/request/util");
|
|
10
|
+
const types_1 = require("@e-mc/types");
|
|
11
|
+
const core_1 = require("@e-mc/core");
|
|
12
|
+
const request_1 = require("@e-mc/request");
|
|
13
|
+
const filegroup_1 = require("@e-mc/watch/filegroup");
|
|
14
14
|
const kInterval = Symbol('interval');
|
|
15
15
|
const kPort = Symbol('port');
|
|
16
16
|
const kSecurePort = Symbol('securePort');
|
|
@@ -113,7 +113,7 @@ class Watch extends core_1.Client {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
catch (err) {
|
|
116
|
-
this.writeFail("Unknown"
|
|
116
|
+
this.writeFail("Unknown", err);
|
|
117
117
|
}
|
|
118
118
|
if (!wss) {
|
|
119
119
|
return null;
|
|
@@ -164,8 +164,8 @@ class Watch extends core_1.Client {
|
|
|
164
164
|
this._extensions = [];
|
|
165
165
|
this._hostEvents = [];
|
|
166
166
|
this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
|
|
167
|
-
this[_b] = 80
|
|
168
|
-
this[_c] = 443
|
|
167
|
+
this[_b] = 80;
|
|
168
|
+
this[_c] = 443;
|
|
169
169
|
this[_d] = '';
|
|
170
170
|
this[_e] = '';
|
|
171
171
|
this[_f] = '';
|
|
@@ -218,7 +218,7 @@ class Watch extends core_1.Client {
|
|
|
218
218
|
continue;
|
|
219
219
|
}
|
|
220
220
|
let watchInterval, bundleMain;
|
|
221
|
-
if (dest
|
|
221
|
+
if (dest.startsWith(':')) {
|
|
222
222
|
items.sort((a, b) => a.bundleIndex - b.bundleIndex);
|
|
223
223
|
bundleMain = items[0];
|
|
224
224
|
dest = bundleMain.localUri;
|
|
@@ -240,7 +240,7 @@ class Watch extends core_1.Client {
|
|
|
240
240
|
other = filegroup_1.default.cloneAsset(other);
|
|
241
241
|
other.watch = { ...watch };
|
|
242
242
|
}
|
|
243
|
-
other.flags &= ~1
|
|
243
|
+
other.flags &= ~1;
|
|
244
244
|
other.invalid = undefined;
|
|
245
245
|
items.push(other);
|
|
246
246
|
}
|
|
@@ -259,10 +259,10 @@ class Watch extends core_1.Client {
|
|
|
259
259
|
const uri = target.value.uri;
|
|
260
260
|
delete map[uri];
|
|
261
261
|
abortTimeout(target);
|
|
262
|
-
this.writeFail(["Unable to watch file"
|
|
262
|
+
this.writeFail(["Unable to watch file", uri], err, 16);
|
|
263
263
|
};
|
|
264
264
|
const watchExpired = (map, target, message = 'Expired') => {
|
|
265
|
-
this.formatMessage(16
|
|
265
|
+
this.formatMessage(16, 'WATCH', [message, target.startTime ? 'since ' + formatDate(target.startTime) : ''], target.uri, { titleColor: 'grey' });
|
|
266
266
|
const data = map[target.uri];
|
|
267
267
|
if (!data || data.size === 0) {
|
|
268
268
|
delete map[target.uri];
|
|
@@ -326,7 +326,7 @@ class Watch extends core_1.Client {
|
|
|
326
326
|
wss = Watch.createServer(port || (port = this.port));
|
|
327
327
|
}
|
|
328
328
|
if (!wss) {
|
|
329
|
-
this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters"
|
|
329
|
+
this.writeFail('Unable to create WebSocket server', (0, types_1.errorMessage)(secure ? 'wss' : 'ws', "Invalid parameters", 'port: ' + (port || "Unknown")), 16);
|
|
330
330
|
socketId = undefined;
|
|
331
331
|
port = undefined;
|
|
332
332
|
secure = undefined;
|
|
@@ -338,7 +338,7 @@ class Watch extends core_1.Client {
|
|
|
338
338
|
}
|
|
339
339
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
340
340
|
const watching = (uri, esm) => {
|
|
341
|
-
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"
|
|
341
|
+
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
342
342
|
group.add(expires, socketId, id);
|
|
343
343
|
if (main) {
|
|
344
344
|
group.main = main;
|
|
@@ -411,7 +411,7 @@ class Watch extends core_1.Client {
|
|
|
411
411
|
wss.close();
|
|
412
412
|
}
|
|
413
413
|
message = 'Destination already watched @ ' + (current.secure ? 'wss' : 'ws') + '://hostname:' + current.port;
|
|
414
|
-
return 3
|
|
414
|
+
return 3;
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
const socket = socketId && current.find(socketId);
|
|
@@ -421,18 +421,18 @@ class Watch extends core_1.Client {
|
|
|
421
421
|
else {
|
|
422
422
|
current.add(expires, socketId, id);
|
|
423
423
|
}
|
|
424
|
-
return 0
|
|
424
|
+
return 0;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
data.set(dest, target);
|
|
428
|
-
return 0
|
|
428
|
+
return 0;
|
|
429
429
|
};
|
|
430
430
|
if (core_1.Client.isFile(uri, 'http/s')) {
|
|
431
431
|
group.url = item.url;
|
|
432
432
|
group.etag = item.etag;
|
|
433
433
|
group.lastModified = item.lastModified;
|
|
434
434
|
if (!group.etag && !group.lastModified) {
|
|
435
|
-
return 1
|
|
435
|
+
return 1;
|
|
436
436
|
}
|
|
437
437
|
if ((status = checkPreceding(HTTP_MAP)) !== undefined) {
|
|
438
438
|
return status;
|
|
@@ -454,7 +454,7 @@ class Watch extends core_1.Client {
|
|
|
454
454
|
return;
|
|
455
455
|
}
|
|
456
456
|
const statusCode = res.statusCode;
|
|
457
|
-
const valid = statusCode >= 200
|
|
457
|
+
const valid = statusCode >= 200 && statusCode < 300;
|
|
458
458
|
const map = HTTP_MAP[uri];
|
|
459
459
|
const etag = res.headers.etag;
|
|
460
460
|
const lastModified = res.headers['last-modified'];
|
|
@@ -510,15 +510,15 @@ class Watch extends core_1.Client {
|
|
|
510
510
|
resolve();
|
|
511
511
|
})
|
|
512
512
|
.on('error', err => {
|
|
513
|
-
if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10
|
|
513
|
+
if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
|
|
514
514
|
reject(err);
|
|
515
515
|
return;
|
|
516
516
|
}
|
|
517
517
|
resolve();
|
|
518
518
|
})
|
|
519
519
|
.on('timeout', () => {
|
|
520
|
-
if (!timeout.aborted && ++timeout.retries > 10
|
|
521
|
-
reject((0, types_1.errorMessage)(408
|
|
520
|
+
if (!timeout.aborted && ++timeout.retries > 10) {
|
|
521
|
+
reject((0, types_1.errorMessage)(408, 'HTTP request timeout'));
|
|
522
522
|
return;
|
|
523
523
|
}
|
|
524
524
|
resolve();
|
|
@@ -588,7 +588,7 @@ class Watch extends core_1.Client {
|
|
|
588
588
|
break;
|
|
589
589
|
}
|
|
590
590
|
catch (err) {
|
|
591
|
-
this.writeFail(["Unable to read file"
|
|
591
|
+
this.writeFail(["Unable to read file", path.basename(uri)], err, { type: 32, fatal: false });
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
}
|
|
@@ -604,9 +604,9 @@ class Watch extends core_1.Client {
|
|
|
604
604
|
DISK_MAP[uri] = new Map([[dest, target]]);
|
|
605
605
|
}
|
|
606
606
|
else {
|
|
607
|
-
return 2
|
|
607
|
+
return 2;
|
|
608
608
|
}
|
|
609
|
-
return 0
|
|
609
|
+
return 0;
|
|
610
610
|
};
|
|
611
611
|
if ((0, types_1.isArray)(sourceFiles) && sourceFiles.some(file => this.canRead(file, { hostPermissionOnly: !!this.host }))) {
|
|
612
612
|
let index = 0;
|
|
@@ -628,33 +628,33 @@ class Watch extends core_1.Client {
|
|
|
628
628
|
if (status > 0) {
|
|
629
629
|
if (!message) {
|
|
630
630
|
switch (status) {
|
|
631
|
-
case 1
|
|
631
|
+
case 1:
|
|
632
632
|
if ((0, types_1.existsFlag)(item.flags)) {
|
|
633
633
|
continue;
|
|
634
634
|
}
|
|
635
635
|
message = 'ETag unavailable';
|
|
636
636
|
break;
|
|
637
|
-
case 2
|
|
637
|
+
case 2:
|
|
638
638
|
message = 'No read permission';
|
|
639
639
|
break;
|
|
640
|
-
case 3
|
|
640
|
+
case 3:
|
|
641
641
|
message = 'Server already in use';
|
|
642
642
|
break;
|
|
643
643
|
default:
|
|
644
|
-
message = "Unknown"
|
|
644
|
+
message = "Unknown";
|
|
645
645
|
break;
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
|
-
this.formatFail((16
|
|
648
|
+
this.formatFail((16 | (status === 2 ? 8192 : 0)), 'WATCH', ["Unable to watch file", watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
|
|
649
649
|
}
|
|
650
650
|
else {
|
|
651
|
-
this.formatMessage(16
|
|
651
|
+
this.formatMessage(16, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
}
|
|
655
655
|
}
|
|
656
656
|
async modified(watch) {
|
|
657
|
-
this.formatMessage(16
|
|
657
|
+
this.formatMessage(16, 'WATCH', 'File modified', watch.uri, { ...core_1.Client.LOG_STYLE_WARN });
|
|
658
658
|
const { host, assets } = this;
|
|
659
659
|
let items, sanitize = false;
|
|
660
660
|
if (watch.main) {
|
|
@@ -684,7 +684,7 @@ class Watch extends core_1.Client {
|
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
686
|
if (!sanitize) {
|
|
687
|
-
items.forEach(item => item.flags |= 2
|
|
687
|
+
items.forEach(item => item.flags |= 2);
|
|
688
688
|
}
|
|
689
689
|
watch.captured = false;
|
|
690
690
|
try {
|
|
@@ -732,7 +732,7 @@ class Watch extends core_1.Client {
|
|
|
732
732
|
return await manager.start();
|
|
733
733
|
}
|
|
734
734
|
catch (err) {
|
|
735
|
-
this.writeFail(["Unknown"
|
|
735
|
+
this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
|
|
736
736
|
}
|
|
737
737
|
}
|
|
738
738
|
configureServer({ ca, key, cert, passphrase, version, config }) {
|
|
@@ -791,7 +791,7 @@ class Watch extends core_1.Client {
|
|
|
791
791
|
return !!this[kTlsKey] && !!this[kTlsCert];
|
|
792
792
|
}
|
|
793
793
|
willAbort(value) {
|
|
794
|
-
return this.host ? this.host.willAbort(value) : value === "(watch)"
|
|
794
|
+
return this.host ? this.host.willAbort(value) : value === "(watch)";
|
|
795
795
|
}
|
|
796
796
|
set host(value) {
|
|
797
797
|
super.host = value;
|
|
@@ -839,7 +839,7 @@ class Watch extends core_1.Client {
|
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
841
|
_a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kTlsKey, _f = kTlsCert, _g = kTlsPassphrase, _h = kTlsVersion, _j = kTlsConfig;
|
|
842
|
-
Watch.PROCESS_TIMEOUT = 5 * 1000
|
|
842
|
+
Watch.PROCESS_TIMEOUT = 5 * 1000;
|
|
843
843
|
exports.default = Watch;
|
|
844
844
|
|
|
845
845
|
if (exports.default) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/watch",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Watch constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,13 +17,13 @@
|
|
|
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.6.
|
|
24
|
-
"@e-mc/request": "0.6.
|
|
25
|
-
"@e-mc/types": "0.6.
|
|
23
|
+
"@e-mc/core": "0.6.2",
|
|
24
|
+
"@e-mc/request": "0.6.2",
|
|
25
|
+
"@e-mc/types": "0.6.2",
|
|
26
26
|
"picomatch": "^2.3.1",
|
|
27
|
-
"ws": "^8.
|
|
27
|
+
"ws": "^8.16.0"
|
|
28
28
|
}
|
|
29
29
|
}
|