Skip to content

Commit 246bb60

Browse files
committed
fix: write null aftering reset()
1 parent 13d9f99 commit 246bb60

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

packages/node/src/DirectoryProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export class DirectoryProvider {
4141
return join(this.temporaryPath, `${filename}-${Date.now()}.json`)
4242
}
4343

44-
createTemporaryFile<T>(filename: string, data: T) {
44+
createTemporaryFile<T>(filename: string, data: T | null) {
45+
if (!data) return
46+
4547
const file = this.temporaryFilePath(filename)
4648
const writer = new Writer(file)
4749
const parsedData =

packages/node/src/adapter/AsyncWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AsyncWriter<T> extends BaseWriter<T> implements AsyncAdapter<T> {
3535
async reset(initialData: T): Promise<void> {
3636
try {
3737
const data = await this.read()
38-
await this.directory.createTemporaryFile(this.name, data).writeAsync()
38+
await this.directory.createTemporaryFile(this.name, data)?.writeAsync()
3939
await this.write(initialData)
4040
} catch (err) {
4141
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {

packages/node/src/adapter/SyncWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class SyncWriter<T> extends BaseWriter<T> implements SyncAdapter<T> {
3535
reset(initialData: T): void {
3636
try {
3737
const data = this.read()
38-
this.directory.createTemporaryFile(this.name, data).write()
38+
this.directory.createTemporaryFile(this.name, data)?.write()
3939
this.write(initialData)
4040
} catch (err) {
4141
throw err

0 commit comments

Comments
 (0)