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
feat(pkg-manifest): preserve comments in json5 manifests #5677
Merged
Commits on Nov 26, 2022
-
feat(manifest): preserve comments in JSON5 manifests
Use npm package `strip-comments-strings` to find all comments in any manifest file as it is read. Save them as part of the "file formatting" detected by the manifest reader, noting for each the text of the lines they are on, before, and after, and the line number as a fallback. When the manifest is written, attempt to place each comment back in the resulting JSON5 text, so that the text of the line it is on, before, or after (in that priority order) matches the text at time of reading. Otherwise, so that no comments are lost, replace the comment on the same line number, adding a notation that it may have been relocated (due to sorting dependencies, for example, it may no longer be in the same "logical position" in the file, even though it is on the same physical line number). When comments are in fairly ordinary positions and the manifest does not change too drastically (i.e. once the dependencies are sorted as pnpm prefers, and there are not many parameters added all at once), this strategy results in exact preservation of the comments, as a new test shows. The motivation for this commit is to take advantage of the feature of JSON5 that it allows human-readable comments. For this feature to be useful in the case of package.json5 manifests, those comments must be preserved across manifest changes. Partially resolves pnpm#2008. [That issue requests comment preservation also for YAML manifests, but I have no experience working with YAML, and it also requests that key order be preserved, but I did not address key order because current code in the the pnpm manifest reader/writer _explicitly_ reorders keys -- clearly deliberately -- so I did not want to simply remove code that appeared to have been purposefully written and included.]
Configuration menu - View commit details
-
Copy full SHA for ed25f2a - Browse repository at this point
Copy the full SHA ed25f2aView commit details -
Configuration menu - View commit details
-
Copy full SHA for d77f945 - Browse repository at this point
Copy the full SHA d77f945View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5469140 - Browse repository at this point
Copy the full SHA 5469140View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2a74c22 - Browse repository at this point
Copy the full SHA 2a74c22View commit details -
(Including one unused variable that was inadvertently left in.)
Configuration menu - View commit details
-
Copy full SHA for 5c3d64b - Browse repository at this point
Copy the full SHA 5c3d64bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 843becc - Browse repository at this point
Copy the full SHA 843beccView commit details -
refactor(pkg-manifest): separate comment-handling code
Move comment extraction and reinsertion into their own functions, called only when the manifest is Json5.
Configuration menu - View commit details
-
Copy full SHA for 7fba4af - Browse repository at this point
Copy the full SHA 7fba4afView commit details -
Configuration menu - View commit details
-
Copy full SHA for b48d0f0 - Browse repository at this point
Copy the full SHA b48d0f0View commit details
Commits on Nov 27, 2022
-
Configuration menu - View commit details
-
Copy full SHA for 1704039 - Browse repository at this point
Copy the full SHA 1704039View commit details -
Configuration menu - View commit details
-
Copy full SHA for d2c346c - Browse repository at this point
Copy the full SHA d2c346cView commit details -
Configuration menu - View commit details
-
Copy full SHA for cc40d7a - Browse repository at this point
Copy the full SHA cc40d7aView commit details -
Configuration menu - View commit details
-
Copy full SHA for aa572b3 - Browse repository at this point
Copy the full SHA aa572b3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 82b6190 - Browse repository at this point
Copy the full SHA 82b6190View commit details -
Configuration menu - View commit details
-
Copy full SHA for eb17e8d - Browse repository at this point
Copy the full SHA eb17e8dView commit details
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.