@@ -49,14 +49,46 @@ export const loadOptions = async (): Promise<ModuleOptions> => {
4949 try {
5050 // Try to load Nuxt configuration first
5151 console . log ( '[Nuxt Users] Loading Nuxt project...' )
52- const nuxt = await loadNuxt ( { cwd : process . cwd ( ) } )
53- const nuxtUsersConfig = nuxt . options . nuxtUsers as ModuleOptions
52+ const nuxt = await loadNuxt ( { cwd : process . cwd ( ) , ready : false } )
53+
54+ // Get both configurations BEFORE module processing
55+ // 1. Top-level nuxtUsers (for module-style config)
56+ // 2. runtimeConfig.nuxtUsers (for runtime-style config - read from the original config)
57+ const topLevelConfig = nuxt . options . nuxtUsers as ModuleOptions
58+
59+ // Read the original runtime config before it gets processed by the module
60+ const originalRuntimeConfig = await ( async ( ) => {
61+ try {
62+ // Load the nuxt.config.ts file directly to get the original runtime config
63+ const configPath = await import ( 'path' ) . then ( p => p . resolve ( process . cwd ( ) , 'nuxt.config.ts' ) )
64+ const config = await import ( configPath ) . then ( m => m . default )
65+ return config ?. runtimeConfig ?. nuxtUsers
66+ } catch {
67+ // Fallback to processed config if direct loading fails
68+ return nuxt . options . runtimeConfig ?. nuxtUsers
69+ }
70+ } ) ( )
71+
72+
5473 await nuxt . close ( )
5574
56- if ( nuxtUsersConfig ) {
57- console . log ( '[Nuxt Users] Using configuration from Nuxt project' )
58- // Deep merge with defaultOptions to ensure all required fields are present
59- return defu ( nuxtUsersConfig , defaultOptions )
75+ // Check if we have any configuration
76+ if ( topLevelConfig || originalRuntimeConfig ) {
77+ console . log ( '[Nuxt Users] Using configuration from nuxt.config' )
78+ // Merge configurations with priority: topLevel > runtime > defaults
79+ // Special handling for connector to avoid mixing sqlite and mysql settings
80+ let mergedConfig = defu ( topLevelConfig , originalRuntimeConfig , defaultOptions )
81+
82+ // If a specific connector is configured, ensure we don't mix default connector settings
83+ const configuredConnector = topLevelConfig ?. connector || originalRuntimeConfig ?. connector
84+ if ( configuredConnector ) {
85+ mergedConfig = {
86+ ...mergedConfig ,
87+ connector : configuredConnector
88+ }
89+ }
90+
91+ return mergedConfig
6092 }
6193 else {
6294 console . log ( '[Nuxt Users] No nuxt-users configuration found, using environment variables' )
0 commit comments