Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mpharmony平台路由api不要tree-shaking处理 #561

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions packages/taro-mpharmony/src/api/route/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
/**
* @canUse navigateBack
* @__object [delta]
*/

/**
* @canUse navigateTo
* @__object [url, events]
*/

/**
* @canUse redirectTo
* @object [url]
*/

/**
* @canUse reLaunch
* @__object [url]
*/

/**
* @canUse switchTab
* @__object [url]
*/

export { navigateBack, navigateTo, redirectTo, reLaunch, switchTab } from '@tarojs/router'

// FIXME 方法导出类型未对齐,后续修复
Expand Down
68 changes: 67 additions & 1 deletion packages/taro-mpharmony/src/api/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ export * from './background-fetch'
export const createCacheManager = /* @__PURE__ */ temporarilyNotSupport('createCacheManager')


/**
* Taro.setStorage 的同步版本
*
* @canUse setStorageSync
* @__object [key, data]
*/
export const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
const status = native.setStorageSync({ key, data: JSON.stringify(handleData(data)) })
displayExecRes(status, setStorageSync.name)
}

/**
* 将数据存储在本地缓存中指定的 key 中
*
* @canUse setStorage
* @__object [data, key]
*/
// @ts-ignore
export const setStorage: typeof Taro.setStorage = (options) => {
// options must be an Object
Expand All @@ -48,13 +60,29 @@ export const setStorage: typeof Taro.setStorage = (options) => {
})
}

/**
* 根据 URL 销毁存在内存中的数据
*
* @canNotUse revokeBufferURL
*/
export const revokeBufferURL = /* @__PURE__ */ temporarilyNotSupport('revokeBufferURL')

/**
* Taro.removeStorage 的同步版本
*
* @canUse removeStorageSync
*/
export const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
const status = native.removeStorageSync({ key })
displayExecRes(status, removeStorageSync.name)
}

/**
* 从本地缓存中移除指定 key
*
* @canUse removeStorage
* @__object [key]
*/
export const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
// options must be an Object
const isObject = shouldBeObject(options)
Expand All @@ -79,6 +107,11 @@ export const removeStorage: typeof Taro.removeStorage = (options: Taro.removeSto
})
}

/**
* Taro.getStorage 的同步版本
*
* @canUse getStorageSync
*/
// @ts-ignore
export const getStorageSync: typeof Taro.getStorageSync = (key) => {
const status = native.getStorageSync({ key })
Expand All @@ -95,6 +128,13 @@ export const getStorageSync: typeof Taro.getStorageSync = (key) => {
return ''
}

/**
* 从本地缓存中异步获取指定 key 的内容
*
* @canUse getStorage
* @__object [key]
* @__success [data]
*/
export const getStorage: typeof Taro.getStorage = <T>(options) => {
// options must be an Object
const isObject = shouldBeObject(options)
Expand Down Expand Up @@ -136,7 +176,12 @@ export const getStorage: typeof Taro.getStorage = <T>(options) => {

}


/**
* Taro.getStorageInfo 的同步版本
*
* @canUse getStorageInfoSync
* @__return [currentSize, keys, limitSize]
*/
export const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
const res: Taro.getStorageInfoSync.Option = {
keys: [],
Expand All @@ -152,6 +197,12 @@ export const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
return res
}

/**
* 异步获取当前storage的相关信息
*
* @canUse getStorageInfo
* @__success [currentSize, keys, limitSize]
*/
export const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
const handle = new MethodHandler<Taro.getStorageInfo.SuccessCallbackOption>({
name: 'getStorageInfo',
Expand All @@ -178,13 +229,28 @@ export const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, comp
}


/**
* 根据传入的 buffer 创建一个唯一的 URL 存在内存中
*
* @canNotUse createBufferURL
*/
export const createBufferURL = /* @__PURE__ */ temporarilyNotSupport('createBufferURL')

/**
* Taro.clearStorage 的同步版本
*
* @canUse clearStorageSync
*/
export const clearStorageSync: typeof Taro.clearStorageSync = () => {
const status = native.clearStorageSync({ key: '' })
displayExecRes(status, clearStorageSync.name)
}

/**
* 清除storage信息
*
* @canUse clearStorage
*/
export const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"onStop": true,
"onTimeUpdate": true
},
"CacheManager": false,
"CameraContext": {
"startRecord": true,
"stopRecord": true,
Expand Down Expand Up @@ -1284,18 +1283,7 @@
"phoneNumber": true
}
},
"navigateBack": {
"object": {
"delta": true
}
},
"navigateBackMiniProgram": false,
"navigateTo": {
"object": {
"url": true,
"events": true
}
},
"navigateToMiniProgram": {
"object": {
"appId": true,
Expand Down Expand Up @@ -1592,19 +1580,13 @@
"current": true
}
},
"reLaunch": {
"object": {
"url": true
}
},
"readBLECharacteristicValue": {
"object": {
"characteristicId": true,
"deviceId": true,
"serviceId": true
}
},
"redirectTo": true,
"removeSavedFile": {
"object": {
"filePath": true
Expand Down Expand Up @@ -1943,11 +1925,6 @@
"stopVoice": false,
"stopWifi": true,
"subscribeVoIPVideoMembers": false,
"switchTab": {
"object": {
"url": true
}
},
"tradePay": false,
"updateShareMenu": false,
"updateVoIPChatMuteConfig": false,
Expand Down
5 changes: 4 additions & 1 deletion packages/taro-platform-mpharmony/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ export default class H5 extends TaroPlatformWeb {
const rules = chain.module.rules
const script = rules.get('script')
const babelLoader = script.uses.get('babelLoader')
const routerApis = new Set(['navigateTo', 'navigateBack', 'redirectTo', 'reLaunch', 'switchTab'])
let apis = require(resolveSync('./taroApis'))
apis = new Set(Array.from(apis).filter((x: string) => !routerApis.has(x)))
babelLoader.set('options', {
...babelLoader.get('options'),
plugins: [
[
require('babel-plugin-transform-taroapi'),
{
packageName: '@tarojs/taro',
apis: require(resolveSync('./taroApis')),
apis,
definition: require(this.libraryDefinition),
},
],
Expand Down
Loading