Comparar commits
2 Commits
fdeb3b2a2c
...
30d2b35bda
| Autor | SHA1 | Fecha | |
|---|---|---|---|
|
30d2b35bda
|
|||
| 2fccf3fd48 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "alepm",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "Advanced and secure Node.js package manager with binary storage, intelligent caching, and comprehensive security features",
|
||||
"main": "src/index.js",
|
||||
"bin": {
|
||||
|
||||
27
src/cache/cache-manager.js
vendido
27
src/cache/cache-manager.js
vendido
@@ -11,13 +11,15 @@ class CacheManager {
|
||||
constructor() {
|
||||
this.cacheDir = path.join(require('os').homedir(), '.alepm', 'cache');
|
||||
this.metadataFile = path.join(this.cacheDir, 'metadata.json');
|
||||
this.init();
|
||||
this._initialized = false;
|
||||
}
|
||||
|
||||
async init() {
|
||||
if (this._initialized) return;
|
||||
|
||||
await fs.ensureDir(this.cacheDir);
|
||||
|
||||
if (!fs.existsSync(this.metadataFile)) {
|
||||
if (!await fs.pathExists(this.metadataFile)) {
|
||||
await this.saveMetadata({
|
||||
version: '1.0.0',
|
||||
entries: {},
|
||||
@@ -25,9 +27,12 @@ class CacheManager {
|
||||
lastCleanup: Date.now()
|
||||
});
|
||||
}
|
||||
|
||||
this._initialized = true;
|
||||
}
|
||||
|
||||
async get(packageName, version) {
|
||||
await this.init();
|
||||
const key = this.generateKey(packageName, version);
|
||||
const metadata = await this.loadMetadata();
|
||||
|
||||
@@ -38,7 +43,7 @@ class CacheManager {
|
||||
const entry = metadata.entries[key];
|
||||
const filePath = path.join(this.cacheDir, entry.file);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
if (!await fs.pathExists(filePath)) {
|
||||
// Remove stale entry
|
||||
delete metadata.entries[key];
|
||||
await this.saveMetadata(metadata);
|
||||
@@ -67,6 +72,7 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async has(packageName, version) {
|
||||
await this.init();
|
||||
const key = this.generateKey(packageName, version);
|
||||
const metadata = await this.loadMetadata();
|
||||
|
||||
@@ -78,7 +84,7 @@ class CacheManager {
|
||||
const filePath = path.join(this.cacheDir, entry.file);
|
||||
|
||||
// Check if file exists
|
||||
if (!fs.existsSync(filePath)) {
|
||||
if (!await fs.pathExists(filePath)) {
|
||||
// Remove stale entry
|
||||
delete metadata.entries[key];
|
||||
await this.saveMetadata(metadata);
|
||||
@@ -89,6 +95,7 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async store(packageName, version, data) {
|
||||
await this.init();
|
||||
const key = this.generateKey(packageName, version);
|
||||
const metadata = await this.loadMetadata();
|
||||
|
||||
@@ -117,7 +124,7 @@ class CacheManager {
|
||||
if (metadata.entries[key]) {
|
||||
const oldEntry = metadata.entries[key];
|
||||
const oldFilePath = path.join(this.cacheDir, oldEntry.file);
|
||||
if (fs.existsSync(oldFilePath)) {
|
||||
if (await fs.pathExists(oldFilePath)) {
|
||||
await fs.remove(oldFilePath);
|
||||
metadata.totalSize -= oldEntry.size;
|
||||
}
|
||||
@@ -135,6 +142,7 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async remove(packageName, version) {
|
||||
await this.init();
|
||||
const key = this.generateKey(packageName, version);
|
||||
const metadata = await this.loadMetadata();
|
||||
|
||||
@@ -145,7 +153,7 @@ class CacheManager {
|
||||
const entry = metadata.entries[key];
|
||||
const filePath = path.join(this.cacheDir, entry.file);
|
||||
|
||||
if (fs.existsSync(filePath)) {
|
||||
if (await fs.pathExists(filePath)) {
|
||||
await fs.remove(filePath);
|
||||
}
|
||||
|
||||
@@ -157,13 +165,14 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async clean() {
|
||||
await this.init();
|
||||
const metadata = await this.loadMetadata();
|
||||
let cleanedSize = 0;
|
||||
|
||||
for (const [, entry] of Object.entries(metadata.entries)) {
|
||||
const filePath = path.join(this.cacheDir, entry.file);
|
||||
|
||||
if (fs.existsSync(filePath)) {
|
||||
if (await fs.pathExists(filePath)) {
|
||||
await fs.remove(filePath);
|
||||
cleanedSize += entry.size;
|
||||
}
|
||||
@@ -182,6 +191,7 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async verify() {
|
||||
await this.init();
|
||||
const metadata = await this.loadMetadata();
|
||||
const corrupted = [];
|
||||
const missing = [];
|
||||
@@ -189,7 +199,7 @@ class CacheManager {
|
||||
for (const [key, entry] of Object.entries(metadata.entries)) {
|
||||
const filePath = path.join(this.cacheDir, entry.file);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
if (!await fs.pathExists(filePath)) {
|
||||
missing.push(key);
|
||||
continue;
|
||||
}
|
||||
@@ -220,6 +230,7 @@ class CacheManager {
|
||||
}
|
||||
|
||||
async getStats() {
|
||||
await this.init();
|
||||
const metadata = await this.loadMetadata();
|
||||
const entries = Object.values(metadata.entries);
|
||||
|
||||
|
||||
@@ -281,6 +281,34 @@ class PackageManager {
|
||||
// Update lock file
|
||||
await this.lock.update(results.filter(r => !r.error));
|
||||
|
||||
// Show installation summary only for main installations (not dependency installations)
|
||||
if (!options.fromPackageJson) {
|
||||
const successfulInstalls = results.filter(r => !r.error);
|
||||
const failedInstalls = results.filter(r => r.error);
|
||||
|
||||
console.log('');
|
||||
console.log(chalk.green('📦 Installation Summary:'));
|
||||
console.log('');
|
||||
|
||||
if (successfulInstalls.length > 0) {
|
||||
console.log(chalk.green(`✓ Successfully installed ${successfulInstalls.length} package(s):`));
|
||||
successfulInstalls.forEach(result => {
|
||||
const sourceLabel = result.source === 'cache' ? '(cached)' : `(${result.source})`;
|
||||
console.log(chalk.green(` • ${result.name}@${result.version} ${chalk.gray(sourceLabel)}`));
|
||||
});
|
||||
}
|
||||
|
||||
if (failedInstalls.length > 0) {
|
||||
console.log('');
|
||||
console.log(chalk.red(`✗ Failed to install ${failedInstalls.length} package(s):`));
|
||||
failedInstalls.forEach(result => {
|
||||
console.log(chalk.red(` • ${result.packageSpec}: ${result.error}`));
|
||||
});
|
||||
}
|
||||
|
||||
console.log('');
|
||||
}
|
||||
|
||||
console.log(chalk.green(`Installation completed. ${results.filter(r => !r.error).length} packages installed.`));
|
||||
return results;
|
||||
}
|
||||
|
||||
Referencia en una nueva incidencia
Block a user