delete file descript.ion when empty

Massimo Melina committed Apr 9, 2024 at 11:26 UTC aeabf4ab94534d4d22b9b8df20631294b0078f3c
1 file changed +5 -1
src/comments.ts
+5 -1
@@ -6,6 +6,7 @@ import { createWriteStream } from 'fs'
6 import { singleWorkerFromBatchWorker } from './misc'
7 import _ from 'lodash'
8 import iconv from 'iconv-lite'
9 +import { unlink } from 'node:fs/promises'
10
11 export const DESCRIPT_ION = 'descript.ion'
12 export const descriptIon = defineConfig('descript_ion', true)
@@ -27,8 +28,11 @@ export const setCommentFor = singleWorkerFromBatchWorker(async (jobs: [path: str
28 else
29 comments.set(file, comment)
30 }
31 + const path = join(folder, DESCRIPT_ION)
32 + if (!comments.size)
33 + return unlink(path)
34 // encode comments in descript.ion format
31 - const ws = createWriteStream(join(folder, DESCRIPT_ION))
35 + const ws = createWriteStream(path)
36 comments.forEach((comment, filename) => {
37 const multiline = comment.includes('\n')
38 const line = (filename.includes(' ') ? `"${filename}"` : filename)