@ac-kit/app-system 0.1.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 +28 -0
- package/README.md +45 -0
- package/dist/async/file-lock.d.ts +38 -0
- package/dist/async/file-lock.d.ts.map +1 -0
- package/dist/async/file-lock.js +67 -0
- package/dist/async/file-lock.js.map +1 -0
- package/dist/async/udp-bind-lock.d.ts +75 -0
- package/dist/async/udp-bind-lock.d.ts.map +1 -0
- package/dist/async/udp-bind-lock.js +85 -0
- package/dist/async/udp-bind-lock.js.map +1 -0
- package/dist/fs/artifact-cache.d.ts +124 -0
- package/dist/fs/artifact-cache.d.ts.map +1 -0
- package/dist/fs/artifact-cache.js +183 -0
- package/dist/fs/artifact-cache.js.map +1 -0
- package/dist/fs/rotate-log-files.d.ts +20 -0
- package/dist/fs/rotate-log-files.d.ts.map +1 -0
- package/dist/fs/rotate-log-files.js +45 -0
- package/dist/fs/rotate-log-files.js.map +1 -0
- package/dist/fs/rotating-file-sink.d.ts +42 -0
- package/dist/fs/rotating-file-sink.d.ts.map +1 -0
- package/dist/fs/rotating-file-sink.js +213 -0
- package/dist/fs/rotating-file-sink.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/os/get-processes-snapshot.d.ts +56 -0
- package/dist/os/get-processes-snapshot.d.ts.map +1 -0
- package/dist/os/get-processes-snapshot.js +197 -0
- package/dist/os/get-processes-snapshot.js.map +1 -0
- package/dist/os/host-metrics.d.ts +43 -0
- package/dist/os/host-metrics.d.ts.map +1 -0
- package/dist/os/host-metrics.js +78 -0
- package/dist/os/host-metrics.js.map +1 -0
- package/dist/os/process-kill-by-pid-file.d.ts +35 -0
- package/dist/os/process-kill-by-pid-file.d.ts.map +1 -0
- package/dist/os/process-kill-by-pid-file.js +48 -0
- package/dist/os/process-kill-by-pid-file.js.map +1 -0
- package/dist/os/process-wait-pid.d.ts +18 -0
- package/dist/os/process-wait-pid.d.ts.map +1 -0
- package/dist/os/process-wait-pid.js +26 -0
- package/dist/os/process-wait-pid.js.map +1 -0
- package/dist/os/ps.d.ts +98 -0
- package/dist/os/ps.d.ts.map +1 -0
- package/dist/os/ps.js +165 -0
- package/dist/os/ps.js.map +1 -0
- package/dist/os/sysfs.d.ts +19 -0
- package/dist/os/sysfs.d.ts.map +1 -0
- package/dist/os/sysfs.js +66 -0
- package/dist/os/sysfs.js.map +1 -0
- package/dist/process/child-process-message-sink.d.ts +21 -0
- package/dist/process/child-process-message-sink.d.ts.map +1 -0
- package/dist/process/child-process-message-sink.js +16 -0
- package/dist/process/child-process-message-sink.js.map +1 -0
- package/dist/process/error-listeners.d.ts +56 -0
- package/dist/process/error-listeners.d.ts.map +1 -0
- package/dist/process/error-listeners.js +113 -0
- package/dist/process/error-listeners.js.map +1 -0
- package/dist/process/exit-manager.d.ts +58 -0
- package/dist/process/exit-manager.d.ts.map +1 -0
- package/dist/process/exit-manager.js +88 -0
- package/dist/process/exit-manager.js.map +1 -0
- package/dist/process/has-binary.d.ts +25 -0
- package/dist/process/has-binary.d.ts.map +1 -0
- package/dist/process/has-binary.js +35 -0
- package/dist/process/has-binary.js.map +1 -0
- package/dist/process/pid-file.d.ts +17 -0
- package/dist/process/pid-file.d.ts.map +1 -0
- package/dist/process/pid-file.js +25 -0
- package/dist/process/pid-file.js.map +1 -0
- package/dist/process/process-pid-file.d.ts +37 -0
- package/dist/process/process-pid-file.d.ts.map +1 -0
- package/dist/process/process-pid-file.js +57 -0
- package/dist/process/process-pid-file.js.map +1 -0
- package/dist/process/report-process.d.ts +36 -0
- package/dist/process/report-process.d.ts.map +1 -0
- package/dist/process/report-process.js +121 -0
- package/dist/process/report-process.js.map +1 -0
- package/dist/shell/shorten-posix-path.d.ts +10 -0
- package/dist/shell/shorten-posix-path.d.ts.map +1 -0
- package/dist/shell/shorten-posix-path.js +19 -0
- package/dist/shell/shorten-posix-path.js.map +1 -0
- package/dist/terminal/node-terminal.d.ts +11 -0
- package/dist/terminal/node-terminal.d.ts.map +1 -0
- package/dist/terminal/node-terminal.js +162 -0
- package/dist/terminal/node-terminal.js.map +1 -0
- package/dist/text/charset-decode-stream.d.ts +13 -0
- package/dist/text/charset-decode-stream.d.ts.map +1 -0
- package/dist/text/charset-decode-stream.js +51 -0
- package/dist/text/charset-decode-stream.js.map +1 -0
- package/dist/text/charset-encode-stream.d.ts +12 -0
- package/dist/text/charset-encode-stream.d.ts.map +1 -0
- package/dist/text/charset-encode-stream.js +47 -0
- package/dist/text/charset-encode-stream.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-cache.js","sourceRoot":"","sources":["../../src/fs/artifact-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EACN,WAAW,EACX,cAAc,EACd,WAAW,EACX,OAAO,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAsEjD,2EAA2E;AAC3E,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACjD,YAAY,CAAS;IAE9B,YAAY,YAAoB;QAC/B,KAAK,CACJ,aAAa,YAAY,wDAAwD,CACjF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAClC,CAAC;CACD;AAED,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,oBAAoB,GAAG,KAAM,CAAC;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K,EAAE,CAAC;oBAChB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;oBAEpD,qEAAqE;oBACrE,2DAA2D;oBAC3D,IAAI,MAAM,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;wBACvC,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;wBACjD,OAAO,SAAS,CAAC;oBAClB,CAAC;oBACD,MAAM,KAAK,CAAC;gBACb,CAAC;YACF,CAAC;oBAAS,CAAC;gBACV,IAAI,IAAI,EAAE,CAAC;oBACV,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;gBACrB,CAAC;YACF,CAAC;YAED,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,OAAO,SAAS,CAAC;QAClB,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type RotateLogFilesOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* The maximum number of rotated log files to retain.
|
|
4
|
+
*
|
|
5
|
+
* Default is 5.
|
|
6
|
+
*/
|
|
7
|
+
maxRetainedFiles?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The minimum duration (in milliseconds) to retain a log file before it can
|
|
10
|
+
* be deleted.
|
|
11
|
+
*
|
|
12
|
+
* Note: This setting takes precedence over `maxRetainedFiles`.
|
|
13
|
+
*
|
|
14
|
+
* Default is 5 minutes.
|
|
15
|
+
*/
|
|
16
|
+
minFileHistoryDurationMs?: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const ROTATE_LOG_FILES_DEFAULT_OPTIONS: Required<RotateLogFilesOptions>;
|
|
19
|
+
export declare function rotateLogFiles(filePath: string, options?: RotateLogFilesOptions): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=rotate-log-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate-log-files.d.ts","sourceRoot":"","sources":["../../src/fs/rotate-log-files.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;;;OAOG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,qBAAqB,CAI3E,CAAC;AAEH,wBAAsB,cAAc,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAmDf"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readdir, rename, stat, unlink } from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { MS_PER_MINUTE, defaults } from "@ac-kit/core";
|
|
4
|
+
import { existsAsync } from "@ac-kit/node";
|
|
5
|
+
export const ROTATE_LOG_FILES_DEFAULT_OPTIONS = {
|
|
6
|
+
maxRetainedFiles: 5,
|
|
7
|
+
minFileHistoryDurationMs: 5 * MS_PER_MINUTE,
|
|
8
|
+
};
|
|
9
|
+
export async function rotateLogFiles(filePath, options) {
|
|
10
|
+
const effectiveOptions = defaults(options, ROTATE_LOG_FILES_DEFAULT_OPTIONS);
|
|
11
|
+
if (!(await existsAsync(filePath))) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const dirName = path.dirname(filePath);
|
|
15
|
+
const fileName = path.basename(filePath);
|
|
16
|
+
// count of '.' in file name (to handle files with multiple dots correctly)
|
|
17
|
+
const prefixDotsCnt = fileName.split(".").length - 1;
|
|
18
|
+
// get old log files names (sorted by index, descending)
|
|
19
|
+
const oldFilesNames = (await readdir(dirName))
|
|
20
|
+
.map((v) => new RegExp(`${RegExp.escape(fileName)}\\.\\d+\\.?`).test(v)
|
|
21
|
+
? v.split(".")
|
|
22
|
+
: null)
|
|
23
|
+
.filter((v) => v !== null)
|
|
24
|
+
.sort((a, b) => +a[prefixDotsCnt + 1] - +b[prefixDotsCnt + 1])
|
|
25
|
+
.reverse();
|
|
26
|
+
// rename or delete files based on options
|
|
27
|
+
for (const oldFileName of oldFilesNames) {
|
|
28
|
+
const oldFilePath = path.join(dirName, oldFileName.join("."));
|
|
29
|
+
const fileNum = +oldFileName[prefixDotsCnt + 1];
|
|
30
|
+
if (fileNum + 1 > effectiveOptions.maxRetainedFiles &&
|
|
31
|
+
(await stat(oldFilePath)).mtime.getTime() <
|
|
32
|
+
Date.now() - effectiveOptions.minFileHistoryDurationMs) {
|
|
33
|
+
await unlink(oldFilePath);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await rename(oldFilePath, path.join(dirName, [
|
|
37
|
+
...oldFileName.slice(0, prefixDotsCnt + 1),
|
|
38
|
+
fileNum + 1,
|
|
39
|
+
...oldFileName.slice(prefixDotsCnt + 2),
|
|
40
|
+
].join(".")));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
await rename(filePath, `${filePath}.0`);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=rotate-log-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate-log-files.js","sourceRoot":"","sources":["../../src/fs/rotate-log-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqB3C,MAAM,CAAC,MAAM,gCAAgC,GAC5C;IACC,gBAAgB,EAAE,CAAC;IACnB,wBAAwB,EAAE,CAAC,GA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AC,CAAC;QAC9D,MAAM,OAAO,GAAG,CAAC,WAAW,CAAC,aAAa,GAAG,CAAC,CAAE,CAAC;QAEjD,IACC,OAAO,GAAG,CAAC,GAAG,gBAAgB,CAAC,gBAAgB;YAC/C,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE;gBACxC,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,wBAAwB,EACtD,CAAC;YACF,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACP,MAAM,MAAM,CACX,WAAW,EACX,IAAI,CAAC,IAAI,CACR,OAAO,EACP;gBACC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;gBAC1C,OAAO,GAAG,CAAC;gBACX,GAAG,WAAW,CAAC,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC;aACvC,CAAC,IAAI,CAAC,GAAG,CAAC,CACX,CACD,CAAC;QACH,CAAC;IACF,CAAC;IAED,MAAM,MAAM,CAAC,QAAQ,EAAE,GAAG,QAAQ,IAAI,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Formatter, ISink, ReportEvent } from "@ac-kit/app-report";
|
|
2
|
+
import { type RotateLogFilesOptions } from "./rotate-log-files.js";
|
|
3
|
+
export type RotatingFileSinkOptions<TData> = RotateLogFilesOptions & {
|
|
4
|
+
formatter: Formatter<TData>;
|
|
5
|
+
/**
|
|
6
|
+
* The maximum size (in bytes) the file can reach before being rotated.
|
|
7
|
+
* Default is 10 MiB. Set to `null` to disable size-based rotation.
|
|
8
|
+
*/
|
|
9
|
+
cutOffFileSize?: number | null;
|
|
10
|
+
/**
|
|
11
|
+
* The maximum age (in milliseconds) the file can reach before being rotated.
|
|
12
|
+
* Default is `null` (disabled).
|
|
13
|
+
*/
|
|
14
|
+
maxFileAgeMs?: number | null;
|
|
15
|
+
/** Whether to compress rotated files using gzip. Default `false`. */
|
|
16
|
+
useCompression?: boolean;
|
|
17
|
+
/** Appended after every non-`null` formatted line. Default `"\n"`. */
|
|
18
|
+
eol?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Renders through a {@link Formatter} into a file, with rotation by size and/or
|
|
22
|
+
* age. Extracted from `@ac-kit/app-logger`'s `FilePrinter`, generic over
|
|
23
|
+
* `TData` so measure/process output gains rotation for free.
|
|
24
|
+
*/
|
|
25
|
+
export declare class RotatingFileSink<TData> implements ISink<TData> {
|
|
26
|
+
private readonly filePath;
|
|
27
|
+
private readonly scopeTracker;
|
|
28
|
+
private readonly formatter;
|
|
29
|
+
private readonly options;
|
|
30
|
+
private fileStream;
|
|
31
|
+
private readonly streamLock;
|
|
32
|
+
private readonly rotationLock;
|
|
33
|
+
private readonly rotationSqn;
|
|
34
|
+
constructor(filePath: string, options: RotatingFileSinkOptions<TData>);
|
|
35
|
+
write(event: ReportEvent<TData>, signal?: AbortSignal): Promise<void>;
|
|
36
|
+
flush(): Promise<void>;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
private openStream;
|
|
39
|
+
private closeStream;
|
|
40
|
+
private handleRotation;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=rotating-file-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotating-file-sink.d.ts","sourceRoot":"","sources":["../../src/fs/rotating-file-sink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMxE,OAAO,EAGN,KAAK,qBAAqB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,uBAAuB,CAAC,KAAK,IAAI,qBAAqB,GAAG;IACpE,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAE5B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B,qEAAqE;IACrE,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,sEAAsE;IACtE,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAcF;;;;GAIG;AACH,qBAAa,gBAAgB,CAAC,KAAK,CAAE,YAAW,KAAK,CAAC,KAAK,CAAC;IAY1D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAX1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAE1B;IAEF,YACkB,QAAQ,EAAE,MAAM,EACjC,OAAO,EAAE,uBAAuB,CAAC,KAAK,CAAC,EAKvC;IAEK,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB1E;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;YAEa,UAAU;YAeV,WAAW;YAYX,cAAc;CAqC5B"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { once } from "node:events";
|
|
54
|
+
import { createWriteStream } from "node:fs";
|
|
55
|
+
import { stat } from "node:fs/promises";
|
|
56
|
+
import { ScopeTracker } from "@ac-kit/app-report";
|
|
57
|
+
import { LockHold, Mutex } from "@ac-kit/async";
|
|
58
|
+
import { BYTES_PER_MIB, defaults, serializeQueueNext } from "@ac-kit/core";
|
|
59
|
+
import { compressFile, existsAsync, nodeWriteAsync } from "@ac-kit/node";
|
|
60
|
+
import { ROTATE_LOG_FILES_DEFAULT_OPTIONS, rotateLogFiles, } from "./rotate-log-files.js";
|
|
61
|
+
const ROTATING_FILE_SINK_DEFAULT_OPTIONS = {
|
|
62
|
+
...ROTATE_LOG_FILES_DEFAULT_OPTIONS,
|
|
63
|
+
cutOffFileSize: 10 * BYTES_PER_MIB,
|
|
64
|
+
maxFileAgeMs: null,
|
|
65
|
+
useCompression: false,
|
|
66
|
+
eol: "\n",
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Renders through a {@link Formatter} into a file, with rotation by size and/or
|
|
70
|
+
* age. Extracted from `@ac-kit/app-logger`'s `FilePrinter`, generic over
|
|
71
|
+
* `TData` so measure/process output gains rotation for free.
|
|
72
|
+
*/
|
|
73
|
+
export class RotatingFileSink {
|
|
74
|
+
filePath;
|
|
75
|
+
scopeTracker = new ScopeTracker();
|
|
76
|
+
formatter;
|
|
77
|
+
options;
|
|
78
|
+
fileStream = null;
|
|
79
|
+
streamLock = new Mutex();
|
|
80
|
+
rotationLock = new Mutex();
|
|
81
|
+
rotationSqn = serializeQueueNext(() => this.handleRotation());
|
|
82
|
+
constructor(filePath, options) {
|
|
83
|
+
this.filePath = filePath;
|
|
84
|
+
const { formatter, ...rest } = options;
|
|
85
|
+
this.formatter = formatter;
|
|
86
|
+
this.options = defaults(rest, ROTATING_FILE_SINK_DEFAULT_OPTIONS);
|
|
87
|
+
}
|
|
88
|
+
async write(event, signal) {
|
|
89
|
+
this.scopeTracker.observe(event);
|
|
90
|
+
const line = this.formatter(event, { scopes: this.scopeTracker });
|
|
91
|
+
if (line === null) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
{
|
|
95
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
96
|
+
try {
|
|
97
|
+
const _streamLock = __addDisposableResource(env_1, await LockHold.from([this.streamLock]), true);
|
|
98
|
+
const stream = await this.openStream();
|
|
99
|
+
signal?.throwIfAborted();
|
|
100
|
+
await nodeWriteAsync(stream, line + this.options.eol);
|
|
101
|
+
}
|
|
102
|
+
catch (e_1) {
|
|
103
|
+
env_1.error = e_1;
|
|
104
|
+
env_1.hasError = true;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
const result_1 = __disposeResources(env_1);
|
|
108
|
+
if (result_1)
|
|
109
|
+
await result_1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
await this.rotationSqn();
|
|
113
|
+
}
|
|
114
|
+
async flush() {
|
|
115
|
+
await this.rotationSqn();
|
|
116
|
+
}
|
|
117
|
+
async close() {
|
|
118
|
+
{
|
|
119
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
120
|
+
try {
|
|
121
|
+
const _streamLock = __addDisposableResource(env_2, await LockHold.from([this.streamLock]), true);
|
|
122
|
+
await this.closeStream();
|
|
123
|
+
}
|
|
124
|
+
catch (e_2) {
|
|
125
|
+
env_2.error = e_2;
|
|
126
|
+
env_2.hasError = true;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
const result_2 = __disposeResources(env_2);
|
|
130
|
+
if (result_2)
|
|
131
|
+
await result_2;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
await this.rotationSqn();
|
|
135
|
+
}
|
|
136
|
+
async openStream() {
|
|
137
|
+
if (!this.fileStream) {
|
|
138
|
+
const stream = createWriteStream(this.filePath, { flags: "a" });
|
|
139
|
+
// `once()` rejects on an "error" emitted before the awaited event.
|
|
140
|
+
await once(stream, "open");
|
|
141
|
+
this.fileStream = stream;
|
|
142
|
+
this.fileStream.on("close", () => {
|
|
143
|
+
this.fileStream = null;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return this.fileStream;
|
|
147
|
+
}
|
|
148
|
+
async closeStream() {
|
|
149
|
+
const stream = this.fileStream;
|
|
150
|
+
this.fileStream = null;
|
|
151
|
+
if (!stream) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
stream.end();
|
|
155
|
+
await once(stream, "finish");
|
|
156
|
+
}
|
|
157
|
+
async handleRotation() {
|
|
158
|
+
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
159
|
+
try {
|
|
160
|
+
const _rotationLock = __addDisposableResource(env_3, await LockHold.from([this.rotationLock]), true);
|
|
161
|
+
const { cutOffFileSize, maxFileAgeMs, useCompression } = this.options;
|
|
162
|
+
if (cutOffFileSize === null && maxFileAgeMs === null) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
let stats;
|
|
166
|
+
try {
|
|
167
|
+
stats = await stat(this.filePath);
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const exceedsSize = cutOffFileSize !== null && stats.size >= cutOffFileSize;
|
|
173
|
+
const exceedsAge = maxFileAgeMs !== null &&
|
|
174
|
+
Date.now() - stats.mtime.getTime() >= maxFileAgeMs;
|
|
175
|
+
if (!exceedsSize && !exceedsAge) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
{
|
|
179
|
+
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
180
|
+
try {
|
|
181
|
+
const _streamLock = __addDisposableResource(env_4, await LockHold.from([this.streamLock]), true);
|
|
182
|
+
await this.closeStream();
|
|
183
|
+
await rotateLogFiles(this.filePath, this.options);
|
|
184
|
+
}
|
|
185
|
+
catch (e_3) {
|
|
186
|
+
env_4.error = e_3;
|
|
187
|
+
env_4.hasError = true;
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
const result_3 = __disposeResources(env_4);
|
|
191
|
+
if (result_3)
|
|
192
|
+
await result_3;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// `rotateLogFiles` always renames the just-rotated file to `.0` — every
|
|
196
|
+
// older generation shifts up (`.0`→`.1`, …) in the same call, so `.0` is
|
|
197
|
+
// unambiguously *this* rotation's file, unlike a fixed-generation number.
|
|
198
|
+
if (useCompression && (await existsAsync(`${this.filePath}.0`))) {
|
|
199
|
+
await compressFile(`${this.filePath}.0`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (e_4) {
|
|
203
|
+
env_3.error = e_4;
|
|
204
|
+
env_3.hasError = true;
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
const result_4 = __disposeResources(env_3);
|
|
208
|
+
if (result_4)
|
|
209
|
+
await result_4;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=rotating-file-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotating-file-sink.js","sourceRoot":"","sources":["../../src/fs/rotating-file-sink.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;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D,CAAC;YAED,wEAAwE;YACxE,yEAAyE;YACzE,0EAA0E;YAC1E,IAAI,cAAc,IAAI,CAAC,MAAM,WAAW,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;gBACjE,MAAM,YAAY,CAAC,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;YAC1C,CAAC;;;;;;;;;;;IACF,CAAC;CACD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./async/file-lock.js";
|
|
2
|
+
export * from "./async/udp-bind-lock.js";
|
|
3
|
+
export * from "./fs/artifact-cache.js";
|
|
4
|
+
export * from "./fs/rotate-log-files.js";
|
|
5
|
+
export * from "./fs/rotating-file-sink.js";
|
|
6
|
+
export * from "./os/get-processes-snapshot.js";
|
|
7
|
+
export * from "./os/host-metrics.js";
|
|
8
|
+
export * from "./os/process-kill-by-pid-file.js";
|
|
9
|
+
export * from "./os/process-wait-pid.js";
|
|
10
|
+
export * from "./os/ps.js";
|
|
11
|
+
export * from "./os/sysfs.js";
|
|
12
|
+
export * from "./process/child-process-message-sink.js";
|
|
13
|
+
export * from "./process/error-listeners.js";
|
|
14
|
+
export * from "./process/exit-manager.js";
|
|
15
|
+
export * from "./process/has-binary.js";
|
|
16
|
+
export * from "./process/pid-file.js";
|
|
17
|
+
export * from "./process/process-pid-file.js";
|
|
18
|
+
export * from "./process/report-process.js";
|
|
19
|
+
export * from "./shell/shorten-posix-path.js";
|
|
20
|
+
export * from "./terminal/node-terminal.js";
|
|
21
|
+
export * from "./text/charset-decode-stream.js";
|
|
22
|
+
export * from "./text/charset-encode-stream.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,yCAAyC,CAAC;AACxD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from "./async/file-lock.js";
|
|
2
|
+
export * from "./async/udp-bind-lock.js";
|
|
3
|
+
export * from "./fs/artifact-cache.js";
|
|
4
|
+
export * from "./fs/rotate-log-files.js";
|
|
5
|
+
export * from "./fs/rotating-file-sink.js";
|
|
6
|
+
export * from "./os/get-processes-snapshot.js";
|
|
7
|
+
export * from "./os/host-metrics.js";
|
|
8
|
+
export * from "./os/process-kill-by-pid-file.js";
|
|
9
|
+
export * from "./os/process-wait-pid.js";
|
|
10
|
+
export * from "./os/ps.js";
|
|
11
|
+
export * from "./os/sysfs.js";
|
|
12
|
+
export * from "./process/child-process-message-sink.js";
|
|
13
|
+
export * from "./process/error-listeners.js";
|
|
14
|
+
export * from "./process/exit-manager.js";
|
|
15
|
+
export * from "./process/has-binary.js";
|
|
16
|
+
export * from "./process/pid-file.js";
|
|
17
|
+
export * from "./process/process-pid-file.js";
|
|
18
|
+
export * from "./process/report-process.js";
|
|
19
|
+
export * from "./shell/shorten-posix-path.js";
|
|
20
|
+
export * from "./terminal/node-terminal.js";
|
|
21
|
+
export * from "./text/charset-decode-stream.js";
|
|
22
|
+
export * from "./text/charset-encode-stream.js";
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,yCAAyC,CAAC;AACxD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { TupleToUnion } from "type-fest";
|
|
2
|
+
export type ProcessInfo = {
|
|
3
|
+
parentId: number;
|
|
4
|
+
id: number;
|
|
5
|
+
command: [string, ...string[]];
|
|
6
|
+
userName: string;
|
|
7
|
+
groupName: string;
|
|
8
|
+
memoryUsage: number;
|
|
9
|
+
cpuUsage: number;
|
|
10
|
+
accumulatedCpuUsageMs: number;
|
|
11
|
+
startTime: Date;
|
|
12
|
+
};
|
|
13
|
+
export type GetProcessesSnapshotFilters = {
|
|
14
|
+
parentId?: number;
|
|
15
|
+
id?: number;
|
|
16
|
+
command?: [string | RegExp, ...Array<string | RegExp>];
|
|
17
|
+
userName?: string;
|
|
18
|
+
groupName?: string;
|
|
19
|
+
minMemoryUsage?: number;
|
|
20
|
+
maxMemoryUsage?: number;
|
|
21
|
+
minCpuUsage?: number;
|
|
22
|
+
maxCpuUsage?: number;
|
|
23
|
+
minAccumulatedCpuUsageMs?: number;
|
|
24
|
+
maxAccumulatedCpuUsageMs?: number;
|
|
25
|
+
minStartTime?: Date;
|
|
26
|
+
maxStartTime?: Date;
|
|
27
|
+
};
|
|
28
|
+
export type GetProcessesSnapshotOptions = {
|
|
29
|
+
/** Filters to apply to the process list. */
|
|
30
|
+
filters?: GetProcessesSnapshotFilters | null;
|
|
31
|
+
/**
|
|
32
|
+
* Fields to include in the result. Defaults to `null`.
|
|
33
|
+
*
|
|
34
|
+
* If the array is empty or not provided, all available fields will be
|
|
35
|
+
* included in the result.
|
|
36
|
+
*/
|
|
37
|
+
fields?: (keyof ProcessInfo)[] | null;
|
|
38
|
+
/** Optional signal that can be used to abort the operation. */
|
|
39
|
+
signal?: AbortSignal | null;
|
|
40
|
+
};
|
|
41
|
+
export declare function getProcessesSnapshotPosix<O extends GetProcessesSnapshotOptions = GetProcessesSnapshotOptions, R = O["fields"] extends never[] ? ProcessInfo : Pick<ProcessInfo, TupleToUnion<O["fields"]>>>(options?: O): Promise<R[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Not supported on Windows.
|
|
44
|
+
*
|
|
45
|
+
* The POSIX implementation reads `ps`, which Windows has no equivalent of:
|
|
46
|
+
* `tasklist` and WMI both report a different field set under different names,
|
|
47
|
+
* so this would be a second implementation rather than a port. Until one
|
|
48
|
+
* exists, the call fails loudly instead of returning a partial snapshot a
|
|
49
|
+
* caller would read as complete.
|
|
50
|
+
*
|
|
51
|
+
* @throws {UnimplementedError} Always.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getProcessesSnapshotWin32<O extends GetProcessesSnapshotOptions = GetProcessesSnapshotOptions, R = O["fields"] extends never[] ? ProcessInfo : Pick<ProcessInfo, TupleToUnion<O["fields"]>>>(_options?: O): Promise<R[]>;
|
|
54
|
+
export type GetProcessesSnapshot = <O extends GetProcessesSnapshotOptions = GetProcessesSnapshotOptions, R = O["fields"] extends never[] ? ProcessInfo : Pick<ProcessInfo, TupleToUnion<O["fields"]>>>(options?: O) => Promise<R[]>;
|
|
55
|
+
export declare const getProcessesSnapshot: GetProcessesSnapshot;
|
|
56
|
+
//# sourceMappingURL=get-processes-snapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-processes-snapshot.d.ts","sourceRoot":"","sources":["../../src/os/get-processes-snapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,WAAW,CAAC;AAI7D,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wB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