@@ -22,29 +22,53 @@ const getGitUtils = (cwd) => {
2222
2323 // Get file content, coercing Windows `\r\n` newlines to `\n`
2424 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+ }
2834 }
2935
3036 // Append to file, creating if it doesn't exist
3137 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+ }
3547 }
3648
3749 // Write (over) file, creating if it doesn't exist
3850 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+ }
4260 }
4361
4462 // Remove file
4563 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+ }
4872 }
4973
5074 // Wrap execGit to always pass `gitOps`
0 commit comments