risor-io / risor

Fast and flexible scripting for Go developers and DevOps.
https://risor.io
Apache License 2.0
581 stars 24 forks source link

Added YAML module #161

Closed applejag closed 6 months ago

applejag commented 6 months ago

Adds a YAML module.

I was very unsure on where to register the module. I thought just adding it to modules/all/all.go would suffice, but that didn't seem like it.

I added it everywhere the JSON module was registered, even in the decode and encode builtins inside builtins/codecs.go.

This adds a new dependency: gopkg.in/yaml.v3. Given this, should the YAML module then have a build flag?

myzie commented 6 months ago

In short, I think YAML support should be built-in and always available. This makes it an exception from my standard rules, and means what you have here is good as-is.

This addition aside, I did write a bit more about the general rules here: https://risor.io/docs/contributing_modules

  1. If the library isn't in the Go standard lib -> the Risor module should have its own go.mod
  2. If the library increases the Risor CLI binary size significantly -> the Risor module should be on a build tag

Back to this PR... I only wonder if you also need an addition to cmd/risor/root.go to activate it in the CLI? I don't think the CLI uses the "all" module.

myzie commented 6 months ago

Back to this PR... I only wonder if you also need an addition to cmd/risor/root.go to activate it in the CLI? I don't think the CLI uses the "all" module.

Nevermind, this is working well in the CLI. Looks good!