Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace deprecated packages #113

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .circleci/deprecated-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const { spawnSync } = require('child_process');

function execCommandSync(command) {
const [cmd, ...args] = command.split(' '); // Split command into executable and arguments
const result = spawnSync(cmd, args, { encoding: 'utf-8', shell: false });

if (result.error) {
throw result.error; // Handle system errors
}
if (result.status !== 0) {
throw new Error(result.stderr || `Command failed with exit code ${result.status}`);
}
return result.stdout;
}

const dependenciesMap = new Map();
const regex = /(?:@[\w-]+\/)?[\w.-]{1,100}@\d{1,10}\.\d{1,10}\.\d{1,10}(?:[-+][\w.-]{1,50})?/g;

function checkDependencySync(dependency) {
if (dependenciesMap.has(dependency)) return;
try {
const output = execCommandSync(`npm view ${dependency}`);
if (output.includes('DEPRECATED')) {
dependenciesMap.set(dependency, 'DEPRECATED');
} else {
dependenciesMap.set(dependency, 'active');
}
} catch (error) {
dependenciesMap.set(dependency, 'UNKNOWN');
}
}

function processLinesSync(lines) {
for (const line of lines) {
const trimmedLine = line.trim();
const matches = trimmedLine.matchAll(regex);

for (const match of matches) {
const dependency = match[0];
checkDependencySync(dependency);
}
}
}

function checkDependenciesSync(command) {
try {
const stdout = execCommandSync(command);
const lines = stdout.trim().split('\n');
processLinesSync(lines);
} catch (error) {

const errorLines = error.toString().trim().split('\n');
processLinesSync(errorLines); // Process error lines as well
}
}

function runDependencyCheckSync() {
console.log('Checking dependencies at root level...');
checkDependenciesSync('npm ls');

let deprecatedFound = false;
let counter = 0;
dependenciesMap.forEach((status, dependency) => {
if (status === 'DEPRECATED') {
counter++;
deprecatedFound = true;
console.log(`${counter}. ${dependency} ${status}`);
}
});

if (deprecatedFound) {
console.log('\x1b[31mWARNING!! Deprecated results found at root level.\n\x1b[0m');
} else {
console.log('\x1b[32mSUCCESS: No deprecated packages found at root level! Congos!!\n\x1b[0m');
}

console.log('Checking all dependencies (including transitive)...');
checkDependenciesSync('npm ls --all');

deprecatedFound = false;
counter = 0;
dependenciesMap.forEach((status, dependency) => {
if (status === 'DEPRECATED') {
counter++;
deprecatedFound = true;
console.log(`${counter}. ${dependency} ${status}`);
}
});

if (deprecatedFound) {
console.log('\x1b[31mWARNING!! Deprecated results found in dependencies.\n\x1b[0m');
} else {
console.log('\x1b[32mSUCCESS: No deprecated packages found! Congos!!\x1b[0m');
}

}

runDependencyCheckSync();
Loading