Skip to content

Commit c383b57

Browse files
s-prakelnyry-sam-k
andauthored
feat: deprecated dependencies check (#231)
* added deprecated dependencies check to ci * updated dependencies * Update .circleci/config.yml Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com> --------- Co-authored-by: Sam <10507686+elnyry-sam-k@users.noreply.github.com>
1 parent a60c28f commit c383b57

4 files changed

Lines changed: 211 additions & 56 deletions

File tree

‎.circleci/config.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ jobs:
215215
- store_test_results:
216216
path: ./test/results
217217

218+
test-deprecations:
219+
executor: default-docker
220+
steps:
221+
- run:
222+
name: Checking if deprecated dependencies exist
223+
command: node .circleci/deprecated-check.js
224+
218225
test-coverage:
219226
executor: default-docker
220227
steps:

‎.circleci/deprecated-check.js‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
const { exec } = require('child_process');
2+
3+
function execCommand(command) {
4+
return new Promise((resolve, reject) => {
5+
exec(command, (error, stdout, stderr) => {
6+
//console.log(command);
7+
if (error) {
8+
reject(error.message);
9+
} else if (stderr) {
10+
reject(stderr);
11+
} else {
12+
resolve(stdout);
13+
}
14+
});
15+
});
16+
}
17+
const dependencies_map = new Map();
18+
19+
20+
async function checkDependencies(command) {
21+
try {
22+
const stdout = await execCommand(command);
23+
24+
const result = stdout.trim().split("\n");
25+
26+
for (let index = 0; index < result.length; index++) {
27+
let line = result[index].trim();
28+
if(line.includes("UNMET OPTIONAL DEPENDENCY")){
29+
continue;
30+
}
31+
let dep = "";
32+
if(index===0){
33+
dep=line.split(" ")[0];
34+
}
35+
else{
36+
arr=line.split(" ");
37+
if(arr[arr.length-1]=="deduped" || arr[arr.length-1]=="overridden"){
38+
dep=arr[arr.length-2];
39+
}
40+
else{
41+
dep=arr[arr.length-1];
42+
}
43+
}
44+
if(dep.includes(":")){
45+
dep=dep.split(":").pop();
46+
}
47+
if (dependencies_map.has(dep)) {
48+
continue;
49+
} else {
50+
try{
51+
const output = await execCommand(`npm view ${dep}`);
52+
53+
if (output.includes("DEPRECATED")) {
54+
dependencies_map.set(dep, "DEPRECATED");
55+
} else {
56+
dependencies_map.set(dep, "active");
57+
}
58+
}
59+
catch(error){
60+
console.log(error);
61+
}
62+
}
63+
}
64+
65+
//console.log(dependencies_map);
66+
} catch (error) {
67+
console.error(`Error: ${error}`);
68+
}
69+
}
70+
71+
async function runDependencyCheck() {
72+
73+
await checkDependencies('npm ls');
74+
75+
let dep_check = true;
76+
counter=0;
77+
dependencies_map.forEach((val, key) => {
78+
if (val === "DEPRECATED") {
79+
counter++;
80+
dep_check = false;
81+
console.log(counter+". "+key+" "+val);
82+
}
83+
});
84+
85+
if (dep_check) {
86+
console.log("\x1b[32mSUCCESS: All tests passed, no deprecated packages found at root level! Congos!!\n\x1b[0m")
87+
} else {
88+
console.log("\x1b[31mWARNING!!Deprecated results found at root level.\n\x1b[0m");
89+
}
90+
91+
await checkDependencies('npm ls --all');
92+
93+
counter=0;
94+
dependencies_map.forEach((val, key) => {
95+
if (val === "DEPRECATED") {
96+
counter++;
97+
dep_check = false;
98+
console.log(counter+". "+key+" "+val);
99+
}
100+
});
101+
102+
if (dep_check) {
103+
console.log("\x1b[32mSUCCESS: All tests passed, no deprecated packages found! Congos!!\x1b[0m")
104+
} else {
105+
console.log("\x1b[31mWARINING!!Deprecated results found.\x1b[0m");
106+
}
107+
108+
}
109+
110+
111+
runDependencyCheck();

0 commit comments

Comments
 (0)