@snevins/repo-mapper 1.4.4 → 1.5.0
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 +10 -2
- package/dist/cache.d.ts +21 -0
- package/dist/cache.js +50 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,9 +95,17 @@ src/pagerank.ts:
|
|
|
95
95
|
|
|
96
96
|
## Caching
|
|
97
97
|
|
|
98
|
-
Cache is stored in
|
|
98
|
+
Cache is stored in a global directory to avoid polluting your repository:
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
| Platform | Location |
|
|
101
|
+
|----------|----------|
|
|
102
|
+
| Linux | `~/.cache/repo-mapper/` (or `$XDG_CACHE_HOME/repo-mapper/`) |
|
|
103
|
+
| macOS | `~/Library/Caches/repo-mapper/` |
|
|
104
|
+
| Windows | `%LOCALAPPDATA%\repo-mapper\Cache\` |
|
|
105
|
+
|
|
106
|
+
Each project gets a unique subdirectory based on its path. Files are re-parsed only when modified (mtime-based invalidation).
|
|
107
|
+
|
|
108
|
+
Clear cache with: `rm -rf ~/.cache/repo-mapper` (Linux) or equivalent for your platform
|
|
101
109
|
|
|
102
110
|
## How It Works
|
|
103
111
|
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import type { Cache, Tag } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get the global cache directory following platform conventions.
|
|
4
|
+
* - Linux: $XDG_CACHE_HOME/repo-mapper or ~/.cache/repo-mapper
|
|
5
|
+
* - macOS: ~/Library/Caches/repo-mapper
|
|
6
|
+
* - Windows: %LOCALAPPDATA%/repo-mapper/Cache
|
|
7
|
+
*/
|
|
8
|
+
export declare function getGlobalCacheDir(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Get a unique project identifier from the root directory path.
|
|
11
|
+
* Uses first 16 chars of SHA-256 hash to create a unique but short identifier.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getProjectId(rootDir: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get the cache directory for a specific project.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getProjectCacheDir(rootDir: string): string;
|
|
2
18
|
/**
|
|
3
19
|
* Get the shard key (first 2 hex chars of SHA-256 hash).
|
|
4
20
|
*/
|
|
5
21
|
export declare function getShardKey(absPath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Use getProjectCacheDir() for new code.
|
|
24
|
+
* This is kept for migration purposes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getLegacyCacheDir(rootDir: string): string;
|
|
6
27
|
/**
|
|
7
28
|
* Load cache from disk. Returns empty cache if missing, invalid, or refresh=true.
|
|
8
29
|
*/
|
package/dist/cache.js
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
1
|
import { readFile, writeFile, mkdir, rename, readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { homedir, platform } from "node:os";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
5
|
const CACHE_VERSION = 2;
|
|
5
|
-
const CACHE_DIR_NAME = `.repomap.cache.v${String(CACHE_VERSION)}`;
|
|
6
6
|
const TAGS_DIR_NAME = "tags";
|
|
7
|
+
/**
|
|
8
|
+
* Get the global cache directory following platform conventions.
|
|
9
|
+
* - Linux: $XDG_CACHE_HOME/repo-mapper or ~/.cache/repo-mapper
|
|
10
|
+
* - macOS: ~/Library/Caches/repo-mapper
|
|
11
|
+
* - Windows: %LOCALAPPDATA%/repo-mapper/Cache
|
|
12
|
+
*/
|
|
13
|
+
export function getGlobalCacheDir() {
|
|
14
|
+
const plat = platform();
|
|
15
|
+
if (plat === "darwin") {
|
|
16
|
+
return join(homedir(), "Library", "Caches", "repo-mapper");
|
|
17
|
+
}
|
|
18
|
+
if (plat === "win32") {
|
|
19
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
20
|
+
if (localAppData) {
|
|
21
|
+
return join(localAppData, "repo-mapper", "Cache");
|
|
22
|
+
}
|
|
23
|
+
return join(homedir(), "AppData", "Local", "repo-mapper", "Cache");
|
|
24
|
+
}
|
|
25
|
+
// Linux and other Unix-like systems: follow XDG spec
|
|
26
|
+
const xdgCache = process.env.XDG_CACHE_HOME;
|
|
27
|
+
if (xdgCache) {
|
|
28
|
+
return join(xdgCache, "repo-mapper");
|
|
29
|
+
}
|
|
30
|
+
return join(homedir(), ".cache", "repo-mapper");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a unique project identifier from the root directory path.
|
|
34
|
+
* Uses first 16 chars of SHA-256 hash to create a unique but short identifier.
|
|
35
|
+
*/
|
|
36
|
+
export function getProjectId(rootDir) {
|
|
37
|
+
const hash = createHash("sha256").update(rootDir).digest("hex");
|
|
38
|
+
return hash.slice(0, 16);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the cache directory for a specific project.
|
|
42
|
+
*/
|
|
43
|
+
export function getProjectCacheDir(rootDir) {
|
|
44
|
+
const globalDir = getGlobalCacheDir();
|
|
45
|
+
const projectId = getProjectId(rootDir);
|
|
46
|
+
return join(globalDir, `v${String(CACHE_VERSION)}`, projectId);
|
|
47
|
+
}
|
|
7
48
|
/**
|
|
8
49
|
* Get the shard key (first 2 hex chars of SHA-256 hash).
|
|
9
50
|
*/
|
|
@@ -12,11 +53,18 @@ export function getShardKey(absPath) {
|
|
|
12
53
|
return hash.slice(0, 2);
|
|
13
54
|
}
|
|
14
55
|
function getTagsDir(rootDir) {
|
|
15
|
-
return join(rootDir,
|
|
56
|
+
return join(getProjectCacheDir(rootDir), TAGS_DIR_NAME);
|
|
16
57
|
}
|
|
17
58
|
function getShardPath(rootDir, shardKey) {
|
|
18
59
|
return join(getTagsDir(rootDir), `${shardKey}.json`);
|
|
19
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use getProjectCacheDir() for new code.
|
|
63
|
+
* This is kept for migration purposes.
|
|
64
|
+
*/
|
|
65
|
+
export function getLegacyCacheDir(rootDir) {
|
|
66
|
+
return join(rootDir, `.repomap.cache.v${String(CACHE_VERSION)}`);
|
|
67
|
+
}
|
|
20
68
|
/**
|
|
21
69
|
* Load a single shard file.
|
|
22
70
|
*/
|