moon-manifest

    Lossless MoonBit manifest queries and edits

    moonbit
    manifest
    moon-mod
    moon-pkg
    moon-work
    Download zip
    Author
    Version
    0.2.0-alpha.2
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    154

    #unmbt/moon-manifest

    Lossless readers and editors for MoonBit moon.mod, moon.pkg, and moon.work files.

    The package is used by MoonBit release and dependency tools that need to inspect or update a manifest without reformatting it. Parsing is delegated to moonbitlang/moon_config, while edits replace only the selected string value and preserve comments, whitespace, line endings, and unrelated fields.

    #Install

    moon add unmbt/moon-manifest

    Then import the package from MoonBit:

    import "unmbt/moon-manifest"

    #Example

    let document = @manifest.parse(
    @manifest.Kind::Mod,
    "name = \"example/app\"\nversion = \"0.1.0\"\n",
    )
    let name = document.module_name()
    let updated = document.replace_string("version", "0.2.0")

    Document::dependency_version reads a dependency from a parsed manifest; Document::members reads workspace members; Document::find_string returns a byte span for a scalar string; and Document::replace_string performs a lossless replacement. Document::diagnostics exposes parser diagnostics with byte offsets into the original UTF-8 source.

    The 0.2 alpha adds AST-scoped string_field, field_span, member_entries, dependencies, and is_private queries. Located values refer to complete literals in the original UTF-8 bytes (including quotes). Import spans cover the whole name@version literal. Duplicate imports and unsupported module import aliases/kinds are diagnosed instead of omitted. BOM and CRLF input are preserved. is_private describes registry visibility, not an npm-style prohibition on publishing.

    The CLI uses moonbitlang/core/async; the library itself has no async dependency.

    #Supported files and targets

    Kind::Mod, Kind::Pkg, and Kind::Work correspond to the three MoonBit manifest formats. The package targets native because it is intended for CLI, release, and workspace tooling.

    #License

    MIT

    Dependency

    pub struct Dependency {
    name : String
    version : String
    span : Span
    } derive(Eq,
    Debug
    )

    Dependency::equal

    fn Dependency::equal(Dependency, Dependency) -> Bool

    Dependency::not_equal

    fn Dependency::not_equal(x : Dependency, y : Dependency) -> Bool

    Diagnostic

    pub struct Diagnostic {
    message : String
    start : Int
    end : Int
    } derive(Eq,
    Debug
    )

    A diagnostic reported by moon_config or by the lossless edit layer.

    Diagnostic::equal

    fn Diagnostic::equal(Diagnostic, Diagnostic) -> Bool

    Diagnostic::not_equal

    fn Diagnostic::not_equal(x : Diagnostic, y : Diagnostic) -> Bool

    Document

    pub struct Document {
    kind : Kind
    path : String
    source : Bytes
    diagnostics : Array[Diagnostic]
    // private fields
    } derive(
    Debug
    )

    A parsed manifest. source is retained byte-for-byte for stale-plan checks.

    Document::dependencies

    fn Document::dependencies(self : Document) -> Array[Dependency]

    Import literal spans include the name, version, and surrounding quotes.

    Document::dependency_version

    fn Document::dependency_version(self : Document, dependency : String) -> String?

    Document::field_span

    fn Document::field_span(self : Document, key : String) -> Span?

    Document::find_string

    fn Document::find_string(self : Document, key : String) -> Span?

    Find a scalar string assignment without changing comments or surrounding bytes.

    Document::is_private

    fn Document::is_private(self : Document) -> Bool

    A MoonBit private module requests restricted registry visibility.

    Document::member_entries

    fn Document::member_entries(self : Document) -> Array[LocatedString]

    Document::members

    fn Document::members(self : Document) -> Array[String]

    Document::module_name

    fn Document::module_name(self : Document) -> String?

    Document::replace_string

    fn Document::replace_string(self : Document, key : String, value : String) -> String

    Replace the first key = "..." or "key": "..." value.

    Document::string_field

    fn Document::string_field(self : Document, key : String) -> LocatedString?

    Query a top-level string field, never a nested field with the same name.

    Document::to_repr

    Document::version

    fn Document::version(self : Document) -> String?

    Kind

    pub(all) enum Kind {
    Mod
    Pkg
    Work
    } derive(Eq,
    Debug
    )

    A supported MoonBit configuration file.

    Kind::equal

    fn Kind::equal(Kind, Kind) -> Bool

    Kind::not_equal

    fn Kind::not_equal(x : Kind, y : Kind) -> Bool

    Kind::to_repr

    LocatedString

    pub struct LocatedString {
    value : String
    span : Span
    } derive(Eq,
    Debug
    )

    A value and its complete literal span in the original UTF-8 source.

    LocatedString::equal

    LocatedString::not_equal

    fn LocatedString::not_equal(x : LocatedString, y : LocatedString) -> Bool

    Span

    pub struct Span {
    start : Int
    end : Int
    } derive(Eq,
    Debug
    )

    A byte range in the original UTF-8 source.

    Span::equal

    fn Span::equal(Span, Span) -> Bool

    Span::not_equal

    fn Span::not_equal(x : Span, y : Span) -> Bool

    Span::to_repr

    parse

    fn parse(kind : Kind, source : String, path? : String) -> Document