Modules only the package may use

A directory whose name starts with _ keeps its modules to the directory it
is in, and to the project's tests/ and benches/.

🤖 Generated with [ECA](https://eca.dev)

Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
Linus Björnstam 2026-10-22 15:36:57 +02:00
parent c791af1593
commit 3173c7176f

View file

@ -313,6 +313,20 @@ Because @code{bjo} automatically detects the project root by walking upward unti
In @code{bjo run . one two}, the dot specifies the project itself. Any arguments following the target are forwarded directly to the program's @code{main} function, binding @code{args} to @code{[one two]}. You can also point @code{bjo run} at a specific test file, such as @code{bjo run tests/deck-test.bjo}; the file will be compiled and linked against the project's declared packages.
@subsubsection{Modules only the package may use}
An export list says what a module offers, but once a module is exported, any module can import it. As a package grows you want helpers that the package's own modules share without them becoming part of what the package offers to others. Put them in a directory whose name starts with an underscore:
@codeblock[#:lang "text"]|{
cards/
src/
_lib/shuffle.bjo (cards _lib shuffle)
deck.bjo may import (cards _lib shuffle)
tests/shuffle-test.bjo may import it too
}|
A module under @code{src/_lib/} may be imported by the modules under @code{src/}, and by the project's own @code{tests/} and @code{benches/}. Any other package that tries is told the module is internal to @code{(cards)}, and should use a module outside @code{_lib/} instead. The rule works for any directory starting with @code{_}, at any depth: a module in @code{src/game/_rules/} is for the modules under @code{src/game/}. The REPL may import anything.
@subsubsection{Libraries}
A package that lacks an executable entry point (@code{src/main.bjo}) is treated as a library. Running @code{bjo init --lib} initializes a library project, and running @code{bjo build} inside it compiles all modules found under @code{src/}.