depsight-wasm-api

    MoonBit dependency health analysis engine — WASM API for browser/Node.js

    dependency-analysis
    health-score
    moonbit
    wasm
    license-check
    Download zip
    Author
    Version
    0.8.2
    License
    MIT
    Last updated
    last month
    Downloads
    47

    No dependencies

    #depsight-wasm-api

    MoonBit dependency-health analysis engine, compiled to WebAssembly for browser and Node.js hosts.

    It expands a moon.mod into its full transitive dependency graph, scores dependency health 0–100 across five weighted dimensions, and emits diagnostics with concrete fix suggestions.

    Part of Depsight — the same engine powers the web app, which also ships a line-by-line aligned TypeScript fallback for environments without WASM.

    #Package type

    main is declared as pkgtype(kind: "foreign_library") and built for the wasm-gc target with use-js-builtin-string enabled. Its primary consumption path is therefore the compiled WASM artifact loaded by a JS host, not a typical MoonBit library import (although the exported functions are also callable from MoonBit — see below).

    #Exports

    ExportSignatureDescription
    analyze_from_context_json(String) -> StringFull transitive analysis from a complete context; returns JSON
    analyze_from_mod_text(String) -> StringShallow analysis of a single moon.mod; does not expand dependencies
    version() -> StringABI contract version, currently "0.8.0-wasm"

    With use-js-builtin-string, String parameters and return values map directly to JS strings — no encoding or decoding glue is required on the host side.

    #Usage from JavaScript

    const { instance } = await WebAssembly.instantiateStreaming( fetch("./depsight.wasm"), {}, { builtins: ["js-string"], importedStringConstants: "_" }, ); const resultJson = instance.exports.analyze_from_context_json(contextJson); const result = JSON.parse(resultJson); console.log(result.overall_score, result.diagnostics);

    The compileOptions argument is mandatory. Without builtins: ["js-string"] and importedStringConstants: "_", the wasm:js-string imports and the "_" string-constant module cannot be resolved.

    #Input contract

    analyze_from_context_json takes a JSON string:

    { "root": "<moon.mod.json or moon.mod TOML text>", "modules": { "<name@version>": "<moon.mod.json text>" }, "metadata": { "<name@version>": { "license": "MIT", "latest_version": "1.2.3", "last_commit_days_ago": 45, "self_size": 12345, "total_api_count": 256, "deprecated_apis": ["api1"], "yanked": false, "yanked_reason": null, "source_unavailable": false } }, "options": { "max_depth": 10 } }

    root is the text content of the root module's moon.mod (JSON when it starts with {, otherwise TOML) — not a name@version reference. The same key must also appear in modules.

    analyze_from_mod_text takes the raw moon.mod text directly.

    #Output contract

    Returns a JSON string with:

    overall_score · node_count · parse_warnings · diagnostics · suggestions · health_scores · summary · graph · _root_mod · size_offenders_top5 · node_metas · ecosystem_stats

    On invalid input the result carries an error field instead of a score.

    Diagnostic codes: YANKED-001 · OUTDATED-001 · LICENSE-001 · LICENSE-002 · DEPRECATED-001 · SIZE-001 · ACTIVITY-001 · ACTIVITY-002 · DUP-001 · CYCLE-001

    #Usage from MoonBit

    moon add Tino-hue/depsight-wasm-api

    let v = @main.version()
    let json = @main.analyze_from_mod_text(mod_text)

    #Build from source

    moon build --target wasm-gc --release # artifact: _build/wasm-gc/release/build/main/main.wasm

    The artifact is what a JS host loads; rename or copy it to your static asset path (Depsight ships it as depsight.wasm).

    #Versioning

    Two independent version numbers are in play:

    • Package version (moon.mod, e.g. 0.8.2) — the mooncakes.io release version.
    • ABI contract version (version(), "0.8.0-wasm") — the output-contract generation. The 0.8.x line introduced CYCLE-001, version_resolved, license_source, license_families, license_text fingerprinting, and SPDX normalization.

    Hosts are expected to gate on the ABI contract version prefix (0.8.) rather than the package version, so metadata-only releases do not force host updates. Depsight's loader disables WASM and falls back to the TypeScript implementation when the prefix does not match.

    #Tests

    moon test # 47 tests

    Contract tests in main/engine_test.mbt are mirrored by src/lib/analyzer.test.ts in the web app, asserting identical output from both engines for shared fixtures.

    #License

    MIT — see the repository root LICENSE.