cue-lang / docs-and-content

A place to discuss, plan, and track documentation on cuelang.org
6 stars 1 forks source link

`import "path:_"` syntax is entirely undocumented #148

Closed jpluscplusm closed 5 months ago

jpluscplusm commented 6 months ago

What page were you looking at?

https://cuelang.org/docs/concept/modules-packages-instances/

What version of the site were you looking at?

https://github.com/cue-lang/cuelang.org/commit/9adb346c4051adcbb933db4ba9bcf5a31c1acc8b

What's the problem?

https://pkg.go.dev/cuelang.org/go/cue/load#Config says that a :_ package identifier means that CUE will

load files without a package

This also works with the cue command, as demonstrated by this passing test:

exec cue export .:_
cmp stdout out
-- package.cue --
package main

x: 1
-- noPackage.cue --
x: 2
-- out --
{
    "x": 2
}

The other "special value" mentioned on https://pkg.go.dev/cuelang.org/go/cue/load#Config, *, doesn't appear to achieve anything when passed to cue.

The page at https://cuelang.org/docs/concept/modules-packages-instances/#for-those-familiar-with-go-packages says that:

The package clause is optional: such files do not belong to a package and cannot be imported.

This is not the case.

Whilst this page is likely to have a significant overhaul in the light of the acceptance of the modules proposal, this issue tracks that we don't document the :_ syntax anywhere.

Perhaps we shouldn't document it, if there's any chance that the syntax might be removed, pre-1.0. For what it's worth, today is the first time I've ever seen anyone use or mention it (https://cuelang.slack.com/archives/CLT3ULF6C/p1715880703603439)

myitcv commented 6 months ago

Note that I've raised https://github.com/cue-lang/cue/issues/3167; it's not clear to me that we should actually support :_ in import paths, so I would put any work on this issue on hold pending resolution of that issue.

myitcv commented 5 months ago

I'm going to close this on the basis we are indeed going to fix the bug that allowed this behaviour.