devkill 0.12.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 +21 -0
- package/README.es.md +253 -0
- package/README.id.md +238 -0
- package/README.md +377 -0
- package/README.pt.md +241 -0
- package/README.tr.md +242 -0
- package/lib/cli/cli.controller.d.ts +81 -0
- package/lib/cli/cli.controller.js +760 -0
- package/lib/cli/cli.controller.js.map +1 -0
- package/lib/cli/interfaces/cli-options.interface.d.ts +5 -0
- package/lib/cli/interfaces/cli-options.interface.js +2 -0
- package/lib/cli/interfaces/cli-options.interface.js.map +1 -0
- package/lib/cli/interfaces/command-keys.interface.d.ts +17 -0
- package/lib/cli/interfaces/command-keys.interface.js +2 -0
- package/lib/cli/interfaces/command-keys.interface.js.map +1 -0
- package/lib/cli/interfaces/config.interface.d.ts +17 -0
- package/lib/cli/interfaces/config.interface.js +2 -0
- package/lib/cli/interfaces/config.interface.js.map +1 -0
- package/lib/cli/interfaces/index.d.ts +11 -0
- package/lib/cli/interfaces/index.js +12 -0
- package/lib/cli/interfaces/index.js.map +1 -0
- package/lib/cli/interfaces/json-output.interface.d.ts +30 -0
- package/lib/cli/interfaces/json-output.interface.js +2 -0
- package/lib/cli/interfaces/json-output.interface.js.map +1 -0
- package/lib/cli/interfaces/key-press.interface.d.ts +7 -0
- package/lib/cli/interfaces/key-press.interface.js +2 -0
- package/lib/cli/interfaces/key-press.interface.js.map +1 -0
- package/lib/cli/interfaces/node-version.interface.d.ts +5 -0
- package/lib/cli/interfaces/node-version.interface.js +2 -0
- package/lib/cli/interfaces/node-version.interface.js.map +1 -0
- package/lib/cli/interfaces/stats.interface.d.ts +15 -0
- package/lib/cli/interfaces/stats.interface.js +2 -0
- package/lib/cli/interfaces/stats.interface.js.map +1 -0
- package/lib/cli/interfaces/ui-positions.interface.d.ts +5 -0
- package/lib/cli/interfaces/ui-positions.interface.js +2 -0
- package/lib/cli/interfaces/ui-positions.interface.js.map +1 -0
- package/lib/cli/interfaces/version.interface.d.ts +5 -0
- package/lib/cli/interfaces/version.interface.js +2 -0
- package/lib/cli/interfaces/version.interface.js.map +1 -0
- package/lib/cli/models/start-parameters.model.d.ts +7 -0
- package/lib/cli/models/start-parameters.model.js +25 -0
- package/lib/cli/models/start-parameters.model.js.map +1 -0
- package/lib/cli/services/console.service.d.ts +23 -0
- package/lib/cli/services/console.service.js +87 -0
- package/lib/cli/services/console.service.js.map +1 -0
- package/lib/cli/services/https.service.d.ts +4 -0
- package/lib/cli/services/https.service.js +32 -0
- package/lib/cli/services/https.service.js.map +1 -0
- package/lib/cli/services/index.d.ts +7 -0
- package/lib/cli/services/index.js +8 -0
- package/lib/cli/services/index.js.map +1 -0
- package/lib/cli/services/json-output.service.d.ts +20 -0
- package/lib/cli/services/json-output.service.js +101 -0
- package/lib/cli/services/json-output.service.js.map +1 -0
- package/lib/cli/services/results.service.d.ts +13 -0
- package/lib/cli/services/results.service.js +61 -0
- package/lib/cli/services/results.service.js.map +1 -0
- package/lib/cli/services/scan.service.d.ts +13 -0
- package/lib/cli/services/scan.service.js +79 -0
- package/lib/cli/services/scan.service.js.map +1 -0
- package/lib/cli/services/spinner.service.d.ts +9 -0
- package/lib/cli/services/spinner.service.js +27 -0
- package/lib/cli/services/spinner.service.js.map +1 -0
- package/lib/cli/services/ui.service.d.ts +17 -0
- package/lib/cli/services/ui.service.js +59 -0
- package/lib/cli/services/ui.service.js.map +1 -0
- package/lib/cli/services/update.service.d.ts +15 -0
- package/lib/cli/services/update.service.js +37 -0
- package/lib/cli/services/update.service.js.map +1 -0
- package/lib/cli/ui/base.ui.d.ts +28 -0
- package/lib/cli/ui/base.ui.js +49 -0
- package/lib/cli/ui/base.ui.js.map +1 -0
- package/lib/cli/ui/components/general.ui.d.ts +7 -0
- package/lib/cli/ui/components/general.ui.js +13 -0
- package/lib/cli/ui/components/general.ui.js.map +1 -0
- package/lib/cli/ui/components/header/header-ui.constants.d.ts +7 -0
- package/lib/cli/ui/components/header/header-ui.constants.js +7 -0
- package/lib/cli/ui/components/header/header-ui.constants.js.map +1 -0
- package/lib/cli/ui/components/header/header.ui.d.ts +18 -0
- package/lib/cli/ui/components/header/header.ui.js +96 -0
- package/lib/cli/ui/components/header/header.ui.js.map +1 -0
- package/lib/cli/ui/components/header/stats.ui.d.ts +25 -0
- package/lib/cli/ui/components/header/stats.ui.js +198 -0
- package/lib/cli/ui/components/header/stats.ui.js.map +1 -0
- package/lib/cli/ui/components/header/status.ui.d.ts +33 -0
- package/lib/cli/ui/components/header/status.ui.js +188 -0
- package/lib/cli/ui/components/header/status.ui.js.map +1 -0
- package/lib/cli/ui/components/help/help-command.ui.d.ts +9 -0
- package/lib/cli/ui/components/help/help-command.ui.js +61 -0
- package/lib/cli/ui/components/help/help-command.ui.js.map +1 -0
- package/lib/cli/ui/components/help/help.constants.d.ts +8 -0
- package/lib/cli/ui/components/help/help.constants.js +270 -0
- package/lib/cli/ui/components/help/help.constants.js.map +1 -0
- package/lib/cli/ui/components/help/help.ui.d.ts +30 -0
- package/lib/cli/ui/components/help/help.ui.js +176 -0
- package/lib/cli/ui/components/help/help.ui.js.map +1 -0
- package/lib/cli/ui/components/logs.ui.d.ts +24 -0
- package/lib/cli/ui/components/logs.ui.js +132 -0
- package/lib/cli/ui/components/logs.ui.js.map +1 -0
- package/lib/cli/ui/components/options.ui.d.ts +29 -0
- package/lib/cli/ui/components/options.ui.js +327 -0
- package/lib/cli/ui/components/options.ui.js.map +1 -0
- package/lib/cli/ui/components/profile-picker.ui.d.ts +25 -0
- package/lib/cli/ui/components/profile-picker.ui.js +117 -0
- package/lib/cli/ui/components/profile-picker.ui.js.map +1 -0
- package/lib/cli/ui/components/result-details.ui.d.ts +23 -0
- package/lib/cli/ui/components/result-details.ui.js +182 -0
- package/lib/cli/ui/components/result-details.ui.js.map +1 -0
- package/lib/cli/ui/components/results.ui.d.ts +86 -0
- package/lib/cli/ui/components/results.ui.js +620 -0
- package/lib/cli/ui/components/results.ui.js.map +1 -0
- package/lib/cli/ui/components/warning.ui.d.ts +12 -0
- package/lib/cli/ui/components/warning.ui.js +30 -0
- package/lib/cli/ui/components/warning.ui.js.map +1 -0
- package/lib/cli/ui/heavy.ui.d.ts +18 -0
- package/lib/cli/ui/heavy.ui.js +37 -0
- package/lib/cli/ui/heavy.ui.js.map +1 -0
- package/lib/cli/ui/index.d.ts +14 -0
- package/lib/cli/ui/index.js +15 -0
- package/lib/cli/ui/index.js.map +1 -0
- package/lib/constants/cli.constants.d.ts +14 -0
- package/lib/constants/cli.constants.js +138 -0
- package/lib/constants/cli.constants.js.map +1 -0
- package/lib/constants/index.d.ts +8 -0
- package/lib/constants/index.js +9 -0
- package/lib/constants/index.js.map +1 -0
- package/lib/constants/main.constants.d.ts +96 -0
- package/lib/constants/main.constants.js +79 -0
- package/lib/constants/main.constants.js.map +1 -0
- package/lib/constants/messages.constants.d.ts +31 -0
- package/lib/constants/messages.constants.js +37 -0
- package/lib/constants/messages.constants.js.map +1 -0
- package/lib/constants/options.constants.d.ts +6 -0
- package/lib/constants/options.constants.js +8 -0
- package/lib/constants/options.constants.js.map +1 -0
- package/lib/constants/os-service-map.constants.d.ts +10 -0
- package/lib/constants/os-service-map.constants.js +11 -0
- package/lib/constants/os-service-map.constants.js.map +1 -0
- package/lib/constants/result-descriptions.constants.d.ts +142 -0
- package/lib/constants/result-descriptions.constants.js +203 -0
- package/lib/constants/result-descriptions.constants.js.map +1 -0
- package/lib/constants/sort.result.d.ts +6 -0
- package/lib/constants/sort.result.js +22 -0
- package/lib/constants/sort.result.js.map +1 -0
- package/lib/constants/spinner.constants.d.ts +5 -0
- package/lib/constants/spinner.constants.js +88 -0
- package/lib/constants/spinner.constants.js.map +1 -0
- package/lib/constants/status.constants.d.ts +7 -0
- package/lib/constants/status.constants.js +9 -0
- package/lib/constants/status.constants.js.map +1 -0
- package/lib/constants/update.constants.d.ts +2 -0
- package/lib/constants/update.constants.js +3 -0
- package/lib/constants/update.constants.js.map +1 -0
- package/lib/constants/workers.constants.d.ts +14 -0
- package/lib/constants/workers.constants.js +16 -0
- package/lib/constants/workers.constants.js.map +1 -0
- package/lib/core/constants/global-ignored.constants.d.ts +1 -0
- package/lib/core/constants/global-ignored.constants.js +44 -0
- package/lib/core/constants/global-ignored.constants.js.map +1 -0
- package/lib/core/constants/index.d.ts +1 -0
- package/lib/core/constants/index.js +2 -0
- package/lib/core/constants/index.js.map +1 -0
- package/lib/core/constants/profiles.constants.d.ts +8 -0
- package/lib/core/constants/profiles.constants.js +138 -0
- package/lib/core/constants/profiles.constants.js.map +1 -0
- package/lib/core/devkill.d.ts +25 -0
- package/lib/core/devkill.js +129 -0
- package/lib/core/devkill.js.map +1 -0
- package/lib/core/index.d.ts +4 -0
- package/lib/core/index.js +5 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/interfaces/devkill.interface.d.ts +78 -0
- package/lib/core/interfaces/devkill.interface.js +2 -0
- package/lib/core/interfaces/devkill.interface.js.map +1 -0
- package/lib/core/interfaces/devkillrc-config.interface.d.ts +87 -0
- package/lib/core/interfaces/devkillrc-config.interface.js +12 -0
- package/lib/core/interfaces/devkillrc-config.interface.js.map +1 -0
- package/lib/core/interfaces/file-service.interface.d.ts +76 -0
- package/lib/core/interfaces/file-service.interface.js +2 -0
- package/lib/core/interfaces/file-service.interface.js.map +1 -0
- package/lib/core/interfaces/folder.interface.d.ts +89 -0
- package/lib/core/interfaces/folder.interface.js +2 -0
- package/lib/core/interfaces/folder.interface.js.map +1 -0
- package/lib/core/interfaces/index.d.ts +6 -0
- package/lib/core/interfaces/index.js +7 -0
- package/lib/core/interfaces/index.js.map +1 -0
- package/lib/core/interfaces/logger-service.interface.d.ts +59 -0
- package/lib/core/interfaces/logger-service.interface.js +2 -0
- package/lib/core/interfaces/logger-service.interface.js.map +1 -0
- package/lib/core/interfaces/npkill.interface.d.ts +78 -0
- package/lib/core/interfaces/npkill.interface.js +2 -0
- package/lib/core/interfaces/npkill.interface.js.map +1 -0
- package/lib/core/interfaces/npkillrc-config.interface.d.ts +87 -0
- package/lib/core/interfaces/npkillrc-config.interface.js +12 -0
- package/lib/core/interfaces/npkillrc-config.interface.js.map +1 -0
- package/lib/core/interfaces/profile.interface.d.ts +9 -0
- package/lib/core/interfaces/profile.interface.js +2 -0
- package/lib/core/interfaces/profile.interface.js.map +1 -0
- package/lib/core/interfaces/search-status.model.d.ts +35 -0
- package/lib/core/interfaces/search-status.model.js +48 -0
- package/lib/core/interfaces/search-status.model.js.map +1 -0
- package/lib/core/interfaces/services.interface.d.ts +26 -0
- package/lib/core/interfaces/services.interface.js +2 -0
- package/lib/core/interfaces/services.interface.js.map +1 -0
- package/lib/core/npkill.d.ts +25 -0
- package/lib/core/npkill.js +129 -0
- package/lib/core/npkill.js.map +1 -0
- package/lib/core/services/config/config-merger.d.ts +17 -0
- package/lib/core/services/config/config-merger.js +57 -0
- package/lib/core/services/config/config-merger.js.map +1 -0
- package/lib/core/services/config/config-validator.d.ts +3 -0
- package/lib/core/services/config/config-validator.js +43 -0
- package/lib/core/services/config/config-validator.js.map +1 -0
- package/lib/core/services/config/index.d.ts +4 -0
- package/lib/core/services/config/index.js +5 -0
- package/lib/core/services/config/index.js.map +1 -0
- package/lib/core/services/config/profile-validator.d.ts +6 -0
- package/lib/core/services/config/profile-validator.js +68 -0
- package/lib/core/services/config/profile-validator.js.map +1 -0
- package/lib/core/services/config/property-validators.d.ts +33 -0
- package/lib/core/services/config/property-validators.js +125 -0
- package/lib/core/services/config/property-validators.js.map +1 -0
- package/lib/core/services/config.service.d.ts +37 -0
- package/lib/core/services/config.service.js +100 -0
- package/lib/core/services/config.service.js.map +1 -0
- package/lib/core/services/files/files.service.d.ts +28 -0
- package/lib/core/services/files/files.service.js +207 -0
- package/lib/core/services/files/files.service.js.map +1 -0
- package/lib/core/services/files/files.worker.d.ts +1 -0
- package/lib/core/services/files/files.worker.js +286 -0
- package/lib/core/services/files/files.worker.js.map +1 -0
- package/lib/core/services/files/files.worker.service.d.ts +90 -0
- package/lib/core/services/files/files.worker.service.js +216 -0
- package/lib/core/services/files/files.worker.service.js.map +1 -0
- package/lib/core/services/files/index.d.ts +4 -0
- package/lib/core/services/files/index.js +5 -0
- package/lib/core/services/files/index.js.map +1 -0
- package/lib/core/services/files/unix-files.service.d.ts +9 -0
- package/lib/core/services/files/unix-files.service.js +28 -0
- package/lib/core/services/files/unix-files.service.js.map +1 -0
- package/lib/core/services/files/windows-files.service.d.ts +9 -0
- package/lib/core/services/files/windows-files.service.js +16 -0
- package/lib/core/services/files/windows-files.service.js.map +1 -0
- package/lib/core/services/index.d.ts +5 -0
- package/lib/core/services/index.js +6 -0
- package/lib/core/services/index.js.map +1 -0
- package/lib/core/services/logger.service.d.ts +22 -0
- package/lib/core/services/logger.service.js +84 -0
- package/lib/core/services/logger.service.js.map +1 -0
- package/lib/core/services/profiles.service.d.ts +54 -0
- package/lib/core/services/profiles.service.js +86 -0
- package/lib/core/services/profiles.service.js.map +1 -0
- package/lib/core/services/stream.service.d.ts +12 -0
- package/lib/core/services/stream.service.js +39 -0
- package/lib/core/services/stream.service.js.map +1 -0
- package/lib/dirname.d.ts +2 -0
- package/lib/dirname.js +6 -0
- package/lib/dirname.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/main.d.ts +2 -0
- package/lib/main.js +19 -0
- package/lib/main.js.map +1 -0
- package/lib/utils/get-file-content.d.ts +1 -0
- package/lib/utils/get-file-content.js +6 -0
- package/lib/utils/get-file-content.js.map +1 -0
- package/lib/utils/is-safe-to-delete.d.ts +1 -0
- package/lib/utils/is-safe-to-delete.js +9 -0
- package/lib/utils/is-safe-to-delete.js.map +1 -0
- package/lib/utils/unit-conversions.d.ts +11 -0
- package/lib/utils/unit-conversions.js +54 -0
- package/lib/utils/unit-conversions.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type MessagePort } from 'node:worker_threads';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
import { EVENTS } from '../../../constants/workers.constants.js';
|
|
4
|
+
import type { ScanOptions } from '../../index.js';
|
|
5
|
+
import type { ScanStatus } from '../../interfaces/search-status.model.js';
|
|
6
|
+
import type { LoggerService } from '../logger.service.js';
|
|
7
|
+
export type WorkerStatus = 'stopped' | 'scanning' | 'dead' | 'finished';
|
|
8
|
+
export interface WorkerScanOptions extends ScanOptions {
|
|
9
|
+
rootPath: string;
|
|
10
|
+
}
|
|
11
|
+
export type WorkerMessage = {
|
|
12
|
+
type: typeof EVENTS.scanResult;
|
|
13
|
+
value: {
|
|
14
|
+
results: Array<{
|
|
15
|
+
path: string;
|
|
16
|
+
isTarget: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
workerId: number;
|
|
19
|
+
pending: number;
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
type: typeof EVENTS.GetSizeResult;
|
|
23
|
+
value: {
|
|
24
|
+
results: {
|
|
25
|
+
path: string;
|
|
26
|
+
size: number;
|
|
27
|
+
};
|
|
28
|
+
workerId: number;
|
|
29
|
+
pending: number;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
type: typeof EVENTS.explore | typeof EVENTS.getFolderSize;
|
|
33
|
+
value: {
|
|
34
|
+
path: string;
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
type: typeof EVENTS.exploreConfig;
|
|
38
|
+
value: WorkerScanOptions;
|
|
39
|
+
} | {
|
|
40
|
+
type: typeof EVENTS.startup;
|
|
41
|
+
value: {
|
|
42
|
+
channel: MessagePort;
|
|
43
|
+
id: number;
|
|
44
|
+
};
|
|
45
|
+
} | {
|
|
46
|
+
type: typeof EVENTS.alive;
|
|
47
|
+
value?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
type: typeof EVENTS.stop;
|
|
50
|
+
value?: undefined;
|
|
51
|
+
} | {
|
|
52
|
+
type: typeof EVENTS.error;
|
|
53
|
+
value: {
|
|
54
|
+
error: Error;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export interface WorkerStats {
|
|
58
|
+
pendingSearchTasks: number;
|
|
59
|
+
completedSearchTasks: number;
|
|
60
|
+
procs: number;
|
|
61
|
+
}
|
|
62
|
+
export declare class FileWorkerService {
|
|
63
|
+
private readonly logger;
|
|
64
|
+
private readonly searchStatus;
|
|
65
|
+
private index;
|
|
66
|
+
private workers;
|
|
67
|
+
private workersPendingJobs;
|
|
68
|
+
private getSizePendings;
|
|
69
|
+
private pendingJobs;
|
|
70
|
+
private totalJobs;
|
|
71
|
+
private tunnels;
|
|
72
|
+
private shouldStop;
|
|
73
|
+
private readonly SIZE_TIMEOUT_MS;
|
|
74
|
+
constructor(logger: LoggerService, searchStatus: ScanStatus);
|
|
75
|
+
startScan(stream$: Subject<string>, params: WorkerScanOptions): Promise<void>;
|
|
76
|
+
getFolderSize(stream$: Subject<number>, path: string): void;
|
|
77
|
+
stopScan(): void;
|
|
78
|
+
private listenEvents;
|
|
79
|
+
private newWorkerMessage;
|
|
80
|
+
/** Jobs are distributed following the round-robin algorithm. */
|
|
81
|
+
private addJob;
|
|
82
|
+
private checkJobComplete;
|
|
83
|
+
private instantiateWorkers;
|
|
84
|
+
private setWorkerConfig;
|
|
85
|
+
private killWorkers;
|
|
86
|
+
private getPendingJobs;
|
|
87
|
+
private updateStats;
|
|
88
|
+
private getWorkerPath;
|
|
89
|
+
private getOptimalNumberOfWorkers;
|
|
90
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { dirname, extname } from 'node:path';
|
|
3
|
+
import { MessageChannel, Worker } from 'node:worker_threads';
|
|
4
|
+
import { Subject } from 'rxjs';
|
|
5
|
+
import { EVENTS, MAX_WORKERS } from '../../../constants/workers.constants.js';
|
|
6
|
+
export class FileWorkerService {
|
|
7
|
+
logger;
|
|
8
|
+
searchStatus;
|
|
9
|
+
index = 0;
|
|
10
|
+
workers = [];
|
|
11
|
+
workersPendingJobs = [];
|
|
12
|
+
getSizePendings = [];
|
|
13
|
+
pendingJobs = 0;
|
|
14
|
+
totalJobs = 0;
|
|
15
|
+
tunnels = [];
|
|
16
|
+
shouldStop = false;
|
|
17
|
+
SIZE_TIMEOUT_MS = 60000; // 1 minute timeout per folder
|
|
18
|
+
constructor(logger, searchStatus) {
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
this.searchStatus = searchStatus;
|
|
21
|
+
}
|
|
22
|
+
async startScan(stream$, params) {
|
|
23
|
+
await this.killWorkers();
|
|
24
|
+
this.totalJobs = 0;
|
|
25
|
+
this.pendingJobs = 0;
|
|
26
|
+
this.index = 0;
|
|
27
|
+
this.workersPendingJobs = [];
|
|
28
|
+
this.shouldStop = false;
|
|
29
|
+
this.instantiateWorkers(this.getOptimalNumberOfWorkers());
|
|
30
|
+
this.listenEvents(stream$);
|
|
31
|
+
this.setWorkerConfig(params);
|
|
32
|
+
// Manually add the first job.
|
|
33
|
+
this.addJob({ job: EVENTS.explore, value: { path: params.rootPath } });
|
|
34
|
+
}
|
|
35
|
+
getFolderSize(stream$, path) {
|
|
36
|
+
if (this.workers.length === 0) {
|
|
37
|
+
this.instantiateWorkers(this.getOptimalNumberOfWorkers());
|
|
38
|
+
this.listenEvents(new Subject());
|
|
39
|
+
this.setWorkerConfig({ rootPath: path });
|
|
40
|
+
}
|
|
41
|
+
const timeoutId = setTimeout(() => {
|
|
42
|
+
const index = this.getSizePendings.findIndex((p) => p.path === path);
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
this.logger.error(`Timeout calculating size for: ${path} (${this.SIZE_TIMEOUT_MS}ms)`);
|
|
45
|
+
const pending = this.getSizePendings[index];
|
|
46
|
+
pending.stream$.error(new Error(`Timeout calculating size for ${path}`));
|
|
47
|
+
this.getSizePendings.splice(index, 1);
|
|
48
|
+
}
|
|
49
|
+
}, this.SIZE_TIMEOUT_MS);
|
|
50
|
+
this.getSizePendings.push({ path, stream$, timeoutId });
|
|
51
|
+
this.addJob({ job: EVENTS.getFolderSize, value: { path } });
|
|
52
|
+
}
|
|
53
|
+
stopScan() {
|
|
54
|
+
this.logger.info('Stopping scan...');
|
|
55
|
+
this.shouldStop = true;
|
|
56
|
+
this.searchStatus.workerStatus = 'stopped';
|
|
57
|
+
this.tunnels.forEach((tunnel) => {
|
|
58
|
+
tunnel.postMessage({
|
|
59
|
+
type: EVENTS.stop,
|
|
60
|
+
value: undefined,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
void this.killWorkers();
|
|
64
|
+
}
|
|
65
|
+
listenEvents(stream$) {
|
|
66
|
+
this.tunnels.forEach((tunnel) => {
|
|
67
|
+
tunnel.on('message', (data) => {
|
|
68
|
+
this.newWorkerMessage(data, stream$);
|
|
69
|
+
});
|
|
70
|
+
this.workers.forEach((worker, index) => {
|
|
71
|
+
worker.on('exit', () => {
|
|
72
|
+
this.logger.info(`Worker ${index} exited.`);
|
|
73
|
+
});
|
|
74
|
+
worker.on('error', (error) => {
|
|
75
|
+
// Respawn worker.
|
|
76
|
+
throw error;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
newWorkerMessage(message, stream$) {
|
|
82
|
+
const { type, value } = message;
|
|
83
|
+
if (type === EVENTS.scanResult) {
|
|
84
|
+
const results = value.results;
|
|
85
|
+
const workerId = value.workerId;
|
|
86
|
+
this.workersPendingJobs[workerId] = value.pending;
|
|
87
|
+
results.forEach((result) => {
|
|
88
|
+
const { path, isTarget } = result;
|
|
89
|
+
if (isTarget) {
|
|
90
|
+
stream$.next(path);
|
|
91
|
+
}
|
|
92
|
+
else if (!this.shouldStop) {
|
|
93
|
+
this.addJob({
|
|
94
|
+
job: EVENTS.explore,
|
|
95
|
+
value: { path },
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
this.pendingJobs = this.getPendingJobs();
|
|
100
|
+
this.checkJobComplete(stream$);
|
|
101
|
+
}
|
|
102
|
+
if (type === EVENTS.GetSizeResult) {
|
|
103
|
+
const result = value.results;
|
|
104
|
+
const workerId = value.workerId;
|
|
105
|
+
this.workersPendingJobs[workerId] = value.pending;
|
|
106
|
+
const index = this.getSizePendings.findIndex((pending) => pending.path === result.path);
|
|
107
|
+
if (index !== -1) {
|
|
108
|
+
const pending = this.getSizePendings[index];
|
|
109
|
+
if (pending.timeoutId) {
|
|
110
|
+
clearTimeout(pending.timeoutId);
|
|
111
|
+
}
|
|
112
|
+
pending.stream$.next(result.size);
|
|
113
|
+
pending.stream$.complete();
|
|
114
|
+
this.getSizePendings.splice(index, 1);
|
|
115
|
+
}
|
|
116
|
+
this.pendingJobs = this.getPendingJobs();
|
|
117
|
+
this.checkJobComplete(stream$);
|
|
118
|
+
}
|
|
119
|
+
if (type === EVENTS.alive) {
|
|
120
|
+
this.searchStatus.workerStatus = 'scanning';
|
|
121
|
+
}
|
|
122
|
+
if (type === EVENTS.error) {
|
|
123
|
+
this.logger.error(`Worker error: ${value.error.message}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Jobs are distributed following the round-robin algorithm. */
|
|
127
|
+
addJob(job) {
|
|
128
|
+
if (this.shouldStop) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const tunnel = this.tunnels[this.index];
|
|
132
|
+
const message = { type: job.job, value: job.value };
|
|
133
|
+
tunnel.postMessage(message);
|
|
134
|
+
this.workersPendingJobs[this.index]++;
|
|
135
|
+
this.totalJobs++;
|
|
136
|
+
this.pendingJobs++;
|
|
137
|
+
this.index = this.index >= this.workers.length - 1 ? 0 : this.index + 1;
|
|
138
|
+
}
|
|
139
|
+
checkJobComplete(stream$) {
|
|
140
|
+
this.updateStats();
|
|
141
|
+
const isCompleted = this.getPendingJobs() === 0;
|
|
142
|
+
if (isCompleted) {
|
|
143
|
+
this.searchStatus.workerStatus = 'finished';
|
|
144
|
+
stream$.complete();
|
|
145
|
+
void this.killWorkers();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
instantiateWorkers(amount) {
|
|
149
|
+
this.logger.info(`Instantiating ${amount} workers..`);
|
|
150
|
+
const workerPath = this.getWorkerPath();
|
|
151
|
+
// When running TypeScript source directly (dev/strip mode), workers need
|
|
152
|
+
// tsx's loader so that .js imports resolve to .ts files inside the worker.
|
|
153
|
+
const execArgv = workerPath.pathname.endsWith('.ts')
|
|
154
|
+
? ['--import', 'tsx/esm']
|
|
155
|
+
: undefined;
|
|
156
|
+
for (let i = 0; i < amount; i++) {
|
|
157
|
+
const { port1, port2 } = new MessageChannel();
|
|
158
|
+
const worker = new Worker(workerPath, { execArgv });
|
|
159
|
+
this.tunnels.push(port1);
|
|
160
|
+
worker.postMessage({ type: EVENTS.startup, value: { channel: port2, id: i } }, [port2]);
|
|
161
|
+
this.workers.push(worker);
|
|
162
|
+
this.logger.info(`Worker ${i} instantiated.`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
setWorkerConfig(params) {
|
|
166
|
+
this.tunnels.forEach((tunnel) => tunnel.postMessage({
|
|
167
|
+
type: EVENTS.exploreConfig,
|
|
168
|
+
value: params,
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
async killWorkers() {
|
|
172
|
+
this.getSizePendings.forEach((pending) => {
|
|
173
|
+
if (pending.timeoutId) {
|
|
174
|
+
clearTimeout(pending.timeoutId);
|
|
175
|
+
}
|
|
176
|
+
if (!pending.stream$.closed) {
|
|
177
|
+
pending.stream$.error(new Error('Workers terminated before completion'));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
this.getSizePendings = [];
|
|
181
|
+
for (let i = 0; i < this.workers.length; i++) {
|
|
182
|
+
this.workers[i].removeAllListeners();
|
|
183
|
+
this.tunnels[i].removeAllListeners();
|
|
184
|
+
await this.workers[i]
|
|
185
|
+
.terminate()
|
|
186
|
+
.catch((error) => this.logger.error(error));
|
|
187
|
+
}
|
|
188
|
+
this.workers = [];
|
|
189
|
+
this.tunnels = [];
|
|
190
|
+
}
|
|
191
|
+
getPendingJobs() {
|
|
192
|
+
return this.workersPendingJobs.reduce((acc, x) => x + acc, 0);
|
|
193
|
+
}
|
|
194
|
+
updateStats() {
|
|
195
|
+
this.searchStatus.pendingSearchTasks = this.pendingJobs;
|
|
196
|
+
this.searchStatus.completedSearchTasks = this.totalJobs;
|
|
197
|
+
this.searchStatus.workersJobs = this.workersPendingJobs;
|
|
198
|
+
}
|
|
199
|
+
getWorkerPath() {
|
|
200
|
+
const actualFilePath = import.meta.url;
|
|
201
|
+
const dirPath = dirname(actualFilePath);
|
|
202
|
+
// Extension = .ts if is not transpiled.
|
|
203
|
+
// Extension = .js if is a build
|
|
204
|
+
const extension = extname(actualFilePath);
|
|
205
|
+
const workerName = 'files.worker';
|
|
206
|
+
return new URL(`${dirPath}/${workerName}${extension}`);
|
|
207
|
+
}
|
|
208
|
+
getOptimalNumberOfWorkers() {
|
|
209
|
+
const cores = os.cpus().length;
|
|
210
|
+
// TODO calculate amount of RAM available and take it
|
|
211
|
+
// as part on the ecuation.
|
|
212
|
+
const numWorkers = cores > MAX_WORKERS ? MAX_WORKERS : cores - 1;
|
|
213
|
+
return numWorkers < 1 ? 1 : numWorkers;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=files.worker.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.worker.service.js","sourceRoot":"","sources":["../../../../src/core/services/files/files.worker.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAoB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAgD9E,MAAM,OAAO,iBAAi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CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StreamService } from '../stream.service.js';
|
|
2
|
+
import { FileService } from './files.service.js';
|
|
3
|
+
import type { FileWorkerService } from './files.worker.service.js';
|
|
4
|
+
export declare class UnixFilesService extends FileService {
|
|
5
|
+
protected streamService: StreamService;
|
|
6
|
+
fileWorkerService: FileWorkerService;
|
|
7
|
+
constructor(streamService: StreamService, fileWorkerService: FileWorkerService);
|
|
8
|
+
deleteDir(path: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { exec } from 'node:child_process';
|
|
2
|
+
import { FileService } from './files.service.js';
|
|
3
|
+
export class UnixFilesService extends FileService {
|
|
4
|
+
streamService;
|
|
5
|
+
fileWorkerService;
|
|
6
|
+
constructor(streamService, fileWorkerService) {
|
|
7
|
+
super(fileWorkerService);
|
|
8
|
+
this.streamService = streamService;
|
|
9
|
+
this.fileWorkerService = fileWorkerService;
|
|
10
|
+
}
|
|
11
|
+
async deleteDir(path) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const command = `rm -rf "${path}"`;
|
|
14
|
+
exec(command, (error, stdout, stderr) => {
|
|
15
|
+
if (error !== null) {
|
|
16
|
+
reject(error);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (stderr !== '') {
|
|
20
|
+
reject(stderr);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
resolve(true);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=unix-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unix-files.service.js","sourceRoot":"","sources":["../../../../src/core/services/files/unix-files.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAK1C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAEnC;IACM;IAFlB,YACY,aAA4B,EACtB,iBAAoC;QAEpD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAHf,kBAAa,GAAb,aAAa,CAAe;QACtB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAGtD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,WAAW,IAAI,GAAG,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;gBACtC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,MAAM,CAAC,KAAK,CAAC,CAAC;oBACd,OAAO;gBACT,CAAC;gBACD,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;oBAClB,MAAM,CAAC,MAAM,CAAC,CAAC;oBACf,OAAO;gBACT,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StreamService } from '../stream.service.js';
|
|
2
|
+
import { FileService } from './files.service.js';
|
|
3
|
+
import type { FileWorkerService } from './files.worker.service.js';
|
|
4
|
+
export declare class WindowsFilesService extends FileService {
|
|
5
|
+
private readonly streamService;
|
|
6
|
+
fileWorkerService: FileWorkerService;
|
|
7
|
+
constructor(streamService: StreamService, fileWorkerService: FileWorkerService);
|
|
8
|
+
deleteDir(path: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises';
|
|
2
|
+
import { FileService } from './files.service.js';
|
|
3
|
+
export class WindowsFilesService extends FileService {
|
|
4
|
+
streamService;
|
|
5
|
+
fileWorkerService;
|
|
6
|
+
constructor(streamService, fileWorkerService) {
|
|
7
|
+
super(fileWorkerService);
|
|
8
|
+
this.streamService = streamService;
|
|
9
|
+
this.fileWorkerService = fileWorkerService;
|
|
10
|
+
}
|
|
11
|
+
async deleteDir(path) {
|
|
12
|
+
await rm(path, { recursive: true, force: true });
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=windows-files.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"windows-files.service.js","sourceRoot":"","sources":["../../../../src/core/services/files/windows-files.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAItC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAE/B;IACD;IAFlB,YACmB,aAA4B,EAC7B,iBAAoC;QAEpD,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAHR,kBAAa,GAAb,aAAa,CAAe;QAC7B,sBAAiB,GAAjB,iBAAiB,CAAmB;IAGtD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ILoggerService, LogEntry } from '@core/interfaces/logger-service.interface.js';
|
|
2
|
+
import { type Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Implementation of the logging service for npkill.
|
|
5
|
+
* Manages application logs with different severity levels and provides
|
|
6
|
+
* reactive streams for log observation and file output capabilities.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LoggerService implements ILoggerService {
|
|
9
|
+
private log;
|
|
10
|
+
private logSubject;
|
|
11
|
+
info(message: string): void;
|
|
12
|
+
warn(message: string): void;
|
|
13
|
+
error(message: string): void;
|
|
14
|
+
get(type?: 'all' | 'info' | 'warn' | 'error'): LogEntry[];
|
|
15
|
+
getLog$(): Observable<LogEntry[]>;
|
|
16
|
+
getLogByType$(type?: 'all' | 'info' | 'warn' | 'error'): Observable<LogEntry[]>;
|
|
17
|
+
saveToFile(path: string): void;
|
|
18
|
+
getSuggestLogFilePath(): string;
|
|
19
|
+
private rotateLogFile;
|
|
20
|
+
private addToLog;
|
|
21
|
+
private getTimestamp;
|
|
22
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { existsSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { BehaviorSubject } from 'rxjs';
|
|
5
|
+
import { map } from 'rxjs/operators';
|
|
6
|
+
const LATEST_TAG = 'latest';
|
|
7
|
+
const OLD_TAG = 'old';
|
|
8
|
+
/**
|
|
9
|
+
* Implementation of the logging service for npkill.
|
|
10
|
+
* Manages application logs with different severity levels and provides
|
|
11
|
+
* reactive streams for log observation and file output capabilities.
|
|
12
|
+
*/
|
|
13
|
+
export class LoggerService {
|
|
14
|
+
log = [];
|
|
15
|
+
logSubject = new BehaviorSubject([]);
|
|
16
|
+
info(message) {
|
|
17
|
+
this.addToLog({
|
|
18
|
+
type: 'info',
|
|
19
|
+
timestamp: this.getTimestamp(),
|
|
20
|
+
message,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
warn(message) {
|
|
24
|
+
this.addToLog({
|
|
25
|
+
type: 'warn',
|
|
26
|
+
timestamp: this.getTimestamp(),
|
|
27
|
+
message,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
error(message) {
|
|
31
|
+
this.addToLog({
|
|
32
|
+
type: 'error',
|
|
33
|
+
timestamp: this.getTimestamp(),
|
|
34
|
+
message,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
get(type = 'all') {
|
|
38
|
+
if (type === 'all') {
|
|
39
|
+
return this.log;
|
|
40
|
+
}
|
|
41
|
+
return this.log.filter((entry) => entry.type === type);
|
|
42
|
+
}
|
|
43
|
+
getLog$() {
|
|
44
|
+
return this.logSubject.asObservable();
|
|
45
|
+
}
|
|
46
|
+
getLogByType$(type = 'all') {
|
|
47
|
+
return this.logSubject
|
|
48
|
+
.asObservable()
|
|
49
|
+
.pipe(map((entries) => type === 'all'
|
|
50
|
+
? entries
|
|
51
|
+
: entries.filter((entry) => entry.type === type)));
|
|
52
|
+
}
|
|
53
|
+
saveToFile(path) {
|
|
54
|
+
const convertTime = (timestamp) => timestamp;
|
|
55
|
+
const content = this.log.reduce((log, actual) => {
|
|
56
|
+
const line = `[${convertTime(actual.timestamp)}](${actual.type}) ${actual.message}\n`;
|
|
57
|
+
return log + line;
|
|
58
|
+
}, '');
|
|
59
|
+
this.rotateLogFile(path);
|
|
60
|
+
writeFileSync(path, content);
|
|
61
|
+
}
|
|
62
|
+
getSuggestLogFilePath() {
|
|
63
|
+
const filename = `devkill-${LATEST_TAG}.log`;
|
|
64
|
+
return join(tmpdir(), filename);
|
|
65
|
+
}
|
|
66
|
+
rotateLogFile(newLogPath) {
|
|
67
|
+
if (!existsSync(newLogPath)) {
|
|
68
|
+
return; // Rotation is not necessary
|
|
69
|
+
}
|
|
70
|
+
const basePath = dirname(newLogPath);
|
|
71
|
+
const logName = basename(newLogPath);
|
|
72
|
+
const oldLogName = logName.replace(LATEST_TAG, OLD_TAG);
|
|
73
|
+
const oldLogPath = join(basePath, oldLogName);
|
|
74
|
+
renameSync(newLogPath, oldLogPath);
|
|
75
|
+
}
|
|
76
|
+
addToLog(entry) {
|
|
77
|
+
this.log = [...this.log, entry];
|
|
78
|
+
this.logSubject.next(this.log);
|
|
79
|
+
}
|
|
80
|
+
getTimestamp() {
|
|
81
|
+
return new Date().getTime();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=logger.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.service.js","sourceRoot":"","sources":["../../../src/core/services/logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMpD,OAAO,EAAE,eAAe,EAAmB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,OAAO,GAAG,KAAK,CAAC;AAEtB;;;;GAIG;AACH,MAAM,OAAO,aAAa;IAChB,GAAG,GAAe,EAAE,CAAC;IACrB,UAAU,GAAG,IAAI,eAAe,CAAa,EAAE,CAAC,CAAC;IAEzD,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,MAAM;YACZ,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE;YAC9B,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,MAAM;YACZ,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE;YAC9B,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAe;QACnB,IAAI,CAAC,QAAQ,CAAC;YACZ,IAAI,EA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AAqB;QACnB,MAAM,QAAQ,GAAG,WAAW,UAAU,MAAM,CAAC;QAC7C,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IAEO,aAAa,CAAC,UAAkB;QACtC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,4BAA4B;QACtC,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACxD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC9C,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IAEO,QAAQ,CAAC,KAAe;QAC9B,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { PROFILE } from '../interfaces/profile.interface.js';
|
|
2
|
+
export type ProfileFilterType = 'base' | 'user' | 'all';
|
|
3
|
+
/**
|
|
4
|
+
* Service responsible for managing profiles.
|
|
5
|
+
* Handles profile registration, retrieval, and target resolution.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ProfilesService {
|
|
8
|
+
private userDefinedProfiles;
|
|
9
|
+
/**
|
|
10
|
+
* Sets user-defined profiles loaded from .npkillrc configuration.
|
|
11
|
+
* @param profiles Record of user-defined profile configurations
|
|
12
|
+
*/
|
|
13
|
+
setUserDefinedProfiles(profiles: Record<string, PROFILE>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Gets profiles based on the specified filter type.
|
|
16
|
+
* @param filterType Type of profiles to retrieve:
|
|
17
|
+
* - 'base': Only built-in profiles
|
|
18
|
+
* - 'user': Only user-defined profiles from .npkillrc
|
|
19
|
+
* - 'all': Both base and user-defined (user profiles override base)
|
|
20
|
+
* @returns Record of profiles matching the filter
|
|
21
|
+
*/
|
|
22
|
+
getProfiles(filterType?: ProfileFilterType): Record<string, PROFILE>;
|
|
23
|
+
/**
|
|
24
|
+
* Gets a specific profile by name.
|
|
25
|
+
* Searches user-defined profiles first, then base profiles.
|
|
26
|
+
* @param name Name of the profile to retrieve
|
|
27
|
+
* @returns The profile if found, undefined otherwise
|
|
28
|
+
*/
|
|
29
|
+
getProfileByName(name: string): PROFILE | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a profile with the given name exists.
|
|
32
|
+
* @param name Name of the profile to check
|
|
33
|
+
* @returns true if the profile exists, false otherwise
|
|
34
|
+
*/
|
|
35
|
+
hasProfile(name: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the targets from multiple profiles by their names.
|
|
38
|
+
* Combines targets from all specified profiles, removing duplicates.
|
|
39
|
+
* @param profileNames Array of profile names to get targets from
|
|
40
|
+
* @returns Array of unique target directory names
|
|
41
|
+
*/
|
|
42
|
+
getTargetsFromProfiles(profileNames: string[]): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Validates an array of profile names.
|
|
45
|
+
* @param profileNames Array of profile names to validate
|
|
46
|
+
* @returns Array of invalid profile names (profiles that don't exist)
|
|
47
|
+
*/
|
|
48
|
+
getInvalidProfileNames(profileNames: string[]): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Gets the default profile name.
|
|
51
|
+
* @returns Name of the default profile
|
|
52
|
+
*/
|
|
53
|
+
getDefaultProfileName(): string;
|
|
54
|
+
}
|