Skip to content

Commit

Permalink
feat: ✨ add maxSearchRecursionDepth setting to control file search depth
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelGil committed Jan 17, 2025
1 parent edfe0a9 commit 1b8d942
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 17 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.18.0] - 2025-01-17

### Added

- Add `maxSearchRecursionDepth` setting to control file search depth.

## [1.17.0] - 2025-01-08

### Added
Expand Down Expand Up @@ -177,7 +183,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add basic functionality for generating barrel files.
- Add support for TypeScript and JavaScript projects.

[Unreleased]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.17.0...HEAD
[Unreleased]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.18.0...HEAD
[1.18.0]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.17.0...v1.18.0
[1.17.0]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.16.1...v1.17.0
[1.16.1]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.16.0...v1.16.1
[1.16.0]: https://github.com/ManuelGil/vscode-auto-barrel/compare/v1.15.0...v1.16.0
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Configure your project by creating or updating a settings.json file at the proje
"autoBarrel.files.disableRecursiveBarrelling": false,
"autoBarrel.files.includeExtensionOnExport": ["ts", "tsx", "vue"],
"autoBarrel.files.ignoreFilePathPatternOnExport": ["**/*.spec.*", "**/*.test.*"],
"autoBarrel.files.maxSearchRecursionDepth": 10,
"autoBarrel.files.supportsHiddenFiles": true,
"autoBarrel.files.preserveGitignoreSettings": false,
"autoBarrel.files.keepExtensionOnExport": false,
Expand Down Expand Up @@ -121,6 +122,7 @@ Configure Auto Barrel settings in your `.vscode/settings.json` file to tailor th
- `autoBarrel.files.disableRecursiveBarrelling`: Whether to disable recursive barrelling for subdirectories. Default is `false`.
- `autoBarrel.files.includeExtensionOnExport`: An array of file extensions to include when exporting modules. Default is `["ts", "tsx", "vue"]`.
- `autoBarrel.files.ignoreFilePathPatternOnExport`: An array of file path patterns to ignore when exporting modules. Default is `["**/*.spec.*", "**/*.test.*"]`.
- `autoBarrel.files.maxSearchRecursionDepth`: The maximum recursion depth when searching for files to export. Use `0` for infinite recursion.
- `autoBarrel.files.supportsHiddenFiles`: Whether to include hidden files and directories when exporting modules. Default is `true`.
- `autoBarrel.files.preserveGitignoreSettings`: Whether to preserve the `.gitignore` settings when exporting modules. Default is `false`.
- `autoBarrel.files.keepExtensionOnExport`: Whether to keep the file extension when exporting modules. Default is `false`.
Expand All @@ -145,6 +147,7 @@ JavaScript example settings:
"autoBarrel.files.disableRecursiveBarrelling": false,
"autoBarrel.files.includeExtensionOnExport": ["js", "jsx"],
"autoBarrel.files.ignoreFilePathPatternOnExport": ["**/*.spec.*", "**/*.test.*"],
"autoBarrel.files.maxSearchRecursionDepth": 10,
"autoBarrel.files.supportsHiddenFiles": true,
"autoBarrel.files.preserveGitignoreSettings": false,
"autoBarrel.files.keepExtensionOnExport": false,
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-auto-barrel",
"displayName": "Auto Barrel for VSCode",
"description": "🛢️ Automatically generate index files for your project.",
"version": "1.17.0",
"version": "1.18.0",
"icon": "icon.png",
"license": "MIT",
"publisher": "imgildev",
Expand Down Expand Up @@ -112,6 +112,12 @@
"scope": "resource",
"description": "%autoBarrel.files.ignoreFilePathPatternOnExport%"
},
"autoBarrel.files.maxSearchRecursionDepth": {
"type": "number",
"default": 0,
"scope": "resource",
"description": "%autoBarrel.files.maxSearchRecursionDepth%"
},
"autoBarrel.files.supportsHiddenFiles": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions package.nls.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"autoBarrel.files.disableRecursiveBarrelling": "Deshabilitar la recursión para subdirectorios al crear el archivo de barril.",
"autoBarrel.files.includeExtensionOnExport": "Extensiones a incluir en la exportación. Esto se utiliza para filtrar los archivos a exportar.",
"autoBarrel.files.ignoreFilePathPatternOnExport": "Patrones globales a ignorar en la exportación. Esto se utiliza para filtrar los archivos a exportar.",
"autoBarrel.files.maxSearchRecursionDepth": "Profundidad máxima de recursión al buscar archivos a exportar. 0 significa sin límite.",
"autoBarrel.files.supportsHiddenFiles": "Soportar archivos y directorios ocultos al exportar (archivos que comienzan con un punto).",
"autoBarrel.files.preserveGitignoreSettings": "Preservar la configuración del archivo .gitignore al exportar.",
"autoBarrel.files.keepExtensionOnExport": "Mantener la extensión del archivo en la exportación.",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"autoBarrel.files.disableRecursiveBarrelling": "Disable the recurtion for subdirectories when creating the barrel file.",
"autoBarrel.files.includeExtensionOnExport": "Extensions to include on the export. This is used to filter the files to export.",
"autoBarrel.files.ignoreFilePathPatternOnExport": "Glob patterns to ignore on the export. This is used to filter the files to export.",
"autoBarrel.files.maxSearchRecursionDepth": "Maximum recursion depth when searching for files to export. 0 means no limit.",
"autoBarrel.files.supportsHiddenFiles": "Support hidden files and directories when exporting (files starting with a dot).",
"autoBarrel.files.preserveGitignoreSettings": "Preserve the settings from the .gitignore file when exporting.",
"autoBarrel.files.keepExtensionOnExport": "Keep the file extension on the export.",
Expand Down
6 changes: 6 additions & 0 deletions schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"scope": "resource",
"description": "Glob patterns to ignore on the export. This is used to filter the files to export."
},
"autoBarrel.files.maxSearchRecursionDepth": {
"type": "number",
"default": 0,
"scope": "resource",
"description": "Maximum recursion depth when searching for files to export. 0 means no limit."
},
"autoBarrel.files.supportsHiddenFiles": {
"type": "boolean",
"default": true,
Expand Down
12 changes: 12 additions & 0 deletions src/app/configs/constants.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ export const EXCLUDE_PATTERNS: string[] = [
'**/index.js',
];

/**
* RECURSION_DEPTH: The recursion depth.
* @type {number}
* @public
* @memberof Constants
* @example
* console.log(RECURSION_DEPTH);
*
* @returns {number} - The recursion depth
*/
export const RECURSION_DEPTH: number = 0;

/**
* SUPPORTS_HIDDEN: The flag to support hidden files and directories (files that start with a dot).
* @type {boolean}
Expand Down
21 changes: 21 additions & 0 deletions src/app/configs/extension.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
INSERT_FINAL_NEWLINE,
KEEP_EXTENSION,
PRESERVE_GITIGNORE,
RECURSION_DEPTH,
SUPPORTS_HIDDEN,
USE_NAMED_EXPORTS,
USE_SINGLE_QUOTES,
Expand All @@ -32,6 +33,7 @@ import {
* @property {boolean} disableRecursiveBarrelling - The flag to disable recursive barrelling
* @property {string[]} includeExtensionOnExport - The extensions to include in the export
* @property {string[]} ignoreFilePathPatternOnExport - The file path patterns to ignore on export
* @property {number} maxSearchRecursionDepth - The maximum search recursion depth
* @property {boolean} supportsHiddenFiles - The flag to allow hidden files
* @property {boolean} preserveGitignoreSettings - The flag to respect the .gitignore file
* @property {boolean} keepExtensionOnExport - The flag to keep the extension on export
Expand Down Expand Up @@ -110,6 +112,17 @@ export class ExtensionConfig {
*/
ignoreFilePathPatternOnExport: string[];

/**
* The maximum search recursion depth.
* @type {number}
* @public
* @memberof Config
* @example
* const config = new Config(workspace.getConfiguration());
* console.log(config.maxSearchRecursionDepth);
*/
maxSearchRecursionDepth: number;

/**
* The flag to allow hidden files.
* @type {boolean}
Expand Down Expand Up @@ -272,6 +285,10 @@ export class ExtensionConfig {
'files.ignoreFilePathPatternOnExport',
EXCLUDE_PATTERNS,
);
this.maxSearchRecursionDepth = config.get<number>(
'files.maxSearchRecursionDepth',
RECURSION_DEPTH,
);
this.supportsHiddenFiles = config.get<boolean>(
'files.supportsHiddenFiles',
SUPPORTS_HIDDEN,
Expand Down Expand Up @@ -353,6 +370,10 @@ export class ExtensionConfig {
'files.ignoreFilePathPatternOnExport',
this.ignoreFilePathPatternOnExport,
);
this.maxSearchRecursionDepth = config.get<number>(
'files.maxSearchRecursionDepth',
this.maxSearchRecursionDepth,
);
this.supportsHiddenFiles = config.get<boolean>(
'files.supportsHiddenFiles',
this.supportsHiddenFiles,
Expand Down
38 changes: 23 additions & 15 deletions src/app/controllers/files.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class FilesController {
disableRecursiveBarrelling,
includeExtensionOnExport,
ignoreFilePathPatternOnExport,
maxSearchRecursionDepth,
supportsHiddenFiles,
preserveGitignoreSettings,
useSingleQuotes,
Expand Down Expand Up @@ -251,7 +252,8 @@ export class FilesController {
folderPath,
[include],
ignoreFilePathPatternOnExport,
!disableRecursiveBarrelling,
disableRecursiveBarrelling,
maxSearchRecursionDepth,
supportsHiddenFiles,
preserveGitignoreSettings,
);
Expand Down Expand Up @@ -510,8 +512,13 @@ export class FilesController {
*
* @function findFiles
* @param {string} baseDir - The base directory
* @param {string[]} include - The include pattern
* @param {string[]} exclude - The exclude pattern
* @param {string[]} includeFilePatterns - The include pattern
* @param {string[]} excludedPatterns - The exclude pattern
* @param {boolean} includeOnlyFiles - The flag to include only files
* @param {boolean} disableRecursive - The flag to disable recursive searching
* @param {number} deep - The recursion depth
* @param {boolean} includeDotfiles - The flag to include dotfiles
* @param {boolean} enableGitignoreDetection - The flag to enable .gitignore detection
* @private
* @async
* @memberof FilesController
Expand All @@ -522,15 +529,16 @@ export class FilesController {
*/
private async findFiles(
baseDir: string,
include: string[], // Include patterns
exclude: string[], // Exclude patterns
allowRecursion: boolean = true, // Toggle recursive search
allowHidden: boolean = true, // Toggle hidden files
respectGitignore: boolean = false, // Toggle .gitignore respect
includeFilePatterns: string[],
excludedPatterns: string[],
disableRecursive: boolean = false,
deep: number = 0,
includeDotfiles: boolean = false,
enableGitignoreDetection: boolean = false,
): Promise<Uri[]> {
// If we need to respect .gitignore, we need to load it
let gitignore;
if (respectGitignore) {
if (enableGitignoreDetection) {
const gitignorePath = join(baseDir, '.gitignore');
// Load .gitignore if it exists
if (existsSync(gitignorePath)) {
Expand All @@ -540,17 +548,17 @@ export class FilesController {

// Configure fast-glob options
const options = {
cwd: baseDir, // Set base directory for searching
absolute: true, // Ensure paths are absolute
cwd: baseDir, // Set the base directory for searching
absolute: true, // Return absolute paths for files found
onlyFiles: true, // Match only files, not directories
dot: allowHidden, // Include files and directories starting with a dot
deep: allowRecursion ? undefined : 1, // Toggle recursion
ignore: exclude, // Exclude patterns
dot: includeDotfiles, // Include the files and directories starting with a dot
deep: disableRecursive ? 1 : deep === 0 ? undefined : deep, // Set the recursion depth
ignore: excludedPatterns, // Set the patterns to ignore files and directories
};

try {
// Use fast-glob to find matching files
let foundFilePaths = await fastGlob(include, options);
let foundFilePaths = await fastGlob(includeFilePatterns, options);

if (gitignore) {
// Filter out files that are ignored by .gitignore
Expand Down

0 comments on commit 1b8d942

Please sign in to comment.