@riebeckite/plugin-diff 0.0.22 → 0.0.24

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.
@@ -0,0 +1,7 @@
1
+ import type { PostDiff as PostDiffData } from "../src/types.js";
2
+ export type PostDiffProps = {
3
+ readonly diff: PostDiffData | null;
4
+ readonly title?: string;
5
+ };
6
+ declare const PostDiff: ({ diff, title }: Readonly<PostDiffProps>) => import("hono/jsx/jsx-dev-runtime").JSX.Element;
7
+ export default PostDiff;
@@ -0,0 +1,28 @@
1
+ // components/post-diff.tsx
2
+ import { jsx, jsxs } from "hono/jsx/jsx-runtime";
3
+ var PostDiff = (({ diff, title = "History" }) => {
4
+ if (!diff) return null;
5
+ return /* @__PURE__ */ jsxs("section", { class: "rr-diff-history", "data-rr-diff-history": true, children: [
6
+ /* @__PURE__ */ jsx("h2", { class: "rr-diff-history__title", children: title }),
7
+ /* @__PURE__ */ jsxs("p", { class: "rr-diff-history__meta", children: [
8
+ diff.from ? `${diff.from.shortHash} → ` : "",
9
+ diff.to.shortHash
10
+ ] }),
11
+ /* @__PURE__ */ jsx("pre", { class: "rr-diff-history__diff", children: /* @__PURE__ */ jsx("code", { children: diff.lines.map((line, index) => /* @__PURE__ */ jsxs(
12
+ "span",
13
+ {
14
+ class: `rr-diff-line rr-diff-line--${line.type}`,
15
+ children: [
16
+ line.type === "added" ? "+" : line.type === "removed" ? "-" : " ",
17
+ line.content,
18
+ "\n"
19
+ ]
20
+ },
21
+ `${line.oldLineNumber}-${line.newLineNumber}-${index}`
22
+ )) }) })
23
+ ] });
24
+ });
25
+ var post_diff_default = PostDiff;
26
+ export {
27
+ post_diff_default as default
28
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { type PluginDataHelper } from "@riebeckite/core";
2
+ export type { PostDiffProps } from "./components/post-diff.js";
3
+ export { default as PostDiffView } from "./components/post-diff.js";
1
4
  export { renderDiffHistory } from "./src/components/diff-history.js";
2
5
  export { renderDiffLine } from "./src/components/diff-line.js";
3
6
  export { renderDiffPanel, renderDiffViewer, } from "./src/components/diff-viewer.js";
@@ -14,5 +17,9 @@ export type PostDiffApi = {
14
17
  getCurrentDiff(filePath: string): Promise<PostDiff | null>;
15
18
  compareRevisions(input: RevisionComparisonInput): Promise<PostDiff | null>;
16
19
  };
20
+ export declare const getPostDiff: PluginDataHelper<{
21
+ api: PostDiffApi;
22
+ filePath: string;
23
+ }, Promise<PostDiff | null>>;
17
24
  export declare function diff(options?: DiffPluginOptions): import("@riebeckite/core").RiebeckitePlugin<DiffPluginOptions>;
18
25
  export declare function createPostDiffApi(options?: GitHistoryReaderOptions): PostDiffApi;
package/dist/index.js CHANGED
@@ -1,11 +1,37 @@
1
1
  // index.ts
2
2
  import {
3
- appendContentBodySlot,
4
3
  createClientEntry,
5
4
  createStyleAsset,
6
- definePlugin
5
+ definePlugin,
6
+ fingerprintExternalValue
7
7
  } from "@riebeckite/core";
8
8
 
9
+ // components/post-diff.tsx
10
+ import { jsx, jsxs } from "hono/jsx/jsx-runtime";
11
+ var PostDiff = (({ diff: diff2, title = "History" }) => {
12
+ if (!diff2) return null;
13
+ return /* @__PURE__ */ jsxs("section", { class: "rr-diff-history", "data-rr-diff-history": true, children: [
14
+ /* @__PURE__ */ jsx("h2", { class: "rr-diff-history__title", children: title }),
15
+ /* @__PURE__ */ jsxs("p", { class: "rr-diff-history__meta", children: [
16
+ diff2.from ? `${diff2.from.shortHash} → ` : "",
17
+ diff2.to.shortHash
18
+ ] }),
19
+ /* @__PURE__ */ jsx("pre", { class: "rr-diff-history__diff", children: /* @__PURE__ */ jsx("code", { children: diff2.lines.map((line, index) => /* @__PURE__ */ jsxs(
20
+ "span",
21
+ {
22
+ class: `rr-diff-line rr-diff-line--${line.type}`,
23
+ children: [
24
+ line.type === "added" ? "+" : line.type === "removed" ? "-" : " ",
25
+ line.content,
26
+ "\n"
27
+ ]
28
+ },
29
+ `${line.oldLineNumber}-${line.newLineNumber}-${index}`
30
+ )) }) })
31
+ ] });
32
+ });
33
+ var post_diff_default = PostDiff;
34
+
9
35
  // src/components/diff-line.tsx
10
36
  function renderDiffLine({ line }) {
11
37
  const prefix = line.type === "added" ? "+" : line.type === "removed" ? "-" : " ";
@@ -356,6 +382,23 @@ var GitMarkdownHistoryReader = class {
356
382
  );
357
383
  return result.ok ? result.stdout : null;
358
384
  }
385
+ async getStateFingerprint() {
386
+ const repository = await this.#resolvePaths();
387
+ if (!repository) return null;
388
+ const results = await Promise.all([
389
+ runGit(["rev-parse", "HEAD"], repository.repositoryRoot),
390
+ runGit(
391
+ ["status", "--porcelain=v1", "--untracked-files=all"],
392
+ repository.repositoryRoot
393
+ ),
394
+ runGit(
395
+ ["for-each-ref", "--format=%(refname):%(objectname)"],
396
+ repository.repositoryRoot
397
+ )
398
+ ]);
399
+ if (results.some((result) => !result.ok)) return null;
400
+ return results.filter((result) => result.ok).map((result) => result.stdout).join("");
401
+ }
359
402
  /** `null` when the content directory has no readable work tree. */
360
403
  async #resolvePaths() {
361
404
  this.#repository ??= resolveRepositoryPaths(this.#contentRoot);
@@ -385,6 +428,7 @@ function getRevisionPath(nameStatusLines, fallbackPath) {
385
428
  }
386
429
 
387
430
  // index.ts
431
+ var getPostDiff = ({ api, filePath }) => api.getCurrentDiff(filePath);
388
432
  function diff(options = {}) {
389
433
  const ui = { enabled: true, maxRevisions: 20, ...options.ui };
390
434
  let api;
@@ -395,15 +439,53 @@ function diff(options = {}) {
395
439
  version: "diff-v3",
396
440
  dependencyMode: "unsafe"
397
441
  },
398
- options,
399
- assets: ui.enabled === false ? [] : [createStyleAsset("diff")],
400
- clientEntries: ui.enabled === false ? [] : [createClientEntry("diff", "initDiffHistory")],
401
- onManifestCreated: async (context) => {
402
- if (ui.enabled === false) return;
403
- api ??= createPostDiffApi({
442
+ contentOutputDependencies: ui.enabled === false ? [] : [{ type: "external", id: "diff:git-history" }],
443
+ resolveExternalDependencies: async (context) => {
444
+ if (ui.enabled === false) return [];
445
+ const reader = new GitMarkdownHistoryReader({
404
446
  ...options,
405
447
  cwd: options.cwd ?? context.config?.content.directory
406
448
  });
449
+ const state = await reader.getStateFingerprint();
450
+ if (state === null) {
451
+ return [
452
+ {
453
+ kind: "unavailable",
454
+ failure: {
455
+ id: "diff:git-history",
456
+ reason: "Git history could not be fingerprinted."
457
+ }
458
+ }
459
+ ];
460
+ }
461
+ return [
462
+ {
463
+ kind: "resolved",
464
+ snapshot: {
465
+ id: "diff:git-history",
466
+ fingerprint: fingerprintExternalValue(state),
467
+ scope: { type: "content" },
468
+ value: reader
469
+ }
470
+ }
471
+ ];
472
+ },
473
+ options,
474
+ assets: ui.enabled === false ? [] : [createStyleAsset("diff", "@riebeckite/plugin-diff/style.css")],
475
+ clientEntries: ui.enabled === false ? [] : [
476
+ createClientEntry(
477
+ "diff",
478
+ "@riebeckite/plugin-diff/client",
479
+ "initDiffHistory"
480
+ )
481
+ ],
482
+ onManifestCreated: async (context) => {
483
+ if (ui.enabled === false) return;
484
+ const snapshot = context.externalDependencies?.get("diff:git-history");
485
+ if (!snapshot || !(snapshot.value instanceof GitMarkdownHistoryReader)) {
486
+ return;
487
+ }
488
+ api ??= createPostDiffApiFromReader(snapshot.value);
407
489
  for (const entry of context.manifest.discoverableEntries) {
408
490
  const filePath = resolvePostFilePath({
409
491
  slug: entry.slug,
@@ -421,17 +503,11 @@ function diff(options = {}) {
421
503
  context.output.emit({
422
504
  path: payloadPath,
423
505
  content: JSON.stringify({ revisions }).replace(/</g, "\\u003c"),
424
- dependencies: [{ type: "content", slug: entry.slug }]
506
+ dependencies: [
507
+ { type: "content", slug: entry.slug },
508
+ { type: "external", id: "diff:git-history" }
509
+ ]
425
510
  });
426
- appendContentBodySlot(
427
- entry,
428
- "article.footer",
429
- renderDiffHistory({
430
- revisions,
431
- selected,
432
- payloadPath: `/${payloadPath}`
433
- })
434
- );
435
511
  }
436
512
  }
437
513
  });
@@ -440,7 +516,9 @@ function diffPayloadPath(slug) {
440
516
  return `_riebeckite/diff/${Buffer.from(slug).toString("base64url")}.json`;
441
517
  }
442
518
  function createPostDiffApi(options = {}) {
443
- const reader = new GitMarkdownHistoryReader(options);
519
+ return createPostDiffApiFromReader(new GitMarkdownHistoryReader(options));
520
+ }
521
+ function createPostDiffApiFromReader(reader) {
444
522
  return {
445
523
  getHistory: (filePath) => reader.getHistory(filePath),
446
524
  getRevisionMarkdown: (filePath, hash) => reader.getRevisionMarkdown(filePath, hash),
@@ -505,9 +583,11 @@ function buildPostDiff(input) {
505
583
  }
506
584
  export {
507
585
  GitMarkdownHistoryReader,
586
+ post_diff_default as PostDiffView,
508
587
  createLineDiff,
509
588
  createPostDiffApi,
510
589
  diff,
590
+ getPostDiff,
511
591
  renderDiffHistory,
512
592
  renderDiffLine,
513
593
  renderDiffPanel,
@@ -17,4 +17,5 @@ export declare class GitMarkdownHistoryReader {
17
17
  getHistory(filePath: string): Promise<DiffRevision[]>;
18
18
  /** Content of one revision of a file, or `null` when Git cannot read it. */
19
19
  getRevisionMarkdown(filePath: string, hash: string): Promise<string | null>;
20
+ getStateFingerprint(): Promise<string | null>;
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-diff",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,15 +18,22 @@
18
18
  "source": "./client.ts",
19
19
  "default": "./dist/client.js"
20
20
  },
21
+ "./components": {
22
+ "types": "./dist/components/post-diff.d.ts",
23
+ "import": "./dist/components/post-diff.js",
24
+ "source": "./components/post-diff.tsx",
25
+ "default": "./dist/components/post-diff.js"
26
+ },
21
27
  "./style.css": "./style.css"
22
28
  },
23
29
  "dependencies": {
24
- "@riebeckite/core": "0.0.22"
30
+ "hono": "^4.12.25",
31
+ "@riebeckite/core": "0.0.24"
25
32
  },
26
33
  "devDependencies": {
27
34
  "@types/node": "^24.5.2",
28
35
  "tsx": "^4.22.4",
29
- "@riebeckite/test": "0.0.22"
36
+ "@riebeckite/test": "0.0.24"
30
37
  },
31
38
  "publishConfig": {
32
39
  "access": "public"