Skip to content

Commit

Permalink
fix(runtime-mini): replace @morjs/api with @morjs/runtime-base to avo…
Browse files Browse the repository at this point in the history
…id cycle references
  • Loading branch information
lyfeyaj committed Mar 10, 2023
1 parent 5d22b11 commit 84b4a0c
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/runtime-mini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
},
"sideEffects": false,
"dependencies": {
"@morjs/api": "1.0.0",
"@morjs/core": "1.0.4",
"@morjs/runtime-base": "1.0.0",
"clone-deep": "^4.0.1",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/apisToAlipay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
IAPITransformConfig,
logger,
transformApis
} from '@morjs/api'
} from '@morjs/runtime-base'
import { needPromisfiedApis } from './needPromisfiedApis'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/apisToOther.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IAPITransformConfig,
logger,
transformApis
} from '@morjs/api'
} from '@morjs/runtime-base'
import { needPromisfiedApis } from './needPromisfiedApis'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/behaviorToAlipay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '@morjs/api'
import { logger } from '@morjs/runtime-base'
import type { BehaviorOptions, DefinitionFilter } from './utilsToAlipay'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/componentToAlipay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compose, getGlobalObject, logger } from '@morjs/api'
import { compose, getGlobalObject, logger } from '@morjs/runtime-base'
import get from 'lodash.get'
import has from 'lodash.has'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/componentToOther.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
generateId,
getSharedProperty,
logger
} from '@morjs/api'
} from '@morjs/runtime-base'
import clone from 'clone-deep'
import { addEventProxy, injectInstanceMethodsSupport } from './utilsToOther'

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/pageToAlipay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compose } from '@morjs/api'
import { compose } from '@morjs/runtime-base'
import {
injectComponentSelectorMethodsSupport,
injectCreateIntersectionObserverSupport,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/utilsToAlipay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, markAsUnsupport } from '@morjs/api'
import { getGlobalObject, markAsUnsupport } from '@morjs/runtime-base'

/**
* 标记不支持的实例方法
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/alipay/utilsToOther.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSharedProperty, logger } from '@morjs/api'
import { getSharedProperty, logger } from '@morjs/runtime-base'

interface IEventDetail {
name?: string
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/baidu/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, transformApis } from '@morjs/api'
import { getGlobalObject, transformApis } from '@morjs/runtime-base'
import { needPromisfiedApis as needPromisfiedApisForWechat } from '../wechat/apis'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/bytedance/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, transformApis } from '@morjs/api'
import { getGlobalObject, transformApis } from '@morjs/runtime-base'
import { needPromisfiedApis as needPromisfiedApisForWechat } from '../wechat/apis'

/**
Expand Down
34 changes: 23 additions & 11 deletions packages/runtime-mini/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { createApi, MorAPIAdapter } from '@morjs/api'
import {
MorComponentAdapter,
MorPageAdapter,
registerComponentAdapters,
registerPageAdapters
} from '@morjs/core'
import * as apisToAlipay from './alipay/apisToAlipay'
import * as apisToOther from './alipay/apisToOther'
import * as componentToAlipay from './alipay/componentToAlipay'
Expand All @@ -17,20 +10,39 @@ import * as apisToKuaishou from './kuaishou/apis'
import * as apisToQQ from './qq/apis'
import * as apisToWechat from './wechat/apis'

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
}

/**
* 初始化转端适配逻辑
* @param sourceType - 源码类型
* @param target - 目标平台
*/
export function initAdapters(sourceType: 'alipay' | 'wechat', target: string) {
export function initAdapters(options: InitAdapterOptions) {
const {
sourceType,
target,
createApi,
registerComponentAdapters,
registerPageAdapters
} = options || {}

// 源码和目标平台一致时不转换
if (sourceType === target) return

// target 的 adapter 需要放在 source adapter 之前
// 和编译时自动注入逻辑保持一致
const componentAdapters: MorComponentAdapter[] = []
const pageAdapters: MorPageAdapter[] = []
const apiAdapters: MorAPIAdapter[] = []
const componentAdapters: Record<string, any>[] = []
const pageAdapters: Record<string, any>[] = []
const apiAdapters: Record<string, any>[] = []

// 支付宝转其他端
if (sourceType === 'alipay') {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/kuaishou/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, transformApis } from '@morjs/api'
import { getGlobalObject, transformApis } from '@morjs/runtime-base'
import { needPromisfiedApis as needPromisfiedApisForWechat } from '../wechat/apis'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/qq/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, transformApis } from '@morjs/api'
import { getGlobalObject, transformApis } from '@morjs/runtime-base'
import { needPromisfiedApis as needPromisfiedApisForWechat } from '../wechat/apis'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-mini/src/wechat/apis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalObject, transformApis } from '@morjs/api'
import { getGlobalObject, transformApis } from '@morjs/runtime-base'

/**
* 微信需要被 promisified 的接口
Expand Down

0 comments on commit 84b4a0c

Please sign in to comment.