Skip to content

feat(cli): Rsbuild template detection and scaffolding in arkenv init - #1809

Merged
yamcodes merged 5 commits into
v1from
tackle_issue_1800
Sep 5, 2026
Merged

feat(cli): Rsbuild template detection and scaffolding in arkenv init#1809
yamcodes merged 5 commits into
v1from
tackle_issue_1800

Conversation

@yamcodes

@yamcodes yamcodes commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Fixes #1800

Summary

  • Added Rsbuild framework detection to arkenv init via @rsbuild/core dependencies and rsbuild.config.* files.
  • Added @arkenv/rsbuild-plugin dependency injection and rsbuild.config.* AST bootstrapping with magicast.
  • Set default client prefix to PUBLIC_ for Rsbuild projects.
  • Added comprehensive unit and integration tests for AST mutation, idempotency (including aliased imports), framework planning, and project scanning.
  • Included changeset for arkenv.

@yamcodes yamcodes added enhancement New feature or improvement arkenv Changes to the `arkenv` npm package. @arkenv/cli Issues or Pull Requests involving the ArkEnv CLI labels Sep 5, 2026
@pullfrog

pullfrog Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f15f377

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
arkenv Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added docs Adds or changes documentation, or acts as documentation in and of itself @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv github actions Pull requests that update GitHub Actions code example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests @arkenv/bun-plugin Issues or Pull Requests involving the Bun plugin for ArkEnv @arkenv/fumadocs-ui Issues or Pull Requests involving the ArkEnv Fumadocs UI theme playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) @arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv labels Sep 5, 2026
@yamcodes
yamcodes changed the base branch from dev to v1 September 5, 2026 06:30
@yamcodes

yamcodes commented Sep 5, 2026

Copy link
Copy Markdown
Owner Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Minor suggestions only — clean implementation, two rough edges worth a look.

