difit 2.0.0 → 2.0.3

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.
Files changed (35) hide show
  1. package/README.md +4 -4
  2. package/dist/cli/index.js +1 -1
  3. package/dist/cli/index.test.js +17 -17
  4. package/dist/cli/utils.js +41 -5
  5. package/dist/cli/utils.test.js +33 -0
  6. package/dist/client/assets/index-8bOJqzQC.js +190 -0
  7. package/dist/client/assets/index-sXbQL2XR.css +1 -0
  8. package/dist/client/assets/{prism-java-fRxbL3-m.js → prism-java-XP5rs1ZV.js} +1 -1
  9. package/dist/client/assets/{prism-php-CcaSYv4J.js → prism-php-CYxq20-J.js} +1 -1
  10. package/dist/client/assets/{prism-ruby-vYjZ5d92.js → prism-ruby-BoO_oIbk.js} +1 -1
  11. package/dist/client/assets/{prism-solidity-DEbM6fQo.js → prism-solidity-CHQMoOrF.js} +1 -1
  12. package/dist/client/assets/prism-vim-uciLQ2PQ.js +1 -0
  13. package/dist/client/index.html +2 -2
  14. package/dist/server/git-diff.js +3 -7
  15. package/dist/server/git-diff.test.js +26 -1
  16. package/dist/server/server.js +2 -2
  17. package/dist/server/server.test.js +40 -5
  18. package/dist/tui/App.js +13 -9
  19. package/dist/tui/components/DiffViewer.d.ts +1 -1
  20. package/dist/tui/components/DiffViewer.js +1 -1
  21. package/dist/tui/components/FileList.d.ts +1 -1
  22. package/dist/tui/components/FileList.js +1 -1
  23. package/dist/tui/components/SideBySideDiffViewer.d.ts +1 -1
  24. package/dist/tui/components/SideBySideDiffViewer.js +50 -47
  25. package/dist/tui/components/StatusBar.js +5 -5
  26. package/dist/tui/utils/parseDiff.d.ts +1 -1
  27. package/dist/types/diff.d.ts +2 -1
  28. package/dist/utils/gitUtils.d.ts +4 -0
  29. package/dist/utils/gitUtils.js +29 -0
  30. package/dist/utils/gitUtils.test.d.ts +1 -0
  31. package/dist/utils/gitUtils.test.js +63 -0
  32. package/package.json +4 -1
  33. package/dist/client/assets/index-C2KvF1_C.js +0 -190
  34. package/dist/client/assets/index-CoxWiu5U.css +0 -1
  35. package/dist/server/comment-store.js +0 -140
@@ -39,10 +39,11 @@ export interface DiffResponse {
39
39
  baseCommitish?: string;
40
40
  targetCommitish?: string;
41
41
  }
