depguard
Version:
A powerful CLI tool to check and update npm/yarn dependencies in your projects
39 lines (38 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NpmPackageManager = void 0;
const child_process_1 = require("child_process");
class NpmPackageManager {
constructor() {
this.name = 'npm';
}
async initialize() {
// No initialization needed for npm
}
async getLatestVersion(packageName) {
try {
const output = (0, child_process_1.execSync)(`npm view ${packageName} version`, { encoding: 'utf-8' });
return output.trim();
}
catch (error) {
return null;
}
}
async updatePackage(packageName, version) {
(0, child_process_1.execSync)(`npm install ${packageName}@${version}`, { stdio: 'inherit' });
}
async updateAllPackages(packages) {
const updates = packages.map(pkg => `${pkg.name}@${pkg.version}`).join(' ');
(0, child_process_1.execSync)(`npm install ${updates}`, { stdio: 'inherit' });
}
async install() {
(0, child_process_1.execSync)('npm install', { stdio: 'inherit' });
}
getLockFile() {
return 'package-lock.json';
}
async getPackageManager() {
return 'npm';
}
}
exports.NpmPackageManager = NpmPackageManager;