fix(angular): optimize ng-packagr-lite watch mode file writing#31434
fix(angular): optimize ng-packagr-lite watch mode file writing#31434
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
View your CI Pipeline Execution ↗ for commit fb8d31b.
☁️ Nx Cloud last updated this comment at |
| newContent: string | ||
| ): Promise<boolean> { | ||
| try { | ||
| if (!existsSync(filePath)) { |
There was a problem hiding this comment.
There's a potential race condition in this code. The existsSync() check followed by readFile() isn't thread-safe - the file could be deleted between these operations. Since the try-catch already handles file read failures, you can simplify by removing the existence check and directly attempting to read the file:
async function shouldWriteFile(filePath: string, newContent: string): Promise<boolean> {
try {
const existingContent = await readFile(filePath, 'utf-8');
return existingContent !== newContent;
} catch (error) {
// If we can't read the existing file (including if it doesn't exist), write the new one
return true;
}
}This approach is more robust and eliminates the race condition while maintaining the same functionality.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Claude finished @Coly010's task in 1m 22s —— View job
Applied Review Suggestion ✅
Successfully applied the suggested refactor to eliminate the race condition in the shouldWriteFile function.
Todo List:
- Read the current file implementation
- Apply the suggested refactor to remove race condition
- Commit the changes to the PR branch
Changes applied:
- Removed the
existsSyncimport and check - Simplified the function to directly attempt reading the file
- The try-catch now handles both file existence and read errors in one place
This change makes the code more robust by eliminating the potential race condition between the file existence check and the actual file read operation. The function now relies solely on the try-catch mechanism to handle all error cases, including file not found errors.
Commit: d6d3796
0111568 to
023d605
Compare
|
@claude can you resolve the file conflicts in this PR |
|
Claude finished @Coly010's task in 1m 55s —— View job I'll help you resolve the file conflicts in this PR. Todo List:
✅ Merge Conflicts Resolved SuccessfullyThe merge conflict in Conflict Details:
Resolution:
Changes Made:
The PR is now ready for review and should merge cleanly with the master branch. The functionality for optimizing ng-packagr-lite watch mode file writing has been preserved along with the latest changes from master. |
|
@claude the latest commit message does not follow the conventional commits format. It is missing a scope. Can you amend the commit message to start with |
|
Claude finished @Coly010's task in 58s —— View job I'll fix the commit message to follow the conventional commits format with the proper scope. Todo List:
✅ Commit Message Fixed SuccessfullyThe latest commit message has been updated to follow the conventional commits format: Before: Changes Made:
The commit now properly follows the conventional commits format with the appropriate scope for Angular-related changes. |
b1b79ea to
304e6d0
Compare
In ng-packagr-lite watch mode, all output files are written to disk on every incremental build regardless of whether their content actually changed. This causes downstream watchers (like Vite) to see all files as "changed" and trigger full rebuilds instead of incremental ones. Only files with changed content should be written to disk during incremental builds in watch mode. This allows downstream watchers to properly detect which files actually changed and perform efficient incremental rebuilds. Fixes #31033 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> fix(angular): eliminate race condition in shouldWriteFile function - Remove existsSync check before readFile to prevent race condition - Simplify error handling by relying on try-catch for both file existence and read errors - This makes the code more robust and thread-safe Co-authored-by: Coly010 <Coly010@users.noreply.github.com> chore(angular): format code with prettier after merge conflict resolution
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
In ng-packagr-lite watch mode, all output files are written to disk on every incremental build regardless of whether their content actually changed. This causes downstream watchers (like Vite) to see all files as "changed" and trigger full rebuilds instead of incremental ones.
Expected Behavior
Only files with changed content should be written to disk during incremental builds in watch mode. This allows downstream watchers to properly detect which files actually changed and perform efficient incremental rebuilds.
Related Issue(s)
Fixes #31033
🤖 Generated with Claude Code