You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(preprocess): optimize file patching and fix edge-case bugs - #4021
Speeds up spicetify apply and cleans up a few issues in preprocess and utils:
Cache compiled regexes and move static []Patch slices to package level.
Use Find*SubmatchIndex in Replace* / FindFirstMatch / FindLastMatch to avoid matching twice and stop after the first match in ReplaceOnce.
Use strings.NewReplacer for cssTranslationMap on CSS files (same as JS) and combine literal hex color patches.
Parallelize file patching in Start and StartCSS using filepath.WalkDir.
Fix potential nil dereference in StartCSS, duplicate Spicetify.URI patch, missing bounds check in SeekToCloseParen, and defer inside loops in Unzip/Copy.
Skip writing unchanged files in ModifyFile.
Note: also removed --spice-card-elevated from colorPatches since it used the exact same #(242424|1f1f1f)\b regex as --spice-main-elevated above it and was unreachable.
Summary by CodeRabbit
Performance
Preprocessing and CSS color conversion now run concurrently, which can speed up builds.
Bug Fixes
CSS replacements are applied consistently, and XPUI stylesheets retain the legacy fixed-width grid rule.
Improved handling of logging and vendor integrations when processing supported application files.
File and archive operations now handle unchanged content and extraction errors more reliably.
Reviewing files that changed from the base of the PR and between 1684023 and a60d020.
📒 Files selected for processing: 2
src/preprocess/preprocess.go
src/utils/utils.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
The changes update utility regex and file operations, and revise preprocessing to discover and process files concurrently. Preprocessing also uses precomputed CSS replacements and shared patch definitions, with checks for context-menu and vendor URI matches.
Changes: Preprocessing and Utilities
Layer / File(s)
Summary
Regex matching and scanning helpers src/utils/utils.go
Compiled regexes are cached. Replacement and matching helpers use match indices, and parenthesis scanning is bounded by the content length.
Archive and file operations src/utils/utils.go
Archive entries are opened during extraction and closed after copying. Copy delegates to CopyFile. ModifyFile reports errors through PrintError, skips unchanged writes, and writes changed content with mode 0644.
Start and StartCSS discover files with WalkDir and process them concurrently with CPU-count limits. CSS-map replacers are precomputed, and color conversion patches are shared.
Preprocessing patch rules and safeguards src/preprocess/preprocess.go
Logging, RTL, GraphQL, XPUI, and vendor patch definitions move to package scope. Context-menu discovery checks for a useRef match, and vendor URI export insertion checks for a URI body.
sequenceDiagram
participant Start
participant WalkDir
participant Workers as Worker goroutines
participant Progress as Progress bar
Start->>WalkDir: Discover files
WalkDir-->>Start: Return file entries
Start->>Workers: Dispatch file processing
Workers->>Progress: Increment progress under lock
Loading
Suggested reviewers:rxri
Merge Risk:⚪ Minimal · up to a60d0
The inspected preprocessing changes preserve the relevant replacement behavior. No actionable issue remains from this review; the PR is mergeable after normal checks.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 2 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title accurately summarizes the pull request. It identifies both the file-patching optimizations and the edge-case fixes described in the changes.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Speeds up
spicetify applyand cleans up a few issues inpreprocessandutils:[]Patchslices to package level.Find*SubmatchIndexinReplace*/FindFirstMatch/FindLastMatchto avoid matching twice and stop after the first match inReplaceOnce.strings.NewReplacerforcssTranslationMapon CSS files (same as JS) and combine literal hex color patches.StartandStartCSSusingfilepath.WalkDir.nildereference inStartCSS, duplicateSpicetify.URIpatch, missing bounds check inSeekToCloseParen, anddeferinside loops inUnzip/Copy.ModifyFile.Note: also removed
--spice-card-elevatedfromcolorPatchessince it used the exact same#(242424|1f1f1f)\bregex as--spice-main-elevatedabove it and was unreachable.Summary by CodeRabbit