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

Support custom clone operation #10

Open
pokey opened this issue Apr 8, 2023 · 0 comments · May be fixed by #12
Open

Support custom clone operation #10

pokey opened this issue Apr 8, 2023 · 0 comments · May be fixed by #12

Comments

@pokey
Copy link

pokey commented Apr 8, 2023

I'm trying to update a yaml file while preserving comments, using the yaml npm library. In order to preserve comments, I need the parsed file to be a yaml.Document, but that cannot be cloned using the default clone method provided by meta-updater. It would be great if custom formats supported an optional clone field that I could use to provide my own cloning methodology (I'd just use Document.clone).

I would be happy to contribute a PR

Fwiw, the error I get today is as follows:

DOMException [DataCloneError]: (value) => value instanceof Uint8Array could not be cloned.
    at new DOMException (node:internal/per_context/domexception:53:5)
    at structuredClone (node:internal/structured_clone:23:17)
    at performUpdates (file:///Users/pokey/src/cursorless/node_modules/.pnpm/@[email protected][email protected]/node_modules/@pnpm/meta-updater/lib/index.js:51:56)
    at async default (file:///Users/pokey/src/cursorless/node_modules/.pnpm/@[email protected][email protected]/node_modules/@pnpm/meta-updater/lib/index.js:16:20)
b0o added a commit to b0o/meta-updater that referenced this issue Feb 1, 2024
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 `json-comments`, 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
b0o added a commit to b0o/meta-updater that referenced this issue Feb 1, 2024
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
@b0o b0o linked a pull request Feb 1, 2024 that will close this issue
b0o added a commit to b0o/meta-updater that referenced this issue Feb 1, 2024
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
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 a pull request may close this issue.

1 participant