dependency-radar 0.1.1

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/cli.js ADDED
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const path_1 = __importDefault(require("path"));
8
+ const aggregator_1 = require("./aggregator");
9
+ const depcheckRunner_1 = require("./runners/depcheckRunner");
10
+ const licenseChecker_1 = require("./runners/licenseChecker");
11
+ const madgeRunner_1 = require("./runners/madgeRunner");
12
+ const npmAudit_1 = require("./runners/npmAudit");
13
+ const npmLs_1 = require("./runners/npmLs");
14
+ const report_1 = require("./report");
15
+ const promises_1 = __importDefault(require("fs/promises"));
16
+ const utils_1 = require("./utils");
17
+ function parseArgs(argv) {
18
+ const opts = {
19
+ command: 'scan',
20
+ project: process.cwd(),
21
+ out: 'dependency-radar.html',
22
+ keepTemp: false,
23
+ maintenance: false,
24
+ audit: true
25
+ };
26
+ const args = [...argv];
27
+ if (args[0] && !args[0].startsWith('-')) {
28
+ opts.command = args.shift();
29
+ }
30
+ while (args.length) {
31
+ const arg = args.shift();
32
+ if (!arg)
33
+ break;
34
+ if (arg === '--project' && args[0])
35
+ opts.project = args.shift();
36
+ else if (arg === '--out' && args[0])
37
+ opts.out = args.shift();
38
+ else if (arg === '--keep-temp')
39
+ opts.keepTemp = true;
40
+ else if (arg === '--maintenance')
41
+ opts.maintenance = true;
42
+ else if (arg === '--no-audit')
43
+ opts.audit = false;
44
+ else if (arg === '--help' || arg === '-h') {
45
+ printHelp();
46
+ process.exit(0);
47
+ }
48
+ }
49
+ return opts;
50
+ }
51
+ function printHelp() {
52
+ console.log(`dependency-radar scan [options]
53
+
54
+ Options:
55
+ --project <path> Project folder (default: cwd)
56
+ --out <path> Output HTML file (default: dependency-radar.html)
57
+ --keep-temp Keep .dependency-radar folder
58
+ --maintenance Enable slow maintenance checks (npm registry calls)
59
+ --no-audit Skip npm audit (useful for offline scans)
60
+ `);
61
+ }
62
+ async function run() {
63
+ const opts = parseArgs(process.argv.slice(2));
64
+ if (opts.command !== 'scan') {
65
+ printHelp();
66
+ process.exit(1);
67
+ return;
68
+ }
69
+ const projectPath = path_1.default.resolve(opts.project);
70
+ let outputPath = path_1.default.resolve(opts.out);
71
+ const startTime = Date.now();
72
+ let dependencyCount = 0;
73
+ try {
74
+ const stat = await promises_1.default.stat(outputPath).catch(() => undefined);
75
+ const endsWithSeparator = opts.out.endsWith('/') || opts.out.endsWith('\\');
76
+ const hasExtension = Boolean(path_1.default.extname(outputPath));
77
+ if ((stat && stat.isDirectory()) || endsWithSeparator || (!stat && !hasExtension)) {
78
+ outputPath = path_1.default.join(outputPath, 'dependency-radar.html');
79
+ }
80
+ }
81
+ catch (e) {
82
+ // ignore, best-effort path normalization
83
+ }
84
+ const tempDir = path_1.default.join(projectPath, '.dependency-radar');
85
+ const stopSpinner = startSpinner(`Scanning project at ${projectPath}`);
86
+ try {
87
+ await (0, utils_1.ensureDir)(tempDir);
88
+ const [auditResult, npmLsResult, licenseResult, depcheckResult, madgeResult] = await Promise.all([
89
+ opts.audit ? (0, npmAudit_1.runNpmAudit)(projectPath, tempDir) : Promise.resolve(undefined),
90
+ (0, npmLs_1.runNpmLs)(projectPath, tempDir),
91
+ (0, licenseChecker_1.runLicenseChecker)(projectPath, tempDir),
92
+ (0, depcheckRunner_1.runDepcheck)(projectPath, tempDir),
93
+ (0, madgeRunner_1.runMadge)(projectPath, tempDir)
94
+ ]);
95
+ if (opts.maintenance) {
96
+ stopSpinner(true);
97
+ console.log('Running maintenance checks (slow mode)');
98
+ console.log('This may take several minutes depending on dependency count.');
99
+ }
100
+ const aggregated = await (0, aggregator_1.aggregateData)({
101
+ projectPath,
102
+ maintenanceEnabled: opts.maintenance,
103
+ onMaintenanceProgress: opts.maintenance
104
+ ? (current, total, name) => {
105
+ process.stdout.write(`\r[${current}/${total}] ${name} `);
106
+ }
107
+ : undefined,
108
+ auditResult,
109
+ npmLsResult,
110
+ licenseResult,
111
+ depcheckResult,
112
+ madgeResult
113
+ });
114
+ dependencyCount = aggregated.dependencies.length;
115
+ if (opts.maintenance) {
116
+ process.stdout.write('\n');
117
+ }
118
+ await (0, report_1.renderReport)(aggregated, outputPath);
119
+ stopSpinner(true);
120
+ console.log(`Report written to ${outputPath}`);
121
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
122
+ console.log(`Scan complete: ${dependencyCount} dependencies analysed in ${elapsed}s`);
123
+ }
124
+ catch (err) {
125
+ stopSpinner(false);
126
+ console.error('Failed to generate report:', err);
127
+ process.exit(1);
128
+ }
129
+ finally {
130
+ if (!opts.keepTemp) {
131
+ await (0, utils_1.removeDir)(tempDir);
132
+ }
133
+ else {
134
+ console.log(`Temporary data kept at ${tempDir}`);
135
+ }
136
+ }
137
+ // Always show CTA as the last output
138
+ console.log('');
139
+ console.log('Get additional risk analysis and a management-ready summary at https://dependency-radar.com');
140
+ }
141
+ run();
142
+ function startSpinner(text) {
143
+ const frames = ['|', '/', '-', '\\'];
144
+ let i = 0;
145
+ process.stdout.write(`${frames[i]} ${text}`);
146
+ const timer = setInterval(() => {
147
+ i = (i + 1) % frames.length;
148
+ process.stdout.write(`\r${frames[i]} ${text}`);
149
+ }, 120);
150
+ let stopped = false;
151
+ return (success = true) => {
152
+ if (stopped)
153
+ return;
154
+ stopped = true;
155
+ clearInterval(timer);
156
+ process.stdout.write(`\r${success ? '✔' : '✖'} ${text}\n`);
157
+ };
158
+ }
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./aggregator"), exports);
18
+ __exportStar(require("./report"), exports);