-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(core): add ai rule files to gitignore #31238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): add ai rule files to gitignore #31238
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
View your CI Pipeline Execution ↗ for commit 775ada7.
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds new ignore rules for AI-generated Nx Console files in both new workspaces and existing ones via a migration.
- Updates generator templates to include
.cursor/rules/nx-rules.mdc
and.github/instructions/nx.instructions.md
in.gitignore
- Implements a migration (
add-gitignore-entry.ts
) that appends those entries to existing workspaces’.gitignore
- Adds tests for the migration and registers it in
migrations.json
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
packages/workspace/src/generators/new/files-root-app/__dot__gitignore | Added two new ignore patterns for rule and instruction files |
packages/workspace/src/generators/new/files-package-based-repo/__dot__gitignore | Mirror of root-app updates |
packages/workspace/src/generators/new/files-integrated-repo/__dot__gitignore | Mirror of root-app updates |
packages/nx/src/migrations/update-21-1-0/add-gitignore-entry.ts | Migration to append ignore entries if missing |
packages/nx/src/migrations/update-21-1-0/add-gitignore-entry.spec.ts | Tests covering addition, duplication avoidance, and absence case |
packages/nx/migrations.json | Registers the new migration under version 21.1.0 |
for (const entry of GITIGNORE_ENTRIES) { | ||
if (!content.includes(entry)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using String.includes
may match substrings inside other lines (e.g., commented examples). Consider splitting content
into lines and checking each line for an exact match or using a regex anchored to the start/end of the line.
for (const entry of GITIGNORE_ENTRIES) { | |
if (!content.includes(entry)) { | |
const lines = content.split('\n'); | |
for (const entry of GITIGNORE_ENTRIES) { | |
if (!lines.some((line) => line.trim() === entry)) { |
Copilot uses AI. Check for mistakes.
let updated = false; | ||
for (const entry of GITIGNORE_ENTRIES) { | ||
if (!content.includes(entry)) { | ||
content = content.trim() + '\n' + entry + '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using trim()
will remove leading whitespace/newlines at the start of the file, potentially altering existing formatting. Consider trimEnd()
(or a right-trim) to preserve leading content.
content = content.trim() + '\n' + entry + '\n'; | |
content = content.trimEnd() + '\n' + entry + '\n'; |
Copilot uses AI. Check for mistakes.
.nx/cache | ||
.nx/workspace-data | ||
.cursor/rules/nx-rules.mdc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The new ignore entries are appended at the end without grouping or sorting. For consistency, consider placing them alongside related patterns (e.g., under .nx/cache
) or alphabetizing entries.
.nx/cache | |
.nx/workspace-data | |
.cursor/rules/nx-rules.mdc | |
.cursor/rules/nx-rules.mdc | |
.nx/cache | |
.nx/workspace-data |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds gitignore entries for rule files generated by Nx Console, ensuring that these files are not tracked by version control.
- Added two new entries (.cursor/rules/nx-rules.mdc and .github/instructions/nx.instructions.md) to various .gitignore templates.
- Introduced a migration and updated initialization utilities to append these new entries to existing .gitignore files.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
packages/workspace/src/generators/new/files-root-app/__dot__gitignore | Appends new rule file entries to the gitignore template for root apps. |
packages/workspace/src/generators/new/files-package-based-repo/__dot__gitignore | Appends new rule file entries to the gitignore template for package-based repos. |
packages/workspace/src/generators/new/files-integrated-repo/__dot__gitignore | Appends new rule file entries to the gitignore template for integrated repos. |
packages/nx/src/migrations/update-21-1-0/add-gitignore-entry.ts | Implements a migration to update existing .gitignore files. |
packages/nx/src/migrations/update-21-1-0/add-gitignore-entry.spec.ts | Tests the migration to ensure proper addition and prevention of duplicates. |
packages/nx/src/command-line/init/implementation/utils.ts | Updates the gitignore file during initialization to include the new entries. |
packages/nx/migrations.json | Registers the migration for the new gitignore entries. |
const ig = ignore().add(content); | ||
for (const entry of GITIGNORE_ENTRIES) { | ||
if (!ig.ignores(entry)) { | ||
content = content.trimEnd() + '\n' + entry + '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider updating the ignore instance after appending a new entry so that the check reflects the most recent content. This makes the logic more robust if additional processing is added later.
const ig = ignore().add(content); | |
for (const entry of GITIGNORE_ENTRIES) { | |
if (!ig.ignores(entry)) { | |
content = content.trimEnd() + '\n' + entry + '\n'; | |
let ig = ignore().add(content); | |
for (const entry of GITIGNORE_ENTRIES) { | |
if (!ig.ignores(entry)) { | |
content = content.trimEnd() + '\n' + entry + '\n'; | |
ig = ignore().add(content); // Update the ignore instance with the new content |
Copilot uses AI. Check for mistakes.
@@ -222,6 +222,21 @@ export function updateGitIgnore(root: string) { | |||
} | |||
lines.push('.nx/workspace-data'); | |||
} | |||
if (!contents.includes('.cursor/rules/nx-rules.mdc')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The logic for conditionally adding a new line and appending entries is repeated for each rule. Consider extracting a helper function to handle appending new gitignore rules with proper newline separation.
Copilot uses AI. Check for mistakes.
Current Behavior
Rule files are created by Nx Console, and gitignore updates are done there.
Expected Behavior
Rule files are still created by Nx Console, but there is now a migration to add those files to the gitignore rules on migration and new workspaces.
Related Issue(s)
Fixes #