@e-mc/watch 0.3.0 → 0.3.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/index.js +34 -5
- package/package.json +6 -5
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require("path");
|
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const https = require("https");
|
|
7
7
|
const ws = require("ws");
|
|
8
|
+
const pm = require("picomatch");
|
|
8
9
|
const util_1 = require("../request/util");
|
|
9
10
|
const types_1 = require("../types");
|
|
10
11
|
const core_1 = require("../core");
|
|
@@ -19,6 +20,7 @@ const kTlsCert = Symbol('tlsCert');
|
|
|
19
20
|
const kTlsVersion = Symbol('tlsVersion');
|
|
20
21
|
const kTlsPassphrase = Symbol('tlsPassphrase');
|
|
21
22
|
const kTlsConfig = Symbol('tlsConfig');
|
|
23
|
+
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
22
24
|
let STATE_MAP = new WeakSet();
|
|
23
25
|
let HTTP_MAP = {};
|
|
24
26
|
let DISK_MAP = {};
|
|
@@ -187,8 +189,9 @@ class Watch extends core_1.Client {
|
|
|
187
189
|
if (permission) {
|
|
188
190
|
this.permission = permission;
|
|
189
191
|
}
|
|
190
|
-
const destMap = Object.create(null);
|
|
191
192
|
const startTime = Date.now();
|
|
193
|
+
const username = this.host?.username;
|
|
194
|
+
const destMap = Object.create(null);
|
|
192
195
|
for (const item of assets) {
|
|
193
196
|
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
194
197
|
continue;
|
|
@@ -240,9 +243,8 @@ class Watch extends core_1.Client {
|
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
245
|
for (const item of items) {
|
|
243
|
-
|
|
246
|
+
let { watch, sourceFiles } = item;
|
|
244
247
|
if (watch) {
|
|
245
|
-
const interval = getInterval(item) || watchInterval || this.interval;
|
|
246
248
|
const fatalError = (map, target, err) => {
|
|
247
249
|
const uri = target.value.uri;
|
|
248
250
|
delete map[uri];
|
|
@@ -258,7 +260,32 @@ class Watch extends core_1.Client {
|
|
|
258
260
|
}
|
|
259
261
|
return false;
|
|
260
262
|
};
|
|
261
|
-
let expires = 0, status = 0, wss, main, id, socketId, port, secure, hot, always, watched, message;
|
|
263
|
+
let expires = 0, status = 0, wss, main, id, socketId, port, secure, hot, always, watched, message, settings;
|
|
264
|
+
if (watch === true && username && (settings = this.settings.users?.[username])) {
|
|
265
|
+
const { uri, localUri, mimeType } = item;
|
|
266
|
+
watch = false;
|
|
267
|
+
if (uri && !(watch = settings[uri])) {
|
|
268
|
+
for (const pattern in settings) {
|
|
269
|
+
if ((0, types_1.hasGlob)(pattern) && pm.isMatch(uri, pattern, { matchBase: true }) && (watch = settings[pattern])) {
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (!watch && localUri && !(watch = settings[localUri])) {
|
|
275
|
+
for (const pattern in settings) {
|
|
276
|
+
if ((0, types_1.hasGlob)(pattern) && pm.isMatch(localUri, pattern, { nocase: PLATFORM_WIN32 }) && (watch = settings[pattern])) {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!watch && mimeType && !(watch = settings[mimeType])) {
|
|
282
|
+
for (const pattern in settings) {
|
|
283
|
+
if (/^[^*/]+\/\*+$/.test(pattern) && pm.isMatch(mimeType, pattern) && (watch = settings[pattern])) {
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
262
289
|
if ((0, types_1.isPlainObject)(watch)) {
|
|
263
290
|
const reload = watch.reload;
|
|
264
291
|
id = watch.id;
|
|
@@ -290,7 +317,9 @@ class Watch extends core_1.Client {
|
|
|
290
317
|
always = undefined;
|
|
291
318
|
}
|
|
292
319
|
}
|
|
320
|
+
item.watch = watch;
|
|
293
321
|
}
|
|
322
|
+
const interval = getInterval(item) || watchInterval || this.interval;
|
|
294
323
|
const watching = (uri, esm) => {
|
|
295
324
|
const group = new filegroup_1.default(uri, main ? assets : items, startTime, this.willAbort("(watch)" /* ABORT_NAME.WATCH */));
|
|
296
325
|
group.add(expires, socketId, id);
|
|
@@ -595,7 +624,7 @@ class Watch extends core_1.Client {
|
|
|
595
624
|
break;
|
|
596
625
|
}
|
|
597
626
|
}
|
|
598
|
-
this.formatFail((16 /* LOG_TYPE.WATCH */ | (status === 2 /* ERR.LOCAL_ACCESS */ ? 8192 /* LOG_TYPE.PERMISSION */ : 0)), 'WATCH', ["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, path.basename(watched)], (0, types_1.errorValue)(message, watched));
|
|
627
|
+
this.formatFail((16 /* LOG_TYPE.WATCH */ | (status === 2 /* ERR.LOCAL_ACCESS */ ? 8192 /* LOG_TYPE.PERMISSION */ : 0)), 'WATCH', ["Unable to watch file" /* ERR_MESSAGE.WATCH_FILE */, watched && path.basename(watched)], (0, types_1.errorValue)(message, watched));
|
|
599
628
|
}
|
|
600
629
|
else {
|
|
601
630
|
this.formatMessage(16 /* LOG_TYPE.WATCH */, 'WATCH', ['Start', interval + 'ms ' + (expires ? formatDate(expires) : 'never')], watched, { titleColor: 'blue' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/watch",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Watch constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.3.
|
|
24
|
-
"@e-mc/request": "0.3.
|
|
25
|
-
"@e-mc/types": "0.3.
|
|
26
|
-
"
|
|
23
|
+
"@e-mc/core": "0.3.2",
|
|
24
|
+
"@e-mc/request": "0.3.2",
|
|
25
|
+
"@e-mc/types": "0.3.2",
|
|
26
|
+
"picomatch": "^2.3.1",
|
|
27
|
+
"ws": "^8.13.0"
|
|
27
28
|
}
|
|
28
29
|
}
|