The surgical refactoring tool for TypeScript monorepos. Move files between packages, rename exports, and watch every import update automatically β with zero breaking changes.
Built on the TypeScript Compiler API for AST-level precision. Understands your barrel files, respects your path aliases, and handles the gnarly edge cases that break other tools.
Refactoring in monorepos is painful. Move a utility from your app to a shared package and you'll spend the next hour:
- Hunting down every import that needs updating
- Figuring out which barrel files need new exports
- Rebuilding packages in the right order
- Fixing the type errors you inevitably missed
module-master does all of this in one command:
bun src/cli.ts move apps/web/src/utils/formatDate.ts packages/shared/src/formatDate.tsThat's it. Every import updated. Barrel files handled. Packages rebuilt. Type-checked and verified.
bun install# Move a file and update all imports
bun src/cli.ts move src/old/file.ts src/new/file.ts
# Preview changes without modifying files
bun src/cli.ts move src/old.ts src/new.ts --dry-run
# Move between packages in a monorepo
bun src/cli.ts move apps/web/src/utils/helper.ts packages/shared/src/helper.tsThe killer feature. Move files between packages in your monorepo and module-master handles everything:
bun src/cli.ts move apps/main-web/lib/utils/date-formatter.ts packages/shared-utils/src/date-formatter.ts --verbose- Workspace discovery β Detects pnpm, yarn, or npm workspaces
- Smart import updates β Changes imports to use package names (
@scope/shared) instead of brittle relative paths - Barrel file management β Adds export to destination package's index.ts, removes from source
- Import splitting β When a file imports multiple things from a barrel and only some are moving, splits the import correctly:
// Before: importing from a barrel that re-exports the moved file
import { formatDate, makeAuthorUrl } from "@/lib/utils";
// After: automatically split into two imports
import { formatDate } from "@plugg/shared-utils";
import { makeAuthorUrl } from "@/lib/utils";- Package rebuilds β Runs build scripts on affected packages so dist/ stays in sync
- Type verification β Runs
tsc --noEmitbefore and after to catch any issues
Other tools naively change export * from "./moved-file" to export * from "@scope/package", which pulls in everything and causes conflicts. module-master removes the re-export entirely β the destination package exports it now.
Move a file and update all import references across the codebase.
bun src/cli.ts move src/utils/old.ts src/helpers/new.ts --dry-runHandles:
- All import statements referencing the moved file
- Path aliases from tsconfig.json
- Barrel file re-exports (
export * from) - Dynamic imports and
require()calls - Internal imports within the moved file
- Jest/Vitest mock calls
Rename an exported symbol and update all imports.
bun src/cli.ts rename src/components/Button.tsx Button PrimaryButton --dry-run- Renames the export in the source file
- Updates all named imports across the codebase
- Updates barrel file re-exports
- Preserves import aliases (
import { Old as X }βimport { New as X })
Understand a module's place in your codebase.
bun src/cli.ts analyze src/components/Button.tsx --verboseShows:
- All exports from the file
- All imports used by the file
- All files that reference this module
- Barrel files that re-export this module
Search for files and exports by name.
bun src/cli.ts find User -p /path/to/project
bun src/cli.ts find Button --type export
bun src/cli.ts find helpers --type file- Case-insensitive partial matching
- Searches filenames and export names simultaneously
- Smart sorting: exact matches first
Normalize import paths using tsconfig aliases, relative paths, or the shortest option.
bun src/cli.ts alias src/components --prefer=alias
bun src/cli.ts alias src --prefer=relative
bun src/cli.ts alias . --prefer=shortestMap all tsconfig.json files in a project.
bun src/cli.ts discover /path/to/monorepo --verboseShows tsconfig inheritance, project references, file ownership, and path aliases.
Discover monorepo workspace packages and their structure.
bun src/cli.ts workspace /path/to/monorepo --jsonSupports pnpm, yarn, and npm workspaces. Shows packages, entrypoints, barrel files, and internal dependencies.
- AST-level precision β Uses TypeScript Compiler API, not regex
- Type-safe refactoring β Runs
tsc --noEmitbefore and after changes - Full import coverage β Named, default, namespace, dynamic, require, require.resolve
- Test mock support β jest.mock(), vi.mock(), vitest.mock()
- Path alias preservation β Respects your tsconfig paths
- Barrel file intelligence β recursively resolves re-export chains to find deep dependencies
- Monorepo-native β First-class support for pnpm, yarn, and npm workspaces
- Cross-package moves β The hard problem, solved
- Import splitting β Handles mixed imports from barrels correctly
- Auto-rebuild β Keeps dist/ in sync after cross-package moves
- Dry-run mode β Preview everything before committing
| Option | Short | Description |
|---|---|---|
--help |
-h |
Show help message |
--version |
-v |
Show version |
--dry-run |
-n |
Preview changes without modifying files |
--project |
-p |
Path to project directory or tsconfig.json |
--verbose |
Enable detailed output | |
--no-verify |
Skip type checking verification (not recommended) | |
--type |
-t |
Filter find results by type: file, export, or all |
--prefer |
Alias strategy: alias, relative, or shortest |
|
--json |
Output in JSON format (workspace command) |
- Load project β Parse tsconfig.json, extract compiler options and path aliases
- Discover workspace β Find all packages, barrel files, and tsconfigs
- Build dependency graph β Scan all files, create import/importedBy maps with recursive barrel resolution
- Find references β Query graph for files importing target module (direct and through barrels)
- Calculate changes β Determine new specifiers, split imports if needed, identify removals
- Apply updates β Modify source text at precise AST node positions
- Update barrels β Add exports to destination, remove from source
- Rebuild packages β Run build scripts on affected packages
- Verify types β Run tsc to ensure no breaking changes
bun test # Run tests
bun run lint # Lint and format with Biome
bun run typecheck # Type check with tsc
bun run build # Compile to standalone binaryMIT