Skip to content

Should document cue.mod/module.cue and module vs package #2186

Closed

Description

@jpadams

What is the issue?

After a dagger project init (without args), the created cue.mod/module.cue file contains:

module: ""

It's not clear to a new user what that means (if something is missing/wrong) and if it's related to the package name in their cue files.

https://cuelang.org/docs/concepts/packages/#packages
https://cuelang.org/docs/concepts/packages/#modules
https://cuelang.org/docs/tutorials/tour/packages/packages/
https://cuelang.org/docs/tutorials/tour/packages/imports/
#1685

It's also probably not clear to new users when they need to create a module name and how it relates to package name when building a dagger package destined to be shared (often via github, etc).

#2175

foo ➤ dagger project init --name github.com/jpadams/foo
foo ➤ cat cue.mod/module.cue
module: "github.com/jpadams/foo"%

Activity

  1. added
    area/documentation
    on Apr 13, 2022
  2. morlay commented on Apr 21, 2022

    @morlay
    Contributor

    it is old issue of cue

    once official mod manager support, it goes better.

    cue-lang/cue#851

    I created a simple one for now.
    https://github.com/octohelm/cuemod

  3. helderco commented on May 6, 2022

    @helderco
    Contributor

    TLDR: The use of a module is optional, but required if one wants to import files from it.

    Documentation for this is being worked on:

    I can help give a bit o clarity in the meantime.

    In summary:

    • CUE Package: directory with cue files, each including a package definition on top, making it importable (e.g, universe.dagger.io/docker is a package, universe.dagger.io/docker/cli is another package);
    • CUE Module: directory with a cue.mod directory which makes for the prefix/root of importable packages (e.g, universe.dagger.io is a module;

    Anonymous module (default)

    The default module name is an empty string, which means it's anonymous. That's when you don't need to import other packages inside your module. It represents most cases where someone has a dagger plan and imports everything from third-party packages like universe.

    When to use a module

    You can add a different module name, if you want to import other packages from inside your module. This is required so you have a prefix/root before your imports. This is when you want to split your code into multiple files.

    The module path becomes the import path prefix for packages in the module. This might be the name of a domain you own or another name you control (such as your company name), even your email, followed optionally by a descriptive path (e.g., project name).

    You import packages by prefixing the module name they're a part of, plus the path to them, relative to the cue.mod directory.

    Example:

    root                    // <- this is a module because it includes a cue.mod dir
    |-- cue.mod
    |   |-- module.cue      // module: "example.com/pkg"
    |-- schemas
    |   |-- compose         // <- this is a package because it includes files with a package directive
    |   |   |-- spec.cue    // package compose
    ...
    |-- plan.cue            // import "example.com/pkg/schemas/compose"
    

    /cc @grouville

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions