@vinean/dependency-analyzer 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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # 🛡️ @vinean/dependency-analyzer
2
+
3
+ A high-performance CLI for analyzing the **Replaceability** of your project's dependencies. Supports both **NPM** and **Go Modules**.
4
+
5
+ ## 🚀 Usage
6
+
7
+ Run it directly via `npx`:
8
+
9
+ ```bash
10
+ npx @vinean/dependency-analyzer
11
+ ```
12
+
13
+ Or install it globally:
14
+
15
+ ```bash
16
+ npm install -g @vinean/dependency-analyzer
17
+ @vinean/dependency-analyzer --project ./my-cool-project
18
+ ```
19
+
20
+ ## ⚙️ Options
21
+
22
+ - `--project <path>`: Path to the project root (default: current directory).
23
+ - `--open=false`: Disable auto-opening the generated HTML report.
24
+ - `--json`: Print the raw analysis summary (JSON) to stdout.
25
+
26
+ ## 📊 What is Replaceability?
27
+
28
+ `@vinean/dependency-analyzer` deep-dives into your project's `node_modules` or Go proxy source code to calculate a **Replaceability Score (0-100)** based on:
29
+
30
+ 1. **Native Presence**: Detects C++/CGO/Unsafe code.
31
+ 2. **Code Volume**: Measures physical size and SLOC.
32
+ 3. **API Surface**: Evaluates the breadth and complexity of the public interface.
33
+ 4. **Entanglement**: Tracks dependency chains and OS-level integrations.
34
+ 5. **Logic Complexity**: Proxies cognitive load and concurrency features.
35
+
36
+ ## 📑 Output
37
+
38
+ Generates a `dep-report.html` interactive dashboard in your project directory, allowing you to explore the metrics, check maintenance status, and export results.
39
+
40
+ ---
41
+
42
+ [View full documentation on GitHub](https://github.com/hakanolgun/dependency-analyzer)
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, chmod } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { spawn, spawnSync } from "node:child_process";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const packageRoot = path.resolve(__dirname, "..");
11
+
12
+ const platformMap = {
13
+ win32: "windows",
14
+ darwin: "darwin",
15
+ linux: "linux",
16
+ };
17
+
18
+ const archMap = {
19
+ x64: "amd64",
20
+ arm64: "arm64",
21
+ };
22
+
23
+ const platform = platformMap[process.platform] ?? process.platform;
24
+ const arch = archMap[process.arch] ?? process.arch;
25
+ const ext = process.platform === "win32" ? ".exe" : "";
26
+ const binaryName = `dependency-analyzer-${platform}-${arch}${ext}`;
27
+ const binaryPath = path.join(packageRoot, "dist", binaryName);
28
+
29
+ async function ensureBinaryExecutable(targetPath) {
30
+ if (platform !== "win32") {
31
+ await chmod(targetPath, 0o755);
32
+ }
33
+ }
34
+
35
+ function runBinary(targetPath) {
36
+ const child = spawn(targetPath, process.argv.slice(2), {
37
+ stdio: "inherit",
38
+ });
39
+ child.on("exit", (code) => process.exit(code ?? 1));
40
+ }
41
+
42
+ function tryBuildFromSource() {
43
+ // Fallback for local development or source installs.
44
+ const repoRoot = path.resolve(packageRoot, "..", "..");
45
+ const goModuleDir = path.join(repoRoot, "cli-go");
46
+ const sourceMain = path.join(goModuleDir, "cmd", "dependency-analyzer", "main.go");
47
+ if (!existsSync(sourceMain)) {
48
+ return null;
49
+ }
50
+
51
+ const outDir = path.join(packageRoot, "dist");
52
+ const outFile = binaryPath;
53
+ return mkdir(outDir, { recursive: true })
54
+ .then(() => {
55
+ const result = spawnSync("go", ["build", "-o", outFile, "./cmd/dependency-analyzer"], {
56
+ cwd: goModuleDir,
57
+ stdio: "inherit",
58
+ });
59
+ if (result.status !== 0) {
60
+ return null;
61
+ }
62
+ return outFile;
63
+ })
64
+ .catch(() => null);
65
+ }
66
+
67
+ const start = async () => {
68
+ if (existsSync(binaryPath)) {
69
+ await ensureBinaryExecutable(binaryPath);
70
+ runBinary(binaryPath);
71
+ return;
72
+ }
73
+
74
+ const builtPath = await tryBuildFromSource();
75
+ if (builtPath && existsSync(builtPath)) {
76
+ await ensureBinaryExecutable(builtPath);
77
+ runBinary(builtPath);
78
+ return;
79
+ }
80
+
81
+ console.error(
82
+ "dependency-analyzer: no bundled binary found and fallback Go build failed. Reinstall package or install Go toolchain.",
83
+ );
84
+ process.exit(1);
85
+ };
86
+
87
+ start();
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vinean/dependency-analyzer",
3
+ "version": "0.1.0",
4
+ "description": "Dependency Analyzer for npm and go packages with replaceability analysis",
5
+ "type": "module",
6
+ "bin": {
7
+ "dependency-analyzer": "bin/dependency-analyzer.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build:binaries": "node ./scripts/build-binaries.mjs",
16
+ "prepublishOnly": "npm run build:binaries"
17
+ },
18
+ "author": "Hakan Olgun <hakan@vinean.com>",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hakanolgun/dependency-analyzer.git",
22
+ "directory": "packages/dependency-analyzer"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/hakanolgun/dependency-analyzer/issues"
26
+ },
27
+ "homepage": "https://github.com/hakanolgun/dependency-analyzer/tree/main/packages/dependency-analyzer#readme",
28
+ "keywords": [
29
+ "dependency",
30
+ "analyzer",
31
+ "scanner",
32
+ "replaceability",
33
+ "npm",
34
+ "go",
35
+ "security",
36
+ "cli",
37
+ "scan"
38
+ ],
39
+ "engines": {
40
+ "node": ">=18"
41
+ },
42
+ "license": "MIT"
43
+ }