@e-mc/watch 0.8.7 → 0.9.0
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 +10 -10
- package/README.md +77 -11
- package/filegroup/index.js +1 -6
- package/index.d.ts +4 -4
- package/index.js +87 -95
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
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
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
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
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.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/watch
|
|
2
2
|
|
|
3
|
-
* NodeJS 14
|
|
3
|
+
* NodeJS 14/16
|
|
4
4
|
* ES2020
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.0/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IFileManager, ModuleConstructor } from "./index";
|
|
16
16
|
import type { ExternalAsset } from "./asset";
|
|
17
|
-
import type { IClient, IPermission } from "./core";
|
|
17
|
+
import type { HostInitConfig, IClient, IPermission } from "./core";
|
|
18
18
|
import type { FinalizeResult, PostFinalizeCallback } from "./filemanager";
|
|
19
19
|
import type { WatchModule } from "./settings";
|
|
20
20
|
import type { IFileGroup, ModifiedPostFinalizeListener, SecureOptions } from "./watch";
|
|
@@ -23,6 +23,7 @@ import type * as ws from "ws";
|
|
|
23
23
|
|
|
24
24
|
interface IWatch extends IClient<IFileManager, WatchModule, ModifiedPostFinalizeListener> {
|
|
25
25
|
connectTimeout: number;
|
|
26
|
+
init(config?: HostInitConfig): this;
|
|
26
27
|
start(assets: ExternalAsset[], permission?: IPermission | null): void;
|
|
27
28
|
modified(watch: IFileGroup<ExternalAsset>): Promise<FinalizeResult | void>;
|
|
28
29
|
configureServer(options: SecureOptions): boolean;
|
|
@@ -31,7 +32,7 @@ interface IWatch extends IClient<IFileManager, WatchModule, ModifiedPostFinalize
|
|
|
31
32
|
setSSLCert(value: string): boolean;
|
|
32
33
|
hasSecureProtocol(): boolean;
|
|
33
34
|
whenModified?(assets: ExternalAsset[], postFinalize: PostFinalizeCallback): IFileManager;
|
|
34
|
-
whenModified?(assets: ExternalAsset[], sanitize?: boolean
|
|
35
|
+
whenModified?(assets: ExternalAsset[], sanitize?: boolean, postFinalize?: PostFinalizeCallback): IFileManager;
|
|
35
36
|
set assets(value: ExternalAsset[]);
|
|
36
37
|
get assets(): ExternalAsset[];
|
|
37
38
|
set interval(value);
|
|
@@ -50,18 +51,83 @@ interface WatchConstructor extends ModuleConstructor {
|
|
|
50
51
|
checkTimeout(client: ws): boolean;
|
|
51
52
|
readonly prototype: IWatch;
|
|
52
53
|
new(module?: WatchModule): IWatch;
|
|
53
|
-
/* @deprecated */
|
|
54
|
-
new(interval?: number, port?: number, securePort?: number, extensions?: unknown[]): IWatch;
|
|
55
54
|
}
|
|
56
55
|
```
|
|
57
56
|
|
|
57
|
+
## Settings
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type { PermittedDirectories } from "./core";
|
|
61
|
+
|
|
62
|
+
import type { SecureVersion } from "tls";
|
|
63
|
+
|
|
64
|
+
interface WatchModule {
|
|
65
|
+
// handler: "@e-mc/watch";
|
|
66
|
+
extensions?: string[];
|
|
67
|
+
timeout?: number | string;
|
|
68
|
+
interval?: number | string;
|
|
69
|
+
port?: number;
|
|
70
|
+
secure?: {
|
|
71
|
+
port?: number;
|
|
72
|
+
ca?: string;
|
|
73
|
+
key?: string;
|
|
74
|
+
cert?: string;
|
|
75
|
+
passphrase?: string;
|
|
76
|
+
version?: SecureVersion;
|
|
77
|
+
};
|
|
78
|
+
settings?: {
|
|
79
|
+
broadcast_id?: string | string[];
|
|
80
|
+
users?: Record<string, Record<string, unknown>>;
|
|
81
|
+
};
|
|
82
|
+
permission?: PermittedDirectories;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Example usage
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const Watch = require("@e-mc/watch");
|
|
90
|
+
|
|
91
|
+
const instance = new Watch({ interval: 100, port: 8080 });
|
|
92
|
+
instance.init();
|
|
93
|
+
|
|
94
|
+
instance.whenModified = (assets) => {
|
|
95
|
+
assets.forEach(item => console.log(item.uri));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const assets = [
|
|
99
|
+
{ localUri: "/path/workspace/output/image1.png", uri: "http://hostname/path/document1.png", watch: true },
|
|
100
|
+
{ localUri: "/path/workspace/output/image2.png", uri: "http://hostname/path/document2.png", watch: true }
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
instance.start(assets, { disk_read: ["/path/workspace/output/**"] });
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## NodeJS 14 LTS
|
|
107
|
+
|
|
108
|
+
Any optional fail safe dependencies were removed as of `E-mc 0.9`. The code itself will still be *ES2020* and will continue to work equivalently when self-installing these dependencies:
|
|
109
|
+
|
|
110
|
+
### Under 15.4 + 16.0
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
npm i abort-controller event-target-shim
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Under 14.17 + 15.6
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
npm i uuid
|
|
120
|
+
```
|
|
121
|
+
|
|
58
122
|
## References
|
|
59
123
|
|
|
60
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
61
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
62
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
63
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
64
|
-
- https://www.unpkg.com/@e-mc/types@0.
|
|
124
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/asset.d.ts
|
|
125
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/core.d.ts
|
|
126
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/filemanager.d.ts
|
|
127
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/settings.d.ts
|
|
128
|
+
- https://www.unpkg.com/@e-mc/types@0.9.0/lib/watch.d.ts
|
|
129
|
+
|
|
130
|
+
* https://www.npmjs.com/package/@types/ws
|
|
65
131
|
|
|
66
132
|
## LICENSE
|
|
67
133
|
|
package/filegroup/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e, _f;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const util = require("util");
|
|
5
4
|
const ws = require("ws");
|
|
6
5
|
const types_1 = require("@e-mc/types");
|
|
@@ -208,9 +207,5 @@ class FileGroup extends core_1.AbortComponent {
|
|
|
208
207
|
_a = kServer, _b = kStarted, _c = kPaused, _d = kEtag, _e = kLastModified, _f = kSockets;
|
|
209
208
|
FileGroup.CONNECTION_TIMEOUT = 10 * 60000;
|
|
210
209
|
FileGroup.CLIENT_SESSION = new Map();
|
|
211
|
-
exports.default = FileGroup;
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
module.exports = exports.default;
|
|
215
|
-
module.exports.default = exports.default;
|
|
216
|
-
}
|
|
211
|
+
module.exports = FileGroup;
|
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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const fs = require("fs");
|
|
6
5
|
const https = require("https");
|
|
@@ -26,6 +25,15 @@ const DISK_MAP = new Map();
|
|
|
26
25
|
const PORT_MAP = new Map();
|
|
27
26
|
const SECURE_MAP = new Map();
|
|
28
27
|
let STATE_MAP = new WeakSet();
|
|
28
|
+
function isConnectionTimeout(err) {
|
|
29
|
+
switch (err instanceof Error && err.code) {
|
|
30
|
+
case 'ETIMEDOUT':
|
|
31
|
+
case 'ECONNRESET':
|
|
32
|
+
return true;
|
|
33
|
+
default:
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
29
37
|
function abortTimeout(group) {
|
|
30
38
|
group.timeout.aborted = true;
|
|
31
39
|
const watcher = group.watcher;
|
|
@@ -63,6 +71,23 @@ function closeServer(map) {
|
|
|
63
71
|
}
|
|
64
72
|
const formatDate = (value) => new Date(value).toLocaleString().replace(/\/20\d+, /, '@').replace(/:\d+ (AM|PM)$/, (...match) => match[1]);
|
|
65
73
|
class Watch extends core_1.Client {
|
|
74
|
+
constructor() {
|
|
75
|
+
super(...arguments);
|
|
76
|
+
this.connectTimeout = Watch.PROCESS_TIMEOUT;
|
|
77
|
+
this._moduleName = 'watch';
|
|
78
|
+
this._assets = [];
|
|
79
|
+
this._extensions = [];
|
|
80
|
+
this._hostEvents = [];
|
|
81
|
+
this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
|
|
82
|
+
this[_b] = 80;
|
|
83
|
+
this[_c] = 443;
|
|
84
|
+
this[_d] = '';
|
|
85
|
+
this[_e] = '';
|
|
86
|
+
this[_f] = '';
|
|
87
|
+
this[_g] = '';
|
|
88
|
+
this[_h] = undefined;
|
|
89
|
+
this[_j] = undefined;
|
|
90
|
+
}
|
|
66
91
|
static createServer(port, secure, active) {
|
|
67
92
|
if (typeof secure === 'boolean') {
|
|
68
93
|
active = secure;
|
|
@@ -76,10 +101,10 @@ class Watch extends core_1.Client {
|
|
|
76
101
|
}
|
|
77
102
|
const { ca, passphrase, version, config } = secure;
|
|
78
103
|
let { key, cert } = secure;
|
|
79
|
-
if (key && cert && (key = request_1.
|
|
104
|
+
if (key && cert && (key = request_1.readTLSKey(key, true)) && (cert = request_1.readTLSKey(cert, true))) {
|
|
80
105
|
const server = https.createServer({
|
|
81
106
|
...config,
|
|
82
|
-
ca: ca && request_1.
|
|
107
|
+
ca: ca && request_1.readCACert(ca, true) || undefined,
|
|
83
108
|
key: passphrase ? [{ pem: key, passphrase }] : key,
|
|
84
109
|
cert,
|
|
85
110
|
minVersion: version || config?.minVersion
|
|
@@ -114,16 +139,16 @@ class Watch extends core_1.Client {
|
|
|
114
139
|
}
|
|
115
140
|
wss.on('connection', function (socket) {
|
|
116
141
|
socket.on('message', function () {
|
|
117
|
-
filegroup_1.
|
|
142
|
+
filegroup_1.CLIENT_SESSION.delete(this);
|
|
118
143
|
});
|
|
119
144
|
socket.on('close', function () {
|
|
120
|
-
filegroup_1.
|
|
145
|
+
filegroup_1.CLIENT_SESSION.delete(this);
|
|
121
146
|
});
|
|
122
|
-
this.clients.forEach(client => filegroup_1.
|
|
147
|
+
this.clients.forEach(client => filegroup_1.checkTimeout(client));
|
|
123
148
|
});
|
|
124
149
|
wss.on('error', function (err) {
|
|
125
150
|
const data = JSON.stringify({ event: types_1.WATCH_EVENT.ERROR, errors: [err.message] });
|
|
126
|
-
this.clients.forEach(client => filegroup_1.
|
|
151
|
+
this.clients.forEach(client => filegroup_1.checkTimeout(client) && client.send(data));
|
|
127
152
|
});
|
|
128
153
|
wss.on('close', function () {
|
|
129
154
|
this.clients.forEach(client => client.terminate());
|
|
@@ -135,50 +160,28 @@ class Watch extends core_1.Client {
|
|
|
135
160
|
closeFileGroup(DISK_MAP);
|
|
136
161
|
closeServer(PORT_MAP);
|
|
137
162
|
closeServer(SECURE_MAP);
|
|
138
|
-
filegroup_1.
|
|
163
|
+
filegroup_1.CLIENT_SESSION.clear();
|
|
139
164
|
STATE_MAP = new WeakSet();
|
|
140
165
|
}
|
|
141
166
|
static checkTimeout(client) {
|
|
142
|
-
return filegroup_1.
|
|
167
|
+
return filegroup_1.checkTimeout(client);
|
|
143
168
|
}
|
|
144
169
|
static setTimeout(value) {
|
|
145
170
|
if ((value = (0, types_1.parseTime)(value)) > 0) {
|
|
146
|
-
filegroup_1.
|
|
171
|
+
filegroup_1.CONNECTION_TIMEOUT = Math.min(value, core_1.Client.MAX_TIMEOUT);
|
|
147
172
|
}
|
|
148
173
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this._hostEvents = [];
|
|
156
|
-
this[_a] = types_1.THRESHOLD.WATCH_INTERVAL;
|
|
157
|
-
this[_b] = 80;
|
|
158
|
-
this[_c] = 443;
|
|
159
|
-
this[_d] = '';
|
|
160
|
-
this[_e] = '';
|
|
161
|
-
this[_f] = '';
|
|
162
|
-
this[_g] = '';
|
|
163
|
-
this[_h] = undefined;
|
|
164
|
-
this[_j] = undefined;
|
|
165
|
-
let interval;
|
|
166
|
-
if ((0, types_1.isPlainObject)(data)) {
|
|
167
|
-
let secure;
|
|
168
|
-
({ interval, port, secure, extensions } = data);
|
|
169
|
-
if (secure) {
|
|
170
|
-
securePort = secure.port;
|
|
171
|
-
if (secure.cert && secure.key) {
|
|
172
|
-
this.configureServer(secure);
|
|
173
|
-
}
|
|
174
|
+
init(config) {
|
|
175
|
+
const { interval, port, secure } = this.module;
|
|
176
|
+
if (secure) {
|
|
177
|
+
this.securePort = (0, util_1.asInt)(secure.port);
|
|
178
|
+
if (secure.cert && secure.key) {
|
|
179
|
+
this.configureServer(secure);
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
this.interval = (0, util_1.asInt)(interval);
|
|
177
183
|
this.port = (0, util_1.asInt)(port);
|
|
178
|
-
|
|
179
|
-
if (Array.isArray(extensions)) {
|
|
180
|
-
this.module.extensions = extensions;
|
|
181
|
-
}
|
|
184
|
+
return super.init(config);
|
|
182
185
|
}
|
|
183
186
|
start(assets, permission) {
|
|
184
187
|
var _k;
|
|
@@ -191,15 +194,14 @@ class Watch extends core_1.Client {
|
|
|
191
194
|
const settings = this.getUserSettings();
|
|
192
195
|
const destMap = Object.create(null);
|
|
193
196
|
for (const item of assets) {
|
|
194
|
-
if ((0, types_1.ignoreFlag)(item.flags)) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
197
|
+
if (!(0, types_1.ignoreFlag)(item.flags)) {
|
|
198
|
+
const { bundleId, uri, localUri } = item;
|
|
199
|
+
if (!(0, types_1.isEmpty)(bundleId)) {
|
|
200
|
+
(destMap[_k = ':' + bundleId] || (destMap[_k] = [])).push(item);
|
|
201
|
+
}
|
|
202
|
+
else if (uri && localUri) {
|
|
203
|
+
(destMap[localUri] || (destMap[localUri] = [])).push(item);
|
|
204
|
+
}
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
207
|
for (let dest in destMap) {
|
|
@@ -227,7 +229,7 @@ class Watch extends core_1.Client {
|
|
|
227
229
|
}
|
|
228
230
|
if ((0, types_1.watchFlag)(other.flags)) {
|
|
229
231
|
if (!other.watch) {
|
|
230
|
-
other = filegroup_1.
|
|
232
|
+
other = filegroup_1.cloneAsset(other);
|
|
231
233
|
other.watch = { ...watch };
|
|
232
234
|
}
|
|
233
235
|
other.flags &= ~1;
|
|
@@ -328,7 +330,7 @@ class Watch extends core_1.Client {
|
|
|
328
330
|
}
|
|
329
331
|
const interval = getInterval(item) || watchInterval || this.interval;
|
|
330
332
|
const watching = (uri, esm) => {
|
|
331
|
-
const group = new filegroup_1
|
|
333
|
+
const group = new filegroup_1(uri, main ? assets : items, startTime, this.willAbort("(watch)"));
|
|
332
334
|
group.add(expires, socketId, id);
|
|
333
335
|
if (main) {
|
|
334
336
|
group.main = main;
|
|
@@ -428,7 +430,7 @@ class Watch extends core_1.Client {
|
|
|
428
430
|
return status;
|
|
429
431
|
}
|
|
430
432
|
const url = group.url || (group.url = new URL(uri));
|
|
431
|
-
const request = this.host?.Request || new request_1
|
|
433
|
+
const request = this.host?.Request || new request_1();
|
|
432
434
|
const agentTimeout = Math.max(timeout.interval * 10, this.connectTimeout);
|
|
433
435
|
const opts = request.opts(url, { method: 'HEAD', httpVersion: 1, timeout: agentTimeout, agentTimeout });
|
|
434
436
|
(function recurse() {
|
|
@@ -488,19 +490,17 @@ class Watch extends core_1.Client {
|
|
|
488
490
|
}
|
|
489
491
|
else {
|
|
490
492
|
if (isMap(map)) {
|
|
491
|
-
reject(valid ? (0, types_1.errorValue)(
|
|
493
|
+
reject(valid ? (0, types_1.errorValue)("ETag not supported", uri) : (0, types_1.errorMessage)(statusCode, 'Invalid HTTP request', uri));
|
|
492
494
|
return;
|
|
493
495
|
}
|
|
494
496
|
watchExpired(HTTP_MAP, group);
|
|
495
497
|
abortTimeout(target);
|
|
496
498
|
}
|
|
497
|
-
|
|
498
|
-
client.destroy();
|
|
499
|
-
}
|
|
499
|
+
client?.destroy();
|
|
500
500
|
resolve();
|
|
501
501
|
})
|
|
502
502
|
.on('error', err => {
|
|
503
|
-
if (!timeout.aborted && !(
|
|
503
|
+
if (!timeout.aborted && !(isConnectionTimeout(err) && ++timeout.retries <= 10)) {
|
|
504
504
|
reject(err);
|
|
505
505
|
return;
|
|
506
506
|
}
|
|
@@ -529,7 +529,7 @@ class Watch extends core_1.Client {
|
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
})
|
|
532
|
-
.catch(err => {
|
|
532
|
+
.catch((err) => {
|
|
533
533
|
fatalError(HTTP_MAP, target, err);
|
|
534
534
|
client?.destroy();
|
|
535
535
|
});
|
|
@@ -548,7 +548,7 @@ class Watch extends core_1.Client {
|
|
|
548
548
|
}
|
|
549
549
|
const map = DISK_MAP.get(uri);
|
|
550
550
|
switch (event) {
|
|
551
|
-
case 'change':
|
|
551
|
+
case 'change':
|
|
552
552
|
if (isMap(map)) {
|
|
553
553
|
try {
|
|
554
554
|
const mtime = Math.floor(fs.statSync(uri).mtimeMs);
|
|
@@ -579,11 +579,8 @@ class Watch extends core_1.Client {
|
|
|
579
579
|
this.writeFail(["Unable to read file", path.basename(uri)], err, { type: 32, fatal: false });
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
|
-
}
|
|
583
582
|
case 'rename':
|
|
584
|
-
|
|
585
|
-
map.clear();
|
|
586
|
-
}
|
|
583
|
+
map?.clear();
|
|
587
584
|
watchExpired(DISK_MAP, group, event === 'rename' ? 'File renamed: ' + filename : undefined);
|
|
588
585
|
abortTimeout(target);
|
|
589
586
|
break;
|
|
@@ -647,7 +644,7 @@ class Watch extends core_1.Client {
|
|
|
647
644
|
let items, sanitize = false;
|
|
648
645
|
if (watch.main) {
|
|
649
646
|
sanitize = watch.assets.length > assets.length;
|
|
650
|
-
items = sanitize ? watch.assets.map(item => filegroup_1.
|
|
647
|
+
items = sanitize ? watch.assets.map(item => filegroup_1.cloneAsset(item)) : assets.map(item => (0, types_1.cloneObject)(item, true));
|
|
651
648
|
}
|
|
652
649
|
else {
|
|
653
650
|
items = [];
|
|
@@ -665,9 +662,9 @@ class Watch extends core_1.Client {
|
|
|
665
662
|
sanitize = true;
|
|
666
663
|
}
|
|
667
664
|
if (sanitize) {
|
|
668
|
-
items = watch.assets.map(item => filegroup_1.
|
|
665
|
+
items = watch.assets.map(item => filegroup_1.cloneAsset(item));
|
|
669
666
|
}
|
|
670
|
-
if (watch.related
|
|
667
|
+
if ((0, types_1.isArray)(watch.related)) {
|
|
671
668
|
items.push(...watch.related);
|
|
672
669
|
}
|
|
673
670
|
}
|
|
@@ -692,32 +689,31 @@ class Watch extends core_1.Client {
|
|
|
692
689
|
catch {
|
|
693
690
|
}
|
|
694
691
|
}
|
|
695
|
-
if (
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
document.dataSource = result.dataSource;
|
|
692
|
+
if (manager) {
|
|
693
|
+
if (host && watch.document) {
|
|
694
|
+
for (const { instance } of host.Document) {
|
|
695
|
+
if (host.hasDocument(instance, watch.document)) {
|
|
696
|
+
const result = instance.watchInit?.(watch, items, sanitize);
|
|
697
|
+
if (result) {
|
|
698
|
+
if ((0, types_1.isArray)(result.using)) {
|
|
699
|
+
manager.using(...result.using);
|
|
700
|
+
}
|
|
701
|
+
if (Array.isArray(result.dataSource)) {
|
|
702
|
+
const document = manager.find(instance.moduleName);
|
|
703
|
+
if (document) {
|
|
704
|
+
document.dataSource = result.dataSource;
|
|
705
|
+
}
|
|
710
706
|
}
|
|
711
707
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
708
|
+
const listener = instance.watchModified?.(watch, items);
|
|
709
|
+
if (typeof listener === 'function') {
|
|
710
|
+
manager.on('end', listener);
|
|
711
|
+
}
|
|
716
712
|
}
|
|
717
713
|
}
|
|
718
714
|
}
|
|
715
|
+
return await manager.start();
|
|
719
716
|
}
|
|
720
|
-
return await manager.start();
|
|
721
717
|
}
|
|
722
718
|
catch (err) {
|
|
723
719
|
this.writeFail(["Unknown", watch.url?.pathname || path.basename(watch.uri)], err);
|
|
@@ -730,10 +726,10 @@ class Watch extends core_1.Client {
|
|
|
730
726
|
if (ca) {
|
|
731
727
|
this.setCA(ca);
|
|
732
728
|
}
|
|
733
|
-
if (request_1.
|
|
729
|
+
if (request_1.isCert(key) || core_1.Client.isPath(key = path.resolve(key = key.trim())) && this.canRead(key, { ownPermissionOnly: true })) {
|
|
734
730
|
this[kTlsKey] = key.trim();
|
|
735
731
|
}
|
|
736
|
-
if (request_1.
|
|
732
|
+
if (request_1.isCert(cert) || core_1.Client.isPath(cert = path.resolve(cert = cert.trim())) && this.canRead(cert, { ownPermissionOnly: true })) {
|
|
737
733
|
this[kTlsCert] = cert.trim();
|
|
738
734
|
}
|
|
739
735
|
if ((0, types_1.isString)(passphrase)) {
|
|
@@ -770,10 +766,10 @@ class Watch extends core_1.Client {
|
|
|
770
766
|
setSSLKey(value) {
|
|
771
767
|
this[kTlsConfig] = { secureProtocol: 'SSLv23_method' };
|
|
772
768
|
this[kTlsVersion] = undefined;
|
|
773
|
-
return !!(this[kTlsKey] = request_1.
|
|
769
|
+
return !!(this[kTlsKey] = request_1.readTLSKey(value, true));
|
|
774
770
|
}
|
|
775
771
|
setSSLCert(value) {
|
|
776
|
-
return !!(this[kTlsCert] = request_1.
|
|
772
|
+
return !!(this[kTlsCert] = request_1.readTLSCert(value, true));
|
|
777
773
|
}
|
|
778
774
|
hasSecureProtocol() {
|
|
779
775
|
return !!this[kTlsKey] && !!this[kTlsCert];
|
|
@@ -783,7 +779,7 @@ class Watch extends core_1.Client {
|
|
|
783
779
|
}
|
|
784
780
|
set host(value) {
|
|
785
781
|
super.host = value;
|
|
786
|
-
if (
|
|
782
|
+
if ((0, types_1.isArray)(value?.assets)) {
|
|
787
783
|
this.assets = value.assets;
|
|
788
784
|
}
|
|
789
785
|
}
|
|
@@ -828,9 +824,5 @@ class Watch extends core_1.Client {
|
|
|
828
824
|
}
|
|
829
825
|
_a = kInterval, _b = kPort, _c = kSecurePort, _d = kCa, _e = kTlsKey, _f = kTlsCert, _g = kTlsPassphrase, _h = kTlsVersion, _j = kTlsConfig;
|
|
830
826
|
Watch.PROCESS_TIMEOUT = 5 * 1000;
|
|
831
|
-
exports.default = Watch;
|
|
832
827
|
|
|
833
|
-
|
|
834
|
-
module.exports = exports.default;
|
|
835
|
-
module.exports.default = exports.default;
|
|
836
|
-
}
|
|
828
|
+
module.exports = Watch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/watch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.
|
|
24
|
-
"@e-mc/request": "0.
|
|
25
|
-
"@e-mc/types": "0.
|
|
26
|
-
"picomatch": "^
|
|
23
|
+
"@e-mc/core": "0.9.0",
|
|
24
|
+
"@e-mc/request": "0.9.0",
|
|
25
|
+
"@e-mc/types": "0.9.0",
|
|
26
|
+
"picomatch": "^4.0.2",
|
|
27
27
|
"ws": "^8.16.0"
|
|
28
28
|
}
|
|
29
29
|
}
|