mirror of
https://github.com/yamadashy/repomix.git
synced 2026-11-20 06:29:20 +01:00
intent(dependencies): reduce the dependency tree where owning the code costs less than carrying the package decision(templates): each output style exports a typed render function built with template literals, so a wrong field name is a type error instead of a silently empty value decision(templates): keep the inputs-we-control rule for dropping dependencies; templates and output structure qualify, glob/ignore handling, tar extraction and git URL parsing do not learned(handlebars): every interpolation in the templates was the raw triple-stash form and every condition was a boolean, string or undefined, so no escaping or Handlebars truthiness had to be reproduced learned(handlebars): standalone block tags drop their whole line; reproduced by letting each optional section carry its own trailing newline constraint(output): generated output must stay byte-identical; verified with a 153-file golden comparison across xml/markdown/plain, git diffs and logs, header, instruction, line numbers, multi-root and skill generation, plus a 10,000-iteration differential fuzz against handlebars 4.7.10 constraint(website-server): website/server/package-lock.json still lists handlebars through the published repomix package until it picks up a release with this change Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
102 lines
3.4 KiB
TypeScript
102 lines
3.4 KiB
TypeScript
import fs from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import process from 'node:process';
|
|
import { defaultConfig, type RepomixConfigMerged } from '../../src/config/configSchema.js';
|
|
import type { RenderContext } from '../../src/core/output/outputGeneratorTypes.js';
|
|
|
|
type DeepPartial<T> = {
|
|
[P in keyof T]?: T[P] extends (infer U)[]
|
|
? DeepPartial<U>[]
|
|
: T[P] extends readonly (infer U)[]
|
|
? readonly DeepPartial<U>[]
|
|
: T[P] extends object
|
|
? DeepPartial<T[P]>
|
|
: T[P];
|
|
};
|
|
|
|
export const createMockConfig = (config: DeepPartial<RepomixConfigMerged> = {}): RepomixConfigMerged => {
|
|
return {
|
|
cwd: config.cwd ?? process.cwd(),
|
|
input: {
|
|
...defaultConfig.input,
|
|
...config.input,
|
|
},
|
|
output: {
|
|
...defaultConfig.output,
|
|
...config.output,
|
|
git: {
|
|
...defaultConfig.output.git,
|
|
...config.output?.git,
|
|
},
|
|
},
|
|
ignore: {
|
|
...defaultConfig.ignore,
|
|
...config.ignore,
|
|
customPatterns: [...(defaultConfig.ignore.customPatterns || []), ...(config.ignore?.customPatterns || [])],
|
|
},
|
|
include: [...(defaultConfig.include || []), ...(config.include || [])],
|
|
security: {
|
|
...defaultConfig.security,
|
|
...config.security,
|
|
},
|
|
tokenCount: {
|
|
...defaultConfig.tokenCount,
|
|
...config.tokenCount,
|
|
},
|
|
// CLI-only optional properties
|
|
...(config.skillGenerate !== undefined && { skillGenerate: config.skillGenerate }),
|
|
...(config.enableFileProcessors !== undefined && { enableFileProcessors: config.enableFileProcessors }),
|
|
};
|
|
};
|
|
|
|
/**
|
|
* A RenderContext with every section disabled and short placeholder values, for
|
|
* testing the output style renderers directly. Override fields to enable sections.
|
|
*/
|
|
export const createMockRenderContext = (overrides: Partial<RenderContext> = {}): RenderContext => ({
|
|
generationHeader: 'GENERATION_HEADER',
|
|
summaryPurpose: 'PURPOSE',
|
|
summaryFileFormat: 'FILE_FORMAT',
|
|
summaryUsageGuidelines: 'USAGE_GUIDELINES',
|
|
summaryNotes: 'NOTES',
|
|
headerText: undefined,
|
|
instruction: '',
|
|
treeString: 'TREE',
|
|
processedFiles: [],
|
|
fileLineCounts: {},
|
|
fileSummaryEnabled: false,
|
|
directoryStructureEnabled: false,
|
|
filesEnabled: false,
|
|
escapeFileContent: false,
|
|
markdownCodeBlockDelimiter: '```',
|
|
gitDiffEnabled: false,
|
|
gitDiffWorkTree: undefined,
|
|
gitDiffStaged: undefined,
|
|
gitLogEnabled: false,
|
|
gitLogContent: undefined,
|
|
gitLogCommits: undefined,
|
|
...overrides,
|
|
});
|
|
|
|
export const isWindows = os.platform() === 'win32';
|
|
export const isMac = os.platform() === 'darwin';
|
|
export const isLinux = os.platform() === 'linux';
|
|
|
|
/**
|
|
* Write a flat dict of `relativePath → content` into `rootDir`, creating
|
|
* parent directories as needed. Used by the spec tests that build small
|
|
* fixture trees in a tmpdir before invoking searchFiles / pack.
|
|
*/
|
|
export const writeFixture = async (rootDir: string, files: Record<string, string>): Promise<void> => {
|
|
for (const [relPath, content] of Object.entries(files)) {
|
|
const fullPath = path.join(rootDir, relPath);
|
|
await fs.mkdir(path.dirname(fullPath), { recursive: true });
|
|
await fs.writeFile(fullPath, content);
|
|
}
|
|
};
|
|
|
|
// MCP SDK v2 types `structuredContent` loosely, so tests read it through this narrowing helper.
|
|
export const structuredContentOf = (result: { structuredContent?: unknown }): Record<string, unknown> =>
|
|
(result.structuredContent ?? {}) as Record<string, unknown>;
|