Skip to content

Commit daba40d

Browse files
authored
refactor: optimize clean command by precomputing paths to clean (#855)
## **Description** This PR optimizes the `_cleanPackage` method by precomputing the paths to clean (`pathsToClean`) before iterating through them. Specifically, relative paths are joined with the package root using `p.join` ahead of time, avoiding repeated path computations during the loop. ### **Key Changes**: **Precomputing Paths**: - `pathsToClean` now contains fully resolved paths created by combining relative paths (`cleanablePubFilePaths` and `.dart_tool`) with the package root. - This eliminates the need for `p.join` operations inside the loop, improving both performance and code readability. --- ## **Type of Change** - [ ] ✨ `feat` -- New feature (non-breaking change which adds functionality) - [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue) - [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing functionality to change) - [x] 🧹 `refactor` -- Code refactor - [ ] ✅ `ci` -- Build configuration change - [ ] 📝 `docs` -- Documentation - [ ] 🗑️ `chore` -- Chore --- ## **Checklist** <!--- Put an `x` in all the boxes that apply: --> - [x] I have read the [[CONTRIBUTING](https://github.com/invertase/melos/blob/main/CONTRIBUTING.md)](https://github.com/invertase/melos/blob/main/CONTRIBUTING.md) guidelines. - [x] I have read the [[Invertase's Code of Conduct](https://github.com/invertase/meta/blob/main/CODE_OF_CONDUCT.md)](https://github.com/invertase/meta/blob/main/CODE_OF_CONDUCT.md). - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added necessary documentation (if applicable). - [x] I have run `melos bootstrap` and confirmed it is working as expected locally.
1 parent 4be680c commit daba40d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

packages/melos/lib/src/commands/clean.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ mixin _CleanMixin on _Melos {
3232
final pathsToClean = [
3333
...cleanablePubFilePaths,
3434
'.dart_tool',
35-
];
35+
].map((relativePath) => p.join(package.path, relativePath));
3636

37-
for (final generatedPubFilePath in pathsToClean) {
38-
deleteEntry(p.join(package.path, generatedPubFilePath));
37+
for (final path in pathsToClean) {
38+
try {
39+
deleteEntry(path);
40+
} catch (error) {
41+
logger.warning('Failed to delete $path: $error');
42+
}
3943
}
4044
}
4145

0 commit comments

Comments
 (0)