Skip to content

feat: add automatic project setup detection to generator lifecycle#344

Open
jonaslagoni wants to merge 9 commits intomainfrom
issue-336-add-automatic-project-setup-de
Open

feat: add automatic project setup detection to generator lifecycle#344
jonaslagoni wants to merge 9 commits intomainfrom
issue-336-add-automatic-project-setup-de

Conversation

@jonaslagoni
Copy link
Contributor

@jonaslagoni jonaslagoni commented Mar 9, 2026

Summary

Resolves #336

See implementation details in .claude/thoughts/issue-336-add-automatic-project-setup-de-2026-03-09/plan.md

Test Plan

  • All unit tests pass
  • All runtime tests pass
  • npm run prepare:pr passes

🤖 Generated with Claude Code


Note

Medium Risk
Changes default configuration behavior for TypeScript generation by auto-setting importExtension, which could affect import paths for projects that previously relied on implicit defaults. The new JSONC parsing and filesystem-based detection logic adds surface area for edge-case mis-detections, though it is covered by targeted tests.

Overview
Adds automatic importExtension detection during realizeGeneratorContext when the option is omitted, inferring none/.ts/.js from bundler config files/dependencies and tsconfig.json (moduleResolution + allowImportingTsExtensions) and logging the chosen value.

Introduces src/codegen/detection.ts (including a JSONC parser for tsconfig.json) plus unit-test fixtures/coverage for detection precedence and error cases, and updates HTTP client runtime test utilities to retry on port collisions (passing the actual bound port into tests). Documentation is updated to describe the new detection behavior and its limitations.

Written by Cursor Bugbot for commit 7eece50. This will update automatically on new commits. Configure here.

Resolves #336

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jonaslagoni jonaslagoni requested a review from ALagoni97 as a code owner March 9, 2026 12:38
@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
the-codegen-project Ready Ready Preview, Comment Mar 9, 2026 1:37pm
the-codegen-project-mcp Ready Ready Preview, Comment Mar 9, 2026 1:37pm

@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for the-codegen-project canceled.

Name Link
🔨 Latest commit 7eece50
🔍 Latest deploy log https://app.netlify.com/projects/the-codegen-project/deploys/69aecc96d868900008280605

@jonaslagoni jonaslagoni changed the title feat: Add automatic project setup detection to generator lifecycle feat: add automatic project setup detection to generator lifecycle Mar 9, 2026
Add parseJsonc() function that strips comments and trailing commas
before JSON parsing. This fixes auto-detection for projects using
TypeScript's official JSONC format in tsconfig.json.

- Added parseJsonc() to strip // comments, /* */ comments, and trailing commas
- Updated readJsonFile() with allowJsonc parameter
- Changed tsconfig.json parsing to use JSONC parser

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replaced naive regex-based comment stripping with a proper state machine
parser that tracks string boundaries and escape sequences. This prevents
corruption of JSON string values containing '//' (like URLs or scoped
package paths such as node_modules//@types).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…gs in JSONC parser

Refactored parseJsonc function by extracting helper functions:
- copyStringLiteral: handles string literal copying with escapes
- skipSingleLineComment: skips // comments
- skipMultiLineComment: skips /* */ comments

Also replaced bracket notation (content[i]) with .charAt() method
to resolve security/detect-object-injection ESLint warnings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move trailing comma detection into the state machine's first pass instead
of applying a regex after. This prevents corruption of string values that
contain patterns like ",}" or ",]" (e.g., "some,}path").

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The isTrailingComma function now skips both single-line (//) and
multi-line (/* */) comments when checking if a comma is trailing.
This fixes parsing of tsconfig.json files with patterns like:
  "moduleResolution": "node16", // comment
}

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Handle EADDRINUSE errors by automatically retrying with a different
random port, preventing flaky CI failures when tests run in parallel.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When runWithServer retried on EADDRINUSE, the test callback still used
the original port from closure. Updated testFn signature to receive the
actual port and modified all HTTP client test files to use it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Tests that don't use runWithServer should reference the locally
defined `port` variable, not `actualPort` which is only available
inside runWithServer callbacks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Add automatic project setup detection to generator lifecycle

1 participant