@tarojs/plugin-platform-harmony-ets 4.0.0-beta.8 → 4.0.0-beta.81
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/dist/apis/base/system.ts +73 -20
- package/dist/apis/canvas/index.ts +10 -1
- package/dist/apis/device/clipboard.ts +16 -8
- package/dist/apis/framework/index.ts +1 -5
- package/dist/apis/index.ts +25 -17
- package/dist/apis/media/image/index.ts +1 -1
- package/dist/apis/network/request.ts +5 -5
- package/dist/apis/route/index.ts +15 -0
- package/dist/apis/storage/index.ts +146 -78
- package/dist/apis/ui/animation/animation.ts +71 -29
- package/dist/apis/ui/background.ts +2 -1
- package/dist/apis/ui/interaction/index.ts +42 -59
- package/dist/apis/ui/navigation-bar/index.ts +1 -1
- package/dist/apis/ui/pull-down-refresh.ts +9 -3
- package/dist/apis/ui/scroll/index.ts +5 -5
- package/dist/apis/ui/tab-bar.ts +3 -3
- package/dist/apis/utils/index.ts +1 -1
- package/dist/apis/wxml/IntersectionObserver.ts +18 -10
- package/dist/apis/wxml/selectorQuery.ts +26 -13
- package/dist/components-harmony-ets/button.ets +64 -34
- package/dist/components-harmony-ets/canvas.ets +51 -0
- package/dist/components-harmony-ets/checkbox.ets +72 -61
- package/dist/components-harmony-ets/form.ets +51 -29
- package/dist/components-harmony-ets/icon.ets +31 -19
- package/dist/components-harmony-ets/image.ets +34 -14
- package/dist/components-harmony-ets/index.ets +92 -0
- package/dist/components-harmony-ets/innerHtml.ets +11 -6
- package/dist/components-harmony-ets/input.ets +49 -41
- package/dist/components-harmony-ets/label.ets +71 -44
- package/dist/components-harmony-ets/listView.ets +26 -0
- package/dist/components-harmony-ets/movableArea.ets +126 -0
- package/dist/components-harmony-ets/movableView.ets +93 -0
- package/dist/components-harmony-ets/navigationBar.ets +65 -0
- package/dist/components-harmony-ets/pageMeta.ets +94 -0
- package/dist/components-harmony-ets/picker.ets +42 -38
- package/dist/components-harmony-ets/progress.ets +52 -0
- package/dist/components-harmony-ets/pseudo.ets +80 -0
- package/dist/components-harmony-ets/radio.ets +74 -64
- package/dist/components-harmony-ets/richText.ets +14 -30
- package/dist/components-harmony-ets/scrollList.ets +94 -0
- package/dist/components-harmony-ets/scrollView.ets +61 -57
- package/dist/components-harmony-ets/slider.ets +18 -14
- package/dist/components-harmony-ets/stickySection.ets +42 -0
- package/dist/components-harmony-ets/style.ets +372 -130
- package/dist/components-harmony-ets/swiper.ets +61 -20
- package/dist/components-harmony-ets/switch.ets +36 -32
- package/dist/components-harmony-ets/{index.ts → tag.ts} +6 -0
- package/dist/components-harmony-ets/text.ets +135 -49
- package/dist/components-harmony-ets/textArea.ets +50 -35
- package/dist/components-harmony-ets/utils/AttributeManager.ets +1 -1
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +2 -2
- package/dist/components-harmony-ets/utils/flexManager.ets +49 -19
- package/dist/components-harmony-ets/utils/helper.ets +18 -5
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +1 -2
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +1 -1
- package/dist/components-harmony-ets/utils/index.ts +54 -50
- package/dist/components-harmony-ets/utils/styles.ets +170 -93
- package/dist/components-harmony-ets/video.ets +34 -21
- package/dist/components-harmony-ets/view.ets +63 -52
- package/dist/components-harmony-ets/webView.ets +40 -34
- package/dist/index.d.ts +152 -0
- package/dist/index.js +87 -43
- package/dist/index.js.map +1 -1
- package/dist/runtime-ets/bom/document.ts +6 -4
- package/dist/runtime-ets/bom/getComputedStyle.ts +2 -2
- package/dist/runtime-ets/bom/window.ts +7 -0
- package/dist/runtime-ets/current.ts +3 -0
- package/dist/runtime-ets/dom/bind.ts +28 -12
- package/dist/runtime-ets/dom/class-list.ts +2 -2
- package/dist/runtime-ets/dom/cssNesting.ts +419 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +28 -42
- package/dist/runtime-ets/dom/document.ts +8 -11
- package/dist/runtime-ets/dom/element/canvas.ts +136 -0
- package/dist/runtime-ets/dom/element/element.ts +348 -57
- package/dist/runtime-ets/dom/element/form.ts +23 -26
- package/dist/runtime-ets/dom/element/index.ts +30 -2
- package/dist/runtime-ets/dom/element/movableArea.ts +11 -0
- package/dist/runtime-ets/dom/element/movableView.ts +244 -0
- package/dist/runtime-ets/dom/element/normal.ts +35 -8
- package/dist/runtime-ets/dom/element/progress.ts +11 -0
- package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
- package/dist/runtime-ets/dom/element/text.ts +1 -8
- package/dist/runtime-ets/dom/element/video.ts +5 -4
- package/dist/runtime-ets/dom/element/webView.ts +12 -5
- package/dist/runtime-ets/dom/event.ts +2 -4
- package/dist/runtime-ets/dom/eventTarget.ts +2 -3
- package/dist/runtime-ets/dom/node.ts +54 -29
- package/dist/runtime-ets/dom/stylesheet/covertWeb2Hm.ts +416 -235
- package/dist/runtime-ets/dom/stylesheet/index.ts +29 -311
- package/dist/runtime-ets/dom/stylesheet/type.ts +49 -9
- package/dist/runtime-ets/dom/stylesheet/util.ts +33 -27
- package/dist/runtime-ets/index.ts +2 -1
- package/dist/runtime-ets/interface/event.ts +1 -1
- package/dist/runtime-ets/utils/index.ts +73 -13
- package/dist/runtime-ets/utils/info.ts +2 -2
- package/dist/runtime-framework/react/app.ts +9 -4
- package/dist/runtime-framework/react/hooks.ts +0 -1
- package/dist/runtime-framework/react/index.ts +0 -2
- package/dist/runtime-framework/react/native-page.ts +154 -77
- package/dist/runtime-framework/react/page.ts +3 -8
- package/dist/runtime-framework/solid/app.ts +25 -45
- package/dist/runtime-framework/solid/connect.ts +21 -3
- package/dist/runtime-framework/solid/hooks.ts +16 -11
- package/dist/runtime-framework/solid/index.ts +6 -2
- package/dist/runtime-framework/solid/page.ts +84 -30
- package/dist/runtime-framework/solid/reconciler/props.ts +70 -25
- package/dist/runtime-framework/solid/reconciler/render.ts +16 -6
- package/dist/runtime-framework/solid/reconciler/use.ts +0 -1
- package/dist/runtime-framework/solid/utils/index.ts +0 -2
- package/dist/runtime-utils.d.ts +827 -0
- package/dist/runtime-utils.js +449 -219
- package/dist/runtime-utils.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +449 -219
- package/dist/runtime.js.map +1 -1
- package/index.js +3 -1
- package/package.json +13 -13
- package/static/media/cancel.svg +1 -1
- package/static/media/circle.svg +1 -1
- package/static/media/clear.svg +1 -1
- package/static/media/download.svg +1 -1
- package/static/media/info.svg +1 -1
- package/static/media/info_circle.svg +1 -1
- package/static/media/search.svg +1 -1
- package/static/media/success.svg +1 -1
- package/static/media/success_no_circle.svg +1 -1
- package/static/media/warn.svg +1 -1
- package/types/harmony.d.ts +4 -0
- package/types/index.d.ts +4 -0
- /package/dist/runtime-framework/solid/{contant.ts → constant.ts} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AREA_CHANGE_EVENT_NAME, eventHandler, getComponentEventCallback, VISIBLE_CHANGE_EVENT_NAME, createTaroEvent } from '@tarojs/runtime'
|
|
2
2
|
|
|
3
3
|
import commonStyleModify from './style'
|
|
4
|
-
import {
|
|
4
|
+
import { shouldBindEvent, getNodeThresholds } from './utils/helper'
|
|
5
5
|
|
|
6
|
-
import type { TaroAny, TaroWebViewElement,
|
|
6
|
+
import type { TaroAny, TaroWebViewElement, TaroEvent } from '@tarojs/runtime'
|
|
7
7
|
|
|
8
8
|
interface IPageLoad {
|
|
9
9
|
url: string
|
|
@@ -14,37 +14,43 @@ interface IError {
|
|
|
14
14
|
error: WebResourceError
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
@
|
|
18
|
-
export default
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
@Component
|
|
18
|
+
export default struct TaroWebView {
|
|
19
|
+
@Builder customBuilder() {}
|
|
20
|
+
@BuilderParam createLazyChildren: (node: TaroWebViewElement) => void = this.customBuilder
|
|
21
|
+
@ObjectLink node: TaroWebViewElement
|
|
22
|
+
|
|
23
|
+
build () {
|
|
24
|
+
Web({ src: this.node._attrs.src, controller: this.node.controller })
|
|
25
|
+
.attributeModifier(commonStyleModify.setNode(this.node))
|
|
26
|
+
.onPageEnd((e: IPageLoad) => {
|
|
27
|
+
// 1. 创建消息端口
|
|
28
|
+
this.node.ports = this.node.controller.createWebMessagePorts(true)
|
|
29
|
+
// 2. 发送端口1到HTML5
|
|
30
|
+
this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
|
|
31
|
+
// 3. 保存端口0到本地
|
|
32
|
+
this.node.nativePort = this.node.ports[0]
|
|
33
|
+
// 4. 设置回调函数
|
|
34
|
+
this.node.nativePort.onMessageEventExt((result) => {
|
|
35
|
+
const message = this.node.handleMessageFromWeb(result)
|
|
36
|
+
const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
|
|
37
|
+
|
|
38
|
+
eventHandler(messageEvent, 'message', this.node)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
|
|
42
|
+
|
|
43
|
+
eventHandler(onLoadEvent, 'load', this.node)
|
|
34
44
|
})
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
47
|
-
node._nodeInfo.areaInfo = res[1]
|
|
48
|
-
}))
|
|
49
|
-
.onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
|
|
45
|
+
.onErrorReceive(shouldBindEvent((e: IError) => {
|
|
46
|
+
const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
|
|
47
|
+
|
|
48
|
+
eventHandler(event, 'error', this.node)
|
|
49
|
+
}, this.node, ['error']))
|
|
50
|
+
.onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
|
|
51
|
+
.onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
|
|
52
|
+
this.node._nodeInfo.areaInfo = res[1]
|
|
53
|
+
}))
|
|
54
|
+
.onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
|
|
55
|
+
}
|
|
50
56
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -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" | "nerv" | "vue";
|
|
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
|
@@ -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
|
|
|
@@ -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,7 +248,7 @@ 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 开始编译
|
|
@@ -303,6 +303,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
303
303
|
this.useJSON5 = true;
|
|
304
304
|
this.runtimePath = [];
|
|
305
305
|
this.taroComponentsPath = `${PACKAGE_NAME}/dist/components-harmony-ets`;
|
|
306
|
+
this.apiEntryList = [
|
|
307
|
+
/(@tarojs[\\/]plugin-platform-harmony-ets|taro-platform-harmony)[\\/]dist[\\/]apis[\\/]index\.ts/,
|
|
308
|
+
];
|
|
306
309
|
_Harmony_defineConstants.set(this, {});
|
|
307
310
|
this.extensions = ['.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs', '.mts', '.vue', '.ets', '.d.ts'];
|
|
308
311
|
this.excludeLibraries = [];
|
|
@@ -317,14 +320,16 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
317
320
|
['react', /^react$|react[\\/]cjs/],
|
|
318
321
|
['react/jsx-runtime', /^react[\\/]jsx-runtime$/], // Note: React 环境下自动注入,避免重复
|
|
319
322
|
];
|
|
323
|
+
this.harmonyScope = [...HARMONY_SCOPES];
|
|
324
|
+
const that = this;
|
|
320
325
|
this.setupTransaction.addWrapper({
|
|
321
326
|
close() {
|
|
322
|
-
|
|
327
|
+
that.modifyViteConfig();
|
|
323
328
|
},
|
|
324
329
|
});
|
|
325
330
|
ctx.onBuildFinish(() => {
|
|
326
331
|
const outDir = path__namespace.resolve(process.cwd(), config.outputRoot);
|
|
327
|
-
|
|
332
|
+
that.handleResourceEmit(outDir);
|
|
328
333
|
});
|
|
329
334
|
}
|
|
330
335
|
get framework() {
|
|
@@ -336,6 +341,9 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
336
341
|
get apiLibrary() {
|
|
337
342
|
return path__namespace.resolve(__dirname, './apis');
|
|
338
343
|
}
|
|
344
|
+
get apiEntry() {
|
|
345
|
+
return this.apiEntryList;
|
|
346
|
+
}
|
|
339
347
|
get componentLibrary() {
|
|
340
348
|
return path__namespace.resolve(__dirname, './components-harmony-ets');
|
|
341
349
|
}
|
|
@@ -372,8 +380,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
372
380
|
return;
|
|
373
381
|
if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
|
|
374
382
|
return;
|
|
383
|
+
const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
|
|
375
384
|
if (sync) {
|
|
376
|
-
const { outputRoot } = this.ctx.runOpts.config;
|
|
377
385
|
const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
|
|
378
386
|
// FIXME 不支持 alias 配置
|
|
379
387
|
const libName = 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
|
-
|
|
426
|
-
|
|
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,16 +483,16 @@ 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
|
-
|
|
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))) {
|
|
482
|
-
|
|
490
|
+
// Note: 查询 externals 内的依赖,并将它们添加到 externalDeps 中
|
|
491
|
+
code = code.replace(/(?:import\s|from\s|require\()['"]([^\\/.][^'"\s]+)['"]\)?/g, (src, p1) => {
|
|
483
492
|
const { outputRoot } = this.ctx.runOpts.config;
|
|
484
493
|
const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
|
|
485
494
|
const relativePath = parseRelativePath(path__namespace.dirname(target), targetPath);
|
|
486
|
-
if (
|
|
495
|
+
if (this.harmonyScope.every(e => !e.test(p1))) {
|
|
487
496
|
if (this.indexOfLibraries(p1) === -1 && !/\.(d\.ts|flow\.js)$/.test(lib)) {
|
|
488
497
|
this.externalDeps.push([p1, new RegExp(`^${p1.replace(/([-\\/$])/g, '\\$1')}$`)]);
|
|
489
498
|
this.moveLibraries(p1, targetPath, path__namespace.dirname(lib), true);
|
|
@@ -492,18 +501,29 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
|
492
501
|
}
|
|
493
502
|
return src;
|
|
494
503
|
});
|
|
495
|
-
const define = Object.assign({}, this.defineConstants)
|
|
504
|
+
const define = Object.assign(Object.assign({}, this.defineConstants), {
|
|
505
|
+
// Note: React 开发环境可能调用 stack 可能导致 appWrapper 实例变更
|
|
506
|
+
'ReactDebugCurrentFrame.getCurrentStack': 'ReactDebugCurrentFrame.getCurrentStack$' });
|
|
496
507
|
if ([/(@tarojs[\\/]runtime|taro-runtime)[\\/]dist/].some(e => e.test(lib))) {
|
|
497
508
|
define.global = 'globalThis';
|
|
498
509
|
}
|
|
499
|
-
code = this.replaceDefineValue(code, define);
|
|
500
510
|
const ext = path__namespace.extname(target);
|
|
511
|
+
if (![/d\.e?tsx?$/, /\.(json|map|md)$/].some(e => e.test(target))) {
|
|
512
|
+
code = this.replaceDefineValue(code, define, ext);
|
|
513
|
+
}
|
|
501
514
|
if (['.ts'].includes(ext)) {
|
|
502
515
|
code = '// @ts-nocheck\n' + code;
|
|
503
516
|
}
|
|
517
|
+
// 处理嵌套样式的编译,需要针对ReactElement进行props操作,dev模式下会Object.freeze,所以需要在开发模式下注入Object.freeze来覆盖解锁
|
|
518
|
+
// 处理的方法再taro-platform-harmony/src/runtime-ets/dom/cssNesting: ele.props.style = declaration
|
|
519
|
+
if (/react\/jsx-runtime/.test(lib) && process.env.NODE_ENV === 'development') {
|
|
520
|
+
code = 'Object.freeze = (obj) => obj \n' + code;
|
|
521
|
+
}
|
|
504
522
|
}
|
|
505
|
-
|
|
506
|
-
|
|
523
|
+
// Note: 传入 chorePackagePrefix 时,不生成核心依赖库
|
|
524
|
+
if (!chorePackagePrefix) {
|
|
525
|
+
if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
|
|
526
|
+
code = `/// <reference path="global.d.ts" />
|
|
507
527
|
|
|
508
528
|
/// <reference path="taro.api.d.ts" />
|
|
509
529
|
/// <reference path="taro.component.d.ts" />
|
|
@@ -523,14 +543,15 @@ declare global {
|
|
|
523
543
|
const defineAppConfig: (config: Taro.Config) => Taro.Config
|
|
524
544
|
const definePageConfig: (config: Taro.Config) => Taro.Config
|
|
525
545
|
}`;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
546
|
+
}
|
|
547
|
+
try {
|
|
548
|
+
const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
|
|
549
|
+
helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
|
|
550
|
+
helper.fs.writeFileSync(targetPath, code);
|
|
551
|
+
}
|
|
552
|
+
catch (e) {
|
|
553
|
+
console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
|
|
554
|
+
}
|
|
534
555
|
}
|
|
535
556
|
}
|
|
536
557
|
else if (stat.isSymbolicLink()) {
|
|
@@ -538,9 +559,13 @@ declare global {
|
|
|
538
559
|
this.moveLibraries(realPath, target, basedir);
|
|
539
560
|
}
|
|
540
561
|
}
|
|
541
|
-
replaceDefineValue(code, define) {
|
|
562
|
+
replaceDefineValue(code, define, ext = '.js') {
|
|
542
563
|
Object.keys(define).forEach(key => {
|
|
543
|
-
|
|
564
|
+
let value = define[key];
|
|
565
|
+
if (/^['"`].*['"`]$/.test(value) && ['.ts', '.tsx', '.ets'].includes(ext)) {
|
|
566
|
+
value = `(${value} as string)`;
|
|
567
|
+
}
|
|
568
|
+
code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), value);
|
|
544
569
|
});
|
|
545
570
|
return code;
|
|
546
571
|
}
|
|
@@ -552,15 +577,15 @@ declare global {
|
|
|
552
577
|
const that = this;
|
|
553
578
|
const { appPath } = that.ctx.paths;
|
|
554
579
|
const { config } = that.ctx.runOpts;
|
|
555
|
-
const { outputRoot } = config;
|
|
580
|
+
const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
|
|
556
581
|
if (!that.framework.includes('vue')) {
|
|
557
582
|
that.excludeLibraries.push(/\bvue\b/);
|
|
558
583
|
}
|
|
559
584
|
// @ts-ignore
|
|
560
585
|
if (that.framework === 'solid') {
|
|
561
586
|
that.externalDeps.push([
|
|
562
|
-
'@tarojs/plugin-framework-react/dist/
|
|
563
|
-
/^@tarojs\/plugin-framework-react\/dist\/
|
|
587
|
+
'@tarojs/plugin-framework-react/dist/reconciler',
|
|
588
|
+
/^@tarojs\/plugin-framework-react\/dist\/reconciler$/,
|
|
564
589
|
path__namespace.join(this.runtimeFrameworkLibrary, 'reconciler')
|
|
565
590
|
]);
|
|
566
591
|
that.externalDeps.push([
|
|
@@ -568,11 +593,29 @@ declare global {
|
|
|
568
593
|
/^solid-js\/universal$/,
|
|
569
594
|
]);
|
|
570
595
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
596
|
+
const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
|
|
597
|
+
function modifyResolveId({ source = '', name = 'modifyResolveId' }) {
|
|
598
|
+
if (externals.includes(source)) {
|
|
599
|
+
return {
|
|
600
|
+
external: true,
|
|
601
|
+
id: source,
|
|
602
|
+
resolvedBy: name,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
else if (source.includes('css_variables')) {
|
|
606
|
+
return {
|
|
607
|
+
external: true,
|
|
608
|
+
id: path__namespace.join(outputRoot, 'css_variables'),
|
|
609
|
+
moduleSideEffects: 'no-treeshake',
|
|
610
|
+
resolvedBy: name,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
|
|
614
|
+
return {
|
|
615
|
+
external: true,
|
|
616
|
+
id: path__namespace.join(chorePackagePrefix, source),
|
|
617
|
+
resolvedBy: name,
|
|
618
|
+
};
|
|
576
619
|
}
|
|
577
620
|
// Note: 映射 Taro 相关依赖到注入 taro 目录
|
|
578
621
|
if (that.indexOfLibraries(source) > -1) {
|
|
@@ -603,19 +646,18 @@ declare global {
|
|
|
603
646
|
}
|
|
604
647
|
function injectLoaderMeta() {
|
|
605
648
|
return {
|
|
606
|
-
name: 'taro:vite-
|
|
649
|
+
name: 'taro:vite-loader-meta',
|
|
607
650
|
buildStart() {
|
|
608
651
|
return __awaiter(this, void 0, void 0, function* () {
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
const compiler = info === null || info === void 0 ? void 0 : info.meta.viteCompilerContext;
|
|
652
|
+
const { getViteHarmonyCompilerContext } = that.ctx.runnerUtils;
|
|
653
|
+
const compiler = getViteHarmonyCompilerContext(this);
|
|
612
654
|
if (compiler) {
|
|
613
655
|
switch (that.framework) {
|
|
614
656
|
// @ts-ignore
|
|
615
657
|
case 'solid':
|
|
616
658
|
compiler.loaderMeta || (compiler.loaderMeta = {});
|
|
617
659
|
compiler.loaderMeta.importFrameworkStatement = ``;
|
|
618
|
-
compiler.mockAppStatement = `
|
|
660
|
+
compiler.loaderMeta.mockAppStatement = `
|
|
619
661
|
function App(props) {
|
|
620
662
|
return null
|
|
621
663
|
}
|
|
@@ -1151,7 +1193,7 @@ class Harmony extends service.TaroPlatformBase {
|
|
|
1151
1193
|
const outDir = path.join(compsOutDir, name);
|
|
1152
1194
|
helper.fs.copy(src, outDir);
|
|
1153
1195
|
});
|
|
1154
|
-
this.
|
|
1196
|
+
this.modifyHostPackage(config.harmony);
|
|
1155
1197
|
});
|
|
1156
1198
|
}
|
|
1157
1199
|
modifyWebpackConfig() {
|
|
@@ -1214,13 +1256,13 @@ class Harmony extends service.TaroPlatformBase {
|
|
|
1214
1256
|
console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
|
|
1215
1257
|
});
|
|
1216
1258
|
}
|
|
1217
|
-
|
|
1259
|
+
modifyHostPackage({ projectPath, hapName = 'entry' }) {
|
|
1218
1260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1261
|
+
const packageJsonFile = path.join(projectPath, hapName, 'package.json');
|
|
1219
1262
|
const hmsDeps = {
|
|
1220
1263
|
'@hmscore/hms-js-base': '^6.1.0-300',
|
|
1221
1264
|
'@hmscore/hms-jsb-account': '^1.0.300'
|
|
1222
1265
|
};
|
|
1223
|
-
const packageJsonFile = path.resolve(dest, '../../../../../package.json');
|
|
1224
1266
|
const isExists = yield helper.fs.pathExists(packageJsonFile);
|
|
1225
1267
|
if (!isExists)
|
|
1226
1268
|
return;
|
|
@@ -1237,6 +1279,7 @@ class Harmony extends service.TaroPlatformBase {
|
|
|
1237
1279
|
}
|
|
1238
1280
|
packageJson = JSON.stringify(packageJson);
|
|
1239
1281
|
yield helper.fs.writeFile(packageJsonFile, packageJson);
|
|
1282
|
+
return packageJson;
|
|
1240
1283
|
});
|
|
1241
1284
|
}
|
|
1242
1285
|
getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {
|
|
@@ -1305,6 +1348,7 @@ function assertHarmonyConfig(ctx, config) {
|
|
|
1305
1348
|
}
|
|
1306
1349
|
}
|
|
1307
1350
|
|
|
1351
|
+
exports.HarmonyOS_ArkTS = Harmony$1;
|
|
1308
1352
|
exports.HarmonyOS_JSUI = Harmony;
|
|
1309
1353
|
exports.default = index;
|
|
1310
1354
|
//# sourceMappingURL=index.js.map
|