42
+ export type LineNumber = number | [number, number];
42
43
  export interface Comment {
43
44
  id: string;
44
45
  file: string;
45
- line: number;
46
+ line: LineNumber;
46
47
  body: string;
47
48
  timestamp: string;
48
49
  codeContent?: string;
@@ -0,0 +1,4 @@
1
+ import type { SimpleGit } from 'simple-git';
2
+ export declare function shortHash(hash: string): string;
3
+ export declare function createCommitRangeString(baseHash: string, targetHash: string): string;
4
+ export declare function resolveCommitDisplayString(baseCommitish: string, targetCommitish: string, git: SimpleGit): Promise<string>;
@@ -0,0 +1,29 @@
1
+ export function shortHash(hash) {
2
+ return hash.substring(0, 7);
3
+ }
4
+ export function createCommitRangeString(baseHash, targetHash) {
5
+ return `${baseHash}...${targetHash}`;
6
+ }
7
+ export async function resolveCommitDisplayString(baseCommitish, targetCommitish, git) {
8
+ // Handle target special chars (base is always a regular commit)
9
+ if (targetCommitish === 'working') {
10
+ // Show unstaged changes (working vs staged)
11
+ return 'Working Directory (unstaged changes)';
12
+ }
13
+ else if (targetCommitish === 'staged') {
14
+ // Show staged changes against base commit
15
+ const baseHash = await git.revparse([baseCommitish]);
16
+ return `${shortHash(baseHash)} vs Staging Area (staged changes)`;
17
+ }
18
+ else if (targetCommitish === '.') {
19
+ // Show all uncommitted changes against base commit
20
+ const baseHash = await git.revparse([baseCommitish]);
21
+ return `${shortHash(baseHash)} vs Working Directory (all uncommitted changes)`;
22
+ }
23
+ else {
24
+ // Both are regular commits: standard commit-to-commit comparison
25
+ const targetHash = await git.revparse([targetCommitish]);
26
+ const baseHash = await git.revparse([baseCommitish]);
27
+ return createCommitRangeString(shortHash(baseHash), shortHash(targetHash));
28
+ }
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { shortHash, createCommitRangeString, resolveCommitDisplayString } from './gitUtils';
3
+ describe('Git Utils', () => {
4
+ describe('shortHash', () => {
5
+ it('should return first 7 characters of hash', () => {
6
+ expect(shortHash('a1b2c3d4e5f6789012345678901234567890abcd')).toBe('a1b2c3d');
7
+ expect(shortHash('1234567890abcdef')).toBe('1234567');
8
+ expect(shortHash('abc123')).toBe('abc123');
9
+ });
10
+ it('should handle short hashes', () => {
11
+ expect(shortHash('abc')).toBe('abc');
12
+ expect(shortHash('')).toBe('');
13
+ expect(shortHash('a')).toBe('a');
14
+ });
15
+ });
16
+ describe('createCommitRangeString', () => {
17
+ it('should create commit range string with triple dots', () => {
18
+ expect(createCommitRangeString('abc1234', 'def5678')).toBe('abc1234...def5678');
19
+ expect(createCommitRangeString('a1b2c3d', '4e5f6g7')).toBe('a1b2c3d...4e5f6g7');
20
+ });
21
+ it('should handle empty strings', () => {
22
+ expect(createCommitRangeString('', '')).toBe('...');
23
+ expect(createCommitRangeString('abc123', '')).toBe('abc123...');
24
+ expect(createCommitRangeString('', 'def456')).toBe('...def456');
25
+ });
26
+ });
27
+ describe('resolveCommitDisplayString', () => {
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ const mockGit = {
30
+ revparse: vi.fn(),
31
+ };
32
+ beforeEach(() => {
33
+ vi.clearAllMocks();
34
+ });
35
+ it('should handle working directory target', async () => {
36
+ const result = await resolveCommitDisplayString('main', 'working', mockGit);
37
+ expect(result).toBe('Working Directory (unstaged changes)');
38
+ expect(mockGit.revparse).not.toHaveBeenCalled();
39
+ });
40
+ it('should handle staged target', async () => {
41
+ mockGit.revparse.mockResolvedValue('a1b2c3d4e5f6789012345678901234567890abcd');
42
+ const result = await resolveCommitDisplayString('main', 'staged', mockGit);
43
+ expect(result).toBe('a1b2c3d vs Staging Area (staged changes)');
44
+ expect(mockGit.revparse).toHaveBeenCalledWith(['main']);
45
+ });
46
+ it('should handle dot (.) target', async () => {
47
+ mockGit.revparse.mockResolvedValue('a1b2c3d4e5f6789012345678901234567890abcd');
48
+ const result = await resolveCommitDisplayString('main', '.', mockGit);
49
+ expect(result).toBe('a1b2c3d vs Working Directory (all uncommitted changes)');
50
+ expect(mockGit.revparse).toHaveBeenCalledWith(['main']);
51
+ });
52
+ it('should handle regular commit to commit comparison', async () => {
53
+ mockGit.revparse
54
+ .mockResolvedValueOnce('def4567890abcdef1234567890abcdef12345678') // target (called first)
55
+ .mockResolvedValueOnce('a1b2c3d4e5f6789012345678901234567890abcd'); // base (called second)
56
+ const result = await resolveCommitDisplayString('main', 'develop', mockGit);
57
+ expect(result).toBe('a1b2c3d...def4567');
58
+ expect(mockGit.revparse).toHaveBeenCalledWith(['develop']);
59
+ expect(mockGit.revparse).toHaveBeenCalledWith(['main']);
60
+ expect(mockGit.revparse).toHaveBeenCalledTimes(2);
61
+ });
62
+ });
63
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "difit",
3
- "version": "2.0.0",
3
+ "version": "2.0.3",
4
4
  "description": "A lightweight command-line tool that spins up a local web server to display Git commit diffs in a GitHub-like Files changed view",
5
5
  "type": "module",
6
6
  "engines": {
@@ -51,6 +51,8 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@eslint/eslintrc": "^3.3.1",
54
+ "@eslint/js": "^9.30.1",
55
+ "@prettier/plugin-oxc": "^0.0.4",
54
56
  "@tailwindcss/forms": "^0.5.10",
55
57
  "@tailwindcss/postcss": "^4.1.11",
56
58
  "@tailwindcss/typography": "^0.5.16",
@@ -73,6 +75,7 @@
73
75
  "eslint-plugin-react": "^7.37.5",
74
76
  "eslint-plugin-react-hooks": "^5.2.0",
75
77
  "eslint-plugin-unused-imports": "^4.1.4",
78
+ "globals": "^16.3.0",
76
79
  "happy-dom": "^18.0.1",
77
80
  "lefthook": "^1.11.14",
78
81
  "postcss": "^8.5.6",