Skip to main content

Overview

@morjs/runtime-mini provides the runtime shim layer that allows a mini-program written for one platform (Alipay or WeChat) to run on a different native platform without source changes. It is injected automatically by the MorJS compiler.
PropertyValue
Package@morjs/runtime-mini
Source platformsalipay, wechat
Target platformsalipay, wechat, baidu, bytedance, qq, kuaishou

Installation

npm install @morjs/runtime-mini

Primary export

initAdapters

Initialises all runtime adapters needed to translate the source platform’s APIs, page lifecycles, and component lifecycles to the target platform.
function initAdapters(options: InitAdapterOptions): void

interface InitAdapterOptions {
  sourceType: 'alipay' | 'wechat'
  target: string
  createApi: (
    api?: any,
    options?: any
  ) => { override: () => any } & Record<string, any>
  registerComponentAdapters: (adapters?: any[]) => void
  registerPageAdapters: (adapters?: any[]) => void
}
options.sourceType
'alipay' | 'wechat'
required
The DSL the source code was written in.
options.target
string
required
The target runtime platform.
options.createApi
function
required
Factory function that wraps the platform’s global API object and returns an override() method to install the translation layer.
options.registerComponentAdapters
function
required
Reference to registerComponentAdapters from @morjs/core.
options.registerPageAdapters
function
required
Reference to registerPageAdapters from @morjs/core.
initAdapters returns immediately without registering any adapters when sourceType === target.

Platform directories

Each directory inside src/ contains adapter modules for a specific cross-platform translation direction.

alipay/

Adapters for Alipay source code running on other platforms.
ModulePurpose
apisToAlipayNo-op shim (source = target)
apisToOtherTranslates Alipay APIs to generic cross-platform equivalents
apisToWechatAlipay → WeChat API translation
componentToAlipayTranslates other platform component options to Alipay format
componentToOtherTranslates Alipay component options to other platforms
pageToAlipayTranslates page options to Alipay format
pageToOtherTranslates Alipay page options to other platforms

wechat/

Adapters for WeChat source code running on other platforms.
ModulePurpose
componentToOtherTranslates WeChat component options to Kuaishou and similar
pageToOtherTranslates WeChat page options to Kuaishou and similar

baidu/

ModulePurpose
apisAPI translation layer for Baidu Smart Mini-Program

bytedance/

ModulePurpose
apisAPI translation layer for ByteDance (Douyin / Toutiao) mini-programs

qq/

ModulePurpose
apisAPI translation layer for QQ mini-programs

kuaishou/

ModulePurpose
apisAPI translation layer for Kuaishou mini-programs

common/

Shared utilities and helpers used by multiple adapter modules.

Adapter selection matrix

The table below shows which adapters initAdapters activates for each source/target combination.
SourceTargetAPI adapterComponent adapterPage adapter
alipaywechatapisToWechat + apisToOtheralipayComponentToOtheralipayPageToOther
alipaybaiduapisToBaidu + apisToOtheralipayComponentToOtheralipayPageToOther
alipaybytedanceapisToByteDance + apisToOtheralipayComponentToOtheralipayPageToOther
alipayqqapisToQQ + apisToOtheralipayComponentToOtheralipayPageToOther
alipaykuaishouapisToKuaishou + apisToOtheralipayComponentToOtheralipayPageToOther
wechatalipayapisToAlipayotherComponentToAlipaypageToAlipay
wechatbaiduapisToBaidu
wechatbytedanceapisToByteDanceotherComponentToAlipaypageToAlipay
wechatqqapisToQQ
wechatkuaishouapisToKuaishouwechatComponentToOtherwechatPageToOther

Build docs developers (and LLMs) love