@bemoje/monorepo
v2.0.0
Published
Monorepo workspace management, package discovery, and TypeScript code processing utilities.
Maintainers
Readme
@mono/monorepo
Monorepo workspace management, package discovery, and TypeScript code processing utilities.
Exports
- AbstractBase: Abstract base class that provides common functionality for monorepo management including parenting and inspection capabilities.
- AbstractCode: Abstract base class for representing code structures in the monorepo with inspection and preview capabilities.
- CodeBlock: Represents a block of code within a larger code structure, defined by an index range.
- File: Represents a file in a workspace with various utility methods to check file types and read contents.
- ImportKeywords: Represents the imported keywords/specifiers in an import statement.
- ImportSpecifiers: Represents and analyzes import specifiers in TypeScript/JavaScript code. This class parses and categorizes different types of import statements such as default imports, named imports, namespace imports, mixed imports, and side effect imports. It provides methods to retrieve specific parts of import statements and to manipulate them.
- ImportStatement: Represents an import statement in TypeScript code with parsing and manipulation capabilities.
- ModuleSpecifier: Represents a module specifier in an import statement. Module specifiers are the strings that indicate where to import from, such as './path/to/file', '
- MonoRepo: Represents a monorepo with workspace management, TypeScript configuration, and dependency analysis capabilities.
- SemanticExtnamePrefix: Constants for semantic filename prefixes used to categorize files by their purpose.
- SemanticExtnamePrefixDescriptions
- TestFile: Represents a test file in the monorepo with TypeScript code analysis capabilities.
- TsCode: Represents TypeScript code with import parsing and manipulation capabilities.
- TsFile: Represents a TypeScript file in the monorepo with code analysis and dependency tracking capabilities.
- Workspace: Represents a workspace within a monorepo, providing functionality to analyze and manage workspace dependencies. A workspace is a directory containing a package.json file and typically source code files. This class provides methods and properties for analyzing: - Source and test files in the workspace - Dependencies declared in package.json - Dependencies imported in source and test files - Missing, unused, and incorrectly imported dependencies
- findWorkspacePackageName: Finds the full package name for a workspace given a partial name.
- getAllImports: Retrieves all import statements from TypeScript source files across all workspaces in the monorepo.
- getAllWorkspacePackageJsonPaths: Gets all workspace package.json file paths.
- getAllWorkspacePackageJsons: Gets all workspace package.json contents.
- getAllWorkspacePackageNames: Gets all workspace package names.
- getAllWorkspacePaths: Returns an array of all workspace directory paths.
- getImportsRecursively: Recursively retrieves all imports for the given entry points, categorizing them into external, builtin, and internal dependencies.
- getRepoPackageJson: Reads the repository's root package.json file.
- getRepoPackageJsonPath: Gets the absolute path to the repository's package.json file.
- getRepoRootDirpath: Get the root directory path of the monorepo by finding the package.json with workspaces configuration.
- getWorkspaceDirpaths: Get all workspace directory paths by reading the workspace patterns from the root package.json.
- hasExtnamePrefix.
- resolveModuleImportPath
- semverVersionBump of a given version string or array based on the specified level. The function supports 'major', 'minor', and 'patch' levels.
Usage
Managing the Repository & Workspaces
The MonoRepo class allows structured, automated tasks against packages and workspaces in a typical monorepo environment (e.g. yarn, npm, pnpm workspaces).
import { MonoRepo } from '@mono/monorepo'
const repo = new MonoRepo()
// Access all registered packages/workspaces
const workspaces = repo.workspaces
console.log(`Found ${workspaces.length} workspaces`)
// Get specific workspaces by name or type
const packageJson = repo.getWorkspace('my-package')?.packageJson
// Bump version for all packages (semver)
repo.bumpVersions('patch')Script & File Operations
import { TsFile, findWorkspacePackageName } from '@mono/monorepo'
const tsFile = new TsFile('path/to/my-file.ts')
// Read structural code representations (imports, blocks, components)
const imports = tsFile.imports
// Use utility functions independently of classes
const packageName = findWorkspacePackageName('libs/my-feature')