@tarojs/plugin-platform-harmony-ets 4.0.0-beta.12 → 4.0.0-beta.121

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 (143) hide show
  1. package/dist/apis/base/system.ts +60 -25
  2. package/dist/apis/base/weapp/life-cycle.ts +1 -1
  3. package/dist/apis/canvas/index.ts +10 -1
  4. package/dist/apis/device/clipboard.ts +23 -8
  5. package/dist/apis/framework/index.ts +2 -6
  6. package/dist/apis/index.ts +25 -17
  7. package/dist/apis/media/image/index.ts +169 -17
  8. package/dist/apis/route/index.ts +1 -2
  9. package/dist/apis/storage/index.ts +135 -131
  10. package/dist/apis/ui/animation/animation.ts +71 -29
  11. package/dist/apis/ui/background.ts +3 -2
  12. package/dist/apis/ui/interaction/index.ts +58 -59
  13. package/dist/apis/ui/navigation-bar/index.ts +2 -2
  14. package/dist/apis/ui/pull-down-refresh.ts +9 -3
  15. package/dist/apis/ui/scroll/index.ts +6 -6
  16. package/dist/apis/ui/tab-bar.ts +4 -5
  17. package/dist/apis/utils/index.ts +20 -2
  18. package/dist/apis/utils/permissions.ts +6 -0
  19. package/dist/apis/wxml/IntersectionObserver.ts +18 -10
  20. package/dist/apis/wxml/selectorQuery.ts +26 -13
  21. package/dist/components-harmony-ets/button.ets +36 -9
  22. package/dist/components-harmony-ets/canvas.ets +51 -0
  23. package/dist/components-harmony-ets/checkbox.ets +69 -60
  24. package/dist/components-harmony-ets/form.ets +33 -15
  25. package/dist/components-harmony-ets/icon.ets +16 -8
  26. package/dist/components-harmony-ets/image.ets +22 -6
  27. package/dist/components-harmony-ets/index.ets +39 -0
  28. package/dist/components-harmony-ets/innerHtml.ets +6 -5
  29. package/dist/components-harmony-ets/input.ets +63 -37
  30. package/dist/components-harmony-ets/label.ets +43 -21
  31. package/dist/components-harmony-ets/listView.ets +32 -0
  32. package/dist/components-harmony-ets/movableArea.ets +110 -51
  33. package/dist/components-harmony-ets/movableView.ets +74 -47
  34. package/dist/components-harmony-ets/navigationBar.ets +65 -0
  35. package/dist/components-harmony-ets/pageMeta.ets +94 -0
  36. package/dist/components-harmony-ets/picker.ets +36 -33
  37. package/dist/components-harmony-ets/progress.ets +31 -24
  38. package/dist/components-harmony-ets/pseudo.ets +80 -0
  39. package/dist/components-harmony-ets/radio.ets +75 -66
  40. package/dist/components-harmony-ets/richText.ets +4 -25
  41. package/dist/components-harmony-ets/scrollList.ets +108 -0
  42. package/dist/components-harmony-ets/scrollView.ets +46 -42
  43. package/dist/components-harmony-ets/slider.ets +19 -15
  44. package/dist/components-harmony-ets/stickySection.ets +42 -0
  45. package/dist/components-harmony-ets/style.ets +386 -129
  46. package/dist/components-harmony-ets/swiper.ets +42 -5
  47. package/dist/components-harmony-ets/switch.ets +36 -32
  48. package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
  49. package/dist/components-harmony-ets/text.ets +102 -46
  50. package/dist/components-harmony-ets/textArea.ets +49 -34
  51. package/dist/components-harmony-ets/utils/AttributeManager.ets +2 -2
  52. package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
  53. package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
  54. package/dist/components-harmony-ets/utils/helper.ets +20 -8
  55. package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
  56. package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
  57. package/dist/components-harmony-ets/utils/index.ts +54 -50
  58. package/dist/components-harmony-ets/utils/styles.ets +169 -91
  59. package/dist/components-harmony-ets/video.ets +28 -20
  60. package/dist/components-harmony-ets/view.ets +45 -39
  61. package/dist/components-harmony-ets/webView.ets +6 -5
  62. package/dist/index.d.ts +152 -0
  63. package/dist/index.js +73 -44
  64. package/dist/index.js.map +1 -1
  65. package/dist/runtime-ets/bom/URL.ts +2 -0
  66. package/dist/runtime-ets/bom/document.ts +5 -4
  67. package/dist/runtime-ets/bom/getComputedStyle.ts +2 -3
  68. package/dist/runtime-ets/bom/history.ts +1 -0
  69. package/dist/runtime-ets/bom/location.ts +1 -0
  70. package/dist/runtime-ets/bom/navigator.ts +1 -21
  71. package/dist/runtime-ets/bom/raf.ts +1 -37
  72. package/dist/runtime-ets/bom/window.ts +10 -4
  73. package/dist/runtime-ets/constant.ts +17 -10
  74. package/dist/runtime-ets/current.ts +5 -2
  75. package/dist/runtime-ets/dom/bind.ts +28 -12
  76. package/dist/runtime-ets/dom/class-list.ts +2 -2
  77. package/dist/runtime-ets/dom/cssNesting.ts +419 -0
  78. package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
  79. package/dist/runtime-ets/dom/document.ts +9 -12
  80. package/dist/runtime-ets/dom/element/canvas.ts +137 -0
  81. package/dist/runtime-ets/dom/element/element.ts +379 -55
  82. package/dist/runtime-ets/dom/element/form.ts +26 -22
  83. package/dist/runtime-ets/dom/element/index.ts +22 -2
  84. package/dist/runtime-ets/dom/element/movableArea.ts +0 -1
  85. package/dist/runtime-ets/dom/element/movableView.ts +238 -2
  86. package/dist/runtime-ets/dom/element/normal.ts +27 -6
  87. package/dist/runtime-ets/dom/element/progress.ts +0 -2
  88. package/dist/runtime-ets/dom/element/text.ts +0 -8
  89. package/dist/runtime-ets/dom/element/video.ts +4 -4
  90. package/dist/runtime-ets/dom/element/webView.ts +4 -5
  91. package/dist/runtime-ets/dom/event-source.ts +1 -0
  92. package/dist/runtime-ets/dom/event.ts +3 -5
  93. package/dist/runtime-ets/dom/eventTarget.ts +3 -4
  94. package/dist/runtime-ets/dom/node.ts +53 -22
  95. package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +418 -237
  96. package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
  97. package/dist/runtime-ets/dom/stylesheet/type.ts +53 -11
  98. package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
  99. package/dist/runtime-ets/emitter/emitter.ts +1 -0
  100. package/dist/runtime-ets/env.ts +1 -0
  101. package/dist/runtime-ets/index.ts +23 -7
  102. package/dist/runtime-ets/interface/event.ts +1 -1
  103. package/dist/runtime-ets/interface/index.ts +6 -0
  104. package/dist/runtime-ets/utils/index.ts +78 -19
  105. package/dist/runtime-ets/utils/info.ts +2 -2
  106. package/dist/runtime-ets/utils/router.ts +9 -0
  107. package/dist/runtime-framework/react/app.ts +15 -11
  108. package/dist/runtime-framework/react/hooks.ts +1 -2
  109. package/dist/runtime-framework/react/index.ts +0 -2
  110. package/dist/runtime-framework/react/native-page.ts +217 -81
  111. package/dist/runtime-framework/react/page.ts +4 -10
  112. package/dist/runtime-framework/react/utils/index.ts +3 -3
  113. package/dist/runtime-framework/solid/app.ts +29 -46
  114. package/dist/runtime-framework/solid/connect.ts +21 -3
  115. package/dist/runtime-framework/solid/hooks.ts +16 -11
  116. package/dist/runtime-framework/solid/index.ts +6 -2
  117. package/dist/runtime-framework/solid/page.ts +84 -31
  118. package/dist/runtime-framework/solid/reconciler/props.ts +73 -29
  119. package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
  120. package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
  121. package/dist/runtime-framework/solid/utils/index.ts +3 -5
  122. package/dist/runtime-utils.d.ts +827 -0
  123. package/dist/runtime-utils.js +574 -285
  124. package/dist/runtime-utils.js.map +1 -1
  125. package/dist/runtime.d.ts +1 -0
  126. package/dist/runtime.js +574 -285
  127. package/dist/runtime.js.map +1 -1
  128. package/index.js +3 -1
  129. package/package.json +14 -15
  130. package/static/media/cancel.svg +1 -1
  131. package/static/media/circle.svg +1 -1
  132. package/static/media/clear.svg +1 -1
  133. package/static/media/download.svg +1 -1
  134. package/static/media/info.svg +1 -1
  135. package/static/media/info_circle.svg +1 -1
  136. package/static/media/search.svg +1 -1
  137. package/static/media/success.svg +1 -1
  138. package/static/media/success_no_circle.svg +1 -1
  139. package/static/media/warn.svg +1 -1
  140. package/types/harmony.d.ts +5 -0
  141. package/types/index.d.ts +4 -0
  142. package/types/runtime.d.ts +1 -1
  143. /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";
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>;
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
@@ -4,10 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var helper = require('@tarojs/helper');
6
6
  var path = require('node:path');
