1- import type { BuildInfo } from '../shared/types'
1+ import type { BuildInfo , EnvType } from '../shared/types'
22import { createResolver , defineNuxtModule } from 'nuxt/kit'
33import { isCI } from 'std-env'
44import { getEnv , getFileLastUpdated , version } from '../config/env'
@@ -10,22 +10,37 @@ export default defineNuxtModule({
1010 name : 'npmx:build-env' ,
1111 } ,
1212 async setup ( _options , nuxt ) {
13- const [ { env, commit, shortCommit, branch } , privacyPolicyDate ] = await Promise . all ( [
14- getEnv ( nuxt . options . dev ) ,
15- getFileLastUpdated ( 'app/pages/privacy.vue' ) ,
16- ] )
17-
13+ let env : EnvType = 'dev'
1814 nuxt . options . appConfig = nuxt . options . appConfig || { }
1915 nuxt . options . appConfig . env = env
20- nuxt . options . appConfig . buildInfo = {
21- version,
22- time : + Date . now ( ) ,
23- commit,
24- shortCommit,
25- branch,
26- env,
27- privacyPolicyDate,
28- } satisfies BuildInfo
16+ if ( process . env . TEST ) {
17+ const time = new Date ( )
18+ nuxt . options . appConfig . buildInfo = {
19+ env,
20+ version : '0.0.0' ,
21+ commit : '704987bba88909f3782d792c224bde989569acb9' ,
22+ shortCommit : '704987b' ,
23+ branch : 'xxx' ,
24+ time : time . getTime ( ) ,
25+ privacyPolicyDate : time . toISOString ( ) ,
26+ } satisfies BuildInfo
27+ } else {
28+ const [ { env : useEnv , commit, shortCommit, branch } , privacyPolicyDate ] = await Promise . all ( [
29+ getEnv ( nuxt . options . dev ) ,
30+ getFileLastUpdated ( 'app/pages/privacy.vue' ) ,
31+ ] )
32+ env = useEnv
33+ nuxt . options . appConfig . env = useEnv
34+ nuxt . options . appConfig . buildInfo = {
35+ version,
36+ time : + Date . now ( ) ,
37+ commit,
38+ shortCommit,
39+ branch,
40+ env,
41+ privacyPolicyDate,
42+ } satisfies BuildInfo
43+ }
2944
3045 nuxt . options . nitro . publicAssets = nuxt . options . nitro . publicAssets || [ ]
3146 if ( env === 'dev' ) nuxt . options . nitro . publicAssets . unshift ( { dir : resolve ( '../public-dev' ) } )
0 commit comments