Skip to content

Commit

Permalink
feat: deprecated dependencies check (#231)
Browse files Browse the repository at this point in the history
* added deprecated dependencies check to ci

* updated dependencies

* Update .circleci/config.yml

Co-authored-by: Sam <[email protected]>

---------

Co-authored-by: Sam <[email protected]>
  • Loading branch information
s-prak and elnyry-sam-k authored Nov 29, 2024
1 parent a60c28f commit c383b57
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 56 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ jobs:
- store_test_results:
path: ./test/results

test-deprecations:
executor: default-docker
steps:
- run:
name: Checking if deprecated dependencies exist
command: node .circleci/deprecated-check.js

test-coverage:
executor: default-docker
steps:
Expand Down
111 changes: 111 additions & 0 deletions .circleci/deprecated-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const { exec } = require('child_process');

function execCommand(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
//console.log(command);
if (error) {
reject(error.message);
} else if (stderr) {
reject(stderr);
} else {
resolve(stdout);
}
});
});
}
const dependencies_map = new Map();


async function checkDependencies(command) {
try {
const stdout = await execCommand(command);

const result = stdout.trim().split("\n");

for (let index = 0; index < result.length; index++) {
let line = result[index].trim();
if(line.includes("UNMET OPTIONAL DEPENDENCY")){
continue;
}
let dep = "";
if(index===0){
dep=line.split(" ")[0];
}
else{
arr=line.split(" ");
if(arr[arr.length-1]=="deduped" || arr[arr.length-1]=="overridden"){
dep=arr[arr.length-2];
}
else{
dep=arr[arr.length-1];
}
}
if(dep.includes(":")){
dep=dep.split(":").pop();
}
if (dependencies_map.has(dep)) {
continue;
} else {
try{
const output = await execCommand(`npm view ${dep}`);

if (output.includes("DEPRECATED")) {
dependencies_map.set(dep, "DEPRECATED");
} else {
dependencies_map.set(dep, "active");
}
}
catch(error){
console.log(error);
}
}
}

//console.log(dependencies_map);
} catch (error) {
console.error(`Error: ${error}`);
}
}

async function runDependencyCheck() {

await checkDependencies('npm ls');

let dep_check = true;
counter=0;
dependencies_map.forEach((val, key) => {
if (val === "DEPRECATED") {
counter++;
dep_check = false;
console.log(counter+". "+key+" "+val);
}
});

if (dep_check) {
console.log("\x1b[32mSUCCESS: All tests passed, no deprecated packages found at root level! Congos!!\n\x1b[0m")
} else {
console.log("\x1b[31mWARNING!!Deprecated results found at root level.\n\x1b[0m");
}

await checkDependencies('npm ls --all');

counter=0;
dependencies_map.forEach((val, key) => {
if (val === "DEPRECATED") {
counter++;
dep_check = false;
console.log(counter+". "+key+" "+val);
}
});

if (dep_check) {
console.log("\x1b[32mSUCCESS: All tests passed, no deprecated packages found! Congos!!\x1b[0m")
} else {
console.log("\x1b[31mWARINING!!Deprecated results found.\x1b[0m");
}

}


runDependencyCheck();
Loading

0 comments on commit c383b57

Please sign in to comment.