Skip to content

Commit

Permalink
Make import of fs optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tsviatkov committed May 29, 2023
1 parent fef546d commit af5eddd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfort/openfort-js",
"version": "0.1.4",
"version": "0.1.5",
"description": "",
"author": "",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions src/storage/file-storage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {BaseStorage} from "./base-storage";
import {resolve} from "path";
import {readFile, writeFile} from "fs/promises";
import {StorageKeys} from "./storage-keys";

export class FileStorage implements BaseStorage {
Expand Down Expand Up @@ -30,7 +29,8 @@ export class FileStorage implements BaseStorage {
}

private async readJsonFile(): Promise<any | null> {
const content = await readFile(this.filePath, {encoding: "utf-8"});
const {readFile} = await import("fs/promises");
const content = await readFile(this.filePath, 'utf-8');
return content ? JSON.parse(content) : null;
}

Expand All @@ -44,6 +44,7 @@ export class FileStorage implements BaseStorage {

private async writeJsonFile(data: any): Promise<void> {
const content = JSON.stringify(data);
const {writeFile} = await import("fs/promises");
await writeFile(this.filePath, content);
}
}

0 comments on commit af5eddd

Please sign in to comment.