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(pkg-manifest): preserve comments in YAML manifests #6273

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danielbayley
Copy link

@danielbayley danielbayley commented Mar 23, 2023

Following on from the basic implementation outlined here in #2008—which works well—am I right in thinking that the manifest: data here (from here) containing the AST (including comments) gets normalized, and therefore lost here?

@zkochan I’m keen to get this feature merged, but could do with some pointers as to the best approach…

Closes #2008.

@welcome
Copy link

welcome bot commented Mar 23, 2023

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.

@danielbayley
Copy link
Author

Would appreciate some pointers on this @zkochan

@@ -1,9 +1,24 @@
import gfs from '@pnpm/graceful-fs'
import { type ProjectManifest } from '@pnpm/types'
import YAML from 'yaml'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use js-yaml
we shouldn't use 2 libraries for parsing yaml.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbayley, can you update the suggestion given by @zkochan?

I am desperate to preserve the comments in the pakcage.yaml.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use js-yaml
we shouldn't use 2 libraries for parsing yaml.

@zkochan I agree that 2 is not ideal… I suppose I’m proposing that we replace js-yaml with eemeli.org/yaml, because it retains comments very well, whereas js-yaml does not, and instead just discards them. Did you take a look at my working implementation here? #2008 (comment)

can you update the suggestion given by @zkochan?

@gusbemacbe Unfortunately it isn’t a suggestion that helps with this implementation…

I am desperate to preserve the comments in the *package.yaml.

Same!

Copy link
Member

@gluxon gluxon Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a bit more research, I'd also be in favor of a move to yaml. It looks like js-yaml hasn't had a release for a few years.

Switching to yaml to avoid 2 libraries for parsing/serializing YAML files will take a bit of work though.

  • Is there a performance difference? It'll be interesting to see a performance benchmark on serializing/deserializing a large pnpm-lock.yaml file between yaml vs js-yaml.
  • There's patches to js-yaml that we'll need to replicate in yaml. nodeca/js-yaml@master...pnpm:js-yaml:features-for-pnpm

@danielbayley Do you happen to have bandwidth for such an investigation? If not, we can spin up a different pull request investigating a switch from js-yaml to yaml that would merge before this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbayley Do you happen to have bandwidth for such an investigation?

Unfortunately not, currently.

If not, we can spin up a different pull request investigating a switch from js-yaml to yaml that would merge before this PR.

@gluxon Fully in favour of the switch… and definitely agree that should be a separate PR, preceding this one. I would be keen to pick up the baton after that to implement comment preservation…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Thanks @danielbayley.

@gusbemacbe
Copy link

@zkochan, do you have to review this PR and to test, modifying a bit, to see if it will work? We are desperate to preserve the comments in the package.yml file.

@gluxon
Copy link
Member

gluxon commented Dec 31, 2023

@zkochan, do you have to review this PR and to test, modifying a bit, to see if it will work? We are desperate to preserve the comments in the package.yml file.

I think Zoltan's last review around avoiding 2 yaml libraries makes sense and still applies today. Would be curious for his thoughts on whether we should migrate in a separate PR though.

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