mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +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 { readFileByLine } from './fetch-text-by-line';
|
||||||
import { writeFile } from './misc';
|
import { writeFile } from './misc';
|
||||||
import { createCompareSource, fileEqualWithCommentComparator } from 'foxts/compare-source';
|
import { createCompareSource, fileEqualWithCommentComparator } from 'foxts/compare-source';
|
||||||
|
import { promisify } from 'node:util';
|
||||||
|
|
||||||
export const fileEqual = createCompareSource(fileEqualWithCommentComparator);
|
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
|
// So we make sure direct write to file if the content is
|
||||||
// most likely less than 250 lines
|
// most likely less than 250 lines
|
||||||
if (linesALen < 250) {
|
if (linesALen < 250) {
|
||||||
return writeFile(filePath, fastStringArrayJoin(linesA, '\n') + '\n');
|
return writeFile(filePath, fastStringArrayJoin(linesA, '\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const writeStream = fs.createWriteStream(filePath);
|
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
|
// eslint-disable-next-line no-await-in-loop -- stream high water mark
|
||||||
if (p) await p;
|
if (p) await p;
|
||||||
}
|
}
|
||||||
|
await promisify(writeStream.end.bind(writeStream))();
|
||||||
writeStream.end();
|
await promisify(writeStream.close.bind(writeStream))();
|
||||||
writeStream.close();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user