Module Configuration#

moon uses the moon.mod.json file to identify and describe a module. For full JSON schema, please check moon’s repository.

Name#

The name field is used to specify the name of the module, and it is required.

{
  "name": "example",
  // ...
}

The module name can contain letters, numbers, _, -, and /.

For modules published to mooncakes.io, the module name must begin with the username. For example:

{
  "name": "moonbitlang/core",
  // ...
}

Version#

The version field is used to specify the version of the module.

This field is optional. For modules published to mooncakes.io, the version number must follow the Semantic Versioning 2.0.0 specification.

{
  "name": "example",
  "version": "0.1.0",
  // ...
}

Deps#

The deps field is used to specify the dependencies of the module.

It is automatically managed by commands like moon add and moon remove.

{
  "name": "username/hello",
  "deps": {
    "moonbitlang/x": "0.4.6"
  }
}

README#

The readme field is used to specify the path to the module’s README file.

Repository#

The repository field is used to specify the URL of the module’s repository.

License#

The license field is used to specify the license of the module. The license type must comply with the SPDX License List.

{
  "license": "MIT"
}

Keywords#

The keywords field is used to specify the keywords for the module.

{
  "keywords": ["example", "test"]
}

Description#

The description field is used to specify the description of the module.

{
  "description": "This is a description of the module."
}

Source directory#

The source field is used to specify the source directory of the module.

It must be a subdirectory of the directory where the moon.mod.json file is located and must be a relative path.

When creating a module using the moon new command, a src directory will be automatically generated, and the default value of the source field will be src.

{
  "source": "src"
}

When the source field does not exist, or its value is null or an empty string "", it is equivalent to setting "source": ".". This means that the source directory is the same as the directory where the moon.mod.json file is located.

{
  "source": null
}
{
  "source": ""
}
{
  "source": "."
}

Warning List#

This is used to disable specific preset compiler warning numbers.

For example, in the following configuration, -2 disables the warning number 2 (Unused variable).

{
  "warn-list": "-2",
}

You can use moonc build-package -warn-help to see the list of preset compiler warning numbers.

$ moonc -v                      
v0.1.20240914+b541585d3

$ moonc build-package -warn-help
Available warnings: 
  1 Unused function.
  2 Unused variable.
  3 Unused type declaration.
  4 Redundant case in a pattern matching (unused match case).
  5 Unused function argument.
  6 Unused constructor.
  7 Unused module declaration.
  8 Unused struct field.
 10 Unused generic type variable.
 11 Partial pattern matching.
 12 Unreachable code.
 13 Unresolved type variable.
 14 Lowercase type name.
 15 Unused mutability.
 16 Parser inconsistency.
 18 Useless loop expression.
 19 Top-level declaration is not left aligned.
 20 Invalid pragma
 21 Some arguments of constructor are omitted in pattern.
 22 Ambiguous block.
 23 Useless try expression.
 24 Useless error type.
 26 Useless catch all.
  A all warnings

Alert List#

Disable user preset alerts.

{
  "alert-list": "-alert_1-alert_2"
}