Skip to content

Commit

Permalink
fix: ensure storage dispose close with grace
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Oct 12, 2023
1 parent b735465 commit 2001928
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"vitest": "^0.34.6"
},
"dependencies": {
"close-with-grace": "^1.2.0",
"consola": "^3.2.3",
"destr": "^2.0.1",
"fast-json-stringify": "^5.8.0",
Expand Down
28 changes: 16 additions & 12 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import destr from "destr";
import { ensureDirSync } from "./fs";
import { createStorage } from "unstorage";
import fsDriver from "unstorage/drivers/fs";
import closeWithGrace from "close-with-grace";
import { normalizeCachePath, normalizePath } from "./path";
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";

Expand All @@ -12,7 +13,7 @@ export function createFsStorage(cachePath?: string) {
}),
});

process.once("beforeExit", async function () {
closeWithGrace({ delay: 500 }, async function () {
await storage.dispose();
});

Expand Down
23 changes: 12 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"compilerOptions": {
"module": "ESNext",
"target": "ES2015",
"incremental": true,
"types": ["vitest"],
"skipLibCheck": true,
"moduleResolution": "node",
"tsBuildInfoFile": ".tsbuildinfo"
},
"include": ["src"],
"exclude": ["dist", "node_modules"]
"compilerOptions": {
"module": "ESNext",
"target": "ES2015",
"incremental": true,
"types": ["vitest"],
"skipLibCheck": true,
"moduleResolution": "node",
"tsBuildInfoFile": ".tsbuildinfo",
"allowSyntheticDefaultImports": true
},
"include": ["src"],
"exclude": ["dist", "node_modules"]
}

0 comments on commit 2001928

Please sign in to comment.