From c136e0b7fe5ce8fc317fc9ec247f8fe98afb8d3f Mon Sep 17 00:00:00 2001 From: Marc Beinder Date: Sun, 15 Mar 2026 08:36:04 -0500 Subject: [PATCH] Add support for skipping specified directories during index generation --- .../index-generation/IndexGenerationRule.d.ts | 1 + .../index-generation/IndexGenerationRule.js | 31 +++++++++++----- dist/index.d.ts | 1 - dist/index.js | 2 - dist/tsfmt.js | 9 ----- .../index-generation/IndexGenerationRule.ts | 37 ++++++++++++++----- 6 files changed, 51 insertions(+), 30 deletions(-) delete mode 100644 dist/tsfmt.js diff --git a/dist/core/formatters/rules/index-generation/IndexGenerationRule.d.ts b/dist/core/formatters/rules/index-generation/IndexGenerationRule.d.ts index 90e2208..a1d3372 100644 --- a/dist/core/formatters/rules/index-generation/IndexGenerationRule.d.ts +++ b/dist/core/formatters/rules/index-generation/IndexGenerationRule.d.ts @@ -7,6 +7,7 @@ export interface IndexGenerationOptions { export interface IndexGenerationConfig { enabled?: boolean; directories?: string[]; + skipDirectories?: string[]; options?: Partial; updateMainIndex?: boolean; } diff --git a/dist/core/formatters/rules/index-generation/IndexGenerationRule.js b/dist/core/formatters/rules/index-generation/IndexGenerationRule.js index b641143..26895e7 100644 --- a/dist/core/formatters/rules/index-generation/IndexGenerationRule.js +++ b/dist/core/formatters/rules/index-generation/IndexGenerationRule.js @@ -62,7 +62,7 @@ class IndexGenerationRule extends BaseFormattingRule.BaseFormattingRule { ]; return testPatterns.some((pattern) => pattern.test(fileName)); } - generateSingleDirectoryIndex(dir, options) { + generateSingleDirectoryIndex(dir, skipPaths, options) { try { const entries = fs__namespace.readdirSync(dir, { withFileTypes: true }); const exports$1 = []; @@ -74,7 +74,11 @@ class IndexGenerationRule extends BaseFormattingRule.BaseFormattingRule { if (this.isTestDirectory(entry.name)) { continue; } - const subIndexPath = path__namespace.join(dir, entry.name, options.indexFileName); + const subDir = path__namespace.join(dir, entry.name); + if (skipPaths.has(subDir)) { + continue; + } + const subIndexPath = path__namespace.join(subDir, options.indexFileName); if (fs__namespace.existsSync(subIndexPath)) { exports$1.push(`export * from "./${entry.name}";`); } @@ -104,7 +108,7 @@ ${exports$1.join("\n")} console.warn(`Warning: Failed to generate index for ${dir}: ${error.message}`); } } - generateIndexExportRecursive(dir, options) { + generateIndexExportRecursive(dir, skipPaths, options) { try { const entries = fs__namespace.readdirSync(dir, { withFileTypes: true }); for (const entry of entries) { @@ -113,22 +117,25 @@ ${exports$1.join("\n")} continue; } const subDir = path__namespace.join(dir, entry.name); - this.generateIndexExportRecursive(subDir, options); + if (skipPaths.has(subDir)) { + continue; + } + this.generateIndexExportRecursive(subDir, skipPaths, options); } } - this.generateSingleDirectoryIndex(dir, options); + this.generateSingleDirectoryIndex(dir, skipPaths, options); } catch (error) { console.warn(`Warning: Failed to process directory ${dir}: ${error.message}`); } } - generateIndexExport(dir, options) { + generateIndexExport(dir, skipPaths, options) { if (!fs__namespace.existsSync(dir)) { return; } if (options.recursive) { - this.generateIndexExportRecursive(dir, options); + this.generateIndexExportRecursive(dir, skipPaths, options); } else { - this.generateSingleDirectoryIndex(dir, options); + this.generateSingleDirectoryIndex(dir, skipPaths, options); } } discoverExportableModules(srcDir) { @@ -180,9 +187,15 @@ ${exports$1} const config = this.getIndexGenerationConfig(); const directories = config?.directories || []; const options = { ...this.defaultOptions, ...config?.options }; + const skipPaths = new Set( + (config?.skipDirectories || []).map((d) => path__namespace.resolve(projectRoot, d)) + ); for (const dir of directories) { const fullDirPath = path__namespace.resolve(projectRoot, dir); - this.generateIndexExport(fullDirPath, options); + if (skipPaths.has(fullDirPath)) { + continue; + } + this.generateIndexExport(fullDirPath, skipPaths, options); } if (config?.updateMainIndex !== false) { const srcDir = path__namespace.join(projectRoot, "src"); diff --git a/dist/index.d.ts b/dist/index.d.ts index 6a56434..912d165 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,4 +2,3 @@ export * from "./build-plugins"; export * from "./core"; export * from "./formatters"; export * from "./shared"; -export { tsfmt } from "./tsfmt"; diff --git a/dist/index.js b/dist/index.js index 4c8b4b7..4970b8c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29,7 +29,6 @@ const StructuralIndentationRule = require("./core/formatters/rules/style/Structu const FormatterPipeline = require("./core/pipeline/FormatterPipeline.js"); const _package = require("./formatters/package.js"); const types = require("./shared/types.js"); -const tsfmt = require("./tsfmt.js"); exports.transformGenericsPlugin = transformGenericsPlugin.transformGenericsPlugin; exports.ASTAnalyzer = ASTAnalyzer.ASTAnalyzer; exports.ASTTransformer = ASTTransformer.ASTTransformer; @@ -65,4 +64,3 @@ exports.FormatterError = FormatterPipeline.FormatterError; exports.FormatterPipeline = FormatterPipeline.FormatterPipeline; exports.sortExportsKeys = _package.sortExportsKeys; exports.DefaultSortOptions = types.DefaultSortOptions; -exports.tsfmt = tsfmt.tsfmt; diff --git a/dist/tsfmt.js b/dist/tsfmt.js deleted file mode 100644 index 1b09d64..0000000 --- a/dist/tsfmt.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; -Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); -require("./core/config/ConfigDefaults.js"); -require("./core/config/ConfigLoader.js"); -const ConfigMerger = require("./core/config/ConfigMerger.js"); -function tsfmt(config = {}) { - return ConfigMerger.ConfigMerger.merge(config); -} -exports.tsfmt = tsfmt; diff --git a/src/core/formatters/rules/index-generation/IndexGenerationRule.ts b/src/core/formatters/rules/index-generation/IndexGenerationRule.ts index 07238e3..a792e86 100644 --- a/src/core/formatters/rules/index-generation/IndexGenerationRule.ts +++ b/src/core/formatters/rules/index-generation/IndexGenerationRule.ts @@ -28,6 +28,9 @@ export interface IndexGenerationConfig { /** Directories to process for index generation */ directories?: string[]; + /** Directories to always skip, even if listed in directories (takes priority) */ + skipDirectories?: string[]; + /** Default options for index generation */ options?: Partial; @@ -88,7 +91,7 @@ export class IndexGenerationRule extends BaseFormattingRule { return testPatterns.some(pattern => pattern.test(fileName)); } - private generateSingleDirectoryIndex(dir: string, options: IndexGenerationOptions): void { + private generateSingleDirectoryIndex(dir: string, skipPaths: Set, options: IndexGenerationOptions): void { try { const entries = fs.readdirSync(dir, {withFileTypes: true}); const exports: string[] = []; @@ -103,8 +106,13 @@ export class IndexGenerationRule extends BaseFormattingRule { if (this.isTestDirectory(entry.name)) { continue; } + const subDir = path.join(dir, entry.name); + + if (skipPaths.has(subDir)) { + continue; + } // Check if subdirectory has an index file - const subIndexPath = path.join(dir, entry.name, options.indexFileName); + const subIndexPath = path.join(subDir, options.indexFileName); if (fs.existsSync(subIndexPath)) { exports.push(`export * from "./${entry.name}";`); @@ -145,7 +153,7 @@ ${exports.join("\n")} } } - private generateIndexExportRecursive(dir: string, options: IndexGenerationOptions): void { + private generateIndexExportRecursive(dir: string, skipPaths: Set, options: IndexGenerationOptions): void { try { const entries = fs.readdirSync(dir, {withFileTypes: true}); @@ -158,25 +166,29 @@ ${exports.join("\n")} const subDir = path.join(dir, entry.name); - this.generateIndexExportRecursive(subDir, options); + if (skipPaths.has(subDir)) { + continue; + } + + this.generateIndexExportRecursive(subDir, skipPaths, options); } } - this.generateSingleDirectoryIndex(dir, options); + this.generateSingleDirectoryIndex(dir, skipPaths, options); } catch (error) { console.warn(`Warning: Failed to process directory ${dir}: ${(error as Error).message}`); } } - private generateIndexExport(dir: string, options: IndexGenerationOptions): void { + private generateIndexExport(dir: string, skipPaths: Set, options: IndexGenerationOptions): void { if (!fs.existsSync(dir)) { return; } if (options.recursive) { - this.generateIndexExportRecursive(dir, options); + this.generateIndexExportRecursive(dir, skipPaths, options); } else { - this.generateSingleDirectoryIndex(dir, options); + this.generateSingleDirectoryIndex(dir, skipPaths, options); } } @@ -247,11 +259,18 @@ ${exports} const config = this.getIndexGenerationConfig(); const directories = config?.directories || []; const options = {...this.defaultOptions, ...config?.options}; + const skipPaths = new Set( + (config?.skipDirectories || []).map(d => path.resolve(projectRoot, d)) + ); for (const dir of directories) { const fullDirPath = path.resolve(projectRoot, dir); - this.generateIndexExport(fullDirPath, options); + if (skipPaths.has(fullDirPath)) { + continue; + } + + this.generateIndexExport(fullDirPath, skipPaths, options); } // Update main src/index.ts if configured