worm-sign
Version:
A prescient scanner to detect and banish Shai Hulud malware from your dependencies.
62 lines (61 loc) • 2.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.report = report;
const cli_table3_1 = __importDefault(require("cli-table3"));
function report(matches, warnings, projectRoot, context = {}) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { chalk, boxen } = context;
// Fallback mocks if not provided
const c = chalk || {
yellow: { bold: (s) => s },
green: { bold: (s) => s },
red: { bold: (s) => s },
bold: (s) => s,
dim: (s) => s,
cyan: (s) => s,
grey: (s) => s,
};
// Handle simple color functions if they are not objects
const b = boxen || ((s) => s);
let output = '';
if (warnings.length > 0) {
output += '\n' + c.yellow.bold('⚠️ Warnings:') + '\n';
warnings.forEach((msg) => {
output += c.yellow(` - ${msg}`) + '\n';
});
}
if (matches.length === 0) {
output +=
'\n' +
b(c.green.bold('✅ No wormsign detected.\nThe spice must flow.'), {
padding: 1,
borderStyle: 'round',
borderColor: 'green',
}) +
'\n';
return output;
}
output +=
'\n' +
b(c.red.bold('🚫 Banned packages detected!'), {
padding: 1,
borderStyle: 'double',
borderColor: 'red',
}) +
'\n\n';
const table = new cli_table3_1.default({
head: [c.bold('Package'), c.bold('Version'), c.bold('Location')],
style: {
head: [], // We handle colors manually
border: [],
},
});
matches.forEach(({ name, version, section }) => {
table.push([c.red.bold(name), c.red(version), c.dim(section)]);
});
output += table.toString() + '\n';
return output;
}