@takazudo/zudo-doc-history-server 1.2.0 → 1.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-TP7M3HUM.js → chunk-ZVJVMECT.js} +33 -5
- package/dist/cli.js +1 -1
- package/dist/git-history.d.ts +9 -1
- package/dist/git-history.js +3 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -9,13 +9,34 @@ var QUIET = {
|
|
|
9
9
|
stdio: ["pipe", "pipe", "pipe"]
|
|
10
10
|
};
|
|
11
11
|
var repoRootCache = null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
var repoRootResolved = false;
|
|
13
|
+
function getRepoRootOrNull() {
|
|
14
|
+
if (repoRootResolved) return repoRootCache;
|
|
15
|
+
repoRootResolved = true;
|
|
16
|
+
try {
|
|
17
|
+
repoRootCache = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
18
|
+
encoding: "utf-8"
|
|
19
|
+
}).trim();
|
|
20
|
+
} catch {
|
|
21
|
+
repoRootCache = null;
|
|
22
|
+
console.warn(
|
|
23
|
+
"doc-history-server: not inside a git repository \u2014 doc history will be empty. Run `git init` and commit to enable Created/Updated/Author metadata."
|
|
24
|
+
);
|
|
25
|
+
}
|
|
17
26
|
return repoRootCache;
|
|
18
27
|
}
|
|
28
|
+
function isGitRepo() {
|
|
29
|
+
return getRepoRootOrNull() != null;
|
|
30
|
+
}
|
|
31
|
+
function getRepoRoot() {
|
|
32
|
+
const root = getRepoRootOrNull();
|
|
33
|
+
if (root == null) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"doc-history-server: getRepoRoot() called outside a git repository \u2014 guard with isGitRepo() first"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return root;
|
|
39
|
+
}
|
|
19
40
|
function gitOpts() {
|
|
20
41
|
return { ...QUIET, cwd: getRepoRoot() };
|
|
21
42
|
}
|
|
@@ -23,6 +44,7 @@ function toRepoRelative(absolutePath) {
|
|
|
23
44
|
return relative(getRepoRoot(), absolutePath);
|
|
24
45
|
}
|
|
25
46
|
function getFileCommits(filePath, maxEntries = 50) {
|
|
47
|
+
if (!isGitRepo()) return [];
|
|
26
48
|
try {
|
|
27
49
|
const output = execFileSync(
|
|
28
50
|
"git",
|
|
@@ -43,6 +65,7 @@ function getFileCommits(filePath, maxEntries = 50) {
|
|
|
43
65
|
}
|
|
44
66
|
}
|
|
45
67
|
function getFirstCommit(filePath) {
|
|
68
|
+
if (!isGitRepo()) return null;
|
|
46
69
|
try {
|
|
47
70
|
const output = execFileSync(
|
|
48
71
|
"git",
|
|
@@ -64,6 +87,7 @@ function getFirstCommit(filePath) {
|
|
|
64
87
|
}
|
|
65
88
|
}
|
|
66
89
|
function getCommitInfo(hash, filePath) {
|
|
90
|
+
if (!isGitRepo()) return { hash, date: "", author: "", message: "" };
|
|
67
91
|
try {
|
|
68
92
|
const output = execFileSync(
|
|
69
93
|
"git",
|
|
@@ -219,6 +243,7 @@ function commitMetaArgs(relPath, maxEntries) {
|
|
|
219
243
|
];
|
|
220
244
|
}
|
|
221
245
|
async function getDocHistoryAsync(filePath, slug, maxEntries = 50) {
|
|
246
|
+
if (!isGitRepo()) return { slug, filePath, entries: [] };
|
|
222
247
|
const relPath = filePath.startsWith("/") ? toRepoRelative(filePath) : filePath;
|
|
223
248
|
const [metaRecords, hashToPath] = await Promise.all([
|
|
224
249
|
execFileAsync("git", commitMetaArgs(relPath, maxEntries), { ...gitOpts() }).then(({ stdout }) => stdout.trim() ? parseCommitLog(stdout.trim()) : []).catch(() => []),
|
|
@@ -312,6 +337,7 @@ async function getFileAtCommitAsync(hash, filePath) {
|
|
|
312
337
|
}
|
|
313
338
|
}
|
|
314
339
|
function getFileCommitsMeta(filePath) {
|
|
340
|
+
if (!isGitRepo()) return [];
|
|
315
341
|
const relPath = filePath.startsWith("/") ? toRepoRelative(filePath) : filePath;
|
|
316
342
|
try {
|
|
317
343
|
const output = execFileSync(
|
|
@@ -333,6 +359,7 @@ function getFileCommitsMeta(filePath) {
|
|
|
333
359
|
}
|
|
334
360
|
var MAX_BUFFER_BYTES = 32 * 1024 * 1024;
|
|
335
361
|
async function getFileCommitsMetaAsync(filePath) {
|
|
362
|
+
if (!isGitRepo()) return [];
|
|
336
363
|
const relPath = filePath.startsWith("/") ? toRepoRelative(filePath) : filePath;
|
|
337
364
|
try {
|
|
338
365
|
const { stdout } = await execFileAsync(
|
|
@@ -381,6 +408,7 @@ function collectContentFiles(dir) {
|
|
|
381
408
|
var getDocHistory = getDocHistoryAsync;
|
|
382
409
|
|
|
383
410
|
export {
|
|
411
|
+
isGitRepo,
|
|
384
412
|
getFileCommits,
|
|
385
413
|
getFirstCommit,
|
|
386
414
|
getCommitInfo,
|
package/dist/cli.js
CHANGED
package/dist/git-history.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { DocHistoryEntry, DocHistoryData } from './types.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* True when the current working tree is inside a git repository. Public entry
|
|
5
|
+
* points call this first and return empty results when it is false, so no git
|
|
6
|
+
* command is spawned (and `getRepoRoot()` never throws) outside a repo. This is
|
|
7
|
+
* what lets `pnpm dev` / `pnpm build` succeed in a project that has not been
|
|
8
|
+
* `git init`-ed yet, instead of crashing the doc-history preBuild hook.
|
|
9
|
+
*/
|
|
10
|
+
declare function isGitRepo(): boolean;
|
|
3
11
|
/**
|
|
4
12
|
* Get the list of commit hashes that touched a file, newest first.
|
|
5
13
|
* Uses --follow to track renames.
|
|
@@ -105,4 +113,4 @@ declare function collectContentFiles(dir: string): Array<{
|
|
|
105
113
|
*/
|
|
106
114
|
declare const getDocHistory: typeof getDocHistoryAsync;
|
|
107
115
|
|
|
108
|
-
export { MAX_BUFFER_BYTES, collectContentFiles, getCommitInfo, getDocHistory, getDocHistoryAsync, getFileCommits, getFileCommitsMeta, getFileCommitsMetaAsync, getFirstCommit, parseHashToPathMap };
|
|
116
|
+
export { MAX_BUFFER_BYTES, collectContentFiles, getCommitInfo, getDocHistory, getDocHistoryAsync, getFileCommits, getFileCommitsMeta, getFileCommitsMetaAsync, getFirstCommit, isGitRepo, parseHashToPathMap };
|
package/dist/git-history.js
CHANGED
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
getFileCommitsMeta,
|
|
9
9
|
getFileCommitsMetaAsync,
|
|
10
10
|
getFirstCommit,
|
|
11
|
+
isGitRepo,
|
|
11
12
|
parseHashToPathMap
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ZVJVMECT.js";
|
|
13
14
|
export {
|
|
14
15
|
MAX_BUFFER_BYTES,
|
|
15
16
|
collectContentFiles,
|
|
@@ -20,5 +21,6 @@ export {
|
|
|
20
21
|
getFileCommitsMeta,
|
|
21
22
|
getFileCommitsMetaAsync,
|
|
22
23
|
getFirstCommit,
|
|
24
|
+
isGitRepo,
|
|
23
25
|
parseHashToPathMap
|
|
24
26
|
};
|
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": "1.
|
|
3
|
+
"version": "1.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",
|