This document provides essential information for AI coding agents working on the git-diff-view codebase.
A high-performance Git diff view component library supporting React, Vue, Solid, and Svelte.
- Language: TypeScript (strict mode, ESNext target)
- Package Manager: pnpm (v9.12.0+) with workspace monorepo
- Build Tool: Custom rollup-based tool (
project-tool) with SWC - Styling: TailwindCSS with PostCSS
pnpm install # Install dependencies
pnpm run build:packages # Build all packages
pnpm run dev:packages # Development mode for packages
pnpm run lint # Run ESLint: eslint --cache --ext ts,tsx .
pnpm run lint:fix # Fix lint issues automatically
pnpm run prettier # Format code with Prettier
pnpm run clean # Remove dist/dev/.cache directories
pnpm run release # Full release: lint + prettier + clean + build + releasepnpm run dev:react # React example (Vite)
pnpm run dev:vue # Vue example (Vite)
pnpm run dev:solid # Solid example
pnpm run dev:svelte # Svelte package dev
pnpm run dev:cli # CLI dev modeNote: No test framework is currently configured. There are no test files or test commands.
- Semicolons: Always required
- Quotes: Double quotes (
") - not single quotes - Indentation: 2 spaces (no tabs)
- Line width: 120 characters maximum
- Trailing commas: ES5 style (arrays, objects)
Order imports with blank lines between groups:
- External dependencies (npm packages)
- Internal monorepo packages (
@git-diff-view/*) - Local relative imports
- Type-only imports (at the end, using
import type)
import { memo, useEffect } from "react";
import { DiffFile, SplitSide } from "@git-diff-view/core";
import { useIsMounted } from "../hooks/useIsMounted";
import type { DiffHighlighter } from "@git-diff-view/core";| Element | Convention | Examples |
|---|---|---|
| Variables/Functions | camelCase | diffFile, getFile, parseInstance |
| Classes/Interfaces/Types/Enums | PascalCase | DiffFile, SplitLineItem, DiffLineType |
| React Components | PascalCase | DiffView, DiffSplitView |
| Custom Hooks | use prefix |
useIsMounted, useDomWidth |
| Component files | PascalCase | DiffView.tsx |
| Utility files | camelCase | utils.ts, diff-file.ts |
| Private class fields | # prefix (ES2022) |
#oldFileResult, #listeners |
| Internal properties | _ prefix |
_oldFileName, _isHidden |
| CSS variable names | camelCase + Name suffix |
diffFontSizeName, emptyBGName |
- Use interfaces for object shapes/data structures
- Use types for unions, intersections, and utility types
- Avoid
any: Useunknownwith generics:<T extends unknown> - Optional chaining: Use extensively:
diffFile?.clear?.()
Named exports only - no default exports:
export const DiffView = InnerDiffView;
export { SplitSide, DiffModeEnum };
export class DiffFile { ... }Barrel exports in index.ts:
export * from "./components/DiffView";
export * from "@git-diff-view/core";Use the __DEV__ global for development-only warnings/errors:
if (__DEV__) {
console.warn('[@git-diff-view/core] The composed files are identical...');
}- Prefix messages with package name:
[@git-diff-view/core] - Use defensive early returns rather than throwing exceptions
__DEV__blocks are stripped in production builds
- Memo pattern:
const MemoedComponent = memo(InternalComponent); - forwardRef: Add
displayNameafter:InnerDiffView.displayName = "DiffView"; - Context: Use
DiffViewContext.Providerfor state management
packages/
core/ # Core diff parsing engine (@git-diff-view/core)
react/ # React components (@git-diff-view/react)
vue/ # Vue components (@git-diff-view/vue)
solid/ # Solid components (@git-diff-view/solid)
svelte/ # Svelte components (@git-diff-view/svelte)
cli/ # CLI tool (@git-diff-view/cli)
file/ # File comparison engine (@git-diff-view/file)
utils/ # Shared utilities (@git-diff-view/utils)
lowlight/ # Lowlight syntax highlighter
shiki/ # Shiki syntax highlighter
ui/
react-example/ # React demo app (Vite)
vue-example/ # Vue demo app (Vite)
solid-example/ # Solid demo app
svelte-example/ # Svelte demo
scripts/ # Build scripts (ts-node)
@git-diff-view/coreis the foundation (all framework packages depend on it)- Framework packages (react, vue, solid, svelte) wrap the core
@git-diff-view/fileprovides file-to-file comparison using thedifflibrary- Syntax highlighting via
lowlight(highlight.js) orshiki
- Base config:
project-tool/baseLint - Ignored:
dist,dev,scripts,node_modules,next-*-example,packages/solid,packages/svelte
- No test infrastructure - be cautious when modifying core logic
- Multi-framework support - changes to core affect all framework bindings
- Performance critical - this library handles large diffs; avoid unnecessary re-renders
- CSS variables - styling uses CSS custom properties for theming
- Private fields - use ES2022
#syntax for true private fields