@@ -36,18 +36,6 @@ export type ModuleOptions = SanityModuleOptions
3636
3737const logger = useLogger ( '@nuxtjs/sanity' )
3838
39- function validateConfig ( { projectId, dataset } : SanityModuleOptions ) {
40- if ( ! projectId ) {
41- logger . warn (
42- `Make sure you specify a ${ chalk . bold ( 'projectId' ) } in your sanity config.` ,
43- )
44- return false
45- } else {
46- logger . info ( `Sanity project ${ chalk . bold ( projectId ) } (${ chalk . bold ( dataset ) } ).` )
47- return true
48- }
49- }
50-
5139function getDefaultSanityConfig ( jsonPath : string ) {
5240 try {
5341 const { projectId, dataset } = fse . readJSONSync ( jsonPath ) . api
@@ -74,15 +62,12 @@ export default defineNuxtModule<SanityModuleOptions>({
7462 withCredentials : false ,
7563 additionalClients : { } ,
7664 ...getDefaultSanityConfig ( resolve ( nuxt . options . rootDir , './sanity.json' ) ) ,
77- ...nuxt . options . publicRuntimeConfig . sanity
7865 } ) ,
7966 async setup ( options , nuxt ) {
8067 if ( ! ( 'useCdn' in options ) ) {
8168 options . useCdn = process . env . NODE_ENV === 'production' && ! options . token
8269 }
8370
84- if ( ! validateConfig ( options ) ) return
85-
8671 try {
8772 if ( ! options . minimal ) {
8873 options . minimal = ! requireModule ( '@sanity/client' )
@@ -93,7 +78,7 @@ export default defineNuxtModule<SanityModuleOptions>({
9378 }
9479
9580 // Final resolved configuration
96- nuxt . options . publicRuntimeConfig . sanity = defu ( nuxt . options . publicRuntimeConfig . sanity , {
81+ nuxt . options . publicRuntimeConfig . sanity = options = defu ( nuxt . options . publicRuntimeConfig . sanity , {
9782 useCdn : options . useCdn ,
9883 projectId : options . projectId ,
9984 dataset : options . dataset ,
@@ -103,6 +88,12 @@ export default defineNuxtModule<SanityModuleOptions>({
10388 additionalClients : options . additionalClients ,
10489 } )
10590
91+ if ( ! options . projectId ) {
92+ logger . warn ( `No Sanity project found. Make sure you specify a ${ chalk . bold ( 'projectId' ) } in your Sanity config.` )
93+ } else {
94+ logger . info ( `Running with Sanity project ${ chalk . bold ( options . projectId ) } (${ chalk . bold ( options . dataset ) } ).` )
95+ }
96+
10697 const runtimeDir = fileURLToPath ( new URL ( './runtime' , import . meta. url ) )
10798 nuxt . options . build . transpile . push ( runtimeDir , '@nuxtjs/sanity' )
10899
0 commit comments