@tmlmobilidade/repo-deps 20260807.1055.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/README.md +25 -0
- package/dist/index.js +110 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
### @tmlmobilidade/bump-version 🧼
|
|
2
|
+
|
|
3
|
+
Bump version is a small util to update the package.json version string using the current timestamp.
|
|
4
|
+
|
|
5
|
+
#### Usage:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npx @tmlmobilidade/repo-version --output=<path-to-package.json | console> --format=<default | code> --prefix=<your-prefix>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
##### `--format`
|
|
12
|
+
- "default" - Output as a formatted string (e.g. `20250101.1026.12`)
|
|
13
|
+
- "code" - Output as number (e.g. `20250101102612`)
|
|
14
|
+
|
|
15
|
+
##### `--prefix`
|
|
16
|
+
- an optional value to prepend to the version string (only in default format)
|
|
17
|
+
|
|
18
|
+
##### `--suffix`
|
|
19
|
+
- an optional value to append to the version string (only in default format)
|
|
20
|
+
|
|
21
|
+
##### `--output`
|
|
22
|
+
- "<path-to-package.json>" - Modify the package.json.
|
|
23
|
+
- "console" - Output to the console. This will hide any other logs.
|
|
24
|
+
|
|
25
|
+
:)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as fs from "fs/promises";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
const EXCLUDED_DIRS = new Set([
|
|
4
|
+
"node_modules",
|
|
5
|
+
".git",
|
|
6
|
+
"dist",
|
|
7
|
+
"build",
|
|
8
|
+
"coverage",
|
|
9
|
+
]);
|
|
10
|
+
const TEXT_EXTENSIONS = new Set([
|
|
11
|
+
".ts",
|
|
12
|
+
".tsx",
|
|
13
|
+
".js",
|
|
14
|
+
".jsx",
|
|
15
|
+
".mjs",
|
|
16
|
+
".cjs",
|
|
17
|
+
".json",
|
|
18
|
+
".md",
|
|
19
|
+
".yml",
|
|
20
|
+
".yaml",
|
|
21
|
+
".html",
|
|
22
|
+
".css",
|
|
23
|
+
".scss",
|
|
24
|
+
".less",
|
|
25
|
+
]);
|
|
26
|
+
async function findPackageJsonFiles(dir) {
|
|
27
|
+
const results = [];
|
|
28
|
+
async function walk(current) {
|
|
29
|
+
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
const fullPath = path.join(current, entry.name);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (!EXCLUDED_DIRS.has(entry.name)) {
|
|
34
|
+
await walk(fullPath);
|
|
35
|
+
}
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (entry.isFile() && entry.name === "package.json") {
|
|
39
|
+
results.push(fullPath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
await walk(dir);
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
async function findDependencyUsage(directory, dependency, packageJsonPath) {
|
|
47
|
+
async function walk(current) {
|
|
48
|
+
const entries = await fs.readdir(current, { withFileTypes: true });
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
const fullPath = path.join(current, entry.name);
|
|
51
|
+
if (entry.isDirectory()) {
|
|
52
|
+
if (EXCLUDED_DIRS.has(entry.name)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (await walk(fullPath)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (fullPath === packageJsonPath) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!TEXT_EXTENSIONS.has(path.extname(fullPath))) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const contents = await fs.readFile(fullPath, "utf8");
|
|
68
|
+
if (contents.includes(dependency)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Ignore unreadable files
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return walk(directory);
|
|
79
|
+
}
|
|
80
|
+
(async function detectUnusedDependencies() {
|
|
81
|
+
const rootDirectory = process.cwd();
|
|
82
|
+
console.log(`Detecting unused dependencies in ${rootDirectory}`);
|
|
83
|
+
const packageJsonFiles = await findPackageJsonFiles(rootDirectory);
|
|
84
|
+
for (const packageJsonPath of packageJsonFiles) {
|
|
85
|
+
try {
|
|
86
|
+
const contents = await fs.readFile(packageJsonPath, "utf8");
|
|
87
|
+
const pkg = JSON.parse(contents);
|
|
88
|
+
const dependencies = Object.keys(pkg.dependencies ?? {});
|
|
89
|
+
if (dependencies.length === 0) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const packageDirectory = path.dirname(packageJsonPath);
|
|
93
|
+
const unused = [];
|
|
94
|
+
for (const dependency of dependencies) {
|
|
95
|
+
const found = await findDependencyUsage(packageDirectory, dependency, packageJsonPath);
|
|
96
|
+
if (!found) {
|
|
97
|
+
unused.push(dependency);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (unused.length > 0) {
|
|
101
|
+
console.log(`\n${packageJsonPath}`);
|
|
102
|
+
console.log(`Unused dependencies:`);
|
|
103
|
+
unused.forEach((dep) => console.log(` - ${dep}`));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.error(`Failed to process ${packageJsonPath}`, err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tmlmobilidade/repo-deps",
|
|
3
|
+
"description": "A CLI tool to detect unused dependencies in a repository.",
|
|
4
|
+
"version": "20260807.1055.2",
|
|
5
|
+
"author": {
|
|
6
|
+
"email": "iso@tmlmobilidade.pt",
|
|
7
|
+
"name": "TML-ISO"
|
|
8
|
+
},
|
|
9
|
+
"license": "AGPL-3.0-or-later",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"bin": {
|
|
16
|
+
"repo-deps": "dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc && resolve-tspaths",
|
|
21
|
+
"lint": "eslint . --fix && tsc --noEmit",
|
|
22
|
+
"lint:fix": "eslint ./src --fix",
|
|
23
|
+
"dev": "tsc && resolve-tspaths && node dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "26.1.2",
|
|
27
|
+
"resolve-tspaths": "0.8.23",
|
|
28
|
+
"typescript": "6.0.3"
|
|
29
|
+
}
|
|
30
|
+
}
|