Skip to content

Commit

Permalink
fix: Try to add a trailing newline if the file had one (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
NyanHelsing authored Sep 12, 2022
1 parent 75bf407 commit da25b94
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/cli/src/api/formats/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ const minimal: CatalogFormatter = {

write(filename, catalog) {
const messages = serialize(catalog)
writeFileIfChanged(filename, JSON.stringify(messages, null, 2))
let file = null
try {
file = await fsPromises.readFile(filePath, 'utf8')
} catch (error) {
if (error.code !== "ENOENT") {
throw error
}
}
const shouldUseTrailingNewline = file === null || file?.endsWith("\n")
const trailingNewLine = shouldUseTrailingNewline ? "\n" : ""
fs.writeFileSync(filename, `${JSON.stringify(messages, null, 2)}${trailingNewLine}`)
},

read(filename) {
Expand Down

1 comment on commit da25b94

@vercel
Copy link

@vercel vercel bot commented on da25b94 Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.