-
Notifications
You must be signed in to change notification settings - Fork 6
Feat: Support custom clone operation #12
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
This method is used to clone the object returned by `read` before passing it to `update`. This is useful when the object returned by `read` is not trivially cloneable. One use case is when trying to preserve comments in a JSONC file using the `comment-json` package, which uses symbol properties on the object to store comments. The default `clone` method would not preserve these symbol properties, so a custom `clone` method is needed. Fixes pnpm#10
ca14774 to
5b50c13
Compare
zkochan
left a comment
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.
I don't have objections but let's add a test for it.
They're now in the order they are called.
also remove the options parameter from the clone function
|
Hey @zkochan, sorry to bother you, but I was wondering if you could take another look at this and let me know if I can do anything to improve it? |
| return fsx.readFile(options.resolvedPath, 'utf8') | ||
| }, | ||
| clone(value) { | ||
| return value |
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.
maybe also do some manipulations here and see if they were reflected
Adds an optional
clonemethod to theFormatPlugininterface. This method is used to clone the object returned byreadbefore passing it toupdate. This is useful when the object returned byreadis not trivially cloneable.One use case is when trying to preserve comments in a JSONC file using the
comment-jsonpackage, which uses symbol properties on the object to store comments. The defaultclonemethod would not preserve these symbol properties, so a customclonemethod is needed.Fixes #10