7
- var runnerUtils = require('@tarojs/runner-utils');
8
- var shared = require('@tarojs/shared');
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
 
@@ -158,7 +157,7 @@ export {
158
157
  const PLATFORM_NAME = 'harmony';
159
158
  const PACKAGE_NAME = '@tarojs/plugin-platform-harmony-ets';
160
159
  const PLUGIN_NAME = 'TaroHarmony';
161
- const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//, /^@jd-oh\//];
160
+ const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//];
162
161
 
163
162
  function parseRelativePath(from, to) {
164
163
  const relativePath = path.relative(from, to).replace(/\\/g, '/');
@@ -180,8 +179,8 @@ class TaroPlatformHarmony extends service.TaroPlatform {
180
179
  * 2. 输出编译提示
181
180
  */
182
181
  setup() {
183
- var _a, _b;
184
182
  return __awaiter(this, void 0, void 0, function* () {
183
+ var _a, _b;
185
184
  yield this.setupTransaction.perform(this.setupHarmonyApp, this);
186
185
  (_b = (_a = this.ctx).onSetupClose) === null || _b === void 0 ? void 0 : _b.call(_a, this);
187
186
  });
@@ -237,6 +236,7 @@ class TaroPlatformHarmony extends service.TaroPlatform {
237
236
  * @param extraOptions 需要额外合入 Options 的配置项
238
237
  */
239
238
  getOptions(extraOptions = {}) {
239
+ var _a, _b, _c;
240
240
  const { ctx } = this;
241
241
  const { recursiveMerge } = ctx.helper;
242
242
  const config = recursiveMerge(Object.assign({}, this.config), {
@@ -248,21 +248,21 @@ class TaroPlatformHarmony extends service.TaroPlatform {
248
248
  SUPPORT_TARO_POLYFILL: 'disabled',
249
249
  },
250
250
  });
251
- 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);
252
252
  }
253
253
  /**
254
254
  * 调用 runner 开始编译
255
255
  * @param extraOptions 需要额外传入 runner 的配置项
256
256
  */
257
- build(extraOptions = {}) {
258
- var _a, _b;
259
- return __awaiter(this, void 0, void 0, function* () {
257
+ build() {
258
+ return __awaiter(this, arguments, void 0, function* (extraOptions = {}) {
259
+ var _a, _b;
260
260
  (_b = (_a = this.ctx).onBuildInit) === null || _b === void 0 ? void 0 : _b.call(_a, this);
261
261
  yield this.buildTransaction.perform(this.buildHarmonyApp, this, extraOptions);
262
262
  });
263
263
  }
264
- buildHarmonyApp(extraOptions = {}) {
265
- return __awaiter(this, void 0, void 0, function* () {
264
+ buildHarmonyApp() {
265
+ return __awaiter(this, arguments, void 0, function* (extraOptions = {}) {
266
266
  const runner = yield this.getRunner();
267
267
  const options = this.getOptions(Object.assign({
268
268
  runtimePath: this.runtimePath,
@@ -285,7 +285,6 @@ class TaroPlatformHarmony extends service.TaroPlatform {
285
285
  var _Harmony_defineConstants;
286
286
  const frameworkAlias = {
287
287
  solid: 'solid',
288
- vue: 'vue2',
289
288
  vue3: 'vue3',
290
289
  };
291
290
  let Harmony$1 = class Harmony extends TaroPlatformHarmony {
@@ -303,6 +302,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
303
302
  this.useJSON5 = true;
304
303
  this.runtimePath = [];
305
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
+ ];
306
308
  _Harmony_defineConstants.set(this, {});
307
309
  this.extensions = ['.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs', '.mts', '.vue', '.ets', '.d.ts'];
308
310
  this.excludeLibraries = [];
@@ -317,14 +319,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
317
319
  ['react', /^react$|react[\\/]cjs/],
318
320
  ['react/jsx-runtime', /^react[\\/]jsx-runtime$/], // Note: React 环境下自动注入,避免重复
319
321
  ];
322
+ this.harmonyScope = [...HARMONY_SCOPES];
323
+ const that = this;
320
324
  this.setupTransaction.addWrapper({
321
325
  close() {
322
- this.modifyViteConfig();
326
+ that.modifyViteConfig();
323
327
  },
324
328
  });
325
329
  ctx.onBuildFinish(() => {
326
330
  const outDir = path__namespace.resolve(process.cwd(), config.outputRoot);
327
- this.handleResourceEmit(outDir);
331
+ that.handleResourceEmit(outDir);
328
332
  });
329
333
  }
330
334
  get framework() {
@@ -336,6 +340,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
336
340
  get apiLibrary() {
337
341
  return path__namespace.resolve(__dirname, './apis');
338
342
  }
343
+ get apiEntry() {
344
+ return this.apiEntryList;
345
+ }
339
346
  get componentLibrary() {
340
347
  return path__namespace.resolve(__dirname, './components-harmony-ets');
341
348
  }
@@ -357,6 +364,7 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
357
364
  env.forEach(([key, value]) => {
358
365
  __classPrivateFieldGet(this, _Harmony_defineConstants, "f")[`process.env.${key}`] = JSON.stringify(value);
359
366
  });
367
+ return __classPrivateFieldGet(this, _Harmony_defineConstants, "f");
360
368
  }
361
369
  indexOfLibraries(lib) {
362
370
  return this.externalDeps.findIndex(([_, rgx]) => rgx.test(lib));
@@ -421,9 +429,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
421
429
  }
422
430
  if (ext) {
423
431
  const code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
424
- if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code)
425
- || /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code))
426
- && `${libName}${path__namespace.extname(libDir)}` !== libDir) {
432
+ if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code) ||
433
+ /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code)) &&
434
+ `${libName}${path__namespace.extname(libDir)}` !== libDir) {
435
+ // Note: 文件包含包内引用的依赖
427
436
  const pkgPath = path__namespace.relative(libName, libDir);
428
437
  if (new RegExp(`^index(${this.extensions.map(e => e.replace('.', '\\.')).join('|')})$`).test(pkgPath)) {
429
438
  // Note: 入口为 index 场景
@@ -474,17 +483,20 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
474
483
  }
475
484
  else if (stat.isFile()) {
476
485
  let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
477
- // TODO: 后续这部分代码应该根据使用的框架抽离到对应的平台插件处
478
- if ([/(@tarojs[\\/]plugin-platform-harmony-ets|taro-platform-harmony)[\\/]dist[\\/]apis[\\/]index\.ts/].some(e => e.test(lib))) {
486
+ if (this.apiEntry.some(e => e.test(lib))) {
479
487
  code = apiLoader(code);
480
488
  }
481
489
  if (this.extensions.includes(path__namespace.extname(lib))) {
490
+ // Note: 移除 onpm 不能装载的类型,新版本会导致 ets-loader 抛出 resolvedFileName 异常
491
+ code = code.replace(/\/{3}\s*<reference\s+types=['"]([^'"\s]+)['"]\s*\/>\n*/g, '');
482
492
  // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps 中
483
- code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
493
+ code = code.replace(/(?:import\s|from\s|require\()['"]([^\\/.][^'"\s]+)['"]\)?/g, (src, p1 = '') => {
494
+ if (p1.startsWith('node:') || p1.endsWith('.so'))
495
+ return src;
484
496
  const { outputRoot } = this.ctx.runOpts.config;
485
497
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
486
498
  const relativePath = parseRelativePath(path__namespace.dirname(target), targetPath);
487
- if (HARMONY_SCOPES.every(e => !e.test(p1))) {
499
+ if (this.harmonyScope.every(e => !e.test(p1))) {
488
500
  if (this.indexOfLibraries(p1) === -1 && !/\.(d\.ts|flow\.js)$/.test(lib)) {
489
501
  this.externalDeps.push([p1, new RegExp(`^${p1.replace(/([-\\/$])/g, '\\$1')}$`)]);
490
502
  this.moveLibraries(p1, targetPath, path__namespace.dirname(lib), true);
@@ -493,15 +505,24 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
493
505
  }
494
506
  return src;
495
507
  });
496
- const define = Object.assign({}, this.defineConstants);
508
+ const define = Object.assign(Object.assign({}, this.defineConstants), {
509
+ // Note: React 开发环境可能调用 stack 可能导致 appWrapper 实例变更
510
+ 'ReactDebugCurrentFrame.getCurrentStack': 'ReactDebugCurrentFrame.getCurrentStack$' });
497
511
  if ([/(@tarojs[\\/]runtime|taro-runtime)[\\/]dist/].some(e => e.test(lib))) {
498
512
  define.global = 'globalThis';
499
513
  }
500
- code = this.replaceDefineValue(code, define);
501
514
  const ext = path__namespace.extname(target);
515
+ if (![/d\.e?tsx?$/, /\.(json|map|md)$/].some(e => e.test(target))) {
516
+ code = this.replaceDefineValue(code, define, ext);
517
+ }
502
518
  if (['.ts'].includes(ext)) {
503
519
  code = '// @ts-nocheck\n' + code;
504
520
  }
521
+ // 处理嵌套样式的编译,需要针对ReactElement进行props操作,dev模式下会Object.freeze,所以需要在开发模式下注入Object.freeze来覆盖解锁
522
+ // 处理的方法再taro-platform-harmony/src/runtime-ets/dom/cssNesting: ele.props.style = declaration
523
+ if (/react\/jsx-runtime/.test(lib) && process.env.NODE_ENV === 'development') {
524
+ code = 'Object.freeze = (obj) => obj \n' + code;
525
+ }
505
526
  }
506
527
  // Note: 传入 chorePackagePrefix 时,不生成核心依赖库
507
528
  if (!chorePackagePrefix) {
@@ -542,9 +563,13 @@ declare global {
542
563
  this.moveLibraries(realPath, target, basedir);
543
564
  }
544
565
  }
545
- replaceDefineValue(code, define) {
566
+ replaceDefineValue(code, define, ext = '.js') {
546
567
  Object.keys(define).forEach(key => {
547
- code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), define[key]);
568
+ let value = define[key];
569
+ if (/^['"`].*['"`]$/.test(value) && ['.ts', '.tsx', '.ets'].includes(ext)) {
570
+ value = `(${value} as string)`;
571
+ }
572
+ code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), value);
548
573
  });
549
574
  return code;
550
575
  }
@@ -563,8 +588,8 @@ declare global {
563
588
  // @ts-ignore
564
589
  if (that.framework === 'solid') {
565
590
  that.externalDeps.push([
566
- '@tarojs/plugin-framework-react/dist/runtime/reconciler',
567
- /^@tarojs\/plugin-framework-react\/dist\/runtime\/reconciler$/,
591
+ '@tarojs/plugin-framework-solid/dist/reconciler',
592
+ /^@tarojs\/plugin-framework-solid\/dist\/reconciler$/,
568
593
  path__namespace.join(this.runtimeFrameworkLibrary, 'reconciler')
569
594
  ]);
570
595
  that.externalDeps.push([
@@ -572,15 +597,24 @@ declare global {
572
597
  /^solid-js\/universal$/,
573
598
  ]);
574
599
  }
600
+ const chorePkgRgx = new RegExp(`^${(chorePackagePrefix || '').replace(/[\\/]+/g, '[\\\\/]+').replace(/[-^$*?.|]/g, '\\$&')}`);
575
601
  const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
576
- function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
577
- if (externals.includes(source)) {
602
+ function modifyResolveId({ source = '', name = 'modifyResolveId' }) {
603
+ if (externals.includes(source) || (chorePackagePrefix && chorePkgRgx.test(source))) {
578
604
  return {
579
605
  external: true,
580
606
  id: source,
581
607
  resolvedBy: name,
582
608
  };
583
609
  }
610
+ else if (source.includes('css_variables')) {
611
+ return {
612
+ external: true,
613
+ id: path__namespace.join(outputRoot, 'css_variables'),
614
+ moduleSideEffects: 'no-treeshake',
615
+ resolvedBy: name,
616
+ };
617
+ }
584
618
  if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
585
619
  return {
586
620
  external: true,
@@ -588,11 +622,6 @@ declare global {
588
622
  resolvedBy: name,
589
623
  };
590
624
  }
591
- if (shared.isFunction(resolve)) {
592
- if (source === that.runtimePath || that.runtimePath.includes(source)) {
593
- return resolve('@tarojs/runtime', importer, options);
594
- }
595
- }
596
625
  // Note: 映射 Taro 相关依赖到注入 taro 目录
597
626
  if (that.indexOfLibraries(source) > -1) {
598
627
  return {
@@ -622,19 +651,18 @@ declare global {
622
651
  }
623
652
  function injectLoaderMeta() {
624
653
  return {
625
- name: 'taro:vite-h5-loader-meta',
654
+ name: 'taro:vite-loader-meta',
626
655
  buildStart() {
627
656
  return __awaiter(this, void 0, void 0, function* () {
628
- yield this.load({ id: runnerUtils.VITE_COMPILER_LABEL });
629
- const info = this.getModuleInfo(runnerUtils.VITE_COMPILER_LABEL);
630
- const compiler = info === null || info === void 0 ? void 0 : info.meta.viteCompilerContext;
657
+ const { getViteHarmonyCompilerContext } = that.ctx.runnerUtils;
658
+ const compiler = getViteHarmonyCompilerContext(this);
631
659
  if (compiler) {
632
660
  switch (that.framework) {
633
661
  // @ts-ignore
634
662
  case 'solid':
635
663
  compiler.loaderMeta || (compiler.loaderMeta = {});
636
664
  compiler.loaderMeta.importFrameworkStatement = ``;
637
- compiler.mockAppStatement = `
665
+ compiler.loaderMeta.mockAppStatement = `
638
666
  function App(props) {
639
667
  return null
640
668
  }
@@ -1030,7 +1058,7 @@ class Harmony extends service.TaroPlatformBase {
1030
1058
  * 等鸿蒙支持 template 后需要重构
1031
1059
  */
1032
1060
  addEntry() {
1033
- this.ctx.onCompilerMake(({ compilation, plugin }) => __awaiter(this, void 0, void 0, function* () {
1061
+ this.ctx.onCompilerMake((_a) => __awaiter(this, [_a], void 0, function* ({ compilation, plugin }) {
1034
1062
  // container/index.hml
1035
1063
  const filePath = path.resolve(__dirname, 'template/container');
1036
1064
  plugin.addEntry(filePath, 'container/index', helper.META_TYPE.STATIC);
@@ -1233,8 +1261,8 @@ class Harmony extends service.TaroPlatformBase {
1233
1261
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1234
1262
  });
1235
1263
  }
1236
- modifyHostPackage({ projectPath, hapName = 'entry' }) {
1237
- return __awaiter(this, void 0, void 0, function* () {
1264
+ modifyHostPackage(_a) {
1265
+ return __awaiter(this, arguments, void 0, function* ({ projectPath, hapName = 'entry' }) {
1238
1266
  const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1239
1267
  const hmsDeps = {
1240
1268
  '@hmscore/hms-js-base': '^6.1.0-300',
@@ -1259,7 +1287,7 @@ class Harmony extends service.TaroPlatformBase {
1259
1287
  return packageJson;
1260
1288
  });
1261
1289
  }
1262
- getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {
1290
+ getChunkEntryModule(compilation, chunk, compiler = 'webpack5') {
1263
1291
  if (compiler === 'webpack5') {
1264
1292
  const chunkGraph = compilation.chunkGraph;
1265
1293
  const entryModules = Array.from(chunkGraph.getChunkEntryModulesIterable(chunk));
@@ -1300,8 +1328,8 @@ var index = (ctx, options = {}) => {
1300
1328
  ctx.registerPlatform({
1301
1329
  name: PLATFORM_NAME,
1302
1330
  useConfigName: options.useConfigName || PLATFORM_NAME,
1303
- fn({ config }) {
1304
- return __awaiter(this, void 0, void 0, function* () {
1331
+ fn(_a) {
1332
+ return __awaiter(this, arguments, void 0, function* ({ config }) {
1305
1333
  const program = new Harmony$2(ctx, config);
1306
1334
  yield program.start();
1307
1335
  });
@@ -1325,6 +1353,7 @@ function assertHarmonyConfig(ctx, config) {
1325
1353
  }
1326
1354
  }
1327
1355
 
1356
+ exports.HarmonyOS_ArkTS = Harmony$1;
1328
1357
  exports.HarmonyOS_JSUI = Harmony;
1329
1358
  exports.default = index;
1330
1359
  //# sourceMappingURL=index.js.map