@tarojs/plugin-platform-harmony-cpp 4.1.0-alpha.0 → 4.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tarojs/plugin-platform-harmony-cpp
2
2
 
3
- ## 功能
3
+ ## 快速开始
4
4
 
5
5
  ### 安装和使用
6
6
 
@@ -23,24 +23,49 @@
23
23
  // ...
24
24
  plugin: ['@tarojs/plugin-platform-harmony-cpp'],
25
25
  harmony: {
26
+ // 当前仅支持使用 Vite 编译鸿蒙应用
26
27
  compiler: 'vite',
27
- projectPath: path.join(os.homedir(), 'projects/my-business-module'),
28
- hapName: 'library',
28
+ // Note: 鸿蒙工程路径,可以参考 [鸿蒙应用创建导读](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V2/start-with-ets-stage-0000001477980905-V2) 创建
29
+ projectPath: path.join(os.homedir(), 'projects/my-business-project'),
30
+ // Taro 项目编译到对应鸿蒙模块名,默认为 entry
31
+ hapName: 'entry',
29
32
  },
30
33
  // ...
31
34
  }
32
35
  ```
33
36
 
37
+ ### 编译项目
38
+
39
+ ```sh
40
+ # 编译鸿蒙应用
41
+ $ taro build --type harmony_cpp
42
+ # 编译鸿蒙原生组件
43
+ $ taro build native-components --type harmony_cpp
44
+ ```
45
+
46
+ 如果需要编译鸿蒙应用,同时使用编译鸿蒙原生组件,可以在页面配置中添加 `entryOption: false` 表示该页面是组件,同时可以用过 `componentName` 指定组件导出名。
47
+
48
+ ```diff
49
+ export default {
50
+ navigationBarTitleText: 'Hello World',
51
+ + componentName: 'MyComponent',
52
+ + entryOption: false,
53
+ }
54
+ ```
55
+
56
+ ## 功能
57
+
34
58
  ### 使用公共依赖库
35
59
 
36
- 插件默认使用对应版本的公共依赖库,可以通过 useChoreLibrary 配置禁用。
60
+ 插件默认使用内置版本的公共依赖库,可以通过 useChoreLibrary 配置禁用或者配置指定版本依赖。
37
61
 
38
62
  ```ts
39
63
  const config = {
40
64
  // ...
41
65
  plugin: [
42
- '@tarojs/plugin-platform-harmony-cpp',
66
+ '@tarojs/plugin-platform-harmony-cpp', // useChoreLibrary: 'local'
43
67
  // ['@tarojs/plugin-platform-harmony-cpp', { useChoreLibrary: false }],
68
+ // ['@tarojs/plugin-platform-harmony-cpp', { useChoreLibrary: '4.1.0-alpha.0' }],
44
69
  ],
45
70
  harmony: {
46
71
  ohPackage: {
@@ -55,7 +80,7 @@ const config = {
55
80
 
56
81
  插件版本可以通过 `ohPackage.dependencies` 配置或者鸿蒙工程内 `oh-package.json5` 配置覆盖。
57
82
 
58
- ## 类型定义
83
+ ### 类型定义
59
84
 
60
85
  需要在 Taro 项目的 types/global.d.ts 文件夹里添加对插件类型的引用
61
86
 
@@ -64,3 +89,189 @@ const config = {
64
89
  /// <reference path="../node_modules/@tarojs/plugin-platform-harmony-cpp/types/define.d.ts" />
65
90
 
66
91
  ```
92
+
93
+ ## 项目集成
94
+
95
+ Taro 默认支持构建鸿蒙应用,同时也允许开发者灵活扩展功能。你可以在 Taro 项目中使用鸿蒙原生模块,也可以在鸿蒙项目中集成 Taro 模块。
96
+
97
+ ### 在 Taro 中使用鸿蒙原生模块
98
+
99
+ 与 Taro 在其他端类似,可以通过配置 `usingComponents` 来引入鸿蒙原生组件。
100
+
101
+ ```ts
102
+ /** index.config.ts */
103
+ export default {
104
+ usingComponents: {
105
+ title: './path/to/title-component'
106
+ }
107
+ }
108
+
109
+ /** index.ts */
110
+ import { View } from '@tarojs/components'
111
+
112
+ export default function Index () {
113
+ return <View>
114
+ <title title="Hello World!" />
115
+ </View>
116
+ }
117
+ ```
118
+
119
+ 如果希望使用 Taro 构建的鸿蒙原生组件或者为原生组件提供类型提示,也可以通过 `importNativeComponent` 方法来引入。
120
+
121
+ ```ts
122
+ /** title.ts */
123
+ import { View } from '@tarojs/components'
124
+
125
+ definePageConfig({
126
+ entryOption: false,
127
+ componentName: 'Title',
128
+ })
129
+
130
+ export default function Title ({ title = 'Hello World' }) {
131
+ return <View>{title}</View>
132
+ }
133
+
134
+ // importNativeComponent(path, moduleName, componentName)
135
+ export const Title = importNativeComponent<typeof import('./title').default>('./title', 'title', 'Title')
136
+
137
+ /** index.ts */
138
+ import { View } from '@tarojs/components'
139
+ import { Title } from './title'
140
+
141
+ export default function Index () {
142
+ return <View>
143
+ <Title title="Hello World!" />
144
+ </View>
145
+ }
146
+ ```
147
+
148
+ ### 在鸿蒙项目中集成 Taro 模块
149
+
150
+ 在鸿蒙项目中可以通过页面或者组件的形式来接入 Taro 模块,但如果不是 Taro 创建的鸿蒙项目需要在入口处添加 Taro 相关的初始化方法:
151
+
152
+ ```ts
153
+ import { context, Current } from "@taro-oh/library/src/main/ets/npm/@tarojs/runtime"
154
+ import { TaroWindowUtil } from "@taro-oh/library/src/main/ets/npm/@tarojs/runtime"
155
+
156
+ export default class EntryAbility extends UIAbility {
157
+ ...
158
+ onWindowStageCreate(stage: ohWindow.WindowStage) {
159
+ context.resolver(this.context)
160
+ TaroWindowUtil.setWindowStage(stage)
161
+
162
+ stage.loadContent('home_page', (err, data) => {
163
+ const windowClass = stage.getMainWindowSync()
164
+ Current.uiContext = windowClass.getUIContext()
165
+ windowClass.setWindowLayoutFullScreen(true)
166
+ })
167
+ }
168
+ }
169
+ ```
170
+
171
+ 更多配置可以参考项目生成的 `app.ts` 文件改造。
172
+
173
+ 通过页面接入需要在模块配置文件 `module.json5` 中配置 pages 参数,如果是组件模式,可以参考原生 ets 组件方法引入。
174
+
175
+ ```plain
176
+ import { Title } from './components/title'
177
+
178
+ @Builder
179
+ function render () {
180
+ Title({
181
+ props: {
182
+ title: 'Hello World!'
183
+ }
184
+ })
185
+ }
186
+ ```
187
+
188
+ ### 定制 Taro 运行时
189
+
190
+ 与其他端类似,开发者同样可以通过继承 HarmonyCPP 实例来修改 Taro 的默认行为,包括新增运行时代码等。
191
+
192
+ ```ts
193
+ import { HarmonyCPP } from '@tarojs/plugin-platform-harmony-cpp'
194
+
195
+ export default class MyTaro extends HarmonyCPP {
196
+ // ...
197
+ constructor () {
198
+ super()
199
+ // ...
200
+ if (typeof this.runtimePath === 'string') {
201
+ this.runtimePath = [this.runtimePath, path.resolve(__dirname, 'my-runtime')] // Note: 如果有需要可以覆盖 runtime 禁用 taro 默认 API 行为
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ > 如果不想构建端应用插件,也可以通过配置 copy 将自定义 ets 代码注入到项目中。
208
+
209
+ 通过注入运行时,开发者可以监听 Taro 抛出的 `__taroPluginEtsMethodsTrigger` 事件,可以通过监听事件实现获取开发用户调用 Taro 方法的参数,或者修改 Taro 的默认行为。
210
+
211
+ ```ts
212
+ import { eventCenter } from '@tarojs/runtime'
213
+ import { IEtsMethodsOptions } from '@tarojs/plugin-platform-harmony-cpp/dist/runtime/runtime-harmony'
214
+
215
+ /**
216
+ * interface IEtsMethodsOptions {
217
+ * methodName?: string
218
+ * name?: string
219
+ * scope?: string
220
+ * type?: string
221
+ * args?: TaroAny[]
222
+ * successHandler?: (...args: TaroAny[]) => void
223
+ * errorHandler?: (...args: TaroAny[]) => void
224
+ * onInit?: (obj: TaroAny) => void
225
+ * }
226
+ */
227
+
228
+ eventCenter?.on('__taroPluginEtsMethodsTrigger', (option: IEtsMethodsOptions) => {
229
+ switch (option.scope) {
230
+ case 'route':
231
+ // ...
232
+ break
233
+ default:
234
+ break
235
+ }
236
+ })
237
+ ```
238
+
239
+ > 未实现的 API 可以通过监听 `__taroNotSupport` 事件自定义实现。
240
+
241
+ ## 常见问题
242
+
243
+ ### **ERROR: Failed to get ModuleInfo properties 'meta.pkgPath'**
244
+
245
+ 本地可能存在部分混淆导致 IDE 无法正确解析依赖,需要检查 `build-profile.json5`、`obfuscation-rules.txt` 等文件中是否开启混淆配置,需要关闭后清理 IDE 缓存重新编译。
246
+
247
+ ```diff
248
+ - -enable-property-obfuscation
249
+ - -enable-toplevel-obfuscation
250
+ - -enable-filename-obfuscation
251
+ - -enable-export-obfuscation
252
+ ```
253
+
254
+ ### **ERROR: Cannot resolved import statement**
255
+
256
+ 本地执行 library 编译时,启用 `useNormalizedOHMUrl` 配置会导致外部依赖无法解析,建议在 library 模块中使用 `useNormalizedOHMUrl: false` 或者移除该配置。
257
+
258
+ ### **ERROR: Duplicated files found in module default**
259
+
260
+ 不使用核心库切换到使用核心库时可能会出现该问题,需要清理 build-profile.json5 文件中关于 so 包的配置项。
261
+
262
+ ```diff
263
+ {
264
+ "apiType": "stageMode",
265
+ "buildOption": {
266
+ - "externalNativeOptions": {
267
+ - "path": "./src/main/cpp/CMakeLists.txt",
268
+ - "arguments": "-DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link -DCMAKE_JOB_POOLS:STRING=compile=8;link=8",
269
+ - "cppFlags": "",
270
+ - "abiFilters": [
271
+ - "arm64-v8a"
272
+ - ]
273
+ - }
274
+ },
275
+ ...
276
+ }
277
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-platform-harmony-cpp",
3
- "version": "4.1.0-alpha.0",
3
+ "version": "4.1.0-alpha.1",
4
4
  "description": "鸿蒙系统插件 C-API 版本",
5
5
  "author": "O2Team",
6
6
  "homepage": "https://gitee.com/openharmony-sig/taro",
@@ -31,6 +31,7 @@
31
31
  "@tarojs/parse-css-to-stylesheet": "^1.1.5 ",
32
32
  "@types/react": "^18.3.3",
33
33
  "@types/react-reconciler": "^0.28.8",
34
+ "fast-glob": "^3.3.2",
34
35
  "react": "^18.3.1",
35
36
  "react-dom": "^18.3.1",
36
37
  "react-reconciler": "0.29.0",
@@ -39,14 +40,13 @@
39
40
  "rollup-plugin-node-externals": "^5.1.3",
40
41
  "rollup-plugin-ts": "^3.4.5",
41
42
  "scheduler": "^0.23.2",
42
- "@tarojs/react": "4.1.0-alpha.0",
43
- "@tarojs/runner-utils": "4.1.0-alpha.0",
44
- "@tarojs/service": "4.1.0-alpha.0"
43
+ "@tarojs/runner-utils": "4.1.0-alpha.1",
44
+ "@tarojs/react": "4.1.0-alpha.1",
45
+ "@tarojs/service": "4.1.0-alpha.1"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@rollup/plugin-typescript": "^11.1.6",
48
49
  "@types/node": "^18.19.34",
49
- "fast-glob": "^3.3.2",
50
50
  "postcss": "^8.4.38",
51
51
  "prettier": "^2.8.8",
52
52
  "solid-js": "^1.8.17",
@@ -56,34 +56,35 @@
56
56
  "tslib": "^2.6.3",
57
57
  "typescript": "~5.4.5",
58
58
  "vite": "^4.2.0",
59
- "@tarojs/components": "4.1.0-alpha.0",
60
- "@tarojs/helper": "4.1.0-alpha.0",
61
- "@tarojs/plugin-framework-react": "4.1.0-alpha.0",
62
- "@tarojs/plugin-platform-harmony-ets": "4.1.0-alpha.0",
63
- "@tarojs/react": "4.1.0-alpha.0",
64
- "@tarojs/runtime": "4.1.0-alpha.0",
65
- "@tarojs/shared": "4.1.0-alpha.0",
66
- "@tarojs/taro": "4.1.0-alpha.0",
67
- "@tarojs/vite-runner": "4.1.0-alpha.0",
68
- "rollup-plugin-copy": "4.1.0-alpha.0"
59
+ "@tarojs/plugin-framework-react": "4.1.0-alpha.1",
60
+ "@tarojs/components": "4.1.0-alpha.1",
61
+ "@tarojs/helper": "4.1.0-alpha.1",
62
+ "@tarojs/plugin-platform-harmony-ets": "4.1.0-alpha.1",
63
+ "@tarojs/react": "4.1.0-alpha.1",
64
+ "@tarojs/runtime": "4.1.0-alpha.1",
65
+ "@tarojs/shared": "4.1.0-alpha.1",
66
+ "@tarojs/taro": "4.1.0-alpha.1",
67
+ "@tarojs/vite-runner": "4.1.0-alpha.1",
68
+ "rollup-plugin-copy": "4.1.0-alpha.1"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "less": "^4.2.0",
72
72
  "sass": "^1.75.0",
73
73
  "stylus": "^0.63.0",
74
- "@tarojs/components": "4.1.0-alpha.0",
75
- "@tarojs/helper": "4.1.0-alpha.0",
76
- "@tarojs/plugin-framework-react": "4.1.0-alpha.0",
77
- "@tarojs/plugin-platform-harmony-ets": "4.1.0-alpha.0",
78
- "@tarojs/react": "4.1.0-alpha.0",
79
- "@tarojs/runtime": "4.1.0-alpha.0",
80
- "@tarojs/shared": "4.1.0-alpha.0",
81
- "@tarojs/taro": "4.1.0-alpha.0",
82
- "@tarojs/vite-runner": "4.1.0-alpha.0"
74
+ "@tarojs/components": "4.1.0-alpha.1",
75
+ "@tarojs/plugin-platform-harmony-ets": "4.1.0-alpha.1",
76
+ "@tarojs/plugin-framework-react": "4.1.0-alpha.1",
77
+ "@tarojs/helper": "4.1.0-alpha.1",
78
+ "@tarojs/react": "4.1.0-alpha.1",
79
+ "@tarojs/runtime": "4.1.0-alpha.1",
80
+ "@tarojs/shared": "4.1.0-alpha.1",
81
+ "@tarojs/vite-runner": "4.1.0-alpha.1",
82
+ "@tarojs/taro": "4.1.0-alpha.1"
83
83
  },
84
84
  "scripts": {
85
85
  "prebuild": "rimraf --impl=move-remove dist",
86
86
  "build": "pnpm run rollup",
87
+ "build:library": "pnpm run tsx --files ./scripts/build",
87
88
  "dev": "pnpm run rollup -w",
88
89
  "remove:reference": "pnpm run tsx --files ./scripts/reference",
89
90
  "rollup": "rollup --config rollup.config.mts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
package/types/define.d.ts CHANGED
@@ -33,71 +33,7 @@ declare module '@tarojs/taro' {
33
33
  /** 是否可分栏 */
34
34
  canSplit: bool
35
35
  }
36
- }
37
-
38
- declare module '@tarojs/runtime' {
39
- function initHarmonyElement()
40
- function initStyleSheetConfig(size: any, navHeight: any)
41
- enum NodeType {
42
- ELEMENT_NODE = 1,
43
- ATTRIBUTE_NODE = 2,
44
- TEXT_NODE = 3,
45
- CDATA_SECTION_NODE = 4,
46
- ENTITY_REFERENCE_NODE = 5,
47
- PROCESSING_INSTRUCTION_NODE = 7,
48
- COMMENT_NODE = 8,
49
- DOCUMENT_NODE = 9,
50
- DOCUMENT_TYPE_NODE = 10,
51
- DOCUMENT_FRAGMENT_NODE = 11
52
- }
53
- type TFunc = (...args: any[]) => any
54
- type TaroRichTextElement = any
55
- type EventOptions = any
56
- const context: {
57
- resolver: Promise.resolve
58
- value: any
59
- }
60
- const TaroWindowUtil: {
61
- resolver: Promise.resolve
62
- }
63
-
64
- const uiContext: typeof context
65
- declare const Current: {
66
- app: AppInstance | null
67
- entryAsync: AppInstance | null
68
- isDebug: boolean
69
- uiContext: any
70
- router: Router | null
71
- taro: any
72
- contextPromise: Promise<any>
73
- uiContextPromise: Promise<any>
74
- nativeModule: any
75
- createHarmonyElement: null
76
- page: PageInstance | null
77
- preloadData?: any
78
- }
79
-
80
- function getPageById(pageId: string): any
81
- function setPageById(inst: any, id: string): any
82
- function removePageById(pageId: string): any
83
36
 
84
- // cpp/types/taro-native-node/index.d.ts
85
- const TaroNativeModule: any
86
- const systemContext: {
87
- resolve: Promise.resolve
88
- reject: Promise.reject
89
- densityPixels: number
90
- safeArea: any
91
- statusBarHeight: number
92
- windowWidth: number
93
- windowHeight: number
94
- }
95
- const systemPromise: typeof context
96
- const TaroWindowUtil: typeof TaroWindowUtil
97
-
98
- }
99
-
100
- declare module '@tarojs/taro' {
101
37
  interface TaroStatic {
102
38
  /** 尺寸转换
103
39
  * @supported global
@@ -110,4 +46,14 @@ declare global {
110
46
  function $r(resourcePath: string): any
111
47
  function getUIContext(): any
112
48
  function canIUse(name: string): boolean
49
+ const Observed: any
50
+ const SwiperController: any
51
+ const Visibility: any
52
+ type DataChangeListener = any
53
+ type GestureEvent = any
54
+ type VideoController = any
55
+
56
+ interface IDataSource {
57
+ _isDynamicNode?: boolean
58
+ }
113
59
  }
@@ -1,10 +1,27 @@
1
1
  /// <reference types="@tarojs/plugin-platform-harmony-ets/types/harmony" />
2
2
  declare module '@jd-oh/*'
3
+ declare module '@taro-oh/*'
3
4
  declare module '@hmscore/*'
4
5
  declare module '@ohos.*'
5
6
  declare module '@system.*'
6
7
  declare module '@kit.*'
7
8
 
9
+ declare module '@kit.AbilityKit' {
10
+ namespace common {
11
+ type BaseContext = any
12
+ export { BaseContext }
13
+ }
14
+ }
15
+ declare module '@ohos.base' {
16
+ export = any
17
+ }
18
+ declare module '@ohos.web.webview' {
19
+ export = any
20
+ }
21
+ declare module '@ohos.window' {
22
+ export = any
23
+ }
24
+
8
25
  declare module 'libTaroHarmonyLibrary.so' {
9
26
  export = any
10
27
  // export * from '../cpp/types/taro-native-node/index.d.ts'
@@ -0,0 +1,66 @@
1
+ /// <reference types="@tarojs/runtime" />
2
+
3
+ declare module '@tarojs/runtime' {
4
+ function initHarmonyElement()
5
+ function initStyleSheetConfig(size: any, navHeight: any)
6
+ enum NodeType {
7
+ ELEMENT_NODE = 1,
8
+ ATTRIBUTE_NODE = 2,
9
+ TEXT_NODE = 3,
10
+ CDATA_SECTION_NODE = 4,
11
+ ENTITY_REFERENCE_NODE = 5,
12
+ PROCESSING_INSTRUCTION_NODE = 7,
13
+ COMMENT_NODE = 8,
14
+ DOCUMENT_NODE = 9,
15
+ DOCUMENT_TYPE_NODE = 10,
16
+ DOCUMENT_FRAGMENT_NODE = 11
17
+ }
18
+ type TFunc = (...args: any[]) => any
19
+ type TaroRichTextElement = any
20
+ type EventOptions = any
21
+ const context: {
22
+ resolver: Promise.resolve
23
+ value: any
24
+ }
25
+ const TaroWindowUtil: {
26
+ resolver: Promise.resolve
27
+ }
28
+
29
+ const uiContext: typeof context
30
+ declare const Current: {
31
+ app: AppInstance | null
32
+ entryAsync: AppInstance | null
33
+ isDebug: boolean
34
+ uiContext: any
35
+ router: Router | null
36
+ taro: any
37
+ contextPromise: Promise<any>
38
+ uiContextPromise: Promise<any>
39
+ nativeModule: any
40
+ createHarmonyElement: null
41
+ page: PageInstance | null
42
+ preloadData?: any
43
+ }
44
+
45
+ function getPageById(pageId: string): any
46
+ function setPageById(inst: any, id: string): any
47
+ function removePageById(pageId: string): any
48
+
49
+ // cpp/types/taro-native-node/index.d.ts
50
+ const TaroNativeModule: any
51
+ const systemContext: {
52
+ resolve: Promise.resolve
53
+ reject: Promise.reject
54
+ densityPixels: number
55
+ safeArea: any
56
+ statusBarHeight: number
57
+ windowWidth: number
58
+ windowHeight: number
59
+ }
60
+ const systemPromise: typeof context
61
+ const TaroWindowUtil: typeof TaroWindowUtil
62
+
63
+ const TaroElement: any
64
+ type TaroElement = any
65
+ type TaroVideoElement = typeof TaroElement
66
+ }
package/types/global.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="@tarojs/runtime" />