1
- import { execSync } from 'node:child_process'
1
+ import * as child_process from 'node:child_process'
2
2
import { join } from 'node:path'
3
+ import { promisify } from 'node:util'
3
4
4
5
import react from '@vitejs/plugin-react'
5
6
import unocss from 'unocss/vite'
@@ -8,22 +9,27 @@ import { VitePWA as pwa } from 'vite-plugin-pwa'
8
9
9
10
import { description , name , version } from './package.json'
10
11
11
- const getCommitHash = ( ) : string => execSync ( 'git rev-parse --short HEAD' ) . toString ( ) . trimEnd ( )
12
+ const exec = promisify ( child_process . exec )
12
13
13
- const getCommitDate = ( ) : string => {
14
- const commitDate = execSync ( 'git log -1 --format=%cd' ) . toString ( )
15
- return new Date ( commitDate ) . toISOString ( )
14
+ const getCommitHash = async ( ) => {
15
+ const { stdout } = await exec ( 'git rev-parse --short HEAD' )
16
+ return stdout . trim ( )
16
17
}
17
18
18
- export default defineConfig ( {
19
+ const getCommitDate = async ( ) => {
20
+ const { stdout } = await exec ( 'git log -1 --format=%cd' )
21
+ return new Date ( stdout ) . toISOString ( )
22
+ }
23
+
24
+ export default defineConfig ( async ( ) => ( {
19
25
base : './' ,
20
26
build : {
21
27
chunkSizeWarningLimit : 1000 ,
22
28
} ,
23
29
define : {
24
30
__VERSION__ : JSON . stringify ( version ) ,
25
- __COMMIT_HASH__ : JSON . stringify ( getCommitHash ( ) ) ,
26
- __COMMIT_DATE__ : JSON . stringify ( getCommitDate ( ) ) ,
31
+ __COMMIT_HASH__ : JSON . stringify ( await getCommitHash ( ) ) ,
32
+ __COMMIT_DATE__ : JSON . stringify ( await getCommitDate ( ) ) ,
27
33
} ,
28
34
plugins : [
29
35
react ( ) ,
@@ -82,4 +88,4 @@ export default defineConfig({
82
88
ignored : [ / c o v e r a g e / , / d i s t / ] ,
83
89
} ,
84
90
} ,
85
- } )
91
+ } ) )
0 commit comments