Add codemod to cleanup default exports and barrell files#5919
Add codemod to cleanup default exports and barrell files#5919witoszekdev wants to merge 3 commits intomainfrom
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive codemod script to modernize the codebase by removing default exports and barrel files while reorganizing the project structure for better maintainability.
- Converts all default exports to named exports throughout the codebase
- Updates imports from default to named imports accordingly
- Flattens single-file component folders by moving component files up one level
- Removes barrel files (index.ts) that only re-export other files
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| scripts/cleanup-exports-codemod.cjs | Main codemod script implementing 4-stage transformation process |
| package.json | Adds ts-morph dependency and reorganizes jotai package position |
| eslint.config.mjs | Disables TypeScript no-require-imports rule for CommonJS files |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const filePath = sourceFile.getFilePath(); | ||
|
|
||
| // Exclude graphql barrel file - we want to keep it | ||
| if (filePath.includes("src/graphql/index.ts")) { |
There was a problem hiding this comment.
Hard-coded file path check is fragile and doesn't scale. Consider making excluded paths configurable through a constant array or CLI parameter.
| } | ||
|
|
||
| // Skip generated files | ||
| if (filePath.includes(".generated.") || filePath.includes("/__generated__/")) { |
There was a problem hiding this comment.
Hard-coded generated file patterns should be extracted to a configurable constant array for easier maintenance and extensibility.
|
|
||
| const target = mapping.get(exportedName); | ||
| if (!target) { | ||
| throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath}`); |
There was a problem hiding this comment.
Error message should include the file path where the unresolved import occurs to help with debugging. Consider: Unable to resolve export ${exportedName} from barrel ${barrelPath} in file ${filePath}
| throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath}`); | |
| throw new Error(`Unable to resolve export ${exportedName} from barrel ${barrelPath} in file ${filePath}`); |
| } | ||
|
|
||
| // Remove the now-empty folder | ||
| fs.rmdirSync(folderPath); |
There was a problem hiding this comment.
fs.rmdirSync is deprecated. Use fs.rmSync with recursive option instead: fs.rmSync(folderPath, { recursive: true })
| fs.rmdirSync(folderPath); | |
| fs.rmSync(folderPath, { recursive: true }); |
| } | ||
| barrel.delete(); | ||
| if (fs.existsSync(filePath)) { | ||
| fs.unlinkSync(filePath); |
There was a problem hiding this comment.
File deletion should include error handling in case the file is locked or inaccessible. Consider wrapping in try-catch with meaningful error message.
| fs.unlinkSync(filePath); | |
| try { | |
| fs.unlinkSync(filePath); | |
| } catch (err) { | |
| console.error(`Error deleting file "${filePath}": ${err.message}`); | |
| continue; | |
| } |
Differences FoundExpandLicense Package MIT @isaacs/balanced-match MIT @isaacs/brace-expansion MIT @ts-morph/common MIT code-block-writer MIT path-browserify MIT ts-morph SummaryExpand
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5919 +/- ##
========================================
Coverage 39.49% 39.49%
========================================
Files 2429 2429
Lines 39518 39518
Branches 8711 9037 +326
========================================
Hits 15609 15609
Misses 23883 23883
Partials 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR adds a codemod that can be run with multiple stages.
It aims to:
export defaultfrom entire codebase and replace it with named exportssrc/components/AppList/AppList.tsx->src/components/AppList.tsx