blob: 25d204a727743345d96a323a323cbbca11940da4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import { access, constants, mkdir, rm } from 'fs/promises';
import { kFileNotFoundError } from './constants.js';
// File system utilities
export async function rmIfExists(location) {
try {
await access(location, constants.F_OK);
await rm(location, { recursive: true });
}
catch (error) {
if (error.code === kFileNotFoundError) {
return;
}
throw error;
}
}
export async function ensureDirectoryExists(directory) {
try {
await access(directory);
}
catch (error) {
if (error.code === kFileNotFoundError) {
await mkdir(directory, { recursive: true });
return;
}
throw error;
}
}
|