Skip to content

Instantly share code, notes, and snippets.

@JamsMendez
Last active September 10, 2025 04:33
Show Gist options
  • Select an option

  • Save JamsMendez/e243e3404cb3a2596c8fa1b764300788 to your computer and use it in GitHub Desktop.

Select an option

Save JamsMendez/e243e3404cb3a2596c8fa1b764300788 to your computer and use it in GitHub Desktop.
script para revisar versiones (objetivo: maliciosas)
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
const expected = [
"backslash@0.2.1",
"chalk@5.6.1",
"chalk-template@1.1.1",
"color-convert@3.1.1",
"color-name@2.0.1",
"color-string@2.1.1",
"wrap-ansi@9.0.1",
"supports-hyperlinks@4.1.1",
"strip-ansi@7.1.1",
"slice-ansi@7.1.1",
"simple-swizzle@0.2.3",
"is-arrayish@0.3.3",
"error-ex@1.3.3",
"has-ansi@6.0.1",
"ansi-regex@6.2.1",
"ansi-styles@6.2.2",
"supports-color@10.2.1",
"proto-tinker-wc@1.8.7",
"debug@4.4.2",
];
// 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