casey / casey/just

Duplicate recipe and variable override order in imports is backwards

Open
#2,540 3 comments 8 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
35.8k
Forks
846
Avg merge
27m
Merged PRs (30d)
3

Description

When duplicate recipes are in the same module, the later one overrides the earlier one:

```
set allow-duplicate-recipes

foo:

foo:
echo winner
```

When they are in imports, because `just` uses a stack to process imports, the duplicate in the earlier module will win, because it will be processed last:

```
# a.just
foo:
echo winner

# b.just
foo:

# justfile
import 'a.just'
import 'b.just'
```

This was discovered by @redsun82 in #2523.

This is not great behavior, and pretty clearly a bug. I'm not sure, but I don't think we ever considered this case when designing either imports or `allow-duplicate-recipes`. (@neunenak do you have any recollection of this? I'm thinking that we just didn't notice it.)

`just` has a very strong backwards compatibility guarantee, but this is definitely a bug and should probably be fixed.

However, I feel like there are probably a bunch of existing `justfiles` that rely on this behavior, and they're likely especially complicated, so such a bug fix could be disruptive.

The most non-disruptive way to fix it would be:

1. Add a setting which opts into the new behavior
2. Print a warning if a justfile doesn't opt in to the new behavior and doing so would change which recipes are defined
3. Elevate the warning in 2 to an error
4. After some suitably long period of time, change the default to the new behavior, and make the setting a no-op

We could also add a setting which opts into the new behavior, and then wait and see if it's worth actually changing the default behavior.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.