Last active
September 10, 2025 04:33
-
-
Save JamsMendez/e243e3404cb3a2596c8fa1b764300788 to your computer and use it in GitHub Desktop.
script para revisar versiones (objetivo: maliciosas)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { execSync } from "child_process"; | |
import fs from "fs"; | |
import path from "path"; | |
const expected = [ | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
"[email protected]", | |
]; | |
// Pasamos a un mapa {nombre: version} | |
const expectedMap = {}; | |
for (const pkg of expected) { | |
const [name, version] = pkg.split("@"); | |
expectedMap[name] = version; | |
} | |
function checkPackages(dir) { | |
try { | |
// const cmd = `npm list ${Object.keys(expectedMap).join(" ")} --depth=0 --json`; | |
const cmd = `npm list ${Object.keys(expectedMap).join(" ")} --json`; | |
const result = execSync(cmd, { cwd: dir, stdio: ["pipe", "pipe", "ignore"] }).toString(); | |
const json = JSON.parse(result); | |
const found = json.dependencies || {}; | |
const matches = []; | |
for (const [pkg, expectedVersion] of Object.entries(expectedMap)) { | |
if (found[pkg]) { | |
const actualVersion = found[pkg].version; | |
if (actualVersion === expectedVersion) { | |
matches.push(`✅ ${pkg}@${actualVersion} (coincide)`); | |
} else { | |
matches.push(`⚠️ ${pkg}@${actualVersion} (se esperaba ${expectedVersion})`); | |
} | |
} | |
} | |
if (matches.length > 0) { | |
console.log(`📂 Proyecto: ${dir}`); | |
matches.forEach((m) => console.log(" " + m)); | |
console.log(""); | |
} | |
} catch { | |
// ignorar proyectos sin node_modules o con errores | |
} | |
} | |
function searchProjects(startDir) { | |
if (!fs.existsSync(startDir)) return | |
const entries = fs.readdirSync(startDir, { withFileTypes: true }); | |
if (entries.some((e) => e.name === "package.json")) { | |
checkPackages(startDir); | |
return; | |
} | |
for (const entry of entries) { | |
if (entry.isDirectory()) { | |
searchProjects(path.join(startDir, entry.name)); | |
} | |
} | |
} | |
// find . -name "node_modules" -type d -prune | |
const dirs = [ | |
]; | |
console.log("🔍 Revisando proyectos específicos...\n"); | |
dirs.forEach((d) => { | |
searchProjects(d); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment