request: Support YAML anchors to in Melos YAML schema to limit repetition
- Dominant language
- Dart
- Stars
- 1.5k
- Forks
- 259
- Avg merge
- 2h 57m
- Merged PRs (30d)
- 21
Description
### Is there an existing feature request for this?
- [X] I have searched the existing issues.
### Command
_No response_
### Description
Suppose `melos.yaml` to contain:
```yaml
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:
```yaml
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:
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_
Contributor guide
Research direction
Start by locating Melos's YAML schema validation and the schema definition used for melos.yaml, then reproduce the issue with the x-exec anchor example from the report. Done means arbitrary extension fields used for YAML anchors are accepted while regular Melos configuration remains validated; no specific files or tests are named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100