@matterbridge/utils 3.9.3-dev-20260628-fa05360 → 3.9.3-dev-20260629-7c47082
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/dist/githubVersion.js +13 -26
- package/dist/npmVersion.js +15 -27
- package/dist/tracker.d.ts +2 -1
- package/dist/tracker.js +12 -6
- package/package.json +1 -1
package/dist/githubVersion.js
CHANGED
|
@@ -3,33 +3,17 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
3
3
|
const https = await import('node:https');
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
const url = `https://matterbridge.io/${branch}_${file}`;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (settled)
|
|
11
|
-
return;
|
|
12
|
-
settled = true;
|
|
13
|
-
clearTimeout(timeoutId);
|
|
14
|
-
reject(error);
|
|
15
|
-
};
|
|
16
|
-
const resolveOnce = (updateJson) => {
|
|
17
|
-
if (settled)
|
|
18
|
-
return;
|
|
19
|
-
settled = true;
|
|
20
|
-
clearTimeout(timeoutId);
|
|
21
|
-
resolve(updateJson);
|
|
22
|
-
};
|
|
23
|
-
const timeoutError = new Error(`Request timed out after ${timeout / 1000} seconds`);
|
|
24
|
-
timeoutId = setTimeout(() => {
|
|
25
|
-
req?.destroy?.(timeoutError);
|
|
26
|
-
rejectOnce(timeoutError);
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const timeoutId = setTimeout(() => {
|
|
8
|
+
controller.abort();
|
|
9
|
+
reject(new Error(`Request timed out after ${timeout / 1000} seconds`));
|
|
27
10
|
}, timeout).unref();
|
|
28
|
-
req = https.get(url, {}, (res) => {
|
|
11
|
+
const req = https.get(url, { signal: controller.signal }, (res) => {
|
|
29
12
|
let data = '';
|
|
30
13
|
if (res.statusCode !== 200) {
|
|
14
|
+
clearTimeout(timeoutId);
|
|
31
15
|
res.resume();
|
|
32
|
-
|
|
16
|
+
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
33
17
|
return;
|
|
34
18
|
}
|
|
35
19
|
res.on('data', (chunk) => {
|
|
@@ -38,15 +22,18 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
38
22
|
res.on('end', () => {
|
|
39
23
|
try {
|
|
40
24
|
const jsonData = JSON.parse(data);
|
|
41
|
-
|
|
25
|
+
clearTimeout(timeoutId);
|
|
26
|
+
resolve(jsonData);
|
|
42
27
|
}
|
|
43
28
|
catch (error) {
|
|
44
|
-
|
|
29
|
+
clearTimeout(timeoutId);
|
|
30
|
+
reject(new Error(`Failed to parse response JSON: ${getErrorMessage(error)}`));
|
|
45
31
|
}
|
|
46
32
|
});
|
|
47
33
|
});
|
|
48
34
|
req.on('error', (error) => {
|
|
49
|
-
|
|
35
|
+
clearTimeout(timeoutId);
|
|
36
|
+
reject(new Error(`Request failed: ${getErrorMessage(error)}`));
|
|
50
37
|
});
|
|
51
38
|
});
|
|
52
39
|
}
|
package/dist/npmVersion.js
CHANGED
|
@@ -3,33 +3,17 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
3
3
|
const https = await import('node:https');
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
const url = `https://registry.npmjs.org/${packageName}`;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (settled)
|
|
11
|
-
return;
|
|
12
|
-
settled = true;
|
|
13
|
-
clearTimeout(timeoutId);
|
|
14
|
-
reject(error);
|
|
15
|
-
};
|
|
16
|
-
const resolveOnce = (version) => {
|
|
17
|
-
if (settled)
|
|
18
|
-
return;
|
|
19
|
-
settled = true;
|
|
20
|
-
clearTimeout(timeoutId);
|
|
21
|
-
resolve(version);
|
|
22
|
-
};
|
|
23
|
-
const timeoutError = new Error(`Request timed out after ${timeout / 1000} seconds`);
|
|
24
|
-
timeoutId = setTimeout(() => {
|
|
25
|
-
req?.destroy?.(timeoutError);
|
|
26
|
-
rejectOnce(timeoutError);
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const timeoutId = setTimeout(() => {
|
|
8
|
+
controller.abort();
|
|
9
|
+
reject(new Error(`Request timed out after ${timeout / 1000} seconds`));
|
|
27
10
|
}, timeout).unref();
|
|
28
|
-
req = https.get(url, {}, (res) => {
|
|
11
|
+
const req = https.get(url, { signal: controller.signal }, (res) => {
|
|
29
12
|
let data = '';
|
|
30
13
|
if (res.statusCode !== 200) {
|
|
14
|
+
clearTimeout(timeoutId);
|
|
31
15
|
res.resume();
|
|
32
|
-
|
|
16
|
+
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
33
17
|
return;
|
|
34
18
|
}
|
|
35
19
|
res.on('data', (chunk) => {
|
|
@@ -40,19 +24,23 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
40
24
|
const jsonData = JSON.parse(data);
|
|
41
25
|
const version = jsonData['dist-tags']?.[tag];
|
|
42
26
|
if (version) {
|
|
43
|
-
|
|
27
|
+
clearTimeout(timeoutId);
|
|
28
|
+
resolve(version);
|
|
44
29
|
}
|
|
45
30
|
else {
|
|
46
|
-
|
|
31
|
+
clearTimeout(timeoutId);
|
|
32
|
+
reject(new Error(`Tag "${tag}" not found for package "${packageName}"`));
|
|
47
33
|
}
|
|
48
34
|
}
|
|
49
35
|
catch (error) {
|
|
50
|
-
|
|
36
|
+
clearTimeout(timeoutId);
|
|
37
|
+
reject(new Error(`Failed to parse response JSON: ${getErrorMessage(error)}`));
|
|
51
38
|
}
|
|
52
39
|
});
|
|
53
40
|
});
|
|
54
41
|
req.on('error', (error) => {
|
|
55
|
-
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
reject(new Error(`Request failed: ${getErrorMessage(error)}`));
|
|
56
44
|
});
|
|
57
45
|
});
|
|
58
46
|
}
|
package/dist/tracker.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class Tracker extends EventEmitter<TrackerEvents> {
|
|
|
36
36
|
private readonly name;
|
|
37
37
|
private readonly debug;
|
|
38
38
|
private readonly verbose;
|
|
39
|
+
private readonly tracker;
|
|
39
40
|
private trackerInterval?;
|
|
40
41
|
static historyIndex: number;
|
|
41
42
|
static readonly historySize = 2880;
|
|
@@ -43,7 +44,7 @@ export declare class Tracker extends EventEmitter<TrackerEvents> {
|
|
|
43
44
|
private prevCpus;
|
|
44
45
|
private prevCpuUsage;
|
|
45
46
|
private log;
|
|
46
|
-
constructor(name?: string, debug?: boolean, verbose?: boolean);
|
|
47
|
+
constructor(name?: string, debug?: boolean, verbose?: boolean, tracker?: boolean);
|
|
47
48
|
start(sampleIntervalMs?: number): void;
|
|
48
49
|
resetPeaks(): void;
|
|
49
50
|
runGarbageCollector(type?: 'major' | 'minor', execution?: 'sync' | 'async'): void;
|
package/dist/tracker.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import { AnsiLogger, BRIGHT, CYAN, db, RED, RESET, YELLOW } from 'node-ansi-logger';
|
|
4
|
+
import { hasParameter } from './commandLine.js';
|
|
4
5
|
import { formatBytes, formatPercent, formatTimeStamp } from './format.js';
|
|
5
6
|
import { logModuleLoaded } from './loader.js';
|
|
6
7
|
logModuleLoaded('Tracker');
|
|
@@ -8,6 +9,7 @@ export class Tracker extends EventEmitter {
|
|
|
8
9
|
name;
|
|
9
10
|
debug;
|
|
10
11
|
verbose;
|
|
12
|
+
tracker;
|
|
11
13
|
trackerInterval;
|
|
12
14
|
static historyIndex = 0;
|
|
13
15
|
static historySize = 2880;
|
|
@@ -35,18 +37,22 @@ export class Tracker extends EventEmitter {
|
|
|
35
37
|
prevCpus = os.cpus();
|
|
36
38
|
prevCpuUsage = process.cpuUsage();
|
|
37
39
|
log;
|
|
38
|
-
constructor(name = 'Tracker', debug = false, verbose = false) {
|
|
40
|
+
constructor(name = 'Tracker', debug = false, verbose = false, tracker = false) {
|
|
39
41
|
super();
|
|
40
42
|
this.name = name;
|
|
41
43
|
this.debug = debug;
|
|
42
44
|
this.verbose = verbose;
|
|
43
|
-
|
|
45
|
+
this.tracker = tracker;
|
|
46
|
+
if (process.argv.includes('--debug') || process.argv.includes('--verbose') || process.argv.includes('--tracker')) {
|
|
44
47
|
this.debug = true;
|
|
45
48
|
}
|
|
46
|
-
if (process.argv.includes('--verbose')
|
|
49
|
+
if (process.argv.includes('--verbose')) {
|
|
47
50
|
this.verbose = true;
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
if (process.argv.includes('--tracker')) {
|
|
53
|
+
this.tracker = true;
|
|
54
|
+
}
|
|
55
|
+
this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4, logLevel: this.debug || this.tracker ? "debug" : "info" });
|
|
50
56
|
this.log.logNameColor = YELLOW;
|
|
51
57
|
if (this.verbose) {
|
|
52
58
|
this.log.debug(`os.cpus():\n${RESET}`, os.cpus());
|
|
@@ -75,7 +81,7 @@ export class Tracker extends EventEmitter {
|
|
|
75
81
|
this.prevCpuUsage = process.cpuUsage();
|
|
76
82
|
this.trackerInterval = setInterval(() => {
|
|
77
83
|
tryGcCount += sampleIntervalMs / 1000;
|
|
78
|
-
if (tryGcCount > 60 * 60) {
|
|
84
|
+
if (tryGcCount > 60 * 60 || hasParameter('force-gc')) {
|
|
79
85
|
this.runGarbageCollector();
|
|
80
86
|
tryGcCount = 0;
|
|
81
87
|
}
|
|
@@ -125,7 +131,7 @@ export class Tracker extends EventEmitter {
|
|
|
125
131
|
entry.peakArrayBuffers = Math.max(prevEntry.peakArrayBuffers, mem.arrayBuffers);
|
|
126
132
|
this.emit('memory', entry.freeMemory, entry.totalMemory, entry.rss, entry.heapUsed, entry.heapTotal, entry.external, entry.arrayBuffers);
|
|
127
133
|
this.emit('snapshot', entry);
|
|
128
|
-
if (this.debug) {
|
|
134
|
+
if (this.debug || this.tracker) {
|
|
129
135
|
this.log.debug(`Time: ${formatTimeStamp(entry.timestamp)} ` +
|
|
130
136
|
`os ${CYAN}${BRIGHT}${formatPercent(entry.osCpu)}${RESET}${db} (${entry.peakOsCpu > prevEntry.peakOsCpu ? RED : ''}${formatPercent(entry.peakOsCpu)}${db}) ` +
|
|
131
137
|
`process ${CYAN}${BRIGHT}${formatPercent(entry.processCpu)}${RESET}${db} (${entry.peakProcessCpu > prevEntry.peakProcessCpu ? RED : ''}${formatPercent(entry.peakProcessCpu)}${db}) ` +
|
package/package.json
CHANGED