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: add script for analyzing package usage #1925

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 50 additions & 0 deletions analytics/analyzePackageUsage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { glob } from 'glob';
import fs from 'fs';

const packageJsonFiles = await glob('**/package.json', {
ignore: '**/node_modules/**',
});

const errors = [];

const valuesMap = packageJsonFiles.reduce((res, curr) => {
const file = fs.readFileSync(curr, 'utf8', (err, data) => {
if (err) {
errors.push(curr);
return res;
}
});
try {
const json = JSON.parse(file);
const dependencies = json?.dependencies
? Object.keys(json.dependencies)
: [];
const devDependencies = json?.devDependencies
? Object.keys(json.devDependencies)
: [];
const peerDependencies = json?.peerDependencies
? Object.keys(json.peerDependencies)
: [];
const allDeps = dependencies
.concat(devDependencies)
.concat(peerDependencies);

allDeps.forEach(it => {
if (it.startsWith('@sb1/ffe-')) {
res[it] = res[it] ? res[it] + 1 : 1;
}
});
} catch (e) {
errors.push(curr);
}
return res;
}, {});

const output = Object.entries(valuesMap)
.sort(([, valueA], [, valueB]) => valueB - valueA)
.reduce((res, curr) => `${res}\n${curr[0]}: ${curr[1]}`, '');

console.log('usage:', output);
if (errors.length) {
console.log(`errors: ${errors.length} (${errors.join(', ')})`);
}
7 changes: 7 additions & 0 deletions analytics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@sb1/ffe-analytics",
"type": "module",
"dependencies": {
"glob": "^10.3.12"
}
}
Loading