@@ -22,29 +22,53 @@ const getGitUtils = (cwd) => {
22
22
23
23
// Get file content, coercing Windows `\r\n` newlines to `\n`
24
24
const readFile = async ( filename , dir = cwd ) => {
25
- const filepath = path . isAbsolute ( filename ) ? path . normalize ( filename ) : path . join ( dir , filename )
26
- const file = await fs . readFile ( filepath , { encoding : 'utf-8' } )
27
- return normalizeWindowsNewlines ( file )
25
+ const filepath = path . resolve ( dir , filename )
26
+
27
+ try {
28
+ const file = await fs . readFile ( filepath , { encoding : 'utf-8' } )
29
+ return normalizeWindowsNewlines ( file )
30
+ } catch ( error ) {
31
+ console . error ( `Failed to read file "${ filepath } " with error:` , error )
32
+ throw error
33
+ }
28
34
}
29
35
30
36
// Append to file, creating if it doesn't exist
31
37
const appendFile = async ( filename , content , dir = cwd ) => {
32
- const filepath = path . isAbsolute ( filename ) ? path . normalize ( filename ) : path . join ( dir , filename )
33
- await ensureDir ( filepath )
34
- await fs . appendFile ( filepath , content , { encoding : 'utf-8' } )
38
+ const filepath = path . resolve ( dir , filename )
39
+
40
+ try {
41
+ await ensureDir ( filepath )
42
+ await fs . appendFile ( filepath , content , { encoding : 'utf-8' } )
43
+ } catch ( error ) {
44
+ console . error ( `Failed to append file "${ filepath } " with error:` , error )
45
+ throw error
46
+ }
35
47
}
36
48
37
49
// Write (over) file, creating if it doesn't exist
38
50
const writeFile = async ( filename , content , dir = cwd ) => {
39
- const filepath = path . isAbsolute ( filename ) ? path . normalize ( filename ) : path . join ( dir , filename )
40
- await ensureDir ( filepath )
41
- await fs . writeFile ( filepath , content , { encoding : 'utf-8' } )
51
+ const filepath = path . resolve ( dir , filename )
52
+
53
+ try {
54
+ await ensureDir ( filepath )
55
+ await fs . writeFile ( filepath , content , { encoding : 'utf-8' } )
56
+ } catch ( error ) {
57
+ console . error ( `Failed to write file "${ filepath } " with error:` , error )
58
+ throw error
59
+ }
42
60
}
43
61
44
62
// Remove file
45
63
const removeFile = async ( filename , dir = cwd ) => {
46
- const filepath = path . isAbsolute ( filename ) ? path . normalize ( filename ) : path . join ( dir , filename )
47
- await fs . rm ( filepath , { recursive : true } )
64
+ const filepath = path . resolve ( dir , filename )
65
+
66
+ try {
67
+ await fs . rm ( filepath , { recursive : true } )
68
+ } catch ( error ) {
69
+ console . error ( `Failed to remove file "${ filepath } " with error:` , error )
70
+ throw error
71
+ }
48
72
}
49
73
50
74
// Wrap execGit to always pass `gitOps`
0 commit comments