@bekmurod6574/explain-deps 1.0.1 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bekmurod6574/explain-deps",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "explain-deps is a lightweight CLI tool that brings clarity to your terminal. It scans your local package.json file, fetches your project's dependencies, and prints out a clean, plain-English summary of exactly what each package does—saving you from endless searching when trying to understand a new codebase.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/bin/cli.js CHANGED
@@ -19,12 +19,10 @@ try {
19
19
  }
20
20
 
21
21
  async function getPackageDescription(pkgName) {
22
- // 1. Check local cache first
23
22
  if (pkgName in localCache) {
24
23
  return (localCache)[pkgName];
25
24
  }
26
25
 
27
- // 2. Fallback to the live npm registry API if offline/not in cache
28
26
  try {
29
27
  const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`);
30
28
  if (!response.ok) {
@@ -38,23 +36,19 @@ async function getPackageDescription(pkgName) {
38
36
  }
39
37
 
40
38
  async function run() {
41
- console.log("\n🔍 Scanning package.json dependencies...\n");
39
+ console.log("\n Scanning package.json dependencies...\n");
42
40
 
43
- // Locate the package.json file in the folder where the user ran the command
44
41
  const targetPackageJsonPath = path.join(process.cwd(), 'package.json');
45
42
 
46
- // Check if a package.json actually exists here
47
43
  if (!fs.existsSync(targetPackageJsonPath)) {
48
- console.error("Error: No package.json found in this directory.");
44
+ console.error("Error: No package.json found.");
49
45
  process.exit(1);
50
46
  }
51
47
 
52
48
  try {
53
- // Read and parse the target package.json
54
49
  const rawData = fs.readFileSync(targetPackageJsonPath, 'utf-8');
55
50
  const parsedJson = JSON.parse(rawData);
56
51
 
57
- // Extract regular and development dependencies
58
52
  const dependencies = {
59
53
  ...parsedJson.dependencies,
60
54
  ...parsedJson.devDependencies
@@ -63,19 +57,18 @@ async function run() {
63
57
  const packageNames = Object.keys(dependencies);
64
58
 
65
59
  if (packageNames.length === 0) {
66
- console.log("Your package.json doesn't have any dependencies listed!");
60
+ console.log("Your package.json doesn't have any dependencies!");
67
61
  return;
68
62
  }
69
63
 
70
- // Loop through each package, look up its description, and print it
71
64
  for (const pkgName of packageNames) {
72
65
  const description = await getPackageDescription(pkgName);
73
- console.log(`📦 \x1b[36m${pkgName}\x1b[0m: ${description}`);
66
+ console.log(`\x1b[36m${pkgName}\x1b[0m: ${description}`);
74
67
  console.log("------------------------------------------------");
75
68
  }
76
69
 
77
70
  } catch (error) {
78
- console.error("Failed to parse package.json. Ensure it is valid JSON.");
71
+ console.error("Failed to parse package.json. Ensure it is valid JSON.");
79
72
  }
80
73
  }
81
74
 
package/src/index.js CHANGED
@@ -1,34 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- function scanPackageJson(filePath) {
5
- const resolved = path.resolve(filePath);
6
- const raw = fs.readFileSync(resolved, "utf-8");
7
- const pkg = JSON.parse(raw);
8
-
9
- const deps = () => {
10
- const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
11
- return Object.keys(allDeps);
12
- }
13
-
14
- const descriptions = deps().map((dep) => {
15
- try {
16
- const depPkgPath = require.resolve(`${dep}/package.json`, { paths: [path.dirname(resolved)] });
17
- const depPkgRaw = fs.readFileSync(depPkgPath, "utf-8");
18
- const depPkg = JSON.parse(depPkgRaw);
19
- return { name: dep, description: depPkg.description || "(no description)" };
20
- } catch (e) {
21
- return { name: dep, description: "(description not found)" };
22
- }
23
- });
24
-
25
- return {
26
- name: pkg.name ?? "(unknown)",
27
- version: pkg.version ?? "(unknown)",
28
- dependencies: pkg.dependencies ?? {},
29
- devDependencies: pkg.devDependencies ?? {},
30
- descriptions,
31
- };
32
- }
33
-
34
- module.exports = { scanPackageJson };