Skip to content

request: Support YAML anchors to in Melos YAML schema to limit repetition #571

Description

@wujek-srujek

Is there an existing feature request for this?

  • I have searched the existing issues.

Command

No response

Description

Suppose melos.yaml to contain:

scripts:
  foo:
    run: echo foo
    exec:
      concurrency: 1
      orderDependents: true
  
  bar:
    run: echo bar
    exec:
      concurrency: 1
      orderDependents: true

  baz:
    run: echo baz
    exec:
      concurrency: 1
      orderDependents: true

As you can see, the exec configuration is repeated over and over. YAML supports anchors and aliases, so we can instead write this:

x-exec: &execConfig
  concurrency: 1
  orderDependents: true

scripts:
  foo:
    run: echo foo
    exec: *execConfig
  
  bar:
    run: echo bar
    exec: *execConfig

  baz:
    run: echo baz
    exec: *execConfig

This already works and nothing needs to be done, this YAML feature is supported by the Dart YAML parser.

The only 'issue' is that if the Melos plugin is installed, which turns on Melos YAML schema validiation (or without the plugin, validation can also be turned on) this causes an error:
Screenshot 2023-08-24 at 12 51 05

The name x-exec is arbitrary and can be whatever, and it is not expected, hence the error, but this can be fixed. As an example, Docker Compose uses YAML as well for its config and it allows 'extension fields': https://docs.docker.com/compose/compose-file/compose-file-v3/#extension-fields (this is where the x- prefix comes from in my example). Here is how they do it: https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json (search for x-), here more about 'pattern properties': https://json-schema.org/understanding-json-schema/reference/object.html#pattern-properties

Would it be possible to make it work for Melos as well?

Reasoning

This would make the schema more flexible and ready for more advanced YAML features, which are already supported anyway.

Additional context and comments

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions