-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): make barrel file optional in module type
This change is a prerequisite for the upcoming barrel-less mode. The module type has been updated so that a barrel file is no longer mandatory. This affects the `path` property, which previously always pointed to the barrel file. The new implementation supports both barrel-based and barrel-less (inactive) setups Additionally, the barrel file name is added to the config but remains internal.
- Loading branch information
1 parent
883a472
commit 849176c
Showing
25 changed files
with
614 additions
and
330 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
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 |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import getFs from '../fs/getFs'; | ||
import { FsPath } from '../file-info/fs-path'; | ||
import { logger } from '../log'; | ||
import { findModulePathsWithoutBarrel } from "./internal/find-module-paths-without-barrel"; | ||
import { TagConfig } from "../config/tag-config"; | ||
import { findModulePathsWithBarrel } from "./internal/find-module-paths-with-barrel"; | ||
|
||
const log = logger('core.modules.find-path'); | ||
export type ModulePathMap = Record<FsPath, boolean> | ||
|
||
export const findModulePaths = (projectDirs: FsPath[]): Set<FsPath> => { | ||
const fs = getFs(); | ||
let modules: FsPath[] = []; | ||
/** | ||
* Find module paths which can be defined via having a barrel file or the | ||
* configuration's property `modules`. | ||
* | ||
* If a module has a barrel file and an internal, it is of type barrel file. | ||
*/ | ||
export function findModulePaths(projectDirs: FsPath[], moduleConfig: TagConfig, barrelFileName: string): ModulePathMap { | ||
const modulesWithoutBarrel = findModulePathsWithoutBarrel(projectDirs, moduleConfig); | ||
const modulesWithBarrel = findModulePathsWithBarrel(projectDirs, barrelFileName); | ||
const modulePaths: ModulePathMap = {}; | ||
|
||
for (const projectDir of projectDirs) { | ||
modules = modules.concat(fs.findFiles(projectDir, 'index.ts')); | ||
for (const path of modulesWithoutBarrel) { | ||
modulePaths[path] = false; | ||
} | ||
|
||
log.info(modules.join(', ')); | ||
return new Set(modules); | ||
}; | ||
for (const path of modulesWithBarrel) { | ||
modulePaths[path] = true; | ||
} | ||
|
||
return modulePaths; | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/core/src/lib/modules/internal/find-module-paths-with-barrel.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,14 @@ | ||
import { FsPath, toFsPath } from '../../file-info/fs-path'; | ||
import getFs from '../../fs/getFs'; | ||
|
||
export function findModulePathsWithBarrel( | ||
projectDirs: FsPath[], | ||
barrelFileName: string, | ||
): FsPath[] { | ||
return projectDirs.flatMap((projectDir) => | ||
getFs() | ||
.findFiles(projectDir, barrelFileName) | ||
.map((path) => path.slice(0, -(barrelFileName.length + 1))) | ||
.map(toFsPath), | ||
); | ||
} |
Oops, something went wrong.