forked from softarc-consulting/sheriff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add finder method for barrel-less modules
Add a function that traverses through the tagged directories and mark them as modules in the barrel-less mode. This is also supports tagging with placeholders which are interpreted as simple wildcards.
- Loading branch information
1 parent
05eeb71
commit 10cd402
Showing
18 changed files
with
559 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
58 changes: 58 additions & 0 deletions
58
packages/core/src/lib/modules/internal/create-module-path-patterns-tree.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export type ModulePathPatternsTree = { | ||
[basePath: string]: ModulePathPatternsTree; | ||
}; | ||
|
||
/** | ||
* Create a tree structure from a list of module path patterns. | ||
* | ||
* Having a tree structure improves the performance because shared | ||
* parent directories only have to be read once. | ||
* | ||
* For example, given the following patterns: | ||
* ```typescript | ||
* ['src/app/feat-*-module/*', 'src/app/services/*', 'src/app/shared/*'] | ||
* ``` | ||
* | ||
* would end up in the following tree: | ||
* ```typescript | ||
* { | ||
* src: { | ||
* app: { | ||
* feat-*-module: {}, | ||
* services: {}, | ||
* shared: {} | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export function createModulePathPatternsTree( | ||
patterns: string[], | ||
): ModulePathPatternsTree { | ||
const flatTree: Record<string, string[]> = {}; | ||
|
||
for (const pattern of patterns) { | ||
const parts = pattern.split('/'); | ||
const basePath = parts[0]; // Get the top-level directory (e.g., "src") | ||
|
||
const restOfPattern = parts.slice(1).join('/'); // Remove the top-level part | ||
|
||
if (!flatTree[basePath]) { | ||
flatTree[basePath] = []; | ||
} | ||
|
||
flatTree[basePath].push(restOfPattern || ''); | ||
} | ||
|
||
// group next subdirectories | ||
const tree: ModulePathPatternsTree = {}; | ||
for (const basePath in flatTree) { | ||
const subPatterns = flatTree[basePath]; | ||
if (subPatterns.length === 1 && subPatterns[0] === '') { | ||
tree[basePath] = {}; | ||
} else { | ||
tree[basePath] = createModulePathPatternsTree(subPatterns); | ||
} | ||
} | ||
return tree; | ||
} |
Oops, something went wrong.