feat(cli): add Astro framework support#242
feat(cli): add Astro framework support#242ardasoyturk wants to merge 5 commits intoaidenybai:mainfrom
Conversation
- Add Astro detection in detectFramework() and detectReactGrab() - Add transformAstro() for injecting React Grab code into Astro layouts - Add findAstroLayoutFile() and findAllAstroLayoutFile() to locate layout files - Add addAgentToExistingAstro() and removeAgentFromAstro() for agent management - Add addOptionsToAstroScript() for options configuration - Add ASTRO_EFFECT and ASTRO_EFFECT_WITH_AGENT templates - Update FRAMEWORK_NAMES to include Astro - Remove Astro from UNSUPPORTED_FRAMEWORK_NAMES - Update tests for Astro support
|
Error agent completed without reporting progress |
|
@ardasoyturk is attempting to deploy a commit to the Million Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f715dfd58
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
6 issues found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/cli/test/detect.test.ts">
<violation number="1" location="packages/cli/test/detect.test.ts:53">
P2: Missing priority test for Astro vs Vite detection. Since `detectFramework` checks for `vite` before `astro` in the implementation, Astro projects with both dependencies would be misidentified as Vite. A test like "should prioritize Astro over Vite if both are present" should be added to match the existing Next.js vs Vite priority test.</violation>
</file>
<file name="packages/cli/src/utils/transform.ts">
<violation number="1" location="packages/cli/src/utils/transform.ts:809">
P1: addAgentToExistingAstro duplicates the React Grab initialization instead of appending only the agent import. When adding an agent to an existing Astro React Grab configuration, the function inserts the entire ASTRO_EFFECT_WITH_AGENT template (which includes both `import("react-grab")` and `import("@react-grab/${agent}/client")`) after the `<head>` tag, creating a duplicate `import("react-grab")`. When the agent is later removed via `removeAgentFromAstro`, only the agent import is removed, leaving the duplicate react-grab import permanently. This differs from the correct implementation in `addAgentToExistingVite`, `addAgentToExistingWebpack`, and `addAgentToExistingTanStack`, which find the existing react-grab import and append only the agent import.</violation>
<violation number="2" location="packages/cli/src/utils/transform.ts:869">
P2: When `reactGrabAlreadyConfigured` is true but the current file doesn't contain React Grab code, the loop falls through and injects a new full script block into this file instead of continuing to search for the file that already has the configuration. This can create a duplicate config block in the wrong file. Add a `continue` when `reactGrabAlreadyConfigured` is true but `hasReactGrabInFile` is false.</violation>
<violation number="3" location="packages/cli/src/utils/transform.ts:1287">
P2: `findReactGrabFile` for Astro returns the first existing layout file, but `transformAstro` skips files without a `<head>` tag and installs React Grab in the first file that *has* one. If the first layout file exists but lacks `<head>`, React Grab gets installed in a later file, while this function still returns the first file. Subsequent options or agent-removal operations then target the wrong file. This should find the file that actually contains the React Grab code.</violation>
<violation number="4" location="packages/cli/src/utils/transform.ts:1450">
P2: The regex for matching an existing `.then(...)` block only captures up to the inner closing `)` of `m.init(...)` but misses the outer `)` of `.then(...)`. When re-applying options, the replacement leaves a dangling `)` in the output, producing invalid syntax. The `[^}]*\}\s*\)` portion needs an additional `\s*\)` to capture the `.then(` closing parenthesis.</violation>
</file>
<file name="packages/cli/src/utils/detect.ts">
<violation number="1" location="packages/cli/src/utils/detect.ts:76">
P1: The `astro` check is placed after the `vite` check, but Astro uses Vite internally (and as of Astro v6, `vite` can appear as a peer dependency in the user's `package.json`). When both `vite` and `astro` are listed, the project will be misidentified as Vite. Move the `astro` check before the `vite` check, consistent with how more-specific frameworks (e.g., `@tanstack/react-start`) are already checked before `vite`.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Move Astro detection before Vite to fix misidentification - Fix addAgentToExistingAstro to only add agent import, not full block - Fix addOptionsToAstroScript regex to match full .then() block - Fix findReactGrabFile to find file with React Grab code - Continue scanning Astro files when reactGrabAlreadyConfigured is true
| ]; | ||
|
|
||
| return possiblePaths.filter((filePath) => existsSync(filePath)); | ||
| }; |
There was a problem hiding this comment.
Duplicated Astro layout path lists across files
Low Severity
The same 13 Astro layout file paths are hardcoded in both findAllAstroLayoutFiles in transform.ts and detectReactGrab in detect.ts, but in different order. These duplicate lists can easily drift out of sync. A shared constant or utility function would avoid this maintenance risk.
Additional Locations (1)
There was a problem hiding this comment.
I didn't want to change the constants.ts file for this reason and left the issue as is.
- Add regex escaping for agent package in removeAgentFromAstro - Add Astro to supported frameworks error message
| originalContent, | ||
| newContent, | ||
| }; | ||
| }; |
There was a problem hiding this comment.
Astro functions duplicate existing Vite implementations verbatim
Low Severity
addOptionsToAstroScript is an exact duplicate of addOptionsToViteScript, removeAgentFromAstro is identical to removeAgentFromVite, and addAgentToExistingAstro is functionally identical to addAgentToExistingVite. All three share the same regex, logic, and replacement strategy. This triples the maintenance surface — a bug fix in one copy risks being missed in the others.
Additional Locations (2)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| matchedText, | ||
| `${hasSemicolon ? matchedText.slice(0, -1) : matchedText}; | ||
| ${agentImport}`, | ||
| ); |
There was a problem hiding this comment.
Agent addition corrupts import when options already configured
Medium Severity
The regex in addAgentToExistingAstro — /import\s*\(\s*["']react-grab["']\s*\);?/ — only matches the import("react-grab") portion of a chained expression. If options were previously configured (turning the import into import("react-grab").then((m) => m.init({...}))), the replacement splits the .then() chain away from the react-grab import and leaves it dangling after the newly inserted agent import line, producing broken JavaScript.



Summary
Add full Astro framework support to React Grab's init command. Closes #224
Features Implemented
astropackage indevDependenciessrc/layouts/,layouts/,src/pages/)<head>tag of Astro layout filesHow It Works
For Astro projects, React Grab is initialized using dynamic imports that only run in development mode:
Usage
Note
Medium Risk
Adds a new supported framework path that detects Astro projects and rewrites
.astrolayout/page files to inject/remove scripts and update options; mistakes could lead to incorrect code injection or missed configs in user projects.Overview
Adds Astro as a first-class supported framework in the CLI
initflow, including updated user-facing messaging and removal of Astro from the unsupported-framework list.Extends project detection and React Grab presence checks to recognize Astro projects (including prioritizing
astroovervite) and to scan common.astrolayout/page locations.Implements Astro-specific transforms to inject a dev-only
<script>into an.astrofile’s<head>, plus support for adding/removing agents and updating options by rewriting the dynamicimport("react-grab")block; includes new tests covering Astro detection and precedence.Written by Cursor Bugbot for commit 84d7195. This will update automatically on new commits. Configure here.
Summary by cubic
Adds Astro support to the CLI init flow so
astroprojects auto-detect, inject a dev-only setup, and manage agents/options. Also fixes detection precedence and improves Astro transforms, including--forcehandling and consistent indentation.New Features
astroprojects and treats Astro as a supported framework ininit.<script>into<head>of common.astrolayout files to loadreact-grab(and@react-grab/<agent>/clientwhen selected)..astrofiles; detects existing setup to avoid duplicates.Bug Fixes
astroovervitein detection to avoid misidentification (with a test to prevent regression).react-grabimport; escapes regex for agent package during removal..then((m) => m.init(...))block..astrofile that containsreact-graband continues scanning files if already configured.--forceguard behavior and ensures consistent indentation when injecting Astro script.Written for commit 84d7195. Summary will update on new commits.