@@ -13,7 +13,7 @@ import {
13
13
import type { Nuxt } from '@nuxt/schema'
14
14
import type { ModuleOptions as MDCModuleOptions } from '@nuxtjs/mdc'
15
15
import { hash } from 'ohash'
16
- import { join , isAbsolute } from 'pathe'
16
+ import { join } from 'pathe'
17
17
import htmlTags from '@nuxtjs/mdc/runtime/parser/utils/html-tags-list'
18
18
import { kebabCase , pascalCase } from 'scule'
19
19
import defu from 'defu'
@@ -75,14 +75,6 @@ export default defineNuxtModule<ModuleOptions>({
75
75
} ,
76
76
} ,
77
77
async setup ( options , nuxt ) {
78
- // Provide default database configuration here since nuxt is merging defaults and user options
79
- if ( ! options . database ) {
80
- options . database = {
81
- type : 'sqlite' ,
82
- filename : './contents.sqlite' ,
83
- }
84
- }
85
-
86
78
const resolver = createResolver ( import . meta. url )
87
79
const manifest : Manifest = {
88
80
checksum : { } ,
@@ -91,31 +83,9 @@ export default defineNuxtModule<ModuleOptions>({
91
83
collections : [ ] ,
92
84
}
93
85
94
- // Create local database
95
- await refineDatabaseConfig ( options . _localDatabase , nuxt )
96
- if ( options . _localDatabase ?. type === 'sqlite' ) {
97
- options . _localDatabase ! . filename = isAbsolute ( options . _localDatabase ! . filename )
98
- ? options . _localDatabase ! . filename
99
- : join ( nuxt . options . rootDir , options . _localDatabase ! . filename )
100
- }
101
-
102
- // Create sql database
103
- await refineDatabaseConfig ( options . database , nuxt )
104
-
105
86
const { collections } = await loadContentConfig ( nuxt )
106
87
manifest . collections = collections
107
88
108
- // Module Options
109
- nuxt . options . runtimeConfig . public . content = {
110
- wsUrl : '' ,
111
- }
112
- nuxt . options . runtimeConfig . content = {
113
- version,
114
- database : options . database ,
115
- localDatabase : options . _localDatabase ! ,
116
- integrityCheck : true ,
117
- } as never
118
-
119
89
nuxt . options . vite . optimizeDeps ||= { }
120
90
nuxt . options . vite . optimizeDeps . exclude ||= [ ]
121
91
nuxt . options . vite . optimizeDeps . exclude . push ( '@sqlite.org/sqlite-wasm' )
@@ -159,9 +129,25 @@ export default defineNuxtModule<ModuleOptions>({
159
129
}
160
130
}
161
131
162
- // Load nitro preset and set db adapter
163
132
const preset = findPreset ( nuxt )
164
133
await preset ?. setup ?.( options , nuxt )
134
+
135
+ // Provide default database configuration here since nuxt is merging defaults and user options
136
+ options . database ||= { type : 'sqlite' , filename : './contents.sqlite' }
137
+ await refineDatabaseConfig ( options . _localDatabase , { rootDir : nuxt . options . rootDir , updateSqliteFileName : true } )
138
+ await refineDatabaseConfig ( options . database , { rootDir : nuxt . options . rootDir } )
139
+
140
+ // Module Options
141
+ nuxt . options . runtimeConfig . public . content = {
142
+ wsUrl : '' ,
143
+ }
144
+ nuxt . options . runtimeConfig . content = {
145
+ version,
146
+ database : options . database ,
147
+ localDatabase : options . _localDatabase ! ,
148
+ integrityCheck : true ,
149
+ } as never
150
+
165
151
nuxt . hook ( 'nitro:config' , async ( config ) => {
166
152
const preset = findPreset ( nuxt )
167
153
await preset . setupNitro ( config , { manifest, resolver, moduleOptions : options } )
0 commit comments