diff --git a/packages/agent-cli/README.md b/packages/agent-cli/README.md index 277dd96a441e..ba5f8db963d5 100644 --- a/packages/agent-cli/README.md +++ b/packages/agent-cli/README.md @@ -17,8 +17,16 @@ Use this command in your repository: npx @db-ux/agent-cli ``` +Or with pnpm: + +```shell +pnpm exec @db-ux/agent-cli +``` + The DB UX Design System documentation will be added to (or replaced in subsequent runs, e.g. after a DB UX Design System update) in the file `.github/copilot-instructions.md` (if this file does not yet exist in your codebase, it will be created). +**Note:** The tool works with all package managers (npm, yarn, pnpm) and correctly handles symlinked packages in pnpm's node_modules structure. + ### Advanced Usage You can also change the root path where the tool should check for `node_modules`: diff --git a/packages/agent-cli/src/copilot/index.ts b/packages/agent-cli/src/copilot/index.ts index a542497034e3..91bad3da4c85 100644 --- a/packages/agent-cli/src/copilot/index.ts +++ b/packages/agent-cli/src/copilot/index.ts @@ -13,14 +13,21 @@ function findAllNodeModulesDirectories( .readdirSync(directory, { withFileTypes: true }) .sort((a, b) => a.name.localeCompare(b.name, 'en')); for (const entry of entries) { - if (entry.isDirectory()) { + const fullPath = path.join(directory, entry.name); + // Use statSync to follow symlinks (important for pnpm compatibility) + let isDirectory = false; + try { + isDirectory = fs.statSync(fullPath).isDirectory(); + } catch { + // Skip entries that can't be accessed + continue; + } + + if (isDirectory) { if (entry.name === 'node_modules') { - found.push(path.join(directory, entry.name)); + found.push(fullPath); } else if (!entry.name.startsWith('.')) { - findAllNodeModulesDirectories( - path.join(directory, entry.name), - found - ); + findAllNodeModulesDirectories(fullPath, found); } } } @@ -54,10 +61,19 @@ export const generateCopilot = (rootPath: string) => { withFileTypes: true }); for (const package_ of packages) { - if (package_.isDirectory()) { + const packagePath = path.join(databaseUxPath, package_.name); + // Use statSync to follow symlinks (important for pnpm compatibility) + let isDirectory = false; + try { + isDirectory = fs.statSync(packagePath).isDirectory(); + } catch { + // Skip entries that can't be accessed + continue; + } + + if (isDirectory) { const instructionsPath = path.join( - databaseUxPath, - package_.name, + packagePath, 'agent', '_instructions.md' ); @@ -65,7 +81,7 @@ export const generateCopilot = (rootPath: string) => { let content = fs.readFileSync(instructionsPath, 'utf8'); const relativePath = path.relative( rootPath, - path.join(databaseUxPath, package_.name) + packagePath ); content = content .replaceAll( diff --git a/packages/agent-cli/test/__snapshots__/index.spec.ts.snap b/packages/agent-cli/test/__snapshots__/index.spec.ts.snap index 0bc5aa77a473..936337b1982e 100644 --- a/packages/agent-cli/test/__snapshots__/index.spec.ts.snap +++ b/packages/agent-cli/test/__snapshots__/index.spec.ts.snap @@ -5,11 +5,11 @@ exports[`default > check if docs are created 1`] = ` --- START: DB UX Copilot Instructions – do not edit below --- # @db-ux/components -- use y for frontend/node_modules/@db-ux/components/test.md +- use y for node_modules/@db-ux/components/test.md # @db-ux/foundations -- use x for frontend/node_modules/@db-ux/foundations/test.md +- use x for node_modules/@db-ux/foundations/test.md --- END: DB UX Copilot Instructions – do not edit above --- diff --git a/packages/agent-cli/test/frontend/.github/copilot-instructions.md b/packages/agent-cli/test/frontend/.github/copilot-instructions.md new file mode 100644 index 000000000000..b1ea3d44b9cd --- /dev/null +++ b/packages/agent-cli/test/frontend/.github/copilot-instructions.md @@ -0,0 +1,13 @@ +--- START: DB UX Copilot Instructions – do not edit below --- + +# @db-ux/components +- use y for node_modules/@db-ux/components/test.md + + +# @db-ux/foundations +- use x for node_modules/@db-ux/foundations/test.md + + +--- + +END: DB UX Copilot Instructions – do not edit above --- diff --git a/packages/agent-cli/test/index.spec.ts b/packages/agent-cli/test/index.spec.ts index 55bf527f84d1..2459380c22d9 100644 --- a/packages/agent-cli/test/index.spec.ts +++ b/packages/agent-cli/test/index.spec.ts @@ -6,10 +6,26 @@ import { generateCopilot } from '../src/copilot'; describe('default', () => { test('check if docs are created', async () => { const copilotFile = path.resolve( - 'test/.github/copilot-instructions.md' + 'test/frontend/.github/copilot-instructions.md' ); - generateCopilot('test'); + generateCopilot('test/frontend'); expect(fs.readFileSync(copilotFile).toString()).toMatchSnapshot(); }); + + test('check if docs are created from pnpm symlinked packages', async () => { + const copilotFile = path.resolve( + 'test/pnpm-test/.github/copilot-instructions.md' + ); + generateCopilot('test/pnpm-test'); + + const content = fs.readFileSync(copilotFile).toString(); + + // Verify that the symlinked package was detected and processed + expect(content).toContain('test-symlink-package'); + expect(content).toContain('Symlinked Package Instructions'); + expect(content).toContain( + 'This is a test package accessed via symlink' + ); + }); }); diff --git a/packages/agent-cli/test/pnpm-test/.github/copilot-instructions.md b/packages/agent-cli/test/pnpm-test/.github/copilot-instructions.md new file mode 100644 index 000000000000..993cc9497e80 --- /dev/null +++ b/packages/agent-cli/test/pnpm-test/.github/copilot-instructions.md @@ -0,0 +1,11 @@ +--- START: DB UX Copilot Instructions – do not edit below --- + +# @db-ux/test-symlink-package +# Symlinked Package Instructions + +This is a test package accessed via symlink (simulating pnpm structure). + + +--- + +END: DB UX Copilot Instructions – do not edit above --- diff --git a/packages/agent-cli/test/pnpm-test/.pnpm/@db-ux+test-symlink-package@1.0.0/node_modules/@db-ux/test-symlink-package/agent/_instructions.md b/packages/agent-cli/test/pnpm-test/.pnpm/@db-ux+test-symlink-package@1.0.0/node_modules/@db-ux/test-symlink-package/agent/_instructions.md new file mode 100644 index 000000000000..d02b4f770673 --- /dev/null +++ b/packages/agent-cli/test/pnpm-test/.pnpm/@db-ux+test-symlink-package@1.0.0/node_modules/@db-ux/test-symlink-package/agent/_instructions.md @@ -0,0 +1,3 @@ +# Symlinked Package Instructions + +This is a test package accessed via symlink (simulating pnpm structure). diff --git a/packages/agent-cli/test/pnpm-test/node_modules/@db-ux/test-symlink-package b/packages/agent-cli/test/pnpm-test/node_modules/@db-ux/test-symlink-package new file mode 120000 index 000000000000..36541b3a6888 --- /dev/null +++ b/packages/agent-cli/test/pnpm-test/node_modules/@db-ux/test-symlink-package @@ -0,0 +1 @@ +../../.pnpm/@db-ux+test-symlink-package@1.0.0/node_modules/@db-ux/test-symlink-package \ No newline at end of file