dependency-guardian
Version:
A powerful dependency management and analysis tool for Node.js projects
47 lines (39 loc) • 1.2 kB
JavaScript
const fs = require('fs').promises;
const path = require('path');
const logger = require('../../utils/logger');
class LockAnalyzer {
async analyzeLockFile(projectPath) {
const results = {
npm: await this.analyzeNpmLock(projectPath),
yarn: await this.analyzeYarnLock(projectPath),
pnpm: await this.analyzePnpmLock(projectPath)
};
return {
...results,
summary: this.generateSummary(results)
};
}
async analyzeNpmLock(projectPath) {
try {
const lockPath = path.join(projectPath, 'package-lock.json');
const content = await fs.readFile(lockPath, 'utf8');
const lockfile = JSON.parse(content);
return {
version: lockfile.lockfileVersion,
dependencies: this.extractNpmDependencies(lockfile)
};
} catch (error) {
return null;
}
}
async analyzeYarnLock(projectPath) {
// Implementation for yarn.lock analysis
}
async analyzePnpmLock(projectPath) {
// Implementation for pnpm-lock.yaml analysis
}
generateSummary(results) {
// Generate summary of lock file analysis
}
}
module.exports = new LockAnalyzer();