feat: add automatic project setup detection to generator lifecycle#341
feat: add automatic project setup detection to generator lifecycle#341jonaslagoni wants to merge 13 commits into
Conversation
Resolves #337 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The HTTP runtime tests were using randomly generated ports which could cause EADDRINUSE errors when multiple tests ran in parallel and got the same random port. This fix: - Uses port 0 to let the OS assign an available port - Properly handles server errors with 'error' event listener - Passes the actual assigned port to test callbacks via a new parameter This ensures tests don't fail due to port collisions in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… code - Added renderOAuth2Stubs() to generate type-safe stub functions when OAuth2 is not needed, ensuring TypeScript compilation succeeds - Changed fallback AuthConfig to use 'never' type instead of union of all auth types when no recognized security schemes exist - Added AUTH_FEATURES.oauth2 runtime guards to generated function code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Resolves #336 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for the-codegen-project canceled.
|
- Fix stripJsonComments to properly handle URLs with // inside JSON strings by using a state machine that tracks string boundaries - Remove unused getOperationSecurityRequirements export (dead code) - Remove unused securitySchemes field from RenderHttpParameters type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract helper functions to reduce cognitive complexity from 34 to below 15. Use string.charAt() instead of bracket notation to avoid object injection sink warnings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused OpenAPIOperation type from security.ts (dead code) - Eliminate redundant analyzeSecuritySchemes call in fetch.ts by passing pre-computed requirements - Add trailing comma handling to stripJsonComments for JSONC compatibility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- detection.ts: Fix malformed tsconfig fallback - stop searching parent directories when a tsconfig.json is found but fails to parse - detection.ts: Fix trailing comma regex to respect JSON string boundaries by implementing string-aware removal instead of blanket regex 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The TsConfig interface now accepts `extends` as either `string | string[]` to support TypeScript 5.0+ config composition. The `resolveTsConfigExtends` function iterates through array extends and merges configs in order. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The new automatic importExtension detection feature was incorrectly choosing '.js' for runtime tests because it found the root tsconfig with moduleResolution: node16. Since Jest/SWC handles module resolution without needing file extensions, explicitly set importExtension: 'none' in all runtime test codegen configs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add fileWasFound flag to stop searching parent directories when a package.json is found but fails to parse, matching the behavior of findAndParseTsConfig. This prevents incorrect importExtension detection when a project's package.json has a syntax error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| Logger.debug(`Could not resolve tsconfig extends: ${error}`); | ||
| return tsconfig; | ||
| } | ||
| } |
There was a problem hiding this comment.
Circular tsconfig extends causes unguarded stack overflow
Low Severity
resolveTsConfigExtends recursively follows extends chains without any depth limit or cycle detection. If a tsconfig file has a circular extends reference (e.g., A extends B, B extends A), this will recurse until a stack overflow. While the outer try/catch can catch the RangeError, deep recursion before the crash may degrade performance, and the eventual recovery discards all parent config resolution.
|
|
||
| // Remove trailing commas with string-aware logic | ||
| return removeTrailingCommas(state.result); | ||
| } |
There was a problem hiding this comment.
Custom JSONC parser duplicates well-tested library functionality
Low Severity
The stripJsonComments and removeTrailingCommas functions span ~150 lines with 8 helper functions, reimplementing JSONC parsing that battle-tested libraries like strip-json-comments or jsonc-parser handle comprehensively. This hand-rolled parser processes user-facing configuration files (tsconfig.json), where subtle edge cases in comment/string boundary tracking could lead to silent misparses. The complexity (mutable state object, multiple interacting state machines) increases maintenance burden and risk.


Summary
Resolves #336
See implementation details in
.claude/thoughts/issue-336-add-automatic-project-setup-de-2026-03-09/plan.mdTest Plan
npm run prepare:prpasses🤖 Generated with Claude Code
Note
Medium Risk
Changes generator defaults and alters generated TypeScript output (imports and auth type shapes), which may affect downstream builds or snapshots even though behavior is gated by explicit config and covered by tests.
Overview
Adds automatic
importExtensiondetection duringrealizeGeneratorContextby scanning nearbytsconfig.json/package.json(including JSONC, directory traversal, andextendsresolution) and only applying it when the user hasn’t explicitly setimportExtension.Enhances the TypeScript OpenAPI HTTP client generator to parse OpenAPI/Swagger security schemes and generate only the relevant auth types (and doc defaults like apiKey name/location and OAuth URLs/scopes), with runtime guards/stubs so unused OAuth2 helpers aren’t emitted/called.
Updates snapshots, adds comprehensive unit/integration tests for detection and security extraction, and pins runtime test configs to
importExtension: 'none'to keep Jest/SWC behavior stable.Written by Cursor Bugbot for commit c2e7b64. This will update automatically on new commits. Configure here.