Skip to content

Commit

Permalink
fixed node path import
Browse files Browse the repository at this point in the history
  • Loading branch information
iNerdStack committed Nov 24, 2024
1 parent aa7ac5d commit 53bb500
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/config/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const repomixConfigBaseSchema = z.object({
topFilesLength: z.number().optional(),
showLineNumbers: z.boolean().optional(),
copyToClipboard: z.boolean().optional(),
includeEmptyDirectories: z.boolean().optional()
includeEmptyDirectories: z.boolean().optional(),
})
.optional(),
include: z.array(z.string()).optional(),
Expand Down Expand Up @@ -55,7 +55,7 @@ export const repomixConfigDefaultSchema = z.object({
topFilesLength: z.number().int().min(0).default(5),
showLineNumbers: z.boolean().default(false),
copyToClipboard: z.boolean().default(false),
includeEmptyDirectories: z.boolean().optional()
includeEmptyDirectories: z.boolean().optional(),
})
.default({}),
include: z.array(z.string()).default([]),
Expand Down
14 changes: 5 additions & 9 deletions src/core/file/fileSearch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { globby } from 'globby';
import { minimatch } from 'minimatch';
import type { RepomixConfigMerged } from '../../config/configSchema.js';
import { defaultIgnoreList } from '../../config/defaultIgnore.js';
import { logger } from '../../shared/logger.js';
import { sortPaths } from './filePathSort.js';
import { PermissionError, checkDirectoryPermissions } from './permissionCheck.js';
import { minimatch } from 'minimatch';
import path from 'path';
import fs from 'node:fs/promises';

export interface FileSearchResult {
filePaths: string[];
Expand All @@ -24,13 +24,11 @@ const findEmptyDirectories = async (
const fullPath = path.join(rootDir, dir);
try {
const entries = await fs.readdir(fullPath);
const hasVisibleContents = entries.some(entry => !entry.startsWith('.'));
const hasVisibleContents = entries.some((entry) => !entry.startsWith('.'));

if (!hasVisibleContents) {
// This checks if the directory itself matches any ignore patterns
const shouldIgnore = ignorePatterns.some(pattern =>
minimatch(dir, pattern) || minimatch(`${dir}/`, pattern)
);
const shouldIgnore = ignorePatterns.some((pattern) => minimatch(dir, pattern) || minimatch(`${dir}/`, pattern));

if (!shouldIgnore) {
emptyDirs.push(dir);
Expand Down Expand Up @@ -86,7 +84,6 @@ export const searchFiles = async (rootDir: string, config: RepomixConfigMerged):
throw error;
});


let emptyDirPaths: string[] = [];
if (config.output.includeEmptyDirectories) {
const directories = await globby(includePatterns, {
Expand All @@ -108,7 +105,6 @@ export const searchFiles = async (rootDir: string, config: RepomixConfigMerged):
filePaths: sortPaths(filePaths),
emptyDirPaths: sortPaths(emptyDirPaths),
};

} catch (error: unknown) {
// Re-throw PermissionError as is
if (error instanceof PermissionError) {
Expand Down
6 changes: 2 additions & 4 deletions src/core/output/outputGenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path';
import Handlebars from 'handlebars';
import type { RepomixConfigMerged } from '../../config/configSchema.js';
import { RepomixError } from '../../shared/errorHandle.js';
import { searchFiles } from '../file/fileSearch.js';
import { generateTreeString } from '../file/fileTreeGenerate.js';
import type { ProcessedFile } from '../file/fileTypes.js';
import type { OutputGeneratorContext } from './outputGeneratorTypes.js';
Expand All @@ -17,7 +18,6 @@ import {
import { getMarkdownTemplate } from './outputStyles/markdownStyle.js';
import { getPlainTemplate } from './outputStyles/plainStyle.js';
import { getXmlTemplate } from './outputStyles/xmlStyle.js';
import { searchFiles } from '../file/fileSearch.js';

const createRenderContext = (outputGeneratorContext: OutputGeneratorContext) => {
return {
Expand Down Expand Up @@ -79,9 +79,7 @@ export const buildOutputGeneratorContext = async (
}
}

const emptyDirPaths = config.output.includeEmptyDirectories ?
(await searchFiles(rootDir, config)).emptyDirPaths :
[];
const emptyDirPaths = config.output.includeEmptyDirectories ? (await searchFiles(rootDir, config)).emptyDirPaths : [];

return {
generationDate: new Date().toISOString(),
Expand Down
5 changes: 4 additions & 1 deletion tests/core/packager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ describe('packager', () => {
const mockConfig = createMockConfig();
const suspiciousFile = 'suspicious.txt';
const file2Path = path.join('dir1', 'file2.txt');
vi.mocked(mockDeps.searchFiles).mockResolvedValue({ emptyDirPaths: [], filePaths: ['file1.txt', file2Path, suspiciousFile]});
vi.mocked(mockDeps.searchFiles).mockResolvedValue({
emptyDirPaths: [],
filePaths: ['file1.txt', file2Path, suspiciousFile],
});
vi.mocked(mockDeps.collectFiles).mockResolvedValue([
{ path: 'file1.txt', content: 'raw content 1' },
{ path: file2Path, content: 'raw content 2' },
Expand Down

0 comments on commit 53bb500

Please sign in to comment.