mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-09 21:58:09 -05:00
fix(utils.ts): add existsSync check before removing temp directory to prevent errors if directory does not exist (#401)
This commit is contained in:
committed by
GitHub
parent
e063faa491
commit
68dc9c36eb
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, rm, writeFile } from 'fs';
|
||||
import { existsSync, mkdtemp, rm, writeFile } from 'fs';
|
||||
import { tmpdir } from 'os';
|
||||
import path from 'path';
|
||||
import { promisify } from 'util';
|
||||
@@ -19,7 +19,11 @@ export async function prepareFile(
|
||||
const tempDir = await fsMakeTempDir(path.join(tmpdir(), 'opencommit-test-'));
|
||||
const filePath = path.resolve(tempDir, fileName);
|
||||
await fsWriteFile(filePath, content);
|
||||
const cleanup = async () => fsRemove(tempDir, { recursive: true });
|
||||
const cleanup = async () => {
|
||||
if (existsSync(tempDir)) {
|
||||
await fsRemove(tempDir, { recursive: true });
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
filePath,
|
||||
|
||||
Reference in New Issue
Block a user