feat: Enhance Git Patch Parsing and Refactor Core Logic #1
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Hi!
I've been working on improving how we handle Git patches. As we've started looking at commits in more detail, we realized the old code could be more flexible and easier to work with.
This PR refactors some key parts to make the code cleaner, safer (with better type checking!), and generally more solid. The goal is to make it simpler for all of us to maintain and build upon in the future. Also all the test cases are still valid.
Let me know what you think!
This pull request enhances the Git patch parsing capabilities, introduces structured diff representation, improves type safety, and refactors the core parsing logic for better modularity and maintainability.
Detailed Changes
Added
Enhanced Patch Parsing Logic with Flexible Configuration (src/logics/parse/patch.ts, src/types.ts)
ParseOptionswithparseDates(to convert date strings toDateobjects) andstructuredDiff(to convert diff strings into a structured object array -FileChange[]). This allows for more flexible processing of patch data.ParsedCommittype now dynamically adjusts the type ofdateanddifffields based on these options, utilizing aSelectIfTrueutility type for improved type safety.parseGitPatchfunction now accepts these options to tailor the parsing output.Git Diff String Structurization (src/logics/parse/diffToStructured.ts, src/types.ts)
parseDiffToStructuredfunction to transform raw Git diff strings into an array ofFileChangeobjects.FileChangeobject detailsoldPath,newPath,additions,deletions, and an array ofhunks.DiffHunkcontains aheaderstring and an array ofDiffLineobjects, where each line is typed asaddition,deletion, orcontext.Changed
Improved Type Safety and Modularity in Parsing Logic (src/consts.ts, src/types.ts, src/logics/parse/patch.ts)
HEADERS,REGEX) intosrc/consts.tsfor better organization.ParseOptionsandParsedCommitusing generics insrc/types.tsto ensure stricter type checking.parseGitPatchfunction to leverage these improved and more robust type definitions.Cross-Platform Build Clean Script (scripts/cleanDist.ts)
rm -rf distshell command in the build process with a new Node.js-based TypeScript script,scripts/cleanDist.ts.node:fs/promises'srmfunction for deleting thedistdirectory, ensuring cross-platform compatibility for the clean-up task.Enhanced Readability and Organization of
parseGitPatchTests (src/mocks/patch.ts, src/logics/parse/patch.test.ts, tsconfig.json)parseGitPatchtests to a dedicated file:src/mocks/patch.ts.tsconfig.jsonto correctly include paths for these mock files, facilitating better test organization (Note:CHANGELOG.mdmentionstsconfig.jsonupdate for include paths, but test files are typically run via a test runner likebun:testwhich might handle module resolution differently. The primaryincludeintsconfig.jsonpoints tosrc/index.ts).Refactored Core Parsing Logic File Structure (src/logics/parse/patch.ts, src/logics/parse/patch.test.ts, src/index.ts, src/logics/index.ts, src/types.ts)
src/logics/parse/patch.tsand its test filesrc/logics/parse/patch.test.ts) into thesrc/logics/parse/directory.src/index.tsandsrc/logics/index.ts) for streamlined re-exporting of modules.src/types.tsfile.Style
src/logics/parse/patch.test.tsfile for consistency.