Skip to content

Commit 4fe9c51

Browse files
authored
Ensure that the file we are trying to write JSON to exists (#1856)
1 parent 42acc62 commit 4fe9c51

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

extension/src/fileSystem/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { basename, extname, join, relative, resolve } from 'path'
22
import {
3+
ensureFileSync,
34
existsSync,
45
lstatSync,
56
readdir,
@@ -104,4 +105,7 @@ export const loadJson = <T>(path: string): T | undefined => {
104105
export const writeJson = <T extends Record<string, unknown>>(
105106
path: string,
106107
obj: T
107-
): void => writeFileSync(path, JSON.stringify(obj))
108+
): void => {
109+
ensureFileSync(path)
110+
return writeFileSync(path, JSON.stringify(obj))
111+
}

0 commit comments

Comments
 (0)