UNPKG

repomix

Version:

A tool to pack repository contents to single file for AI consumption

71 lines (70 loc) 2.33 kB
import perf_hooks from 'node:perf_hooks'; import { isMainThread } from 'node:worker_threads'; import { lintSource } from '@secretlint/core'; import { creator } from '@secretlint/secretlint-rule-preset-recommend'; import { logger, setLogLevelByWorkerData } from '../../../shared/logger.js'; setLogLevelByWorkerData(); if (!isMainThread) { try { Object.defineProperty(perf_hooks.performance, 'mark', { value: () => undefined, writable: true, configurable: true, }); } catch (error) { logger.trace('Could not override performance.mark; leaving profiler enabled', error); } } export const createSecretLintConfig = () => ({ rules: [ { id: '@secretlint/secretlint-rule-preset-recommend', rule: creator, }, ], }); const cachedConfig = createSecretLintConfig(); export default async (task) => { const config = cachedConfig; const processStartAt = process.hrtime.bigint(); try { const results = []; for (const item of task.items) { results.push(await runSecretLint(item.filePath, item.content, item.type, config)); } const processEndAt = process.hrtime.bigint(); logger.trace(`Checked security on ${task.items.length} items. Took: ${(Number(processEndAt - processStartAt) / 1e6).toFixed(2)}ms`); return results; } catch (error) { logger.error('Error in security check worker:', error); throw error; } }; export const runSecretLint = async (filePath, content, type, config) => { const result = await lintSource({ source: { filePath: filePath, content: content, ext: filePath.split('.').pop() || '', contentType: 'text', }, options: { config: config, }, }); if (result.messages.length > 0) { const issueCount = result.messages.length; const issueText = issueCount === 1 ? 'security issue' : 'security issues'; logger.trace(`Found ${issueCount} ${issueText} in ${filePath}`); return { filePath, messages: result.messages.map((message) => message.message), type, }; } return null; }; export const onWorkerTermination = async () => { };