Optimize Imports
Automatically refactor imports across the codebase for better tree-shaking and smaller bundles.
What this skill does
- •Convert wildcard imports to named imports
- •Remove unused imports across all files
- •Consolidate duplicate imports from the same module
- •Separate type imports for better tree-shaking
How to use
Optimize all imports in the project:
code
/optimize-imports
Optimize a specific package:
code
/optimize-imports packages/fit
Optimize a single file:
code
/optimize-imports packages/fit/src/adapters/krd-to-fit.converter.ts
Transformations
1. Wildcard to Named Imports
Before:
typescript
import * as z from "zod";
const schema = z.object({ name: z.string() });
After:
typescript
import { object, string } from "zod";
const schema = object({ name: string() });
2. Separate Type Imports
Before:
typescript
import { KRD, toKRD, fromKRD } from "@kaiord/core";
After:
typescript
import type { KRD } from "@kaiord/core";
import { toKRD, fromKRD } from "@kaiord/core";
3. Remove Unused Imports
Before:
typescript
import { map, filter, reduce, sortBy } from "lodash-es";
const result = map(data, fn);
After:
typescript
import { map } from "lodash-es";
const result = map(data, fn);
4. Consolidate Duplicate Imports
Before:
typescript
import { fitToKRD } from "./converters";
// ... 50 lines later
import { krdToFit } from "./converters";
After:
typescript
import { fitToKRD, krdToFit } from "./converters";
Process
- •Analyze: Use TypeScript LSP to find all imports and their usage
- •Transform: Apply optimizations following project style guide
- •Validate: Ensure no type errors after changes
- •Report: Show statistics on optimizations made
Safety Checks
- •Always run
pnpm lintafter transformations - •Run
pnpm -r testto ensure no breaking changes - •Create git commit with detailed changes if requested
Project-Specific Rules
Following CLAUDE.md conventions:
- •Use
typekeyword for type-only imports - •Maintain kebab-case file names
- •Respect the 100-line file limit (may need to split files)
- •Preserve AAA test pattern structure
Output Report
markdown
## Import Optimization Report ### Files Modified: 23 ### Optimizations Applied: - ✅ 12 wildcard imports converted to named imports - ✅ 8 unused imports removed - ✅ 5 type imports separated - ✅ 3 duplicate imports consolidated ### Estimated Bundle Reduction: ~15KB ### Files Changed: - packages/fit/src/adapters/krd-to-fit.converter.ts - packages/tcx/src/adapters/duration/duration.converter.ts - ... ### Next Steps: Run: pnpm -r test && pnpm lint