模块配置#
moon 使用 moon.mod.json
文件来标识和描述一个模块。访问 moon 的仓库 查看完整的 JSON 模式。
名称#
name
字段用于指定模块的名称,它是必需的。
{
"name": "example",
// ...
}
模块名称可以包含字母、数字、_
、-
和 /
。
对于发布到 mooncakes.io 的模块,模块名称必须以用户名开头。例如:
{
"name": "moonbitlang/core",
// ...
}
版本#
version
字段用于指定模块的版本。
此字段是可选的。对于发布到 mooncakes.io 的模块,版本号必须遵循 语义化版本 2.0.0 规范。
{
"name": "example",
"version": "0.1.0",
// ...
}
依赖#
deps
字段用于指定模块的依赖项。
它由 moon add
和 moon remove
等命令自动管理。
{
"name": "username/hello",
"deps": {
"moonbitlang/x": "0.4.6"
}
}
README#
readme
字段用于指定模块的 README 文件的路径。
仓库#
repository
字段用于指定模块的仓库的 URL。
许可证#
license
字段用于指定模块的许可证。许可证类型必须符合 SPDX 许可证列表。
{
"license": "MIT"
}
关键字#
keywords
字段用于指定模块的关键字。
{
"keywords": ["example", "test"]
}
描述#
description
字段用于指定模块的描述。
{
"description": "This is a description of the module."
}
源目录#
source
字段用于指定模块的源目录。
它必须是 moon.mod.json
文件所在目录的子目录,并且必须是相对路径。
当使用 moon new
命令创建一个模块时,将自动生成一个 src
目录,并且 source
字段的默认值将为 src
。
{
"source": "src"
}
如果 source
字段不存在,或其值为 null
或空字符串 ""
,则等同于设置 "source": "."
。这意味着源目录与 moon.mod.json
文件所在目录相同。
{
"source": null
}
{
"source": ""
}
{
"source": "."
}
警告列表#
这用于禁用特定的预设编译器警告编号。
例如,在以下配置中,-2
禁用警告编号 2(未使用的变量)。
{
"warn-list": "-2",
}
你可以使用 moonc build-package -warn-help
来查看预设编译器警告编号列表。
$ 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": "-alert_1-alert_2"
}