[PR #5917] feat(cli): use vite to load auth config when we detect a vite project #31921

Open
opened 2026-04-17 22:48:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5917
Author: @shreyassanthu77
Created: 11/11/2025
Status: 🔄 Open

Base: mainHead: canary


📝 Commits (6)

  • c204c68 chore(refactor): split config file resolution and loading in the cli
  • 19e51c8 feat: use vite to resolve the auth config when available
  • 45f9678 fix: use paths relative to cwd when searching for the auth config
  • 7823834 chore(cli): fix lockfile
  • 93fce94 fix(cli): improve config loading robustness and validation
  • e8d0251 test(cli): add tests for vite config loading path

📊 Changes

4 files changed (+5646 additions, -4054 deletions)

View changed files

📝 packages/cli/package.json (+10 -1)
📝 packages/cli/src/utils/get-config.ts (+157 -107)
📝 packages/cli/test/get-config.test.ts (+82 -0)
📝 pnpm-lock.yaml (+5397 -3946)

📄 Description

When using frameworks that build on top of vite, some imports may not be resolved correctly when using jiti (like path aliases, virtual modules etc)

so this pr uses vite to try and resolve a config file and if one exists we use that with all the plugins enabled to load the auth config file so that will make sure all the imports are resolved properly and any vite specific logic need not be stubbed out just to use the better auth cli

Notes

  • splits out the config file path resolution logic from the actual loading of the file
  • added vite as a dev dependency for type checking
  • loads the actual vite module from the user's project to load the config
  • falls back to jiti if vite is not found, package json is not found or if vite could not load a vite config

Few Considerations

  • the change currently expects a few APIs from node and vite to be available for it to work
    1. we expect the runnerImport API to be available in vite but may not be available in older vite versions, needs better version resolution which currently is not implemented
    2. the runnerImport API used to load the config is marked experimental tho the api didn't change since 6.2
  • some frameworks like astro and solid start wrap vite so we might need special handling for them (or leave it as is and just let it fallback to jiti?)
  • no tests have been implemented for the new vite specific code

Summary by cubic

Use Vite v6–v7 to load the auth config in Vite projects so aliases and plugin-based imports resolve correctly, with a safe fallback to c12/Jiti when Vite isn’t available or fails.

  • New Features

    • Auto-detect Vite and load the auth config with the project’s Vite (plugins on).
    • Resolve TS path aliases, virtual modules, and framework imports.
    • Fallback to c12/Jiti if Vite is missing, runnerImport is unavailable, or Vite load fails.
  • Refactors

    • Split config path resolution from loading; search paths relative to cwd.
    • Stronger validation and errors: try/catch around Vite load, export checks after both loaders, unified “server-only” guidance, and deduped messages.
    • Add Vite dev dep and optional peer; load user’s Vite at runtime via package.json resolution.
    • Tests cover Vite alias resolution and fallback to c12/Jiti when no Vite config is present.

Written for commit e8d0251630. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5917 **Author:** [@shreyassanthu77](https://github.com/shreyassanthu77) **Created:** 11/11/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `canary` --- ### 📝 Commits (6) - [`c204c68`](https://github.com/better-auth/better-auth/commit/c204c68bb05a89aeabb1948597b068a3be594474) chore(refactor): split config file resolution and loading in the cli - [`19e51c8`](https://github.com/better-auth/better-auth/commit/19e51c896002650d43319eb62aead3b3442a60ce) feat: use vite to resolve the auth config when available - [`45f9678`](https://github.com/better-auth/better-auth/commit/45f96783fbf5661254d03072446672a43dff1817) fix: use paths relative to cwd when searching for the auth config - [`7823834`](https://github.com/better-auth/better-auth/commit/782383486dc10921cad9f47797ad0113309575b1) chore(cli): fix lockfile - [`93fce94`](https://github.com/better-auth/better-auth/commit/93fce94d6d7d80c21b0c49b12ed134e67a52243c) fix(cli): improve config loading robustness and validation - [`e8d0251`](https://github.com/better-auth/better-auth/commit/e8d02516309694674a3357db59f5b557eb20cbfc) test(cli): add tests for vite config loading path ### 📊 Changes **4 files changed** (+5646 additions, -4054 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/package.json` (+10 -1) 📝 `packages/cli/src/utils/get-config.ts` (+157 -107) 📝 `packages/cli/test/get-config.test.ts` (+82 -0) 📝 `pnpm-lock.yaml` (+5397 -3946) </details> ### 📄 Description When using frameworks that build on top of vite, some imports may not be resolved correctly when using jiti (like path aliases, virtual modules etc) so this pr uses vite to try and resolve a config file and if one exists we use that with all the plugins enabled to load the auth config file so that will make sure all the imports are resolved properly and any vite specific logic need not be stubbed out just to use the better auth cli ## Notes - splits out the config file path resolution logic from the actual loading of the file - added vite as a dev dependency for type checking - loads the actual vite module from the user's project to load the config - falls back to jiti if vite is not found, package json is not found or if vite could not load a vite config ## Few Considerations - the change currently expects a few APIs from node and vite to be available for it to work 1. we expect the runnerImport API to be available in vite but may not be available in older vite versions, needs better version resolution which currently is not implemented 1. the runnerImport API used to load the config is marked experimental tho the api didn't change since 6.2 - some frameworks like astro and solid start wrap vite so we might need special handling for them (or leave it as is and just let it fallback to jiti?) - no tests have been implemented for the new vite specific code <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Use Vite v6–v7 to load the auth config in Vite projects so aliases and plugin-based imports resolve correctly, with a safe fallback to c12/Jiti when Vite isn’t available or fails. - **New Features** - Auto-detect Vite and load the auth config with the project’s Vite (plugins on). - Resolve TS path aliases, virtual modules, and framework imports. - Fallback to c12/Jiti if Vite is missing, runnerImport is unavailable, or Vite load fails. - **Refactors** - Split config path resolution from loading; search paths relative to cwd. - Stronger validation and errors: try/catch around Vite load, export checks after both loaders, unified “server-only” guidance, and deduped messages. - Add Vite dev dep and optional peer; load user’s Vite at runtime via package.json resolution. - Tests cover Vite alias resolution and fallback to c12/Jiti when no Vite config is present. <sup>Written for commit e8d02516309694674a3357db59f5b557eb20cbfc. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:48:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#31921