mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: close fs write stream properly
Some checks failed
Build / Build (push) Has been cancelled
Build / Diff output (push) Has been cancelled
Build / Deploy to Cloudflare Pages (3.114.12) (push) Has been cancelled
Build / Deploy to GitHub and GitLab (push) Has been cancelled
Build / Remove Artifacts after Deployment (push) Has been cancelled
Some checks failed
Build / Build (push) Has been cancelled
Build / Diff output (push) Has been cancelled
Build / Deploy to Cloudflare Pages (3.114.12) (push) Has been cancelled
Build / Deploy to GitHub and GitLab (push) Has been cancelled
Build / Remove Artifacts after Deployment (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ import type { Span } from '../trace';
|
||||
import { readFileByLine } from './fetch-text-by-line';
|
||||
import { writeFile } from './misc';
|
||||
import { createCompareSource, fileEqualWithCommentComparator } from 'foxts/compare-source';
|
||||
import { promisify } from 'node:util';
|
||||
|
||||
export const fileEqual = createCompareSource(fileEqualWithCommentComparator);
|
||||
|
||||
@@ -31,7 +32,7 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
|
||||
// So we make sure direct write to file if the content is
|
||||
// most likely less than 250 lines
|
||||
if (linesALen < 250) {
|
||||
return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n');
|
||||
return writeFile(filePath, fastStringArrayJoin(linesA, '\n'));
|
||||
}
|
||||
|
||||
const writeStream = fs.createWriteStream(filePath);
|
||||
@@ -40,8 +41,7 @@ export async function compareAndWriteFile(span: Span, linesA: string[], filePath
|
||||
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
||||
if (p) await p;
|
||||
}
|
||||
|
||||
writeStream.end();
|
||||
writeStream.close();
|
||||
await promisify(writeStream.end.bind(writeStream))();
|
||||
await promisify(writeStream.close.bind(writeStream))();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user