@tarojs/plugin-platform-harmony-ets 4.0.0-canary.8 → 4.0.0

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.
Files changed (135) hide show
  1. package/dist/apis/base/system.ts +73 -20
  2. package/dist/apis/canvas/index.ts +10 -1
  3. package/dist/apis/device/clipboard.ts +23 -8
  4. package/dist/apis/framework/index.ts +1 -5
  5. package/dist/apis/index.ts +27 -17
  6. package/dist/apis/media/image/index.ts +169 -17
  7. package/dist/apis/network/request.ts +5 -5
  8. package/dist/apis/route/index.ts +15 -0
  9. package/dist/apis/storage/index.ts +146 -78
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +2 -1
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +1 -1
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +5 -5
  16. package/dist/apis/ui/tab-bar.ts +3 -3
  17. package/dist/apis/utils/index.ts +21 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/index.ts +2 -0
  21. package/dist/apis/wxml/selectorQuery.ts +26 -13
  22. package/dist/components-harmony-ets/button.ets +63 -77
  23. package/dist/components-harmony-ets/canvas.ets +51 -0
  24. package/dist/components-harmony-ets/checkbox.ets +75 -258
  25. package/dist/components-harmony-ets/form.ets +51 -158
  26. package/dist/components-harmony-ets/icon.ets +33 -83
  27. package/dist/components-harmony-ets/image.ets +35 -79
  28. package/dist/components-harmony-ets/index.ets +92 -0
  29. package/dist/components-harmony-ets/innerHtml.ets +11 -6
  30. package/dist/components-harmony-ets/input.ets +64 -101
  31. package/dist/components-harmony-ets/label.ets +72 -174
  32. package/dist/components-harmony-ets/listView.ets +31 -0
  33. package/dist/components-harmony-ets/movableArea.ets +126 -0
  34. package/dist/components-harmony-ets/movableView.ets +93 -0
  35. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  36. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  37. package/dist/components-harmony-ets/picker.ets +46 -163
  38. package/dist/components-harmony-ets/progress.ets +52 -0
  39. package/dist/components-harmony-ets/pseudo.ets +80 -0
  40. package/dist/components-harmony-ets/radio.ets +80 -264
  41. package/dist/components-harmony-ets/richText.ets +20 -102
  42. package/dist/components-harmony-ets/scrollList.ets +108 -0
  43. package/dist/components-harmony-ets/scrollView.ets +71 -160
  44. package/dist/components-harmony-ets/slider.ets +22 -82
  45. package/dist/components-harmony-ets/stickySection.ets +42 -0
  46. package/dist/components-harmony-ets/style.ets +410 -0
  47. package/dist/components-harmony-ets/swiper.ets +64 -87
  48. package/dist/components-harmony-ets/switch.ets +39 -99
  49. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  50. package/dist/components-harmony-ets/text.ets +111 -113
  51. package/dist/components-harmony-ets/textArea.ets +51 -95
  52. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  53. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  54. package/dist/components-harmony-ets/utils/flexManager.ets +50 -19
  55. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  56. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  57. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  58. package/dist/components-harmony-ets/utils/index.ts +54 -50
  59. package/dist/components-harmony-ets/utils/styles.ets +172 -92
  60. package/dist/components-harmony-ets/video.ets +37 -88
  61. package/dist/components-harmony-ets/view.ets +63 -159
  62. package/dist/components-harmony-ets/webView.ets +41 -98
  63. package/dist/index.d.ts +152 -0
  64. package/dist/index.js +187 -56
  65. package/dist/index.js.map +1 -1
  66. package/dist/runtime-ets/bom/document.ts +6 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
  68. package/dist/runtime-ets/bom/window.ts +9 -2
  69. package/dist/runtime-ets/current.ts +5 -1
  70. package/dist/runtime-ets/dom/bind.ts +28 -12
  71. package/dist/runtime-ets/dom/class-list.ts +2 -2
  72. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  73. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  74. package/dist/runtime-ets/dom/document.ts +22 -8
  75. package/dist/runtime-ets/dom/element/canvas.ts +136 -0
  76. package/dist/runtime-ets/dom/element/element.ts +376 -57
  77. package/dist/runtime-ets/dom/element/form.ts +31 -26
  78. package/dist/runtime-ets/dom/element/index.ts +30 -2
  79. package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
  80. package/dist/runtime-ets/dom/element/movableView.ts +248 -0
  81. package/dist/runtime-ets/dom/element/normal.ts +35 -8
  82. package/dist/runtime-ets/dom/element/progress.ts +11 -0
  83. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  84. package/dist/runtime-ets/dom/element/text.ts +1 -8
  85. package/dist/runtime-ets/dom/element/video.ts +5 -4
  86. package/dist/runtime-ets/dom/element/webView.ts +12 -5
  87. package/dist/runtime-ets/dom/event.ts +3 -5
  88. package/dist/runtime-ets/dom/eventTarget.ts +2 -3
  89. package/dist/runtime-ets/dom/node.ts +65 -32
  90. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  91. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  92. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  93. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  94. package/dist/runtime-ets/index.ts +2 -2
  95. package/dist/runtime-ets/interface/event.ts +1 -1
  96. package/dist/runtime-ets/utils/index.ts +74 -13
  97. package/dist/runtime-ets/utils/info.ts +2 -2
  98. package/dist/runtime-framework/react/app.ts +25 -30
  99. package/dist/runtime-framework/react/hooks.ts +3 -4
  100. package/dist/runtime-framework/react/index.ts +0 -2
  101. package/dist/runtime-framework/react/native-page.ts +219 -82
  102. package/dist/runtime-framework/react/page.ts +6 -10
  103. package/dist/runtime-framework/react/utils/index.ts +3 -3
  104. package/dist/runtime-framework/solid/app.ts +30 -46
  105. package/dist/runtime-framework/solid/connect.ts +21 -3
  106. package/dist/runtime-framework/solid/hooks.ts +17 -12
  107. package/dist/runtime-framework/solid/index.ts +6 -2
  108. package/dist/runtime-framework/solid/page.ts +85 -31
  109. package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
  110. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  111. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  112. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  113. package/dist/runtime-utils.d.ts +827 -0
  114. package/dist/runtime-utils.js +618 -245
  115. package/dist/runtime-utils.js.map +1 -1
  116. package/dist/runtime.d.ts +1 -0
  117. package/dist/runtime.js +618 -245
  118. package/dist/runtime.js.map +1 -1
  119. package/index.js +3 -1
  120. package/package.json +14 -15
  121. package/static/media/cancel.svg +1 -1
  122. package/static/media/circle.svg +1 -1
  123. package/static/media/clear.svg +1 -1
  124. package/static/media/download.svg +1 -1
  125. package/static/media/info.svg +1 -1
  126. package/static/media/info_circle.svg +1 -1
  127. package/static/media/search.svg +1 -1
  128. package/static/media/success.svg +1 -1
  129. package/static/media/success_no_circle.svg +1 -1
  130. package/static/media/warn.svg +1 -1
  131. package/types/harmony.d.ts +5 -0
  132. package/types/index.d.ts +4 -0
  133. package/types/runtime.d.ts +3 -1
  134. package/dist/runtime-ets/utils/bind.ts +0 -24
  135. /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
@@ -0,0 +1,152 @@
1
+ /* eslint-disable no-console */
2
+ import { IFileType, TConfig, TaroPlatform, IPluginContext, TaroPlatformBase } from "@tarojs/service";
3
+ import { PLATFORM_TYPE } from "@tarojs/shared";
4
+ declare abstract class TaroPlatformHarmony<T extends TConfig = TConfig> extends TaroPlatform<T> {
5
+ platformType: PLATFORM_TYPE;
6
+ globalObject: string;
7
+ abstract fileType: IFileType;
8
+ abstract useETS: boolean;
9
+ abstract useJSON5: boolean;
10
+ taroComponentsPath: string;
11
+ /**
12
+ * 1. 清空 dist 文件夹
13
+ * 2. 输出编译提示
14
+ */
15
+ private setup;
16
+ private setupHarmonyApp;
17
+ protected printDevelopmentTip(): void;
18
+ /**
19
+ * 返回当前项目内的 runner 包
20
+ */
21
+ protected getRunner(): Promise<any>;
22
+ /**
23
+ * 准备 runner 参数
24
+ * @param extraOptions 需要额外合入 Options 的配置项
25
+ */
26
+ protected getOptions(extraOptions?: {}): any;
27
+ /**
28
+ * 调用 runner 开始编译
29
+ * @param extraOptions 需要额外传入 runner 的配置项
30
+ */
31
+ private build;
32
+ private buildHarmonyApp;
33
+ /**
34
+ * 调用 runner 开启编译
35
+ */
36
+ start(): Promise<void>;
37
+ }
38
+ declare class Harmony extends TaroPlatformHarmony {
39
+ #private;
40
+ platform: string;
41
+ globalObject: string;
42
+ fileType: {
43
+ templ: string;
44
+ style: string;
45
+ config: string;
46
+ script: string;
47
+ };
48
+ useETS: boolean;
49
+ useJSON5: boolean;
50
+ runtimePath: string[] | string;
51
+ taroComponentsPath: string;
52
+ apiEntryList: RegExp[];
53
+ constructor(ctx: IPluginContext, config: TConfig);
54
+ get framework(): "solid" | "vue3" | "react" | "preact" | "none";
55
+ get aliasFramework(): string;
56
+ get apiLibrary(): string;
57
+ get apiEntry(): RegExp[];
58
+ get componentLibrary(): string;
59
+ get runtimeLibrary(): string;
60
+ get runtimeFrameworkLibrary(): string;
61
+ get defineConstants(): Record<string, string> | undefined;
62
+ extensions: string[];
63
+ excludeLibraries: (string | RegExp)[];
64
+ externalDeps: [
65
+ string,
66
+ RegExp,
67
+ string?
68
+ ][];
69
+ harmonyScope: RegExp[];
70
+ indexOfLibraries(lib: string): number;
71
+ removeFromLibraries(lib: string): void;
72
+ moveLibraries(lib: string, target?: string, basedir?: string, sync?: boolean): void;
73
+ replaceDefineValue(code: string, define: Record<string, string>, ext?: string): string;
74
+ /**
75
+ * 修改 Vite 配置
76
+ */
77
+ modifyViteConfig(): void;
78
+ handleResourceEmit(outDir: string, basedir?: string): void;
79
+ }
80
+ declare module HarmonyWrapper {
81
+ export { Harmony };
82
+ }
83
+ import HarmonyOS_ArkTS = HarmonyWrapper.Harmony;
84
+ declare class Harmony$0 extends TaroPlatformBase {
85
+ platform: string;
86
+ globalObject: string;
87
+ runtimePath: string;
88
+ taroComponentsPath: string;
89
+ fileType: {
90
+ templ: string;
91
+ style: string;
92
+ config: string;
93
+ script: string;
94
+ };
95
+ template: any;
96
+ /**
97
+ * 1. setupTransaction - init
98
+ * 2. setup
99
+ * 3. setupTransaction - close
100
+ * 4. buildTransaction - init
101
+ * 5. build
102
+ * 6. buildTransaction - close
103
+ */
104
+ constructor(ctx: any, config: any);
105
+ /**
106
+ * 增加组件或修改组件属性
107
+ */
108
+ modifyComponents(): void;
109
+ /**
110
+ * 不需要转 rpx
111
+ */
112
+ modifyPostcssConfigs(config: Record<string, any>): void;
113
+ /**
114
+ * 模板自定义组件 js
115
+ * 等鸿蒙支持 template 后需要重构
116
+ */
117
+ addEntry(): void;
118
+ /**
119
+ * 把 app、pages、自定义组件的 js 改造为鸿蒙的 export default 导出形式
120
+ */
121
+ modifyTaroExport(): void;
122
+ /**
123
+ * 修改最终的编译产物
124
+ * 1. 生成模板自定义组件的 xml、css 文件
125
+ * 2. 删除多余的文件
126
+ * 3. 把 components-harmony 中被使用到的组件移动到输出目录
127
+ */
128
+ modifyBuildAssets(ctx: any, config: any): void;
129
+ modifyWebpackConfig(): void;
130
+ modifyHarmonyConfig(pages: any, { projectPath, hapName, name }: {
131
+ projectPath: any;
132
+ hapName: any;
133
+ name: any;
134
+ }): void;
135
+ modifyHostPackage({ projectPath, hapName }: {
136
+ projectPath: any;
137
+ hapName?: string | undefined;
138
+ }): Promise<any>;
139
+ getChunkEntryModule(compilation: any, chunk: any, compiler?: string): any;
140
+ checkMetaType(entryModule: any): boolean;
141
+ isHarmonyRequest(request: string): boolean;
142
+ }
143
+ declare module HarmonyWrapper {
144
+ export { Harmony$0 as Harmony };
145
+ }
146
+ import HarmonyOS_JSUI = HarmonyWrapper.Harmony;
147
+ interface IOptions {
148
+ disableArkTS?: boolean;
149
+ useConfigName?: string;
150
+ }
151
+ declare const _default: (ctx: IPluginContext, options?: IOptions) => void;
152
+ export { _default as default, HarmonyOS_ArkTS, HarmonyOS_JSUI, IOptions };
package/dist/index.js CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var helper = require('@tarojs/helper');
6
5
  var path = require('node:path');
7
- var runnerUtils = require('@tarojs/runner-utils');
8
- var shared = require('@tarojs/shared');
6
+ var helper = require('@tarojs/helper');
9
7
  var service = require('@tarojs/service');
10
8
  var _package = require('@tarojs/service/dist/utils/package');
9
+ var shared = require('@tarojs/shared');
11
10
  var webpackSources = require('webpack-sources');
12
11
  var template = require('@tarojs/shared/dist/template');
13
12
 
@@ -75,6 +74,86 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
75
74
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
75
  };
77
76
 
77
+ function apiLoader(str) {
78
+ return `import {
79
+ useAddToFavorites,
80
+ useDidHide,
81
+ useDidShow,
82
+ useError,
83
+ useLaunch,
84
+ useLoad,
85
+ useOptionMenuClick,
86
+ usePageNotFound,
87
+ usePageScroll,
88
+ usePullDownRefresh,
89
+ usePullIntercept,
90
+ useReachBottom,
91
+ useReady,
92
+ useResize,
93
+ useRouter,
94
+ useSaveExitState,
95
+ useShareAppMessage,
96
+ useShareTimeline,
97
+ useTabItemTap,
98
+ useTitleClick,
99
+ useScope,
100
+ useUnhandledRejection,
101
+ useUnload
102
+ } from '@tarojs/plugin-framework-react/dist/runtime'
103
+ ${str}
104
+
105
+ taro.useAddToFavorites = useAddToFavorites
106
+ taro.useDidHide = useDidHide
107
+ taro.useDidShow = useDidShow
108
+ taro.useError = useError
109
+ taro.useLaunch = useLaunch
110
+ taro.useLoad = useLoad
111
+ taro.useOptionMenuClick = useOptionMenuClick
112
+ taro.usePageNotFound = usePageNotFound
113
+ taro.usePageScroll = usePageScroll
114
+ taro.usePullDownRefresh = usePullDownRefresh
115
+ taro.usePullIntercept = usePullIntercept
116
+ taro.useReachBottom = useReachBottom
117
+ taro.useReady = useReady
118
+ taro.useResize = useResize
119
+ taro.useRouter = useRouter
120
+ taro.useSaveExitState = useSaveExitState
121
+ taro.useShareAppMessage = useShareAppMessage
122
+ taro.useShareTimeline = useShareTimeline
123
+ taro.useTabItemTap = useTabItemTap
124
+ taro.useTitleClick = useTitleClick
125
+ taro.useScope = useScope
126
+ taro.useUnhandledRejection = useUnhandledRejection
127
+ taro.useUnload = useUnload
128
+
129
+ export {
130
+ useAddToFavorites,
131
+ useDidHide,
132
+ useDidShow,
133
+ useError,
134
+ useLaunch,
135
+ useLoad,
136
+ useOptionMenuClick,
137
+ usePageNotFound,
138
+ usePageScroll,
139
+ usePullDownRefresh,
140
+ usePullIntercept,
141
+ useReachBottom,
142
+ useReady,
143
+ useResize,
144
+ useRouter,
145
+ useSaveExitState,
146
+ useShareAppMessage,
147
+ useShareTimeline,
148
+ useTabItemTap,
149
+ useTitleClick,
150
+ useScope,
151
+ useUnhandledRejection,
152
+ useUnload
153
+ }
154
+ `;
155
+ }
156
+
78
157
  const PLATFORM_NAME = 'harmony';
79
158
  const PACKAGE_NAME = '@tarojs/plugin-platform-harmony-ets';
80
159
  const PLUGIN_NAME = 'TaroHarmony';
@@ -100,8 +179,8 @@ class TaroPlatformHarmony extends service.TaroPlatform {
100
179
  * 2. 输出编译提示
101
180
  */
102
181
  setup() {
103
- var _a, _b;
104
182
  return __awaiter(this, void 0, void 0, function* () {
183
+ var _a, _b;
105
184
  yield this.setupTransaction.perform(this.setupHarmonyApp, this);
106
185
  (_b = (_a = this.ctx).onSetupClose) === null || _b === void 0 ? void 0 : _b.call(_a, this);
107
186
  });
@@ -157,6 +236,7 @@ class TaroPlatformHarmony extends service.TaroPlatform {
157
236
  * @param extraOptions 需要额外合入 Options 的配置项
158
237
  */
159
238
  getOptions(extraOptions = {}) {
239
+ var _a, _b, _c;
160
240
  const { ctx } = this;
161
241
  const { recursiveMerge } = ctx.helper;
162
242
  const config = recursiveMerge(Object.assign({}, this.config), {
@@ -164,24 +244,25 @@ class TaroPlatformHarmony extends service.TaroPlatform {
164
244
  FRAMEWORK: JSON.stringify(this.config.framework),
165
245
  TARO_ENV: JSON.stringify(this.platform),
166
246
  TARO_PLATFORM: JSON.stringify(this.platformType),
167
- TARO_VERSION: JSON.stringify(_package.getPkgVersion())
247
+ TARO_VERSION: JSON.stringify(_package.getPkgVersion()),
248
+ SUPPORT_TARO_POLYFILL: 'disabled',
168
249
  },
169
250
  });
170
- return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useJSON5: this.useJSON5 }), extraOptions);
251
+ return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useJSON5: this.useJSON5, isPure: Boolean((_c = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.runOpts) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.args) === null || _c === void 0 ? void 0 : _c.pure) }), extraOptions);
171
252
  }
172
253
  /**
173
254
  * 调用 runner 开始编译
174
255
  * @param extraOptions 需要额外传入 runner 的配置项
175
256
  */
176
- build(extraOptions = {}) {
177
- var _a, _b;
178
- return __awaiter(this, void 0, void 0, function* () {
257
+ build() {
258
+ return __awaiter(this, arguments, void 0, function* (extraOptions = {}) {
259
+ var _a, _b;
179
260
  (_b = (_a = this.ctx).onBuildInit) === null || _b === void 0 ? void 0 : _b.call(_a, this);
180
261
  yield this.buildTransaction.perform(this.buildHarmonyApp, this, extraOptions);
181
262
  });
182
263
  }
183
- buildHarmonyApp(extraOptions = {}) {
184
- return __awaiter(this, void 0, void 0, function* () {
264
+ buildHarmonyApp() {
265
+ return __awaiter(this, arguments, void 0, function* (extraOptions = {}) {
185
266
  const runner = yield this.getRunner();
186
267
  const options = this.getOptions(Object.assign({
187
268
  runtimePath: this.runtimePath,
@@ -204,7 +285,6 @@ class TaroPlatformHarmony extends service.TaroPlatform {
204
285
  var _Harmony_defineConstants;
205
286
  const frameworkAlias = {
206
287
  solid: 'solid',
207
- vue: 'vue2',
208
288
  vue3: 'vue3',
209
289
  };
210
290
  let Harmony$1 = class Harmony extends TaroPlatformHarmony {
@@ -222,6 +302,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
222
302
  this.useJSON5 = true;
223
303
  this.runtimePath = [];
224
304
  this.taroComponentsPath = `${PACKAGE_NAME}/dist/components-harmony-ets`;
305
+ this.apiEntryList = [
306
+ /(@tarojs[\\/]plugin-platform-harmony-ets|taro-platform-harmony)[\\/]dist[\\/]apis[\\/]index\.ts/,
307
+ ];
225
308
  _Harmony_defineConstants.set(this, {});
226
309
  this.extensions = ['.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs', '.mts', '.vue', '.ets', '.d.ts'];
227
310
  this.excludeLibraries = [];
@@ -236,14 +319,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
236
319
  ['react', /^react$|react[\\/]cjs/],
237
320
  ['react/jsx-runtime', /^react[\\/]jsx-runtime$/], // Note: React 环境下自动注入,避免重复
238
321
  ];
322
+ this.harmonyScope = [...HARMONY_SCOPES];
323
+ const that = this;
239
324
  this.setupTransaction.addWrapper({
240
325
  close() {
241
- this.modifyViteConfig();
326
+ that.modifyViteConfig();
242
327
  },
243
328
  });
244
329
  ctx.onBuildFinish(() => {
245
330
  const outDir = path__namespace.resolve(process.cwd(), config.outputRoot);
246
- this.handleResourceEmit(outDir);
331
+ that.handleResourceEmit(outDir);
247
332
  });
248
333
  }
249
334
  get framework() {
@@ -255,6 +340,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
255
340
  get apiLibrary() {
256
341
  return path__namespace.resolve(__dirname, './apis');
257
342
  }
343
+ get apiEntry() {
344
+ return this.apiEntryList;
345
+ }
258
346
  get componentLibrary() {
259
347
  return path__namespace.resolve(__dirname, './components-harmony-ets');
260
348
  }
@@ -291,8 +379,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
291
379
  return;
292
380
  if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
293
381
  return;
382
+ const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
294
383
  if (sync) {
295
- const { outputRoot } = this.ctx.runOpts.config;
296
384
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
297
385
  // FIXME 不支持 alias 配置
298
386
  const libName = lib;
@@ -340,9 +428,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
340
428
  }
341
429
  if (ext) {
342
430
  const code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
343
- if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code)
344
- || /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code))
345
- && `${libName}${path__namespace.extname(libDir)}` !== libDir) {
431
+ if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code) ||
432
+ /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code)) &&
433
+ `${libName}${path__namespace.extname(libDir)}` !== libDir) {
434
+ // Note: 文件包含包内引用的依赖
346
435
  const pkgPath = path__namespace.relative(libName, libDir);
347
436
  if (new RegExp(`^index(${this.extensions.map(e => e.replace('.', '\\.')).join('|')})$`).test(pkgPath)) {
348
437
  // Note: 入口为 index 场景
@@ -393,12 +482,18 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
393
482
  }
394
483
  else if (stat.isFile()) {
395
484
  let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
485
+ if (this.apiEntry.some(e => e.test(lib))) {
486
+ code = apiLoader(code);
487
+ }
396
488
  if (this.extensions.includes(path__namespace.extname(lib))) {
397
- code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
489
+ // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps
490
+ code = code.replace(/(?:import\s|from\s|require\()['"]([^\\/.][^'"\s]+)['"]\)?/g, (src, p1 = '') => {
491
+ if (p1.startsWith('node:') || p1.endsWith('.so'))
492
+ return src;
398
493
  const { outputRoot } = this.ctx.runOpts.config;
399
494
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
400
495
  const relativePath = parseRelativePath(path__namespace.dirname(target), targetPath);
401
- if (HARMONY_SCOPES.every(e => !e.test(p1))) {
496
+ if (this.harmonyScope.every(e => !e.test(p1))) {
402
497
  if (this.indexOfLibraries(p1) === -1 && !/\.(d\.ts|flow\.js)$/.test(lib)) {
403
498
  this.externalDeps.push([p1, new RegExp(`^${p1.replace(/([-\\/$])/g, '\\$1')}$`)]);
404
499
  this.moveLibraries(p1, targetPath, path__namespace.dirname(lib), true);
@@ -407,18 +502,29 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
407
502
  }
408
503
  return src;
409
504
  });
410
- const define = Object.assign({}, this.defineConstants);
505
+ const define = Object.assign(Object.assign({}, this.defineConstants), {
506
+ // Note: React 开发环境可能调用 stack 可能导致 appWrapper 实例变更
507
+ 'ReactDebugCurrentFrame.getCurrentStack': 'ReactDebugCurrentFrame.getCurrentStack$' });
411
508
  if ([/(@tarojs[\\/]runtime|taro-runtime)[\\/]dist/].some(e => e.test(lib))) {
412
509
  define.global = 'globalThis';
413
510
  }
414
- code = this.replaceDefineValue(code, define);
415
511
  const ext = path__namespace.extname(target);
512
+ if (![/d\.e?tsx?$/, /\.(json|map|md)$/].some(e => e.test(target))) {
513
+ code = this.replaceDefineValue(code, define, ext);
514
+ }
416
515
  if (['.ts'].includes(ext)) {
417
516
  code = '// @ts-nocheck\n' + code;
418
517
  }
518
+ // 处理嵌套样式的编译,需要针对ReactElement进行props操作,dev模式下会Object.freeze,所以需要在开发模式下注入Object.freeze来覆盖解锁
519
+ // 处理的方法再taro-platform-harmony/src/runtime-ets/dom/cssNesting: ele.props.style = declaration
520
+ if (/react\/jsx-runtime/.test(lib) && process.env.NODE_ENV === 'development') {
521
+ code = 'Object.freeze = (obj) => obj \n' + code;
522
+ }
419
523
  }
420
- if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
421
- code = `/// <reference path="global.d.ts" />
524
+ // Note: 传入 chorePackagePrefix 时,不生成核心依赖库
525
+ if (!chorePackagePrefix) {
526
+ if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
527
+ code = `/// <reference path="global.d.ts" />
422
528
 
423
529
  /// <reference path="taro.api.d.ts" />
424
530
  /// <reference path="taro.component.d.ts" />
@@ -438,14 +544,15 @@ declare global {
438
544
  const defineAppConfig: (config: Taro.Config) => Taro.Config
439
545
  const definePageConfig: (config: Taro.Config) => Taro.Config
440
546
  }`;
441
- }
442
- try {
443
- const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
444
- helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
445
- helper.fs.writeFileSync(targetPath, code);
446
- }
447
- catch (e) {
448
- console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
547
+ }
548
+ try {
549
+ const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
550
+ helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
551
+ helper.fs.writeFileSync(targetPath, code);
552
+ }
553
+ catch (e) {
554
+ console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
555
+ }
449
556
  }
450
557
  }
451
558
  else if (stat.isSymbolicLink()) {
@@ -453,9 +560,13 @@ declare global {
453
560
  this.moveLibraries(realPath, target, basedir);
454
561
  }
455
562
  }
456
- replaceDefineValue(code, define) {
563
+ replaceDefineValue(code, define, ext = '.js') {
457
564
  Object.keys(define).forEach(key => {
458
- code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), define[key]);
565
+ let value = define[key];
566
+ if (/^['"`].*['"`]$/.test(value) && ['.ts', '.tsx', '.ets'].includes(ext)) {
567
+ value = `(${value} as string)`;
568
+ }
569
+ code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), value);
459
570
  });
460
571
  return code;
461
572
  }
@@ -467,15 +578,15 @@ declare global {
467
578
  const that = this;
468
579
  const { appPath } = that.ctx.paths;
469
580
  const { config } = that.ctx.runOpts;
470
- const { outputRoot } = config;
581
+ const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
471
582
  if (!that.framework.includes('vue')) {
472
583
  that.excludeLibraries.push(/\bvue\b/);
473
584
  }
474
585
  // @ts-ignore
475
586
  if (that.framework === 'solid') {
476
587
  that.externalDeps.push([
477
- '@tarojs/plugin-framework-react/dist/runtime/reconciler',
478
- /^@tarojs\/plugin-framework-react\/dist\/runtime\/reconciler$/,
588
+ '@tarojs/plugin-framework-solid/dist/reconciler',
589
+ /^@tarojs\/plugin-framework-solid\/dist\/reconciler$/,
479
590
  path__namespace.join(this.runtimeFrameworkLibrary, 'reconciler')
480
591
  ]);
481
592
  that.externalDeps.push([
@@ -483,11 +594,30 @@ declare global {
483
594
  /^solid-js\/universal$/,
484
595
  ]);
485
596
  }
486
- function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
487
- if (shared.isFunction(resolve)) {
488
- if (source === that.runtimePath || that.runtimePath.includes(source)) {
489
- return resolve('@tarojs/runtime', importer, options);
490
- }
597
+ const chorePkgRgx = new RegExp(`^${(chorePackagePrefix || '').replace(/[\\/]+/g, '[\\\\/]+').replace(/[-^$*?.|]/g, '\\$&')}`);
598
+ const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
599
+ function modifyResolveId({ source = '', name = 'modifyResolveId' }) {
600
+ if (externals.includes(source) || (chorePackagePrefix && chorePkgRgx.test(source))) {
601
+ return {
602
+ external: true,
603
+ id: source,
604
+ resolvedBy: name,
605
+ };
606
+ }
607
+ else if (source.includes('css_variables')) {
608
+ return {
609
+ external: true,
610
+ id: path__namespace.join(outputRoot, 'css_variables'),
611
+ moduleSideEffects: 'no-treeshake',
612
+ resolvedBy: name,
613
+ };
614
+ }
615
+ if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
616
+ return {
617
+ external: true,
618
+ id: path__namespace.join(chorePackagePrefix, source),
619
+ resolvedBy: name,
620
+ };
491
621
  }
492
622
  // Note: 映射 Taro 相关依赖到注入 taro 目录
493
623
  if (that.indexOfLibraries(source) > -1) {
@@ -518,19 +648,18 @@ declare global {
518
648
  }
519
649
  function injectLoaderMeta() {
520
650
  return {
521
- name: 'taro:vite-h5-loader-meta',
651
+ name: 'taro:vite-loader-meta',
522
652
  buildStart() {
523
653
  return __awaiter(this, void 0, void 0, function* () {
524
- yield this.load({ id: runnerUtils.VITE_COMPILER_LABEL });
525
- const info = this.getModuleInfo(runnerUtils.VITE_COMPILER_LABEL);
526
- const compiler = info === null || info === void 0 ? void 0 : info.meta.viteCompilerContext;
654
+ const { getViteHarmonyCompilerContext } = that.ctx.runnerUtils;
655
+ const compiler = getViteHarmonyCompilerContext(this);
527
656
  if (compiler) {
528
657
  switch (that.framework) {
529
658
  // @ts-ignore
530
659
  case 'solid':
531
660
  compiler.loaderMeta || (compiler.loaderMeta = {});
532
661
  compiler.loaderMeta.importFrameworkStatement = ``;
533
- compiler.mockAppStatement = `
662
+ compiler.loaderMeta.mockAppStatement = `
534
663
  function App(props) {
535
664
  return null
536
665
  }
@@ -565,7 +694,7 @@ function App(props) {
565
694
  isFile: (file) => {
566
695
  try {
567
696
  const stat = helper.fs.lstatSync(file);
568
- return stat.isFile() || (file.endsWith(mediaPath) && stat.isDirectory());
697
+ return stat.isFile() || (file.endsWith(mediaPath.replace('/', path__namespace.sep)) && stat.isDirectory());
569
698
  }
570
699
  catch (_) { } // eslint-disable-line no-empty
571
700
  return false;
@@ -926,7 +1055,7 @@ class Harmony extends service.TaroPlatformBase {
926
1055
  * 等鸿蒙支持 template 后需要重构
927
1056
  */
928
1057
  addEntry() {
929
- this.ctx.onCompilerMake(({ compilation, plugin }) => __awaiter(this, void 0, void 0, function* () {
1058
+ this.ctx.onCompilerMake((_a) => __awaiter(this, [_a], void 0, function* ({ compilation, plugin }) {
930
1059
  // container/index.hml
931
1060
  const filePath = path.resolve(__dirname, 'template/container');
932
1061
  plugin.addEntry(filePath, 'container/index', helper.META_TYPE.STATIC);
@@ -1066,7 +1195,7 @@ class Harmony extends service.TaroPlatformBase {
1066
1195
  const outDir = path.join(compsOutDir, name);
1067
1196
  helper.fs.copy(src, outDir);
1068
1197
  });
1069
- this.modifyHostPackageDep(outDir);
1198
+ this.modifyHostPackage(config.harmony);
1070
1199
  });
1071
1200
  }
1072
1201
  modifyWebpackConfig() {
@@ -1129,13 +1258,13 @@ class Harmony extends service.TaroPlatformBase {
1129
1258
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1130
1259
  });
1131
1260
  }
1132
- modifyHostPackageDep(dest) {
1133
- return __awaiter(this, void 0, void 0, function* () {
1261
+ modifyHostPackage(_a) {
1262
+ return __awaiter(this, arguments, void 0, function* ({ projectPath, hapName = 'entry' }) {
1263
+ const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1134
1264
  const hmsDeps = {
1135
1265
  '@hmscore/hms-js-base': '^6.1.0-300',
1136
1266
  '@hmscore/hms-jsb-account': '^1.0.300'
1137
1267
  };
1138
- const packageJsonFile = path.resolve(dest, '../../../../../package.json');
1139
1268
  const isExists = yield helper.fs.pathExists(packageJsonFile);
1140
1269
  if (!isExists)
1141
1270
  return;
@@ -1152,9 +1281,10 @@ class Harmony extends service.TaroPlatformBase {
1152
1281
  }
1153
1282
  packageJson = JSON.stringify(packageJson);
1154
1283
  yield helper.fs.writeFile(packageJsonFile, packageJson);
1284
+ return packageJson;
1155
1285
  });
1156
1286
  }
1157
- getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {
1287
+ getChunkEntryModule(compilation, chunk, compiler = 'webpack5') {
1158
1288
  if (compiler === 'webpack5') {
1159
1289
  const chunkGraph = compilation.chunkGraph;
1160
1290
  const entryModules = Array.from(chunkGraph.getChunkEntryModulesIterable(chunk));
@@ -1195,8 +1325,8 @@ var index = (ctx, options = {}) => {
1195
1325
  ctx.registerPlatform({
1196
1326
  name: PLATFORM_NAME,
1197
1327
  useConfigName: options.useConfigName || PLATFORM_NAME,
1198
- fn({ config }) {
1199
- return __awaiter(this, void 0, void 0, function* () {
1328
+ fn(_a) {
1329
+ return __awaiter(this, arguments, void 0, function* ({ config }) {
1200
1330
  const program = new Harmony$2(ctx, config);
1201
1331
  yield program.start();
1202
1332
  });
@@ -1220,6 +1350,7 @@ function assertHarmonyConfig(ctx, config) {
1220
1350
  }
1221
1351
  }
1222
1352
 
1353
+ exports.HarmonyOS_ArkTS = Harmony$1;
1223
1354
  exports.HarmonyOS_JSUI = Harmony;
1224
1355
  exports.default = index;
1225
1356
  //# sourceMappingURL=index.js.map