@@ -39,26 +39,33 @@ export async function getFileLastModifyTime(url: string) {
39
39
export function getFileLastModifyTimeByGit ( url : string ) : Promise < Date | undefined > {
40
40
return new Promise ( ( resolve ) => {
41
41
const cwd = path . dirname ( url )
42
- if ( ! fs . existsSync ( cwd ) )
43
- return resolve ( undefined )
44
- const fileName = path . basename ( url )
45
-
46
- // 使用异步回调
47
- const child = spawn ( 'git' , [ 'log' , '-1' , '--pretty="%ai"' , fileName ] , {
48
- cwd,
49
- } )
50
- let output = ''
51
- child . stdout . on ( 'data' , d => ( output += String ( d ) ) )
52
- child . on ( 'close' , async ( ) => {
53
- let date : Date | undefined
54
- if ( output . trim ( ) ) {
55
- date = new Date ( output )
56
- }
57
- resolve ( date )
58
- } )
59
- child . on ( 'error' , async ( ) => {
42
+
43
+ // 有额外的耗时,try-catch 处理
44
+ // if (!fs.existsSync(cwd))
45
+ // return resolve(undefined)
46
+ try {
47
+ const fileName = path . basename ( url )
48
+
49
+ // 使用异步回调
50
+ const child = spawn ( 'git' , [ 'log' , '-1' , '--pretty="%ai"' , fileName ] , {
51
+ cwd,
52
+ } )
53
+ let output = ''
54
+ child . stdout . on ( 'data' , d => ( output += String ( d ) ) )
55
+ child . on ( 'close' , async ( ) => {
56
+ let date : Date | undefined
57
+ if ( output . trim ( ) ) {
58
+ date = new Date ( output )
59
+ }
60
+ resolve ( date )
61
+ } )
62
+ child . on ( 'error' , async ( ) => {
63
+ resolve ( undefined )
64
+ } )
65
+ }
66
+ catch {
60
67
resolve ( undefined )
61
- } )
68
+ }
62
69
} )
63
70
}
64
71
0 commit comments