( rootDir: string, config: RepomixConfigMerged, explicitFiles?: string[], )
| 125 | |
| 126 | // Get all file paths considering the config |
| 127 | export const searchFiles = async ( |
| 128 | rootDir: string, |
| 129 | config: RepomixConfigMerged, |
| 130 | explicitFiles?: string[], |
| 131 | ): Promise<FileSearchResult> => { |
| 132 | // Check if the path exists and get its type |
| 133 | let pathStats: Stats; |
| 134 | try { |
| 135 | pathStats = await fs.stat(rootDir); |
| 136 | } catch (error) { |
| 137 | if (error instanceof Error && 'code' in error) { |
| 138 | const errorCode = (error as NodeJS.ErrnoException).code; |
| 139 | if (errorCode === 'ENOENT') { |
| 140 | throw new RepomixError(`Target path does not exist: ${rootDir}`); |
| 141 | } |
| 142 | if (errorCode === 'EPERM' || errorCode === 'EACCES') { |
| 143 | throw new PermissionError( |
| 144 | `Permission denied while accessing path. Please check folder access permissions for your terminal app. path: ${rootDir}`, |
| 145 | rootDir, |
| 146 | errorCode, |
| 147 | ); |
| 148 | } |
| 149 | // Handle other specific error codes with more context |
| 150 | throw new RepomixError(`Failed to access path: ${rootDir}. Error code: ${errorCode}. ${error.message}`); |
| 151 | } |
| 152 | // Preserve original error stack trace for debugging |
| 153 | const repomixError = new RepomixError( |
| 154 | `Failed to access path: ${rootDir}. Reason: ${error instanceof Error ? error.message : JSON.stringify(error)}`, |
| 155 | ); |
| 156 | repomixError.cause = error; |
| 157 | throw repomixError; |
| 158 | } |
| 159 | |
| 160 | // Check if the path is a directory |
| 161 | if (!pathStats.isDirectory()) { |
| 162 | throw new RepomixError( |
| 163 | `Target path is not a directory: ${rootDir}. Please specify a directory path, not a file path.`, |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | // Now check directory permissions |
| 168 | const permissionCheck = await checkDirectoryPermissions(rootDir); |
| 169 | |
| 170 | if (permissionCheck.details?.read !== true) { |
| 171 | if (permissionCheck.error instanceof PermissionError) { |
| 172 | throw permissionCheck.error; |
| 173 | } |
| 174 | throw new RepomixError( |
| 175 | `Target directory is not readable or does not exist. Please check folder access permissions for your terminal app.\npath: ${rootDir}`, |
| 176 | ); |
| 177 | } |
| 178 | |
| 179 | try { |
| 180 | const { adjustedIgnorePatterns, ignoreFilePatterns, deferredIgnorePatterns } = await prepareIgnoreContext( |
| 181 | rootDir, |
| 182 | config, |
| 183 | ); |
| 184 |
no test coverage detected