@takazudo/zudo-doc-history-server 2.2.1 → 2.3.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/dist/{chunk-ZVJVMECT.js → chunk-VENEKCHH.js} +136 -0
- package/dist/cli.js +1 -1
- package/dist/concurrency.d.ts +4 -2
- package/dist/git-history.d.ts +56 -1
- package/dist/git-history.js +5 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { execFile, execFileSync, spawn } from "child_process";
|
|
|
3
3
|
import { promisify } from "util";
|
|
4
4
|
import { readdirSync } from "fs";
|
|
5
5
|
import { join, relative } from "path";
|
|
6
|
+
import { StringDecoder } from "string_decoder";
|
|
6
7
|
var execFileAsync = promisify(execFile);
|
|
7
8
|
var QUIET = {
|
|
8
9
|
encoding: "utf-8",
|
|
@@ -383,6 +384,139 @@ async function getFileCommitsMetaAsync(filePath) {
|
|
|
383
384
|
return [];
|
|
384
385
|
}
|
|
385
386
|
}
|
|
387
|
+
var WALK_COMMIT_SENTINEL = "\0";
|
|
388
|
+
var WALK_FORMAT = "%x00%H%n%aI%n%aN";
|
|
389
|
+
function createFirstLastMetaAccumulator() {
|
|
390
|
+
let state = "expect_hash";
|
|
391
|
+
let curDate = "";
|
|
392
|
+
let curAuthor = "";
|
|
393
|
+
const physicalToKey = /* @__PURE__ */ new Map();
|
|
394
|
+
const result = /* @__PURE__ */ new Map();
|
|
395
|
+
function attribute(key) {
|
|
396
|
+
const commit = { author: curAuthor, date: curDate };
|
|
397
|
+
const existing = result.get(key);
|
|
398
|
+
if (existing) {
|
|
399
|
+
existing.oldest = commit;
|
|
400
|
+
} else {
|
|
401
|
+
result.set(key, { oldest: commit, newest: commit });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function applyRecord(status, paths) {
|
|
405
|
+
const code = status[0];
|
|
406
|
+
if (code === "R" || code === "C") {
|
|
407
|
+
const oldPath = paths[0];
|
|
408
|
+
const newPath = paths[1];
|
|
409
|
+
if (!newPath) return;
|
|
410
|
+
let key2 = physicalToKey.get(newPath);
|
|
411
|
+
if (key2 === void 0) {
|
|
412
|
+
if (result.has(newPath)) return;
|
|
413
|
+
key2 = newPath;
|
|
414
|
+
}
|
|
415
|
+
attribute(key2);
|
|
416
|
+
if (code === "R" && oldPath) {
|
|
417
|
+
physicalToKey.delete(newPath);
|
|
418
|
+
physicalToKey.set(oldPath, key2);
|
|
419
|
+
} else {
|
|
420
|
+
physicalToKey.set(newPath, key2);
|
|
421
|
+
}
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const p = paths[0];
|
|
425
|
+
if (!p) return;
|
|
426
|
+
const key = physicalToKey.get(p);
|
|
427
|
+
if (key === void 0) {
|
|
428
|
+
if (code === "D" || result.has(p)) return;
|
|
429
|
+
physicalToKey.set(p, p);
|
|
430
|
+
attribute(p);
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
if (code === "D") {
|
|
434
|
+
physicalToKey.delete(p);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
attribute(key);
|
|
438
|
+
}
|
|
439
|
+
function pushLine(line) {
|
|
440
|
+
switch (state) {
|
|
441
|
+
case "expect_hash":
|
|
442
|
+
if (line.startsWith(WALK_COMMIT_SENTINEL)) state = "expect_date";
|
|
443
|
+
break;
|
|
444
|
+
case "expect_date":
|
|
445
|
+
curDate = line.trim();
|
|
446
|
+
state = "expect_author";
|
|
447
|
+
break;
|
|
448
|
+
case "expect_author":
|
|
449
|
+
curAuthor = line.trim();
|
|
450
|
+
state = "in_records";
|
|
451
|
+
break;
|
|
452
|
+
case "in_records":
|
|
453
|
+
if (line.startsWith(WALK_COMMIT_SENTINEL)) {
|
|
454
|
+
state = "expect_date";
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
if (line === "") break;
|
|
458
|
+
{
|
|
459
|
+
const fields = line.split(" ");
|
|
460
|
+
const status = fields[0];
|
|
461
|
+
if (status) applyRecord(status, fields.slice(1));
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return { pushLine, finish: () => result };
|
|
467
|
+
}
|
|
468
|
+
function parseFirstLastMeta(output) {
|
|
469
|
+
const acc = createFirstLastMetaAccumulator();
|
|
470
|
+
if (output.length > 0) {
|
|
471
|
+
for (const line of output.split("\n")) acc.pushLine(line);
|
|
472
|
+
}
|
|
473
|
+
return acc.finish();
|
|
474
|
+
}
|
|
475
|
+
function getAllFilesFirstLastMetaAsync(pathspecs = []) {
|
|
476
|
+
if (!isGitRepo()) return Promise.resolve(/* @__PURE__ */ new Map());
|
|
477
|
+
const repoRoot = getRepoRoot();
|
|
478
|
+
const relSpecs = pathspecs.map(
|
|
479
|
+
(p) => p.startsWith("/") ? toRepoRelative(p) : p
|
|
480
|
+
);
|
|
481
|
+
const args = [
|
|
482
|
+
"-c",
|
|
483
|
+
"core.quotePath=false",
|
|
484
|
+
// emit raw UTF-8 paths so keys match content-walker paths
|
|
485
|
+
"log",
|
|
486
|
+
"--full-history",
|
|
487
|
+
"--name-status",
|
|
488
|
+
"--find-renames",
|
|
489
|
+
"-l0",
|
|
490
|
+
`--format=${WALK_FORMAT}`
|
|
491
|
+
];
|
|
492
|
+
if (relSpecs.length > 0) args.push("--", ...relSpecs);
|
|
493
|
+
return new Promise((resolvePromise) => {
|
|
494
|
+
const child = spawn("git", args, {
|
|
495
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
496
|
+
cwd: repoRoot
|
|
497
|
+
});
|
|
498
|
+
const acc = createFirstLastMetaAccumulator();
|
|
499
|
+
const decoder = new StringDecoder("utf-8");
|
|
500
|
+
let buf = "";
|
|
501
|
+
child.stdout.on("data", (chunk) => {
|
|
502
|
+
buf += decoder.write(chunk);
|
|
503
|
+
let nl;
|
|
504
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
505
|
+
acc.pushLine(buf.slice(0, nl));
|
|
506
|
+
buf = buf.slice(nl + 1);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
child.on("error", () => resolvePromise(/* @__PURE__ */ new Map()));
|
|
510
|
+
child.on("close", () => {
|
|
511
|
+
buf += decoder.end();
|
|
512
|
+
if (buf.length > 0) acc.pushLine(buf);
|
|
513
|
+
const relMap = acc.finish();
|
|
514
|
+
const absMap = /* @__PURE__ */ new Map();
|
|
515
|
+
for (const [rel, meta] of relMap) absMap.set(join(repoRoot, rel), meta);
|
|
516
|
+
resolvePromise(absMap);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
}
|
|
386
520
|
function collectContentFiles(dir) {
|
|
387
521
|
const results = [];
|
|
388
522
|
function walk(currentDir, baseDir) {
|
|
@@ -417,6 +551,8 @@ export {
|
|
|
417
551
|
getFileCommitsMeta,
|
|
418
552
|
MAX_BUFFER_BYTES,
|
|
419
553
|
getFileCommitsMetaAsync,
|
|
554
|
+
parseFirstLastMeta,
|
|
555
|
+
getAllFilesFirstLastMetaAsync,
|
|
420
556
|
collectContentFiles,
|
|
421
557
|
getDocHistory
|
|
422
558
|
};
|
package/dist/cli.js
CHANGED
package/dist/concurrency.d.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
declare function makeSemaphore(concurrency: number): () => Promise<() => void>;
|
|
6
6
|
/**
|
|
7
7
|
* Default concurrency for git-history tasks: CPU count clamped to [2, 8].
|
|
8
|
-
* Each
|
|
9
|
-
*
|
|
8
|
+
* Each getDocHistoryAsync call issues one git process, so this saturates git
|
|
9
|
+
* without spawning excessively on many-core machines. Load-bearing for the CLI
|
|
10
|
+
* / postBuild per-file fan-out; the preBuild meta pass no longer uses it — it
|
|
11
|
+
* walks history once via getAllFilesFirstLastMetaAsync (#2517).
|
|
10
12
|
*/
|
|
11
13
|
declare function defaultGitConcurrency(): number;
|
|
12
14
|
|
package/dist/git-history.d.ts
CHANGED
|
@@ -95,8 +95,63 @@ declare const MAX_BUFFER_BYTES: number;
|
|
|
95
95
|
* caused the catch block to swallow the error and return [], dropping the
|
|
96
96
|
* file from the manifest. A warning is now logged on any catch so the
|
|
97
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.
|
|
98
103
|
*/
|
|
99
104
|
declare function getFileCommitsMetaAsync(filePath: string): Promise<Array<Omit<DocHistoryEntry, "content">>>;
|
|
105
|
+
/** Oldest + newest author/date for a single current-path key. */
|
|
106
|
+
interface FirstLastMeta {
|
|
107
|
+
/** The file's creation-side commit (author = page author, date = createdDate). */
|
|
108
|
+
oldest: {
|
|
109
|
+
author: string;
|
|
110
|
+
date: string;
|
|
111
|
+
};
|
|
112
|
+
/** The file's most recent commit (date = updatedDate). */
|
|
113
|
+
newest: {
|
|
114
|
+
author: string;
|
|
115
|
+
date: string;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Pure parser + rename reconstruction for the single-pass walk's stdout.
|
|
120
|
+
* Keyed by CURRENT repo-relative path (exactly what git emits). Exported for
|
|
121
|
+
* unit tests; the streaming walk uses the same accumulator incrementally.
|
|
122
|
+
*/
|
|
123
|
+
declare function parseFirstLastMeta(output: string): Map<string, FirstLastMeta>;
|
|
124
|
+
/**
|
|
125
|
+
* Walk the WHOLE git history ONCE and return `{oldest, newest}` author/date for
|
|
126
|
+
* every current file, keyed by ABSOLUTE path (`<repoRoot>/<relPath>`) so a
|
|
127
|
+
* consumer whose project root differs from the repo root still matches by the
|
|
128
|
+
* absolute paths its content walker produced.
|
|
129
|
+
*
|
|
130
|
+
* ONE streaming `git log --full-history --name-status --find-renames -l0`
|
|
131
|
+
* spawn, parsed incrementally (never execFile+maxBuffer — that reintroduced the
|
|
132
|
+
* #2293 silent-truncation class — and never concat-all-then-parse, since a
|
|
133
|
+
* full-history buffer can be large in arbitrary consumer repos).
|
|
134
|
+
*
|
|
135
|
+
* `-l0` is mandatory: a bulk `--name-status --find-renames` walk runs rename
|
|
136
|
+
* detection per-commit under the global `diff.renameLimit`; a mass-rename commit
|
|
137
|
+
* that hits the limit emits `D`+`A` instead of `R`, silently dropping pre-rename
|
|
138
|
+
* history (wrong createdDate/author) where per-path `--follow` would find it.
|
|
139
|
+
*
|
|
140
|
+
* `--full-history` is required to MATCH per-file `--follow`: default history
|
|
141
|
+
* simplification prunes commits on merged side-branches that are TREESAME to the
|
|
142
|
+
* first parent, so a bounded directory walk would miss updates that `--follow`
|
|
143
|
+
* (which effectively sees the full per-file history) reports. Without it, most
|
|
144
|
+
* pages collapsed updatedDate onto createdDate. Merges still emit header-only
|
|
145
|
+
* name-status under the default `--diff-merges`, so this does not double-count.
|
|
146
|
+
*
|
|
147
|
+
* `pathspecs` bound the walk to the content dirs (absolute or repo-relative;
|
|
148
|
+
* absolute entries are converted to repo-relative like the other helpers). Pass
|
|
149
|
+
* `[]` to walk full history.
|
|
150
|
+
*
|
|
151
|
+
* cwd = repo root (#1907). Returns an empty Map outside a git repo so callers
|
|
152
|
+
* degrade to an empty manifest instead of crashing.
|
|
153
|
+
*/
|
|
154
|
+
declare function getAllFilesFirstLastMetaAsync(pathspecs?: string[]): Promise<Map<string, FirstLastMeta>>;
|
|
100
155
|
/**
|
|
101
156
|
* Collect all MDX/md files in a content directory.
|
|
102
157
|
* Returns array of { filePath, slug } pairs.
|
|
@@ -113,4 +168,4 @@ declare function collectContentFiles(dir: string): Array<{
|
|
|
113
168
|
*/
|
|
114
169
|
declare const getDocHistory: typeof getDocHistoryAsync;
|
|
115
170
|
|
|
116
|
-
export { MAX_BUFFER_BYTES, collectContentFiles, getCommitInfo, getDocHistory, getDocHistoryAsync, getFileCommits, getFileCommitsMeta, getFileCommitsMetaAsync, getFirstCommit, isGitRepo, parseHashToPathMap };
|
|
171
|
+
export { type FirstLastMeta, MAX_BUFFER_BYTES, collectContentFiles, getAllFilesFirstLastMetaAsync, getCommitInfo, getDocHistory, getDocHistoryAsync, getFileCommits, getFileCommitsMeta, getFileCommitsMetaAsync, getFirstCommit, isGitRepo, parseFirstLastMeta, parseHashToPathMap };
|
package/dist/git-history.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MAX_BUFFER_BYTES,
|
|
3
3
|
collectContentFiles,
|
|
4
|
+
getAllFilesFirstLastMetaAsync,
|
|
4
5
|
getCommitInfo,
|
|
5
6
|
getDocHistory,
|
|
6
7
|
getDocHistoryAsync,
|
|
@@ -9,11 +10,13 @@ import {
|
|
|
9
10
|
getFileCommitsMetaAsync,
|
|
10
11
|
getFirstCommit,
|
|
11
12
|
isGitRepo,
|
|
13
|
+
parseFirstLastMeta,
|
|
12
14
|
parseHashToPathMap
|
|
13
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-VENEKCHH.js";
|
|
14
16
|
export {
|
|
15
17
|
MAX_BUFFER_BYTES,
|
|
16
18
|
collectContentFiles,
|
|
19
|
+
getAllFilesFirstLastMetaAsync,
|
|
17
20
|
getCommitInfo,
|
|
18
21
|
getDocHistory,
|
|
19
22
|
getDocHistoryAsync,
|
|
@@ -22,5 +25,6 @@ export {
|
|
|
22
25
|
getFileCommitsMetaAsync,
|
|
23
26
|
getFirstCommit,
|
|
24
27
|
isGitRepo,
|
|
28
|
+
parseFirstLastMeta,
|
|
25
29
|
parseHashToPathMap
|
|
26
30
|
};
|
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": "2.
|
|
3
|
+
"version": "2.3.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",
|