fix(nx): add Nx monorepo support with scaffolding instructions and commands#284
fix(nx): add Nx monorepo support with scaffolding instructions and commands#284frontegg-david merged 3 commits intorelease/1.0.xfrom
Conversation
📝 WalkthroughWalkthroughAdds Nx monorepo scaffolding to the CLI ( Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as FrontMCP CLI
participant FS as File System
participant PM as Package Manager
participant NX as Local Nx (node_modules)
participant Gen as Nx Workspace Generator
CLI->>FS: write bootstrap package.json (nx devDeps)
CLI->>PM: run install in target (bootstrap)
PM->>FS: install nx into node_modules
CLI->>NX: createRequire -> load local nx modules
CLI->>Gen: invoke workspaceGenerator (skipInstall:true, createSampleApp:true)
Gen->>FS: generate workspace files (README, .nvmrc, apps/libs)
CLI->>PM: run install in generated workspace (full deps)
PM->>FS: install project dependencies
CLI->>FS: output next-steps and completion messages
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
libs/cli/src/commands/scaffold/__tests__/create.spec.ts (1)
762-770: Consider using@frontmcp/utilsfor test setup file operations.Direct
require('fs')usage at lines 764-765 bypasses the project convention of using@frontmcp/utilsfor file system operations. While acceptable in test setup code, consider using the utility for consistency.♻️ Optional refactor to use `@frontmcp/utils`
- require('fs').mkdirSync(projectDir); - require('fs').writeFileSync(path.join(projectDir, 'file.txt'), 'content'); + const { mkdirSync, writeFileSync } = require('fs'); + mkdirSync(projectDir); + writeFileSync(path.join(projectDir, 'file.txt'), 'content');Or alternatively, add
mkdirSyncandwriteFileSyncto the imports at line 2 to maintain consistency with the existing directfsusage pattern in this test file.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/cli/src/commands/scaffold/__tests__/create.spec.ts` around lines 762 - 770, The test uses direct require('fs') calls to create files in the "should refuse to scaffold into non-empty directory" test; replace those direct requires with the project's file-utils by importing and using the equivalent helpers from `@frontmcp/utils` (or add mkdirSync and writeFileSync to the existing imports) so the setup uses the same utility abstractions as other tests—adjust the lines that call require('fs').mkdirSync and require('fs').writeFileSync to call the `@frontmcp/utils` helpers instead while keeping the rest of the test (runCreate and the consoleLogs assertion) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/cli/src/commands/scaffold/create.ts`:
- Around line 1182-1205: Replace direct usage of fsp.stat with the project's fs
utility: import and use the stat function from `@frontmcp/utils` instead of
calling fsp.stat(projectDir). In the validation block that references projectDir
(and later calls isDirEmpty and ensureDir), call stat(projectDir) from the utils
package and keep the surrounding logic unchanged so ENOENT handling and
subsequent ensureDir(projectDir) still work.
---
Nitpick comments:
In `@libs/cli/src/commands/scaffold/__tests__/create.spec.ts`:
- Around line 762-770: The test uses direct require('fs') calls to create files
in the "should refuse to scaffold into non-empty directory" test; replace those
direct requires with the project's file-utils by importing and using the
equivalent helpers from `@frontmcp/utils` (or add mkdirSync and writeFileSync to
the existing imports) so the setup uses the same utility abstractions as other
tests—adjust the lines that call require('fs').mkdirSync and
require('fs').writeFileSync to call the `@frontmcp/utils` helpers instead while
keeping the rest of the test (runCreate and the consoleLogs assertion)
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5b35a195-6144-45d4-9bc9-8de9e1fb05a9
📒 Files selected for processing (9)
docs/frontmcp/getting-started/installation.mdxdocs/frontmcp/getting-started/quickstart.mdxeslint.config.mjslibs/cli/src/commands/scaffold/__tests__/create.spec.tslibs/cli/src/commands/scaffold/create.tslibs/nx-plugin/src/generators/workspace/files/README.md__tmpl__libs/nx-plugin/src/generators/workspace/files/__dot__nvmrc__tmpl__libs/nx-plugin/src/generators/workspace/workspace.spec.tsnx.json
Performance Test ResultsStatus: ✅ All tests passed Summary
Total: 100 tests across 21 projects 📊 View full report in workflow run Generated at: 2026-03-17T09:45:45.170Z |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/cli/src/commands/scaffold/__tests__/create.spec.ts`:
- Line 2: Replace the direct Node fs imports (mkdtempSync, mkdirSync, rmSync,
readFileSync, writeFileSync, existsSync) with the corresponding exports from
`@frontmcp/utils` (mkdtemp, mkdir, rm, readFile, writeFile, fileExists); update
the import statement accordingly and refactor test usages to the async variants
where sync counterparts are not provided (await
mkdtemp/mkdir/rm/readFile/writeFile and use await fileExists) and adjust any
assertions or setup/teardown to handle Promises; target usages include the
functions named mkdtempSync, mkdirSync, rmSync, readFileSync, writeFileSync,
existsSync in create.spec.ts and replace them with mkdtemp, mkdir, rm, readFile,
writeFile, fileExists respectively.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9d2a6e5d-c12c-4301-bf6c-b2ea43f52827
📒 Files selected for processing (2)
libs/cli/src/commands/scaffold/__tests__/create.spec.tslibs/cli/src/commands/scaffold/create.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
libs/cli/src/commands/scaffold/__tests__/create.spec.ts (1)
548-563:⚠️ Potential issue | 🟡 MinorResource leak: temp directory is not cleaned up.
The
tempDirvariable is declared locally insidebeforeEach, making it inaccessible inafterEach. This causes temp directories to accumulate without cleanup.🧹 Proposed fix to ensure cleanup
describe('sanitizeForFolder', () => { + let tempDir: string; + beforeEach(async () => { - const tempDir = await mkdtemp(path.join(tmpdir(), 'cli-test-')); + tempDir = await mkdtemp(path.join(tmpdir(), 'cli-test-')); jest.spyOn(process, 'cwd').mockReturnValue(tempDir); jest.spyOn(process, 'chdir').mockImplementation(() => { // No-op for testing }); jest.spyOn(process, 'exit').mockImplementation(((code?: number) => { throw new Error(`process.exit(${code})`); }) as () => never); Object.defineProperty(process.stdin, 'isTTY', { value: false, writable: true, configurable: true }); }); - afterEach(() => { + afterEach(async () => { jest.restoreAllMocks(); + try { + await rm(tempDir, { recursive: true, force: true }); + } catch { + // Ignore cleanup errors + } });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/cli/src/commands/scaffold/__tests__/create.spec.ts` around lines 548 - 563, The test leaks temp dirs because tempDir is declared inside beforeEach; move tempDir to an outer-scoped variable (e.g., let tempDir: string) so afterEach can access it, create it in beforeEach via mkdtemp, and remove it in afterEach using fs.rm or fs.rmSync (with recursive/force) or fs.promises.rm to delete the directory; keep existing jest.restoreAllMocks but ensure you guard removal if tempDir is undefined or already removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@libs/cli/src/commands/scaffold/__tests__/create.spec.ts`:
- Around line 548-563: The test leaks temp dirs because tempDir is declared
inside beforeEach; move tempDir to an outer-scoped variable (e.g., let tempDir:
string) so afterEach can access it, create it in beforeEach via mkdtemp, and
remove it in afterEach using fs.rm or fs.rmSync (with recursive/force) or
fs.promises.rm to delete the directory; keep existing jest.restoreAllMocks but
ensure you guard removal if tempDir is undefined or already removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fdd57186-5b01-4aab-ab77-9455b529f05a
📒 Files selected for processing (1)
libs/cli/src/commands/scaffold/__tests__/create.spec.ts
Cherry-pick CreatedA cherry-pick PR to Please review and merge if this change should also be in If the cherry-pick is not needed, close the PR. |
fixes: #281
Summary by CodeRabbit
Documentation
New Features
Tests
Chores