Skip to content
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: Support custom clone operation #12

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

b0o
Copy link

@b0o b0o commented Feb 1, 2024

Adds an optional clone method to the FormatPlugin interface. 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 #10

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
Copy link
Member

@zkochan zkochan left a 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.

src/index.ts Outdated Show resolved Hide resolved
@b0o b0o marked this pull request as draft February 3, 2024 01:43
@b0o b0o marked this pull request as ready for review February 4, 2024 04:45
@b0o
Copy link
Author

b0o commented Feb 29, 2024

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom clone operation
2 participants