Reviewed changes — adds Rsbuild as a first-class arkenv init target: framework detection via @rsbuild/core deps and rsbuild.config.* files, a magicast-based transformRsbuildConfig/bootstrapRsbuildConfig mutation pipeline, @arkenv/rsbuild-plugin dependency injection, PUBLIC_ default client prefix, an Rsbuild select option, executor wiring, docs, a changeset, and unit/integration tests across the scanner, transformer, workspace, planner, and executor.

  • Framework detection — project scanner, adapter, legacy Workspace, and prompt options all accept "rsbuild".
  • Config bootstrap — injects arkenvRsbuildPlugin() into defineConfig({...}) and plain-object configs with idempotency incl. aliased imports, plus graceful failures for callback forms.
  • Scaffold strategyrsbuildStrategy adds @arkenv/rsbuild-plugin, uses PUBLIC_ client prefix (matching the plugin's own default), and plans the simple schema file.
  • Executor + portsfindRsbuildConfig/bootstrapRsbuildConfig wired through WorkspacePort with human-readable reporting.
  • Verification — all 170 arkenv package tests pass (detector, bootstrapper, workspace integration, planner, executor) and pnpm typecheck is clean.

ℹ️ TanStack Start projects can't reach the new Rsbuild detection

detectFramework returns "vite" for any project with @tanstack/* dependencies before the newly added @rsbuild/core / rsbuild.config.* checks run (packages/arkenv/src/adapters/node-project-scanner/utils/detector.ts:41-47). A TanStack Start app bundled with Rsbuild — exactly the audience @arkenv/rsbuild-plugin's own changeset calls out — will still be scaffolded with @arkenv/vite-plugin and told there's no Vite config. The repo's own TanStack example uses vite.config.ts, so the current ordering is defensible; it's just worth a decision on whether rsbuild.config.* presence should outrank the TanStack default now that the Rsbuild path exists. Not blocking.

Technical details
# TanStack Start ordering vs Rsbuild detection

## Affected sites
- packages/arkenv/src/adapters/node-project-scanner/utils/detector.ts:41-43 — `@tanstack/*` deps force-return `"vite"` before the rsbuild check at :47.

## Required outcome
- Decide whether TanStack Start apps built on Rsbuild (rsbuild.config.* present, no vite.config) should be detected as `rsbuild` and scaffolded with `@arkenv/rsbuild-plugin`.

## Open questions for the human
- Is `@arkenv/vite-plugin` functional in an Rsbuild-bundled TanStack Start app? If not, the current ordering produces a broken recommendation for that subset.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/arkenv/src/adapters/node-workspace/utils/bootstrappers.ts Outdated
@pullfrog

pullfrog Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@github-actions github-actions Bot removed @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv github actions Pull requests that update GitHub Actions code example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) @arkenv/bun-plugin Issues or Pull Requests involving the Bun plugin for ArkEnv @arkenv/fumadocs-ui Issues or Pull Requests involving the ArkEnv Fumadocs UI theme @arkenv/cli Issues or Pull Requests involving the ArkEnv CLI playground Issues or Pull Requests concerning a playground. (Found in the `apps/playgrounds/` directory) @arkenv/nextjs Issues or Pull Requests involving the Next.js integration for ArkEnv labels Sep 5, 2026
@github-actions github-actions Bot removed the @arkenv/nuxt Issues or Pull Requests involving the Nuxt integration for ArkEnv label Sep 5, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

@arkenv/agent-plugin

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/agent-plugin@1809

arkenv

npm i https://pkg.pr.new/yamcodes/arkenv@1809

@arkenv/build

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/build@1809

@arkenv/bun-plugin

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/bun-plugin@1809

@arkenv/core

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/core@1809

@arkenv/fumadocs-ui

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/fumadocs-ui@1809

@arkenv/nextjs

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/nextjs@1809

@arkenv/nuxt

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/nuxt@1809

@arkenv/rsbuild-plugin

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/rsbuild-plugin@1809

@arkenv/standard

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/standard@1809

@arkenv/tanstack-addon

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/tanstack-addon@1809

@arkenv/vite-plugin

npm i https://pkg.pr.new/yamcodes/arkenv/@arkenv/vite-plugin@1809

commit: f15f377

@yamcodes

yamcodes commented Sep 5, 2026

Copy link
Copy Markdown
Owner Author

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No blocking issues — the fix cleanly closes the unregistered-import gap from the prior review. One rough edge inline.

Reviewed changes — commit 1ec36d17 replaces the whole-file regex presence check in transformRsbuildConfig with a plugins-array AST scan and adds alias-aware injection, with two targeted tests.

  • Plugin-presence AST checkhasPlugin now scans config.plugins for function-calls / bare identifiers bound to a name imported from @arkenv/rsbuild-plugin, instead of regex-matching the entire file, so an unregistered import no longer short-circuits injection.
  • Alias-aware injection — when an unregistered import exists, the injected plugin() call reuses the import's local (alias) binding and skips re-adding the import; the __ARK_PLUGIN__(:name) placeholder scheme resolves names post-generation.
  • Tests — added "injects plugin into plugins array even if import already exists but is unregistered" and the aliased variant, both of which fail against the previous implementation. All 43 bootstrapper tests pass locally.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/arkenv/src/adapters/node-workspace/utils/bootstrappers.ts Outdated

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Minor suggestions inline. Two rough edges; nothing blocking.

Reviewed changes

  • Rsbuild framework detectiondetector.ts and Workspace.detectFramework now return rsbuild for @rsbuild/core deps and rsbuild.config.* files; the detector, workspace, and scanner ports all gained the new union member.
  • Rsbuild config bootstrappingtransformRsbuildConfig uses a magicast AST round-trip with a placeholder-then-regex pass to inject arkenvRsbuildPlugin(), with import-aware (alias-tolerant) idempotency and an explicit refusal for the defineConfig(callback) form; findRsbuildConfig / bootstrapRsbuildConfig were added to the workspace port.
  • Scaffold planning + strategy — a new rsbuild strategy (PUBLIC_ client prefix, @arkenv/rsbuild-plugin dependency, arktype peer), an interactive-prompt entry, and an executor bootstrap branch wired in.
  • Tests + docs + changeset — comprehensive new unit/integration coverage (transform shapes, idempotency including aliased imports, detection, planning, executor), init.mdx updated, arkenv minor changeset.

I ran the six touched suites (172 tests) after building the @repo/utils workspace dependency — all pass. I also probed shapes the suite doesn't cover directly: injection into a non-empty plugins array works and preserves existing entries, output of a bootstrap is idempotent under a second pass, and comments survive the magicast round-trip.

ℹ️ Nitpicks

  • No test for a non-empty plugins array — every plugins fixture in the suite is [] or a single plugin. Injecting prepended and preserving existing entries (e.g. pluginReact()) is the most common real-world shape; I confirmed it works, so pinning it would be cheap insurance against the placeholder approach regressing.
  • Populated configs get re-indented — on a config with server / tools / output sections, the magicast round-trip re-indents nested blocks (valid output, but a noisy git diff). Inherited from the existing Vite/Nuxt bootstrappers, but worth knowing since Rsbuild configs are more commonly populated than fresh Vite ones.

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog

pullfrog Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Two findings from my review that should have been inline anchors but landed in the review body instead — anchored here for reference:

1. packages/arkenv/src/adapters/node-project-scanner/utils/detector.ts:83 — missing rsbuild.config.cts

Rsbuild's documented config loader order is ts → js → mts → mjs → cts → cjs (docs). All three of this PR's config lists skip .cts: here, Workspace.detectFramework (node-workspace/workspace.ts), and findRsbuildConfig (node-workspace/utils/bootstrappers.ts:686-692). A TypeScript + CommonJS project is detected as vanilla/bun-fullstack and init never bootstraps its config — minor, but a one-line addition per site (+ a detection test) closes it.

2. packages/arkenv/src/adapters/node-workspace/utils/bootstrappers.ts:292 — misleading "not an array" error for a valid config

Array.isArray(config.plugins) runs against the magicast proxy, so a legitimate const plugins = [...]; export default { plugins } fails with "The 'plugins' property in your Rsbuild config is not an array." The config is fine — only the inline-array shape is unsupported. Repeating "could not find an inline plugins array" would make the follow-up "add the plugin manually" message read correctly.

Neither blocks merge; the full summary is in the review.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found — the commit cleanly closes the remaining existingImport gap from the prior review, with solid regression coverage.

Reviewed changes — commit f15f377d makes existingImport selection in transformRsbuildConfig plugin-aware and adds two regression tests.

  • Plugin-binding preferenceexistingImport now filters @arkenv/rsbuild-plugin imports and prefers the binding whose imported is arkenvRsbuildPlugin or default, falling back to the first import only when no plugin binding exists. A config importing type RsbuildTransformOptions ahead of the plugin no longer injects the type as the plugin call.
  • Type-before-plugin regression test — pins that import { type RsbuildTransformOptions, arkenvRsbuildPlugin } injects arkenvRsbuildPlugin() and never RsbuildTransformOptions(); this fails against the prior implementation.
  • Non-empty plugins array coverage — new test asserts injection into plugins: [pluginReact()] preserves the existing entry alongside the injected plugin, closing the coverage gap flagged in the prior review.

Verified: all 45 bootstrapper tests pass, node-workspace/scanner suites (111 tests) pass, and pnpm typecheck --filter arkenv is clean.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@yamcodes
yamcodes merged commit 6be3c3a into v1 Sep 5, 2026
30 of 32 checks passed
@yamcodes
yamcodes deleted the tackle_issue_1800 branch September 5, 2026 11:58
@arkenv-bot arkenv-bot Bot mentioned this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arkenv Changes to the `arkenv` npm package. docs Adds or changes documentation, or acts as documentation in and of itself enhancement New feature or improvement tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): Rsbuild template detection and scaffolding in arkenv init

1 participant