Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 33x 33x 33x 33x 33x 33x 33x 1x 1x 1x 1x 1x 1x 140x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 140x 140x 140x 140x 140x 140x 140x 140x 140x 140x 140x 140x 140x 1x 1x 1x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 1x 1x 1x 1x 4x 2x 2x 2x 2x 2x 2x 4x 4x 1x 1x 1x 1x 140x 140x 138x 140x 4x 4x 136x 140x 134x 140x 4x 4x 140x 2x 2x 140x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 26x 26x 26x 26x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 15x 6x 11x 5x 9x 3x 4x 1x 1x 15x 1x 1x 1x 1x 11x 11x 1x 1x 1x 1x 1x 1x 1x | /**
* Configuration management for git-ingest
* Centralizes all configuration options and constants
*/
import fs from "fs/promises";
import path from "path";
import { fileURLToPath } from "url";
import { FILE_PROCESSING_CONSTANTS, FORMAT_CONSTANTS } from "./constants.js";
// Safe fallback for import.meta.url in Jest/CommonJS
function getMetaUrl() {
try {
// Only works in ESM
return import.meta.url;
} catch {
return "file://" + process.cwd() + "/src/config.js";
}
}
const __filename = fileURLToPath(getMetaUrl());
const __dirname = path.dirname(__filename);
/**
* Load external configuration file safely
*/
async function loadConfigFile(filename, fallback = []) {
try {
const configPath = path.join(__dirname, "../config", filename);
const content = await fs.readFile(configPath, "utf8");
return JSON.parse(content);
} catch {
// Silent fallback to default values
return fallback;
}
}
// Default configuration constants with fallbacks
export const DEFAULT_CONFIG = {
// File processing
MAX_FILE_SIZE_MB: FILE_PROCESSING_CONSTANTS.DEFAULT_MAX_FILE_SIZE_MB,
TRUNCATE_SIZE_KB: FILE_PROCESSING_CONSTANTS.DEFAULT_TRUNCATE_SIZE_KB,
get TRUNCATE_SIZE_BYTES() {
return this.TRUNCATE_SIZE_KB * 1024;
},
// Output formatting
SEPARATOR_LENGTH: FORMAT_CONSTANTS.SEPARATOR_LENGTH,
SEPARATOR_CHAR: FORMAT_CONSTANTS.SEPARATOR_CHAR,
// Performance settings
LARGE_FILE_THRESHOLD_MB: 1,
MEMORY_LIMIT_MB: 200,
// Fallback patterns (loaded dynamically)
FALLBACK_IGNORE_PATTERNS: [
"node_modules/",
".git/",
"dist/",
"build/",
".cache/",
"*.log"
],
FALLBACK_TEXT_EXTENSIONS: [
".txt",
".md",
".js",
".ts",
".json",
".yaml",
".yml",
".html",
".css"
]
};
/**
* Configuration class for managing git-ingest settings
*/
export class Config {
constructor(options = {}) {
// Merge options with defaults
this.options = { ...DEFAULT_CONFIG, ...options };
// Derived configurations
this.maxFileSizeBytes = this.options.MAX_FILE_SIZE_MB * 1024 * 1024;
this.largeFileThresholdBytes =
this.options.LARGE_FILE_THRESHOLD_MB * 1024 * 1024;
this.memoryLimitBytes = this.options.MEMORY_LIMIT_MB * 1024 * 1024;
// Load external configurations
this.ignorePatterns = null;
this.textExtensions = null;
// Validate configuration
this.validate();
}
/**
* Load ignore patterns (async, cached)
*/
async getIgnorePatterns(customExclude = []) {
if (!this.ignorePatterns) {
const config = await loadConfigFile("default-ignore-patterns.json", {
ignore_patterns: this.options.FALLBACK_IGNORE_PATTERNS
});
this.ignorePatterns =
config.ignore_patterns || this.options.FALLBACK_IGNORE_PATTERNS;
}
return [...this.ignorePatterns, ...customExclude];
}
/**
* Load text extensions (async, cached)
*/
async getTextExtensions() {
if (!this.textExtensions) {
const config = await loadConfigFile("text-extensions.json", {
text_extensions: this.options.FALLBACK_TEXT_EXTENSIONS
});
this.textExtensions =
config.text_extensions || this.options.FALLBACK_TEXT_EXTENSIONS;
}
return this.textExtensions;
}
/**
* Validate configuration values
*/
validate() {
if (
typeof this.options.MAX_FILE_SIZE_MB !== "number" ||
this.options.MAX_FILE_SIZE_MB <= 0
) {
throw new Error("MAX_FILE_SIZE_MB must be a positive number");
}
if (
typeof this.options.TRUNCATE_SIZE_BYTES !== "number" ||
this.options.TRUNCATE_SIZE_BYTES < 0
) {
throw new Error("TRUNCATE_SIZE_BYTES must be a non-negative number");
}
if (this.options.SEPARATOR_LENGTH < 10) {
throw new Error("SEPARATOR_LENGTH must be at least 10");
}
}
/**
* Check if file extension is treated as text (async)
*/
async isTextExtension(filePath) {
const ext = this.getFileExtension(filePath);
const textExtensions = await this.getTextExtensions();
return textExtensions.includes(ext);
}
/**
* Get file extension including the dot
*/
getFileExtension(filePath) {
const lastDot = filePath.lastIndexOf(".");
return lastDot === -1 ? "" : filePath.substring(lastDot).toLowerCase();
}
/**
* Create separator line
*/
createSeparator(length = null, char = null) {
const separatorChar = char || this.options.SEPARATOR_CHAR;
const separatorLength = length || this.options.SEPARATOR_LENGTH;
return separatorChar.repeat(separatorLength);
}
/**
* Check if file size exceeds limits
*/
checkFileSize(sizeBytes) {
return {
exceedsLimit: sizeBytes > this.maxFileSizeBytes,
isLarge: sizeBytes > this.largeFileThresholdBytes,
sizeMB: sizeBytes / (1024 * 1024),
formattedSize: this.formatFileSize(sizeBytes)
};
}
/**
* Format file size for display
*/
formatFileSize(sizeBytes) {
if (sizeBytes < 1024) {
return `${sizeBytes} B`;
} else if (sizeBytes < 1024 * 1024) {
return `${(sizeBytes / 1024).toFixed(2)} KB`;
} else if (sizeBytes < 1024 * 1024 * 1024) {
return `${(sizeBytes / (1024 * 1024)).toFixed(2)} MB`;
} else {
return `${(sizeBytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
}
}
/**
* Clone configuration with overrides
*/
clone(overrides = {}) {
return new Config({ ...this.options, ...overrides });
}
/**
* Get all configuration as plain object
*/
toObject() {
return { ...this.options };
}
}
|