cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.03k stars 287 forks source link

cue/load: do not include module ancestor files in the same package by default; make optional #2000

Open myitcv opened 1 year ago

myitcv commented 1 year ago

Currently, per https://cuelang.org/docs/concepts/packages/:

Within a module, all .cue files with the same package name are part of the same package. A package is evaluated within the context of a certain directory. Within this context, only the files belonging to that package in that directory and its ancestor directories within the module are combined. We call that an instance of a package.

As a demonstration of the current behaviour, the following test passes:

exec cue eval ./...
cmp stdout stdout.golden

-- cue.mod/module.cue --
module: "example.com"
-- root.cue --
package example

x: a: 5
-- subdir/subdir.cue --
package example

x: b: 4
-- stdout.golden --
x: {
    a: 5
}
// ---
x: {
    a: 5
    b: 4
}

Feedback from many users has shown this to be a confusing behaviour by default in certain situations:

This umbrella issue tracks:

  1. Changing the default behaviour of CUE to not include ancestor files in the same package. From experience, this is the most commonly expected default.
  2. Proving a configuration option to enable the current default behaviour.

Concretely, the new proposed default would result in the following test passing:

exec cue eval ./...
cmp stdout stdout.golden

-- cue.mod/module.cue --
module: "example.com"
-- root.cue --
package example

x: a: 5
-- subdir/subdir.cue --
package example

x: b: 4
-- stdout.golden --
x: {
    a: 5
}
// ---
x: {
    b: 4
}

Open questions

myitcv commented 1 year ago

As part of this issue we should also consider how/where cue.mod/{usr,gen} fit into the picture.

myitcv commented 1 year ago

Linking to https://github.com/cue-lang/cue/issues/2004, because a change in the default should be gated on a language/toolchain version.