-
Notifications
You must be signed in to change notification settings - Fork 12
Retain Manifest Formatting on pack Command
#65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ChekTek
commented
Jan 9, 2026
- preserve manifest line endings (CRLF | LF)
- preserve manifest indentation style (tabs | spaces)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the pack command to preserve the original formatting of manifest files when modifying them. Previously, the manifest was always written with tab indentation and LF line endings; now it retains the original file's formatting style.
Changes:
- Detect and preserve original line ending style (CRLF vs LF)
- Detect and preserve original indentation style (tabs vs spaces)
- Apply detected formatting when stringifying the modified manifest
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Detect the original indentation style (tabs or spaces) | ||
| const indentMatch = original.match(/^[\t ]+/m); | ||
| const indent = indentMatch?.[0].startsWith("\t") ? "\t" : indentMatch?.[0] ?? "\t"; |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation detection logic is complex and unclear. If the match finds spaces, it uses all matched spaces as the indent, but if it finds tabs, it only uses a single tab. This inconsistency could lead to incorrect indentation if the original file uses multiple tabs. Consider explicitly handling the tab case to use the full matched string, or document why single tab is preferred.
| const indent = indentMatch?.[0].startsWith("\t") ? "\t" : indentMatch?.[0] ?? "\t"; | |
| const indent = indentMatch?.[0] ?? "\t"; |
|
|
||
| // Preserve original line endings | ||
| if (lineEnding === "\r\n") { | ||
| stringified = stringified.replaceAll("\n", "\r\n"); |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using replaceAll to convert LF to CRLF will cause issues if the stringified content already contains any CRLF sequences (which could happen if manifest values contain embedded newlines). This would result in CRCRLF sequences. Consider using replace with a regex that specifically targets LF not preceded by CR: stringified.replace(/(?<!\r)\n/g, '\r\n')
| stringified = stringified.replaceAll("\n", "\r\n"); | |
| stringified = stringified.replace(/(?<!\r)\n/g, "\r\n"); |