@@ -35,8 +35,11 @@ export default defineNuxtModule<ModuleOptions>({
35
35
const rootDir = nuxt . options . rootDir
36
36
const { resolve } = createResolver ( import . meta. url )
37
37
38
- let remoteArg = parseArgs ( argv , { remote : { type : 'string' } } ) . remote as string
39
- remoteArg = ( remoteArg === '' ? 'true' : remoteArg )
38
+ const cliArgs = parseArgs ( argv , {
39
+ remote : { type : 'string' } ,
40
+ hubEnv : { type : 'string' }
41
+ } )
42
+ const remoteArg = cliArgs . remote === '' ? 'true' : cliArgs . remote
40
43
const runtimeConfig = nuxt . options . runtimeConfig
41
44
const databaseMigrationsDirs = nuxt . options . _layers ?. map ( layer => join ( layer . config . serverDir ! , 'database/migrations' ) ) . filter ( Boolean )
42
45
const hub = defu ( runtimeConfig . hub || { } , options , {
@@ -66,7 +69,7 @@ export default defineNuxtModule<ModuleOptions>({
66
69
databaseQueriesPaths : [ ] ,
67
70
// Other options
68
71
version,
69
- env : process . env . NUXT_HUB_ENV || 'production' ,
72
+ env : process . env . NUXT_HUB_ENV || ( cliArgs . hubEnv as string ) || 'production' ,
70
73
openapi : nuxt . options . nitro . experimental ?. openAPI === true ,
71
74
// Extra bindings for the project
72
75
bindings : {
@@ -79,6 +82,18 @@ export default defineNuxtModule<ModuleOptions>({
79
82
clientSecret : process . env . NUXT_HUB_CLOUDFLARE_ACCESS_CLIENT_SECRET || null
80
83
}
81
84
} )
85
+ if ( ! [ 'test' , 'preview' , 'production' ] . includes ( hub . env ) ) {
86
+ log . error ( 'Invalid hub environment, should be `test`, `preview` or `production`' )
87
+ process . exit ( 1 )
88
+ }
89
+ // If testing environment detects, set the hub env to `test`
90
+ if ( nuxt . options . test ) {
91
+ hub . env = 'test'
92
+ }
93
+ if ( hub . env === 'test' ) {
94
+ log . info ( 'NuxtHub test environment detected, using `test` dataset for all storage & disabling remote storage.' )
95
+ hub . remote = false
96
+ }
82
97
runtimeConfig . hub = hub
83
98
runtimeConfig . public . hub = { }
84
99
// Make sure to tell Nitro to not generate the wrangler.toml file
0 commit comments