@takazudo/zudo-doc-history-server 3.3.0 → 4.0.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 +9 -5
- package/dist/{chunk-VENEKCHH.js → chunk-U4PA3LGK.js} +1 -118
- package/dist/cli.js +1 -1
- package/dist/git-history.d.ts +2 -70
- package/dist/git-history.js +1 -15
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Standalone package for extracting and serving git history of documentation files. Has two modes: an HTTP server for local development and a CLI generator for CI builds.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
History extraction runs independently from the zfb site build so expensive `git log --follow` calls can be generated in a dedicated CI job.
|
|
6
6
|
|
|
7
7
|
## Modes
|
|
8
8
|
|
|
9
9
|
### Server mode (local development)
|
|
10
10
|
|
|
11
|
-
Runs an HTTP server that serves history on demand. Used by `pnpm dev` at the repository root, which starts
|
|
11
|
+
Runs an HTTP server that serves history on demand. Used by `pnpm dev` at the repository root, which starts zfb, this server, and the package dev processes concurrently via `run-p`.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
pnpm dev -- \
|
|
@@ -37,7 +37,7 @@ The file index is refreshed every 10 seconds so newly added or renamed files are
|
|
|
37
37
|
|
|
38
38
|
### CLI mode (CI builds)
|
|
39
39
|
|
|
40
|
-
Generates static `{slug}.json` files into an output directory. Used by the `build-history` CI job, which runs in parallel with the `build-site`
|
|
40
|
+
Generates static `{slug}.json` files into an output directory. Used by the `build-history` CI job, which runs in parallel with the zfb `build-site` job.
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
43
|
pnpm generate -- \
|
|
@@ -55,7 +55,11 @@ pnpm generate -- \
|
|
|
55
55
|
|
|
56
56
|
## zfb integration
|
|
57
57
|
|
|
58
|
-
In dev mode, the zfb
|
|
58
|
+
In dev mode, the zfb plugin implemented at `packages/zudo-doc/src/plugins/internal/doc-history/index.ts` proxies `/doc-history/*` requests to this server. In build mode, preBuild produces the current metadata manifest; standard CI deliberately keeps `SKIP_DOC_HISTORY` unset so that metadata comes from the full clone. The separate `build-history` job generates per-page revision JSON in parallel. `SKIP_DOC_HISTORY=1` remains an explicit escape hatch for shallow/custom builds that cannot read Git history.
|
|
59
|
+
|
|
60
|
+
## Programmatic API
|
|
61
|
+
|
|
62
|
+
The `@takazudo/zudo-doc-history-server/git-history` subpath exposes the current async history path (`getDocHistoryAsync`), the single-pass manifest walk (`getAllFilesFirstLastMetaAsync`), content-file collection, repository detection, and the pure rename parsers. Server and CLI callers both await `getDocHistoryAsync`.
|
|
59
63
|
|
|
60
64
|
## Build
|
|
61
65
|
|
|
@@ -67,7 +71,7 @@ Uses `tsup` to emit ESM output + DTS into `dist/`.
|
|
|
67
71
|
|
|
68
72
|
## Design notes
|
|
69
73
|
|
|
70
|
-
- **Async
|
|
74
|
+
- **Async history extraction** — history walks and content reads use `execFile` / `spawn` (non-blocking). The only synchronous git call is the cached one-time repository-root probe. The CLI batch generator wraps each file in a semaphore-bounded Promise, and the server uses the same async extraction path.
|
|
71
75
|
- **Repo-relative paths** — responses use relative file paths to avoid leaking absolute server paths.
|
|
72
76
|
- **`--follow` for renames** — file history is tracked across renames with multiple fallback strategies.
|
|
73
77
|
- **pnpm --filter CWD** — when run via `pnpm --filter`, the CWD is this package dir. pnpm sets `INIT_CWD` to the repo root, so pass repo-root-relative content paths (e.g. `src/content/docs`) without any `../../` prefix.
|
|
@@ -44,68 +44,6 @@ function gitOpts() {
|
|
|
44
44
|
function toRepoRelative(absolutePath) {
|
|
45
45
|
return relative(getRepoRoot(), absolutePath);
|
|
46
46
|
}
|
|
47
|
-
function getFileCommits(filePath, maxEntries = 50) {
|
|
48
|
-
if (!isGitRepo()) return [];
|
|
49
|
-
try {
|
|
50
|
-
const output = execFileSync(
|
|
51
|
-
"git",
|
|
52
|
-
[
|
|
53
|
-
"log",
|
|
54
|
-
"--follow",
|
|
55
|
-
"--format=%H",
|
|
56
|
-
"-n",
|
|
57
|
-
String(maxEntries),
|
|
58
|
-
"--",
|
|
59
|
-
filePath
|
|
60
|
-
],
|
|
61
|
-
gitOpts()
|
|
62
|
-
).trim();
|
|
63
|
-
return output ? [...new Set(output.split("\n"))] : [];
|
|
64
|
-
} catch {
|
|
65
|
-
return [];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function getFirstCommit(filePath) {
|
|
69
|
-
if (!isGitRepo()) return null;
|
|
70
|
-
try {
|
|
71
|
-
const output = execFileSync(
|
|
72
|
-
"git",
|
|
73
|
-
[
|
|
74
|
-
"log",
|
|
75
|
-
"--follow",
|
|
76
|
-
"--reverse",
|
|
77
|
-
"--format=%H",
|
|
78
|
-
"--",
|
|
79
|
-
filePath
|
|
80
|
-
],
|
|
81
|
-
gitOpts()
|
|
82
|
-
).trim();
|
|
83
|
-
if (!output) return null;
|
|
84
|
-
const first = output.split("\n")[0]?.trim();
|
|
85
|
-
return first ? first : null;
|
|
86
|
-
} catch {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function getCommitInfo(hash, filePath) {
|
|
91
|
-
if (!isGitRepo()) return { hash, date: "", author: "", message: "" };
|
|
92
|
-
try {
|
|
93
|
-
const output = execFileSync(
|
|
94
|
-
"git",
|
|
95
|
-
["log", "-1", "--format=%H%n%aI%n%aN%n%s", hash, "--", filePath],
|
|
96
|
-
gitOpts()
|
|
97
|
-
).trim();
|
|
98
|
-
const lines = output.split("\n");
|
|
99
|
-
return {
|
|
100
|
-
hash: lines[0] ?? hash,
|
|
101
|
-
date: lines[1] ?? "",
|
|
102
|
-
author: lines[2] ?? "",
|
|
103
|
-
message: lines[3] ?? ""
|
|
104
|
-
};
|
|
105
|
-
} catch {
|
|
106
|
-
return { hash, date: "", author: "", message: "" };
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
47
|
function parseCommitLog(output) {
|
|
110
48
|
const records = [];
|
|
111
49
|
const blocks = output.split(/\n\n+/).filter(Boolean);
|
|
@@ -337,53 +275,6 @@ async function getFileAtCommitAsync(hash, filePath) {
|
|
|
337
275
|
return "";
|
|
338
276
|
}
|
|
339
277
|
}
|
|
340
|
-
function getFileCommitsMeta(filePath) {
|
|
341
|
-
if (!isGitRepo()) return [];
|
|
342
|
-
const relPath = filePath.startsWith("/") ? toRepoRelative(filePath) : filePath;
|
|
343
|
-
try {
|
|
344
|
-
const output = execFileSync(
|
|
345
|
-
"git",
|
|
346
|
-
[
|
|
347
|
-
"log",
|
|
348
|
-
"--follow",
|
|
349
|
-
"--format=%H%n%aI%n%aN%n%s%n",
|
|
350
|
-
"--",
|
|
351
|
-
relPath
|
|
352
|
-
],
|
|
353
|
-
gitOpts()
|
|
354
|
-
).trim();
|
|
355
|
-
if (!output) return [];
|
|
356
|
-
return parseCommitLog(output);
|
|
357
|
-
} catch {
|
|
358
|
-
return [];
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
var MAX_BUFFER_BYTES = 32 * 1024 * 1024;
|
|
362
|
-
async function getFileCommitsMetaAsync(filePath) {
|
|
363
|
-
if (!isGitRepo()) return [];
|
|
364
|
-
const relPath = filePath.startsWith("/") ? toRepoRelative(filePath) : filePath;
|
|
365
|
-
try {
|
|
366
|
-
const { stdout } = await execFileAsync(
|
|
367
|
-
"git",
|
|
368
|
-
[
|
|
369
|
-
"log",
|
|
370
|
-
"--follow",
|
|
371
|
-
"--format=%H%n%aI%n%aN%n%s%n",
|
|
372
|
-
"--",
|
|
373
|
-
relPath
|
|
374
|
-
],
|
|
375
|
-
{ ...gitOpts(), maxBuffer: MAX_BUFFER_BYTES }
|
|
376
|
-
);
|
|
377
|
-
if (!stdout.trim()) return [];
|
|
378
|
-
return parseCommitLog(stdout.trim());
|
|
379
|
-
} catch (err) {
|
|
380
|
-
console.warn(
|
|
381
|
-
`doc-history-server: getFileCommitsMetaAsync failed for "${relPath}" \u2014 file will be absent from the manifest.`,
|
|
382
|
-
err instanceof Error ? err.message : String(err)
|
|
383
|
-
);
|
|
384
|
-
return [];
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
278
|
var WALK_COMMIT_SENTINEL = "\0";
|
|
388
279
|
var WALK_FORMAT = "%x00%H%n%aI%n%aN";
|
|
389
280
|
function createFirstLastMetaAccumulator() {
|
|
@@ -539,20 +430,12 @@ function collectContentFiles(dir) {
|
|
|
539
430
|
walk(dir, dir);
|
|
540
431
|
return results;
|
|
541
432
|
}
|
|
542
|
-
var getDocHistory = getDocHistoryAsync;
|
|
543
433
|
|
|
544
434
|
export {
|
|
545
435
|
isGitRepo,
|
|
546
|
-
getFileCommits,
|
|
547
|
-
getFirstCommit,
|
|
548
|
-
getCommitInfo,
|
|
549
436
|
parseHashToPathMap,
|
|
550
437
|
getDocHistoryAsync,
|
|
551
|
-
getFileCommitsMeta,
|
|
552
|
-
MAX_BUFFER_BYTES,
|
|
553
|
-
getFileCommitsMetaAsync,
|
|
554
438
|
parseFirstLastMeta,
|
|
555
439
|
getAllFilesFirstLastMetaAsync,
|
|
556
|
-
collectContentFiles
|
|
557
|
-
getDocHistory
|
|
440
|
+
collectContentFiles
|
|
558
441
|
};
|
package/dist/cli.js
CHANGED
package/dist/git-history.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocHistoryData } from './types.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* True when the current working tree is inside a git repository. Public entry
|
|
@@ -8,33 +8,6 @@ import { DocHistoryEntry, DocHistoryData } from './types.js';
|
|
|
8
8
|
* `git init`-ed yet, instead of crashing the doc-history preBuild hook.
|
|
9
9
|
*/
|
|
10
10
|
declare function isGitRepo(): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Get the list of commit hashes that touched a file, newest first.
|
|
13
|
-
* Uses --follow to track renames.
|
|
14
|
-
* Limits to maxEntries commits (default 50).
|
|
15
|
-
*/
|
|
16
|
-
declare function getFileCommits(filePath: string, maxEntries?: number): string[];
|
|
17
|
-
/**
|
|
18
|
-
* Get the oldest commit hash that touched a file (the file's "first" commit).
|
|
19
|
-
*
|
|
20
|
-
* Uses --follow + --reverse and takes the first emitted line (the oldest
|
|
21
|
-
* commit). We must NOT pass --max-count=1: git applies the count limit during
|
|
22
|
-
* its newest-first traversal *before* --reverse is applied, so the combination
|
|
23
|
-
* emits nothing (verified empirically on git 2.43.0) — which previously made
|
|
24
|
-
* this function return null for every file, collapsing created==updated dates
|
|
25
|
-
* and attributing every page to its latest committer. git still walks the
|
|
26
|
-
* file's full history once, so this is O(history) for that path, not O(1).
|
|
27
|
-
* Acceptable because the caller is a build-time helper run once per content
|
|
28
|
-
* file, not a hot path.
|
|
29
|
-
*
|
|
30
|
-
* Returns null when the file has no git history (untracked / not yet committed).
|
|
31
|
-
*/
|
|
32
|
-
declare function getFirstCommit(filePath: string): string | null;
|
|
33
|
-
/**
|
|
34
|
-
* Get metadata for a specific commit on a file.
|
|
35
|
-
* Returns { hash, date, author, message } with full hash for unique identification.
|
|
36
|
-
*/
|
|
37
|
-
declare function getCommitInfo(hash: string, filePath: string): Omit<DocHistoryEntry, "content">;
|
|
38
11
|
/**
|
|
39
12
|
* Pure parser for `git log --follow --format=%H --name-only` output.
|
|
40
13
|
*
|
|
@@ -68,40 +41,6 @@ declare function parseHashToPathMap(output: string): Map<string, string>;
|
|
|
68
41
|
* semaphore-bounded concurrency actually parallelizes across files (#1986).
|
|
69
42
|
*/
|
|
70
43
|
declare function getDocHistoryAsync(filePath: string, slug: string, maxEntries?: number): Promise<DocHistoryData>;
|
|
71
|
-
/**
|
|
72
|
-
* Get commit metadata for a file using a single `git log --follow` walk.
|
|
73
|
-
* Returns an array of records newest-first (no -n limit = full history).
|
|
74
|
-
* Used by pre-build meta to get both newest and oldest in one spawn.
|
|
75
|
-
*/
|
|
76
|
-
declare function getFileCommitsMeta(filePath: string): Array<Omit<DocHistoryEntry, "content">>;
|
|
77
|
-
/**
|
|
78
|
-
* 32 MB maxBuffer for `getFileCommitsMetaAsync`. The Node default (1 MB) is
|
|
79
|
-
* too small for a doc corpus with long histories: an RangeError / ERR_CHILD_PROCESS_STDIO_MAXBUFFER
|
|
80
|
-
* from execFile's promisified form was previously silently caught and returned
|
|
81
|
-
* [], causing the file to disappear from the manifest without any trace (#2293).
|
|
82
|
-
* 32 MB covers a corpus of ~16 000 commits × 2 KB average format output before
|
|
83
|
-
* the guard kicks in; adjust via the exported MAX_BUFFER_BYTES constant if your
|
|
84
|
-
* project needs a different bound.
|
|
85
|
-
*/
|
|
86
|
-
declare const MAX_BUFFER_BYTES: number;
|
|
87
|
-
/**
|
|
88
|
-
* Get commit metadata for a file using a single `git log --follow` walk
|
|
89
|
-
* (async variant). Runs via execFile (non-blocking) so callers can issue
|
|
90
|
-
* multiple git spawns concurrently. Returns an array of records newest-first
|
|
91
|
-
* (no -n limit). Used by the pre-build parallelization path.
|
|
92
|
-
*
|
|
93
|
-
* maxBuffer is raised to MAX_BUFFER_BYTES (32 MB) to avoid silent data loss
|
|
94
|
-
* for files with very long histories — previously the default 1 MB limit
|
|
95
|
-
* caused the catch block to swallow the error and return [], dropping the
|
|
96
|
-
* file from the manifest. A warning is now logged on any catch so the
|
|
97
|
-
* failure is visible (#2293).
|
|
98
|
-
*
|
|
99
|
-
* Retained as public API for downstream consumers of
|
|
100
|
-
* `@takazudo/zudo-doc-history-server` — the preBuild meta pass no longer calls
|
|
101
|
-
* this in-repo (superseded by `getAllFilesFirstLastMetaAsync`, #2517), but it
|
|
102
|
-
* stays exported for back-compat.
|
|
103
|
-
*/
|
|
104
|
-
declare function getFileCommitsMetaAsync(filePath: string): Promise<Array<Omit<DocHistoryEntry, "content">>>;
|
|
105
44
|
/** Oldest + newest author/date for a single current-path key. */
|
|
106
45
|
interface FirstLastMeta {
|
|
107
46
|
/** The file's creation-side commit (author = page author, date = createdDate). */
|
|
@@ -160,12 +99,5 @@ declare function collectContentFiles(dir: string): Array<{
|
|
|
160
99
|
filePath: string;
|
|
161
100
|
slug: string;
|
|
162
101
|
}>;
|
|
163
|
-
/**
|
|
164
|
-
* Back-compat alias for the public `./git-history` subpath: the sync
|
|
165
|
-
* `getDocHistory` was removed when the duplicated sync orchestration
|
|
166
|
-
* family was deleted (#2011). The alias keeps the exported name resolving
|
|
167
|
-
* for existing consumers — note it is now async (returns a Promise).
|
|
168
|
-
*/
|
|
169
|
-
declare const getDocHistory: typeof getDocHistoryAsync;
|
|
170
102
|
|
|
171
|
-
export { type FirstLastMeta,
|
|
103
|
+
export { type FirstLastMeta, collectContentFiles, getAllFilesFirstLastMetaAsync, getDocHistoryAsync, isGitRepo, parseFirstLastMeta, parseHashToPathMap };
|
package/dist/git-history.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
MAX_BUFFER_BYTES,
|
|
3
2
|
collectContentFiles,
|
|
4
3
|
getAllFilesFirstLastMetaAsync,
|
|
5
|
-
getCommitInfo,
|
|
6
|
-
getDocHistory,
|
|
7
4
|
getDocHistoryAsync,
|
|
8
|
-
getFileCommits,
|
|
9
|
-
getFileCommitsMeta,
|
|
10
|
-
getFileCommitsMetaAsync,
|
|
11
|
-
getFirstCommit,
|
|
12
5
|
isGitRepo,
|
|
13
6
|
parseFirstLastMeta,
|
|
14
7
|
parseHashToPathMap
|
|
15
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-U4PA3LGK.js";
|
|
16
9
|
export {
|
|
17
|
-
MAX_BUFFER_BYTES,
|
|
18
10
|
collectContentFiles,
|
|
19
11
|
getAllFilesFirstLastMetaAsync,
|
|
20
|
-
getCommitInfo,
|
|
21
|
-
getDocHistory,
|
|
22
12
|
getDocHistoryAsync,
|
|
23
|
-
getFileCommits,
|
|
24
|
-
getFileCommitsMeta,
|
|
25
|
-
getFileCommitsMetaAsync,
|
|
26
|
-
getFirstCommit,
|
|
27
13
|
isGitRepo,
|
|
28
14
|
parseFirstLastMeta,
|
|
29
15
|
parseHashToPathMap
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takazudo/zudo-doc-history-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Standalone doc git-history service for zudo-doc — HTTP server + CLI batch generator. Decouples expensive `git log --follow` calls from the main build pipeline.",
|
|
6
6
|
"license": "MIT",
|