Feat/sub barrel files#249
Open
alilaa wants to merge 5 commits intosoftarc-consulting:mainfrom
Open
Conversation
add enableSubBarrelFileSupport config option (default: false) that allows sub-barrel files to be recognized as valid module entry points sub-barrel files follow the convention <barrelBaseName>.<suffix>.<ext> for example, if barrelFileName is 'public-api.ts', files like 'public-api.routing.ts' are treated as valid entry points when enabled when disabled (default), the encapsulation check uses the original barrel path equality with zero performance impact for existing users
add unit tests for Module.isBarrelFile() and integration tests for encapsulation checks with enableSubBarrelFileSupport on and off update error message strings in existing test fixtures
add sub-barrel files section to module boundaries documentation add enableSubBarrelFileSupport config reference
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
This is a suggested implementation to resolve Support multiple entry files for a single module
Adds opt-in support for sub-barrel files — additional module entry points that follow the naming convention
<barrelBaseName>.<suffix>.<ext>.For example, with
barrelFileName: 'public-api.ts', files likepublic-api.routing.tsandpublic-api.bookmarks.tsare recognized as valid imports without triggering encapsulation violations.Motivation
Projects using a barrel file sometimes need to split their public API into logically grouped subsets (routing, bookmarks, models, etc.) to avoid issues with treeshaking . This feature enables that pattern while keeping module boundaries intact.
Changes
Configuration
enableSubBarrelFileSupport: boolean(defaultfalse) — zero impact on existing usersUserSheriffConfig,Configuration, anddefaultConfigCore logic
Module.isBarrelFile(filePath)— new method using pure string operations (no filesystem or path API calls) to check if a file is the main barrel or a sub-barrel. ComputesbarrelPrefixandbarrelExtonce in the constructor.accessesBarrelFileForBarrelModules— delegates tomodule.isBarrelFile()when the feature is enabled; falls back to the existing strictbarrelPath ===check otherwise.ESLint error messages
(index.ts)reference from the deep-import error message, since users can configure a custombarrelFileName— the old message would be confusing when the barrel file is e.g.public-api.tsenableSubBarrelFileSupportis enabled, the message now suggests using "the module's barrel file or a sub-barrel file"index.ts)Documentation
configuration.md: documentedenableSubBarrelFileSupportoption and updatedbarrelFileNamedescriptionmodule_boundaries.md: new "Sub-Barrel Files" sectionTests
Module.isBarrelFile()covering: main barrel, sub-barrel with default/custom barrel names, non-barrel files, files in subdirectories, partial prefix matches, and edge casesCommits
feat(core): support sub-barrel files in encapsulation checks— config + Module.isBarrelFile + encapsulation check + ESLint messagetest(core): add tests for sub-barrel file support— unit and integration teststest(test-projects): update encapsulation fixtures for new error message— fixture updates for wording changedocs(docs): document sub-barrel files and enableSubBarrelFileSupport— documentationNotes
enableSubBarrelFileSupport: falseby default — no behavioral change for existing users