Skip to content

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

Conversation

Cammisuli
Copy link
Member

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 #

@Cammisuli Cammisuli requested review from FrozenPandaz, jaysoo, AgentEnder and a team as code owners May 15, 2025 19:52
Copy link

vercel bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview May 16, 2025 3:33pm

Copy link

nx-cloud bot commented May 15, 2025

View your CI Pipeline Execution ↗ for commit 775ada7.

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 56m View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 18s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 4s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 2s View ↗
nx documentation ✅ Succeeded 1m 25s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-16 16:54:18 UTC

@FrozenPandaz FrozenPandaz requested a review from Copilot May 15, 2025 19:53
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines 13 to 14
for (const entry of GITIGNORE_ENTRIES) {
if (!content.includes(entry)) {
Copy link
Preview

Copilot AI May 15, 2025

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.

Suggested change
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';
Copy link
Preview

Copilot AI May 15, 2025

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.

Suggested change
content = content.trim() + '\n' + entry + '\n';
content = content.trimEnd() + '\n' + entry + '\n';

Copilot uses AI. Check for mistakes.

Comment on lines 41 to +43
.nx/cache
.nx/workspace-data
.cursor/rules/nx-rules.mdc
Copy link
Preview

Copilot AI May 15, 2025

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.

Suggested change
.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.

@FrozenPandaz FrozenPandaz requested a review from Copilot May 16, 2025 16:12
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +17 to +20
const ig = ignore().add(content);
for (const entry of GITIGNORE_ENTRIES) {
if (!ig.ignores(entry)) {
content = content.trimEnd() + '\n' + entry + '\n';
Copy link
Preview

Copilot AI May 16, 2025

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.

Suggested change
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')) {
Copy link
Preview

Copilot AI May 16, 2025

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.

@FrozenPandaz FrozenPandaz merged commit eaf21e9 into master May 16, 2025
6 checks passed
@FrozenPandaz FrozenPandaz deleted the feature/nxa-131-add-new-git-ignored-files-to-nx-generation-and-create branch May 16, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants