Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/core/output/outputGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XMLBuilder from 'fast-xml-builder';
import Handlebars from 'handlebars';
import type { RepomixConfigMerged } from '../../config/configSchema.js';
import { RepomixError } from '../../shared/errorHandle.js';
import { type FileSearchResult, listDirectories, listFiles, searchFiles } from '../file/fileSearch.js';
import { listDirectories, listFiles, searchFiles } from '../file/fileSearch.js';
import { type FilesByRoot, generateTreeString, generateTreeStringWithRoots } from '../file/fileTreeGenerate.js';
import type { ProcessedFile } from '../file/fileTypes.js';
import type { GitDiffResult } from '../git/gitDiffHandle.js';
Expand Down Expand Up @@ -347,7 +347,8 @@ export const buildOutputGeneratorContext = async (
const additionalFiles = allRepoFiles.filter((p) => !includedSet.has(p));

directoryPathsForTree = allDirectories;
filePathsForTree = Array.from(new Set([...allFilePaths, ...additionalFiles]));
// additionalFiles is already disjoint from allFilePaths (filtered above), so no dedup needed
filePathsForTree = allFilePaths.concat(additionalFiles);
Comment thread
yamadashy marked this conversation as resolved.
} catch (error) {
throw new RepomixError(
`Failed to build full directory structure: ${error instanceof Error ? error.message : String(error)}`,
Expand All @@ -357,14 +358,8 @@ export const buildOutputGeneratorContext = async (
} else if (config.output.directoryStructure && config.output.includeEmptyDirectories) {
// Default behavior: include empty directories only
try {
const merged = (await Promise.all(rootDirs.map((rootDir) => deps.searchFiles(rootDir, config)))).reduce(
(acc: FileSearchResult, curr: FileSearchResult) =>
({
filePaths: [...acc.filePaths, ...curr.filePaths],
emptyDirPaths: [...acc.emptyDirPaths, ...curr.emptyDirPaths],
}) as FileSearchResult,
{ filePaths: [], emptyDirPaths: [] },
).emptyDirPaths;
const results = await Promise.all(rootDirs.map((rootDir) => deps.searchFiles(rootDir, config)));
const merged = results.flatMap((r) => r.emptyDirPaths);
directoryPathsForTree = [...new Set(merged)].sort();
} catch (error) {
throw new RepomixError(
Expand Down
3 changes: 1 addition & 2 deletions src/core/output/outputSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ const getFileChangeCounts = async (
const fileChangeCounts = await deps.getFileChangeCount(cwd, maxCommits);
fileChangeCountsCache.set(cacheKey, fileChangeCounts);

const sortedFileChangeCounts = Object.entries(fileChangeCounts).sort((a, b) => b[1] - a[1]);
logger.trace('Git File change counts max commits:', maxCommits);
logger.trace('Git File change counts:', sortedFileChangeCounts);
logger.trace('Git File change counts:', fileChangeCounts);

return fileChangeCounts;
} catch {
Expand Down
15 changes: 12 additions & 3 deletions src/shared/errorHandle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { inspect } from 'node:util';
import { z } from 'zod';
import { REPOMIX_DISCORD_URL, REPOMIX_ISSUES_URL } from './constants.js';
import { logger, repomixLogLevels } from './logger.js';

Expand Down Expand Up @@ -115,9 +114,19 @@ const isRepomixError = (error: unknown): error is RepomixError => {
);
};

/**
* Checks if an error is a ZodError using duck typing to avoid eagerly importing Zod.
* ZodErrors have a `name` of 'ZodError' and an `issues` array.
*/
export const rethrowValidationErrorIfZodError = (error: unknown, message: string): void => {
if (error instanceof z.ZodError) {
const zodErrorText = error.issues.map((err) => `[${err.path.join('.')}] ${err.message}`).join('\n ');
if (
error instanceof Error &&
error.name === 'ZodError' &&
'issues' in error &&
Array.isArray((error as { issues: unknown[] }).issues)
) {
const issues = (error as { issues: Array<{ path: string[]; message: string }> }).issues;
Comment thread
yamadashy marked this conversation as resolved.
const zodErrorText = issues.map((err) => `[${err.path.join('.')}] ${err.message}`).join('\n ');
Comment thread
yamadashy marked this conversation as resolved.
throw new RepomixConfigValidationError(
`${message}\n\n ${zodErrorText}\n\n Please check the config file and try again.`,
);
Expand Down
Loading