From 1b8d942a5af610ce6e38becbf1e533bc8683b0fd Mon Sep 17 00:00:00 2001 From: ManuelGil Date: Fri, 17 Jan 2025 18:20:20 -0500 Subject: [PATCH] feat: :sparkles: add maxSearchRecursionDepth setting to control file search depth --- CHANGELOG.md | 9 +++++- README.md | 3 ++ package.json | 8 +++++- package.nls.es.json | 1 + package.nls.json | 1 + schemas/config.schema.json | 6 ++++ src/app/configs/constants.config.ts | 12 ++++++++ src/app/configs/extension.config.ts | 21 ++++++++++++++ src/app/controllers/files.controller.ts | 38 +++++++++++++++---------- 9 files changed, 82 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 990ffd1..5c8d729 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/README.md b/README.md index 62425f2..bb87681 100644 --- a/README.md +++ b/README.md @@ -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, @@ -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`. @@ -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, diff --git a/package.json b/package.json index 7fe2a63..db576bd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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, diff --git a/package.nls.es.json b/package.nls.es.json index b599979..32532b1 100644 --- a/package.nls.es.json +++ b/package.nls.es.json @@ -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.", diff --git a/package.nls.json b/package.nls.json index 6b90620..2fbcc42 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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.", diff --git a/schemas/config.schema.json b/schemas/config.schema.json index d24f46f..ff309bf 100644 --- a/schemas/config.schema.json +++ b/schemas/config.schema.json @@ -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, diff --git a/src/app/configs/constants.config.ts b/src/app/configs/constants.config.ts index 3e48cc0..a282604 100644 --- a/src/app/configs/constants.config.ts +++ b/src/app/configs/constants.config.ts @@ -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} diff --git a/src/app/configs/extension.config.ts b/src/app/configs/extension.config.ts index 543cdca..67459ba 100644 --- a/src/app/configs/extension.config.ts +++ b/src/app/configs/extension.config.ts @@ -14,6 +14,7 @@ import { INSERT_FINAL_NEWLINE, KEEP_EXTENSION, PRESERVE_GITIGNORE, + RECURSION_DEPTH, SUPPORTS_HIDDEN, USE_NAMED_EXPORTS, USE_SINGLE_QUOTES, @@ -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 @@ -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} @@ -272,6 +285,10 @@ export class ExtensionConfig { 'files.ignoreFilePathPatternOnExport', EXCLUDE_PATTERNS, ); + this.maxSearchRecursionDepth = config.get( + 'files.maxSearchRecursionDepth', + RECURSION_DEPTH, + ); this.supportsHiddenFiles = config.get( 'files.supportsHiddenFiles', SUPPORTS_HIDDEN, @@ -353,6 +370,10 @@ export class ExtensionConfig { 'files.ignoreFilePathPatternOnExport', this.ignoreFilePathPatternOnExport, ); + this.maxSearchRecursionDepth = config.get( + 'files.maxSearchRecursionDepth', + this.maxSearchRecursionDepth, + ); this.supportsHiddenFiles = config.get( 'files.supportsHiddenFiles', this.supportsHiddenFiles, diff --git a/src/app/controllers/files.controller.ts b/src/app/controllers/files.controller.ts index 0cba508..a48e7ed 100644 --- a/src/app/controllers/files.controller.ts +++ b/src/app/controllers/files.controller.ts @@ -224,6 +224,7 @@ export class FilesController { disableRecursiveBarrelling, includeExtensionOnExport, ignoreFilePathPatternOnExport, + maxSearchRecursionDepth, supportsHiddenFiles, preserveGitignoreSettings, useSingleQuotes, @@ -251,7 +252,8 @@ export class FilesController { folderPath, [include], ignoreFilePathPatternOnExport, - !disableRecursiveBarrelling, + disableRecursiveBarrelling, + maxSearchRecursionDepth, supportsHiddenFiles, preserveGitignoreSettings, ); @@ -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 @@ -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 { // 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)) { @@ -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