Skip to content

API HotPatch

Liu.Yandong.Hanks edited this page Aug 19, 2026 · 3 revisions

HotPatch

模块运行时更新

Runtime module updates

脚本 API 目录

概述

HotPatch 仅在宿主启用热更新时可用。补丁的顶层代码会在应用时执行,因此只应对可信脚本和经过验证的模块图使用。replace 清空目标模块原有成员后应用新代码;incremental 保留现有成员并新增或覆盖补丁声明。

HotPatch is available only when the host enables hot reload. Top-level patch code runs while the patch is applied, so use it only for trusted scripts and validated module graphs. replace clears existing target members before applying new code; incremental retains members and adds or overwrites declarations from the patch.

HotPatch.replace(script, [ignoreDepends])

Parameters:

  • script
    当前模块的完整替换源码。

    Complete replacement source for the current module.

  • ignoreDepends
    可选布尔值,是否忽略依赖更新。

    Optional Boolean controlling whether dependency updates are ignored.

Returns

null

null.

@module(MAIN);

export func replaceSelf() {
    HotPatch.replace("@module(MAIN); export func run() { return 42; }");
    return 0;
}

HotPatch.replace(modulePath, script, [ignoreDepends])

Parameters:

  • modulePath
    目标模块路径;相对路径相对当前模块目录解析。

    Target module path; relative paths resolve from the current module directory.

  • script
    完整替换源码。

    Complete replacement source.

  • ignoreDepends
    可选依赖开关。

    Optional dependency flag.

Returns

null

null.

HotPatch.replace("./feature", "@module(FEATURE); export func run() { return 1; }");

HotPatch.incremental(script, [ignoreDepends])

Parameters:

  • script
    当前模块的增量补丁源码。

    Incremental patch source for the current module.

  • ignoreDepends
    可选依赖开关。

    Optional dependency flag.

Returns

null

null.

HotPatch.incremental("export func added() { return 7; }");

HotPatch.incremental(modulePath, script, [ignoreDepends])

Parameters:

  • modulePath
    目标模块路径。

    Target module path.

  • script
    增量源码。

    Incremental source.

  • ignoreDepends
    可选依赖开关。

    Optional dependency flag.

Returns

null

null.

HotPatch.incremental("./feature", "export func refresh() { return true; }");

Clone this wiki locally