@kisaragi-hiu/cached-fetch 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.ts +2 -2
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @kisaragi-hiu/cached-fetch
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A caching function designed for caching fetch GET responses on disk in a command line program.
|
|
4
4
|
|
|
5
5
|
I keep rewriting this logic in multiple projects, so I'm making it a package.
|
|
6
6
|
|
package/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// -*- lsp-disabled-clients: (ts-ls); -*-
|
|
2
1
|
import { mkdirSync, writeFileSync, readFileSync, existsSync } from "node:fs";
|
|
3
2
|
import { dirname, join } from "node:path";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
@@ -19,7 +18,7 @@ export async function cached(
|
|
|
19
18
|
* Response, but the ProcessPromise from the zx library also fits this signature.
|
|
20
19
|
*/
|
|
21
20
|
fetcher: () => Promise<{ text: () => Promise<string> }>
|
|
22
|
-
) {
|
|
21
|
+
): Promise<string> {
|
|
23
22
|
const cacheFile = join(tmpdir(), key);
|
|
24
23
|
const cacheHit = existsSync(cacheFile);
|
|
25
24
|
const text = cacheHit
|
|
@@ -29,4 +28,5 @@ export async function cached(
|
|
|
29
28
|
mkdirSync(dirname(cacheFile), { recursive: true });
|
|
30
29
|
writeFileSync(cacheFile, text, { encoding: "utf-8" });
|
|
31
30
|
}
|
|
31
|
+
return text;
|
|
32
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kisaragi-hiu/cached-fetch",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A cache in OS tmpdir useful for fetch()",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -14,5 +14,9 @@
|
|
|
14
14
|
"homepage": "https://github.com/kisaragi-hiu/cached-fetch",
|
|
15
15
|
"author": "Kisaragi Hiu <mail@kisaragi-hiu.com>",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"files": ["index.ts"]
|
|
17
|
+
"files": ["index.ts"],
|
|
18
|
+
"exports": "index.ts",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^24.3.0"
|
|
21
|
+
}
|
|
18
22
|
}
|