@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var helper = require('@tarojs/helper');
|
|
6
|
+
var path = require('node:path');
|
|
7
|
+
var runnerUtils = require('@tarojs/runner-utils');
|
|
8
|
+
var shared = require('@tarojs/shared');
|
|
9
|
+
var service = require('@tarojs/service');
|
|
10
|
+
var _package = require('@tarojs/service/dist/utils/package');
|
|
11
|
+
var webpackSources = require('webpack-sources');
|
|
12
|
+
var template = require('@tarojs/shared/dist/template');
|
|
13
|
+
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
|
+
|
|
33
|
+
/******************************************************************************
|
|
34
|
+
Copyright (c) Microsoft Corporation.
|
|
35
|
+
|
|
36
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
37
|
+
purpose with or without fee is hereby granted.
|
|
38
|
+
|
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
40
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
41
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
42
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
43
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
44
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
45
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
46
|
+
***************************************************************************** */
|
|
47
|
+
/* global Reflect, Promise */
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
51
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
52
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
53
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
54
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
55
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
56
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
61
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
62
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
63
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
67
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
68
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
69
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
70
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const PLATFORM_NAME = 'harmony';
|
|
74
|
+
const PACKAGE_NAME = '@tarojs/plugin-platform-harmony';
|
|
75
|
+
const PLUGIN_NAME = 'TaroHarmony';
|
|
76
|
+
const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//];
|
|
77
|
+
|
|
78
|
+
function parseRelativePath(from, to) {
|
|
79
|
+
const relativePath = path.relative(from, to).replace(/\\/g, '/');
|
|
80
|
+
return /^\.{1,2}[\\/]/.test(relativePath)
|
|
81
|
+
? relativePath
|
|
82
|
+
: /^\.{1,2}$/.test(relativePath)
|
|
83
|
+
? `${relativePath}/`
|
|
84
|
+
: `./${relativePath}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class TaroPlatformHarmony extends service.TaroPlatform {
|
|
88
|
+
constructor() {
|
|
89
|
+
super(...arguments);
|
|
90
|
+
this.platformType = shared.PLATFORM_TYPE.HARMONY;
|
|
91
|
+
this.globalObject = 'globalThis';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 1. 清空 dist 文件夹
|
|
95
|
+
* 2. 输出编译提示
|
|
96
|
+
*/
|
|
97
|
+
setup() {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
yield this.setupTransaction.perform(this.setupHarmonyApp, this);
|
|
101
|
+
(_b = (_a = this.ctx).onSetupClose) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
setupHarmonyApp() {
|
|
105
|
+
const { output } = this.config;
|
|
106
|
+
// eslint-disable-next-line eqeqeq
|
|
107
|
+
if (output == undefined || output.clean == undefined || output.clean === true) {
|
|
108
|
+
this.emptyOutputDir();
|
|
109
|
+
}
|
|
110
|
+
else if (shared.isObject(output.clean)) {
|
|
111
|
+
this.emptyOutputDir(output.clean.keep || []);
|
|
112
|
+
}
|
|
113
|
+
this.printDevelopmentTip();
|
|
114
|
+
}
|
|
115
|
+
printDevelopmentTip() {
|
|
116
|
+
const tips = [];
|
|
117
|
+
const { chalk } = this.helper;
|
|
118
|
+
if (tips.length) {
|
|
119
|
+
console.log(chalk.yellowBright('Tips:'));
|
|
120
|
+
tips.forEach((item, index) => console.log(`${chalk.yellowBright(index + 1)}. ${item}`));
|
|
121
|
+
console.log('\n');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 返回当前项目内的 runner 包
|
|
126
|
+
*/
|
|
127
|
+
getRunner() {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const compilers = ['vite']; // , 'webpack5'
|
|
130
|
+
const { npm, chalk } = this.helper;
|
|
131
|
+
const { appPath } = this.ctx.paths;
|
|
132
|
+
if (compilers.indexOf(this.compiler) === -1) {
|
|
133
|
+
const errorChalk = chalk.hex('#f00');
|
|
134
|
+
console.log(errorChalk(`目前 Harmony 平台只支持使用 ${compilers.join(', ')} 编译,请在 config/index.ts 中设置 compiler = ${compilers[0]} 或者 harmony.compiler = ${compilers[0]}`));
|
|
135
|
+
process.exit(0);
|
|
136
|
+
}
|
|
137
|
+
let runnerPkg;
|
|
138
|
+
switch (this.compiler) {
|
|
139
|
+
case 'webpack5':
|
|
140
|
+
runnerPkg = '@tarojs/webpack5-runner';
|
|
141
|
+
break;
|
|
142
|
+
case 'vite':
|
|
143
|
+
default:
|
|
144
|
+
runnerPkg = '@tarojs/vite-runner';
|
|
145
|
+
}
|
|
146
|
+
const runner = yield npm.getNpmPkg(runnerPkg, appPath);
|
|
147
|
+
return runner.bind(null, appPath);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 准备 runner 参数
|
|
152
|
+
* @param extraOptions 需要额外合入 Options 的配置项
|
|
153
|
+
*/
|
|
154
|
+
getOptions(extraOptions = {}) {
|
|
155
|
+
const { ctx } = this;
|
|
156
|
+
const { recursiveMerge } = ctx.helper;
|
|
157
|
+
const config = recursiveMerge(Object.assign({}, this.config), {
|
|
158
|
+
env: {
|
|
159
|
+
FRAMEWORK: JSON.stringify(this.config.framework),
|
|
160
|
+
TARO_ENV: JSON.stringify(this.platform),
|
|
161
|
+
TARO_PLATFORM: JSON.stringify(this.platformType),
|
|
162
|
+
TARO_VERSION: JSON.stringify(_package.getPkgVersion())
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
return Object.assign(Object.assign(Object.assign({}, config), { buildAdapter: config.platform, fileType: this.fileType, platformType: this.platformType, useETS: this.useETS, useJSON5: this.useJSON5 }), extraOptions);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 调用 runner 开始编译
|
|
169
|
+
* @param extraOptions 需要额外传入 runner 的配置项
|
|
170
|
+
*/
|
|
171
|
+
build(extraOptions = {}) {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
(_b = (_a = this.ctx).onBuildInit) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
175
|
+
yield this.buildTransaction.perform(this.buildHarmonyApp, this, extraOptions);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
buildHarmonyApp(extraOptions = {}) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const runner = yield this.getRunner();
|
|
181
|
+
const options = this.getOptions(Object.assign({
|
|
182
|
+
runtimePath: this.runtimePath,
|
|
183
|
+
taroComponentsPath: this.taroComponentsPath,
|
|
184
|
+
}, extraOptions));
|
|
185
|
+
yield runner(options);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 调用 runner 开启编译
|
|
190
|
+
*/
|
|
191
|
+
start() {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
yield this.setup();
|
|
194
|
+
yield this.build();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var _Harmony_defineConstants;
|
|
200
|
+
const frameworkAlias = {
|
|
201
|
+
solid: 'solid',
|
|
202
|
+
vue: 'vue2',
|
|
203
|
+
vue3: 'vue3',
|
|
204
|
+
};
|
|
205
|
+
let Harmony$1 = class Harmony extends TaroPlatformHarmony {
|
|
206
|
+
constructor(ctx, config) {
|
|
207
|
+
super(ctx, config);
|
|
208
|
+
this.platform = PLATFORM_NAME;
|
|
209
|
+
this.globalObject = 'globalThis';
|
|
210
|
+
this.fileType = {
|
|
211
|
+
templ: '.hml',
|
|
212
|
+
style: '.css',
|
|
213
|
+
config: '.json',
|
|
214
|
+
script: '.js'
|
|
215
|
+
};
|
|
216
|
+
this.useETS = true;
|
|
217
|
+
this.useJSON5 = true;
|
|
218
|
+
this.runtimePath = [];
|
|
219
|
+
this.taroComponentsPath = `${PACKAGE_NAME}/dist/components-harmony-ets`;
|
|
220
|
+
_Harmony_defineConstants.set(this, {});
|
|
221
|
+
this.extensions = ['.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs', '.mts', '.vue', '.ets', '.d.ts'];
|
|
222
|
+
this.excludeLibraries = [];
|
|
223
|
+
this.externalDeps = [
|
|
224
|
+
['@tarojs/components/types', /^@tarojs[\\/]components[\\/]types/],
|
|
225
|
+
['@tarojs/components', /^@tarojs[\\/]components([\\/].+)?$/, this.componentLibrary],
|
|
226
|
+
['@tarojs/react', /^@tarojs[\\/]react$/],
|
|
227
|
+
['@tarojs/runtime', /^@tarojs[\\/]runtime$/, this.runtimeLibrary],
|
|
228
|
+
['@tarojs/taro/types', /^@tarojs[\\/]taro[\\/]types/],
|
|
229
|
+
['@tarojs/taro', /^@tarojs[\\/]taro$/, this.apiLibrary],
|
|
230
|
+
['@tarojs/plugin-framework-react/dist/runtime', /^@tarojs[\\/]plugin-framework-react[\\/]dist[\\/]runtime$/, this.runtimeFrameworkLibrary],
|
|
231
|
+
['react', /^react$|react[\\/]cjs/],
|
|
232
|
+
['react/jsx-runtime', /^react[\\/]jsx-runtime$/], // Note: React 环境下自动注入,避免重复
|
|
233
|
+
];
|
|
234
|
+
this.setupTransaction.addWrapper({
|
|
235
|
+
close() {
|
|
236
|
+
this.modifyViteConfig();
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
get framework() {
|
|
241
|
+
return this.ctx.initialConfig.framework || 'react';
|
|
242
|
+
}
|
|
243
|
+
get aliasFramework() {
|
|
244
|
+
return frameworkAlias[this.framework] || 'react';
|
|
245
|
+
}
|
|
246
|
+
get apiLibrary() {
|
|
247
|
+
return path__namespace.resolve(__dirname, './apis');
|
|
248
|
+
}
|
|
249
|
+
get componentLibrary() {
|
|
250
|
+
return path__namespace.resolve(__dirname, './components-harmony-ets');
|
|
251
|
+
}
|
|
252
|
+
get runtimeLibrary() {
|
|
253
|
+
return path__namespace.resolve(__dirname, './runtime-ets');
|
|
254
|
+
}
|
|
255
|
+
get runtimeFrameworkLibrary() {
|
|
256
|
+
return path__namespace.resolve(__dirname, `./runtime-framework/${this.aliasFramework}`);
|
|
257
|
+
}
|
|
258
|
+
get defineConstants() {
|
|
259
|
+
var _a, _b;
|
|
260
|
+
if (!helper.isEmptyObject(__classPrivateFieldGet(this, _Harmony_defineConstants, "f"))) {
|
|
261
|
+
return __classPrivateFieldGet(this, _Harmony_defineConstants, "f");
|
|
262
|
+
}
|
|
263
|
+
(_a = this.config).env || (_a.env = {});
|
|
264
|
+
(_b = this.config).defineConstants || (_b.defineConstants = {});
|
|
265
|
+
__classPrivateFieldSet(this, _Harmony_defineConstants, Object.assign({}, this.config.defineConstants), "f");
|
|
266
|
+
const env = [...Object.entries(this.config.env), ...Object.entries(process.env)];
|
|
267
|
+
env.forEach(([key, value]) => {
|
|
268
|
+
__classPrivateFieldGet(this, _Harmony_defineConstants, "f")[`process.env.${key}`] = JSON.stringify(value);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
indexOfLibraries(lib) {
|
|
272
|
+
return this.externalDeps.findIndex(([_, rgx]) => rgx.test(lib));
|
|
273
|
+
}
|
|
274
|
+
removeFromLibraries(lib) {
|
|
275
|
+
const index = this.indexOfLibraries(lib);
|
|
276
|
+
if (index > -1) {
|
|
277
|
+
this.externalDeps.splice(index, 1);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
moveLibraries(lib, target = '', basedir = this.ctx.paths.appPath, sync = false) {
|
|
281
|
+
if (!lib)
|
|
282
|
+
return;
|
|
283
|
+
if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
|
|
284
|
+
return;
|
|
285
|
+
if (sync) {
|
|
286
|
+
const { outputRoot } = this.ctx.runOpts.config;
|
|
287
|
+
const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
|
|
288
|
+
// FIXME 不支持 alias 配置
|
|
289
|
+
const libName = lib;
|
|
290
|
+
lib = helper.resolveSync(lib, {
|
|
291
|
+
basedir,
|
|
292
|
+
extensions: this.extensions,
|
|
293
|
+
mainFields: ['unpkg', ...helper.defaultMainFields],
|
|
294
|
+
preserveSymlinks: false,
|
|
295
|
+
}) || '';
|
|
296
|
+
// Note: 跳过 node 相关或未能找到的依赖
|
|
297
|
+
if (!lib || !path__namespace.isAbsolute(lib)) {
|
|
298
|
+
return this.removeFromLibraries(libName);
|
|
299
|
+
}
|
|
300
|
+
let ext = path__namespace.extname(lib);
|
|
301
|
+
const libDir = lib.replace(/.*[\\/]node_modules[\\/]/, '');
|
|
302
|
+
const basename = path__namespace.basename(lib, ext);
|
|
303
|
+
if (['.cjs', '.mjs'].includes(ext)) {
|
|
304
|
+
ext = '.js';
|
|
305
|
+
}
|
|
306
|
+
else if (ext === '.mts') {
|
|
307
|
+
ext = '.ts';
|
|
308
|
+
}
|
|
309
|
+
if (ext === '.js') {
|
|
310
|
+
let typeName = `@types/${libName.replace('@', '').replace(/\//g, '__')}`;
|
|
311
|
+
let typePath = helper.resolveSync(typeName, {
|
|
312
|
+
basedir,
|
|
313
|
+
extensions: this.extensions,
|
|
314
|
+
mainFields: [...helper.defaultMainFields],
|
|
315
|
+
});
|
|
316
|
+
if (!typePath) {
|
|
317
|
+
typeName = path__namespace.join(path__namespace.dirname(lib), `${basename}.d.ts`);
|
|
318
|
+
typePath = helper.resolveSync(typeName, {
|
|
319
|
+
basedir,
|
|
320
|
+
extensions: this.extensions,
|
|
321
|
+
mainFields: [...helper.defaultMainFields],
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
if (typePath) {
|
|
325
|
+
this.moveLibraries(typePath, path__namespace.extname(target)
|
|
326
|
+
? path__namespace.join(path__namespace.dirname(target), `${basename}.d.ts`)
|
|
327
|
+
: path__namespace.join(target, `index.d.ts`), basedir);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (ext) {
|
|
331
|
+
const code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
|
|
332
|
+
if ((/(?:import\s|from\s|require\()['"]([\\/.][^'"\s]+)['"]\)?/g.test(code)
|
|
333
|
+
|| /\/{3}\s<reference\spath=['"][^'"\s]+['"]\s\/>/g.test(code))
|
|
334
|
+
&& `${libName}${path__namespace.extname(libDir)}` !== libDir) {
|
|
335
|
+
const pkgPath = path__namespace.relative(libName, libDir);
|
|
336
|
+
if (new RegExp(`^index(${this.extensions.map(e => e.replace('.', '\\.')).join('|')})$`).test(pkgPath)) {
|
|
337
|
+
// Note: 入口为 index 场景
|
|
338
|
+
lib = path__namespace.dirname(lib);
|
|
339
|
+
}
|
|
340
|
+
else if (!/[\\/]/.test(pkgPath)) {
|
|
341
|
+
// FIXME: 非 index 入口文件场景,可能存在入口文件引用 index 但该文件被覆盖的情况,需要额外处理
|
|
342
|
+
const isDTS = /\.d\.ts$/.test(target);
|
|
343
|
+
target = path__namespace.join(target, `index${isDTS ? '.d.ts' : ext}`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
// FIXME 多级目录,可能存在入口不为 index 或者引用一级目录文件的情况,需要额外处理
|
|
347
|
+
const dir = path__namespace.dirname(pkgPath);
|
|
348
|
+
target = path__namespace.join(target, dir);
|
|
349
|
+
lib = path__namespace.dirname(lib);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else if (path__namespace.isAbsolute(libDir)) {
|
|
353
|
+
// Note: 本地 link 的依赖
|
|
354
|
+
const isDTS = /\.d\.ts$/.test(target);
|
|
355
|
+
target = path__namespace.extname(target)
|
|
356
|
+
? path__namespace.join(path__namespace.dirname(target), `${basename}${ext}`)
|
|
357
|
+
: path__namespace.join(target, `index${isDTS ? '.d.ts' : ext}`);
|
|
358
|
+
}
|
|
359
|
+
else if (libDir !== path__namespace.relative(targetPath, target)) {
|
|
360
|
+
target = path__namespace.join(targetPath, libDir);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const stat = helper.fs.lstatSync(lib);
|
|
365
|
+
if (stat.isDirectory()) {
|
|
366
|
+
const files = helper.fs.readdirSync(lib);
|
|
367
|
+
files.forEach((file) => {
|
|
368
|
+
if (![helper.NODE_MODULES].includes(file)) {
|
|
369
|
+
this.moveLibraries(path__namespace.join(lib, file), path__namespace.join(target, file));
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
else if (stat.isFile()) {
|
|
374
|
+
let code = helper.fs.readFileSync(lib, { encoding: 'utf8' });
|
|
375
|
+
if (this.extensions.includes(path__namespace.extname(lib))) {
|
|
376
|
+
code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
|
|
377
|
+
const { outputRoot } = this.ctx.runOpts.config;
|
|
378
|
+
const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
|
|
379
|
+
const relativePath = parseRelativePath(path__namespace.dirname(target), targetPath);
|
|
380
|
+
if (HARMONY_SCOPES.every(e => !e.test(p1))) {
|
|
381
|
+
if (this.indexOfLibraries(p1) === -1) {
|
|
382
|
+
this.externalDeps.push([p1, new RegExp(`^${p1.replace(/([-\\/$])/g, '\\$1')}$`)]);
|
|
383
|
+
this.moveLibraries(p1, targetPath, path__namespace.dirname(lib), true);
|
|
384
|
+
}
|
|
385
|
+
return src.replace(p1, relativePath.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm'));
|
|
386
|
+
}
|
|
387
|
+
return src;
|
|
388
|
+
});
|
|
389
|
+
const define = Object.assign({}, this.defineConstants);
|
|
390
|
+
if ([/(@tarojs[\\/]runtime|taro-runtime)[\\/]dist/].some(e => e.test(lib))) {
|
|
391
|
+
define.global = 'globalThis';
|
|
392
|
+
}
|
|
393
|
+
code = this.replaceDefineValue(code, define);
|
|
394
|
+
const ext = path__namespace.extname(target);
|
|
395
|
+
if (['.ts'].includes(ext)) {
|
|
396
|
+
code = '// @ts-nocheck\n' + code;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
|
|
400
|
+
code = `/// <reference path="global.d.ts" />
|
|
401
|
+
|
|
402
|
+
/// <reference path="taro.api.d.ts" />
|
|
403
|
+
/// <reference path="taro.component.d.ts" />
|
|
404
|
+
/// <reference path="taro.config.d.ts" />
|
|
405
|
+
/// <reference path="taro.lifecycle.d.ts" />
|
|
406
|
+
|
|
407
|
+
export = Taro
|
|
408
|
+
export as namespace Taro
|
|
409
|
+
|
|
410
|
+
declare const Taro: Taro.TaroStatic
|
|
411
|
+
|
|
412
|
+
declare namespace Taro {
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
414
|
+
interface TaroStatic {}
|
|
415
|
+
}
|
|
416
|
+
declare global {
|
|
417
|
+
const defineAppConfig: (config: Taro.Config) => Taro.Config
|
|
418
|
+
const definePageConfig: (config: Taro.Config) => Taro.Config
|
|
419
|
+
}`;
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
|
|
423
|
+
helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
|
|
424
|
+
helper.fs.writeFileSync(targetPath, code);
|
|
425
|
+
}
|
|
426
|
+
catch (e) {
|
|
427
|
+
console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else if (stat.isSymbolicLink()) {
|
|
431
|
+
const realPath = helper.fs.realpathSync(lib, { encoding: 'utf8' });
|
|
432
|
+
this.moveLibraries(realPath, target, basedir);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
replaceDefineValue(code, define) {
|
|
436
|
+
Object.keys(define).forEach(key => {
|
|
437
|
+
code = code.replace(new RegExp(`\\b${key}\\b`, 'g'), define[key]);
|
|
438
|
+
});
|
|
439
|
+
return code;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 修改 Vite 配置
|
|
443
|
+
*/
|
|
444
|
+
modifyViteConfig() {
|
|
445
|
+
var _a, _b;
|
|
446
|
+
const that = this;
|
|
447
|
+
const { appPath } = that.ctx.paths;
|
|
448
|
+
const { config } = that.ctx.runOpts;
|
|
449
|
+
const { outputRoot } = config;
|
|
450
|
+
if (!that.framework.includes('vue')) {
|
|
451
|
+
that.excludeLibraries.push(/\bvue\b/);
|
|
452
|
+
}
|
|
453
|
+
// @ts-ignore
|
|
454
|
+
if (that.framework === 'solid') {
|
|
455
|
+
that.externalDeps.push([
|
|
456
|
+
'@tarojs/plugin-framework-react/dist/runtime/reconciler',
|
|
457
|
+
/^@tarojs\/plugin-framework-react\/dist\/runtime\/reconciler$/,
|
|
458
|
+
path__namespace.join(this.runtimeFrameworkLibrary, 'reconciler')
|
|
459
|
+
]);
|
|
460
|
+
that.externalDeps.push([
|
|
461
|
+
'solid-js/universal',
|
|
462
|
+
/^solid-js\/universal$/,
|
|
463
|
+
]);
|
|
464
|
+
}
|
|
465
|
+
function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
|
|
466
|
+
if (shared.isFunction(resolve)) {
|
|
467
|
+
if (source === that.runtimePath || that.runtimePath.includes(source)) {
|
|
468
|
+
return resolve('@tarojs/runtime', importer, options);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
// Note: 映射 Taro 相关依赖到注入 taro 目录
|
|
472
|
+
if (that.indexOfLibraries(source) > -1) {
|
|
473
|
+
return {
|
|
474
|
+
external: 'resolve',
|
|
475
|
+
id: path__namespace.join(outputRoot, 'npm', source),
|
|
476
|
+
moduleSideEffects: false,
|
|
477
|
+
resolvedBy: name,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
(_b = (_a = that.ctx).modifyViteConfig) === null || _b === void 0 ? void 0 : _b.call(_a, ({ viteConfig }) => {
|
|
482
|
+
function externalPlugin() {
|
|
483
|
+
const name = 'taro:vite-harmony-external';
|
|
484
|
+
return {
|
|
485
|
+
name,
|
|
486
|
+
enforce: 'pre',
|
|
487
|
+
resolveId(source = '', importer = '', options = {}) {
|
|
488
|
+
return modifyResolveId({
|
|
489
|
+
source,
|
|
490
|
+
importer,
|
|
491
|
+
options,
|
|
492
|
+
name,
|
|
493
|
+
resolve: this.resolve,
|
|
494
|
+
});
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function injectLoaderMeta() {
|
|
499
|
+
return {
|
|
500
|
+
name: 'taro:vite-h5-loader-meta',
|
|
501
|
+
buildStart() {
|
|
502
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
503
|
+
yield this.load({ id: runnerUtils.VITE_COMPILER_LABEL });
|
|
504
|
+
const info = this.getModuleInfo(runnerUtils.VITE_COMPILER_LABEL);
|
|
505
|
+
const compiler = info === null || info === void 0 ? void 0 : info.meta.viteCompilerContext;
|
|
506
|
+
if (compiler) {
|
|
507
|
+
switch (that.framework) {
|
|
508
|
+
// @ts-ignore
|
|
509
|
+
case 'solid':
|
|
510
|
+
compiler.loaderMeta || (compiler.loaderMeta = {});
|
|
511
|
+
compiler.loaderMeta.importFrameworkStatement = ``;
|
|
512
|
+
compiler.mockAppStatement = `
|
|
513
|
+
function App(props) {
|
|
514
|
+
return null
|
|
515
|
+
}
|
|
516
|
+
`;
|
|
517
|
+
compiler.loaderMeta.frameworkArgs = `config`;
|
|
518
|
+
compiler.loaderMeta.creator = `createSolidApp`;
|
|
519
|
+
compiler.loaderMeta.importFrameworkName = '';
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
compiler.loaderMeta.modifyResolveId = modifyResolveId;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
|
|
529
|
+
// Note: 注入 Taro 相关依赖
|
|
530
|
+
this.externalDeps.forEach(([libName, _, target]) => {
|
|
531
|
+
this.moveLibraries(target || libName, path__namespace.resolve(targetPath, libName), appPath, !target);
|
|
532
|
+
});
|
|
533
|
+
viteConfig.plugins.push(externalPlugin(), injectLoaderMeta());
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
_Harmony_defineConstants = new WeakMap();
|
|
538
|
+
|
|
539
|
+
const components = {
|
|
540
|
+
Checkbox: {
|
|
541
|
+
'group-id': '',
|
|
542
|
+
cn: ''
|
|
543
|
+
},
|
|
544
|
+
Span: {},
|
|
545
|
+
Tabs: {
|
|
546
|
+
index: '0',
|
|
547
|
+
vertical: 'false',
|
|
548
|
+
bindchange: ''
|
|
549
|
+
},
|
|
550
|
+
TabBar: {
|
|
551
|
+
mode: shared.singleQuote('scrollable')
|
|
552
|
+
},
|
|
553
|
+
TabContent: {
|
|
554
|
+
scrollable: 'true'
|
|
555
|
+
},
|
|
556
|
+
List: {
|
|
557
|
+
scrollpage: 'false',
|
|
558
|
+
cachedcount: '0',
|
|
559
|
+
scrollbar: 'off',
|
|
560
|
+
scrolleffect: shared.singleQuote('spring'),
|
|
561
|
+
indexer: 'false',
|
|
562
|
+
indexercircle: '',
|
|
563
|
+
indexermulti: 'false',
|
|
564
|
+
indexerbubble: 'true',
|
|
565
|
+
divider: 'false',
|
|
566
|
+
shapemode: shared.singleQuote('default'),
|
|
567
|
+
itemscale: 'true',
|
|
568
|
+
itemcenter: 'false',
|
|
569
|
+
updateeffect: 'false',
|
|
570
|
+
chainanimation: 'false',
|
|
571
|
+
scrollvibrate: 'true',
|
|
572
|
+
initialindex: '0',
|
|
573
|
+
initialoffset: '0',
|
|
574
|
+
selected: '',
|
|
575
|
+
bindindexerchange: '',
|
|
576
|
+
bindscroll: '',
|
|
577
|
+
bindscrollbottom: '',
|
|
578
|
+
bindscrolltop: '',
|
|
579
|
+
bindscrollend: '',
|
|
580
|
+
bindscrolltouchup: '',
|
|
581
|
+
bindrequestitem: ''
|
|
582
|
+
},
|
|
583
|
+
ListItem: {
|
|
584
|
+
type: shared.singleQuote('default'),
|
|
585
|
+
primary: 'false',
|
|
586
|
+
section: '',
|
|
587
|
+
sticky: shared.singleQuote('none'),
|
|
588
|
+
stickyradius: shared.singleQuote('1000px'),
|
|
589
|
+
clickeffect: 'true',
|
|
590
|
+
bindsticky: ''
|
|
591
|
+
},
|
|
592
|
+
Switch: {
|
|
593
|
+
showtext: 'false',
|
|
594
|
+
texton: shared.singleQuote('On'),
|
|
595
|
+
textoff: shared.singleQuote('Off')
|
|
596
|
+
},
|
|
597
|
+
Textarea: {
|
|
598
|
+
headericon: '',
|
|
599
|
+
showcounter: 'false',
|
|
600
|
+
menuoptions: '[]',
|
|
601
|
+
softkeyboardenabled: 'true',
|
|
602
|
+
bindtranslate: '',
|
|
603
|
+
bindshare: '',
|
|
604
|
+
bindsearch: '',
|
|
605
|
+
bindoptionselect: '',
|
|
606
|
+
bindselectchange: ''
|
|
607
|
+
},
|
|
608
|
+
Progress: {
|
|
609
|
+
'active-color': shared.singleQuote('#09BB07'),
|
|
610
|
+
'background-color': shared.singleQuote('#EBEBEB'),
|
|
611
|
+
type: shared.singleQuote('horizontal'),
|
|
612
|
+
'font-size': shared.singleQuote('25px'),
|
|
613
|
+
secondarypercent: '0',
|
|
614
|
+
clockwise: 'true'
|
|
615
|
+
},
|
|
616
|
+
Slider: {
|
|
617
|
+
showsteps: 'false',
|
|
618
|
+
showtips: 'false'
|
|
619
|
+
},
|
|
620
|
+
Input: {
|
|
621
|
+
'placeholder-color': shared.singleQuote('#99000000')
|
|
622
|
+
},
|
|
623
|
+
Video: {
|
|
624
|
+
speed: '1',
|
|
625
|
+
bindloadedmetadata: '',
|
|
626
|
+
bindprogress: '',
|
|
627
|
+
bindtap: ''
|
|
628
|
+
},
|
|
629
|
+
Image: {
|
|
630
|
+
alt: ''
|
|
631
|
+
},
|
|
632
|
+
Radio: {
|
|
633
|
+
'group-id': ''
|
|
634
|
+
},
|
|
635
|
+
Picker: {
|
|
636
|
+
selected: '',
|
|
637
|
+
hours: '',
|
|
638
|
+
containsecond: 'false',
|
|
639
|
+
vibrate: 'true',
|
|
640
|
+
lunar: 'false',
|
|
641
|
+
lunarswitch: 'false'
|
|
642
|
+
},
|
|
643
|
+
PickerView: {
|
|
644
|
+
mode: '',
|
|
645
|
+
range: '',
|
|
646
|
+
selected: '',
|
|
647
|
+
hours: '',
|
|
648
|
+
indicatorprefix: '',
|
|
649
|
+
indicatorsuffix: '',
|
|
650
|
+
containsecond: 'false',
|
|
651
|
+
vibrate: 'true',
|
|
652
|
+
lunar: 'false',
|
|
653
|
+
lunarswitch: 'false',
|
|
654
|
+
bindcolumnchange: '',
|
|
655
|
+
cn: ''
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
class Template extends template.RecursiveTemplate {
|
|
660
|
+
constructor() {
|
|
661
|
+
super();
|
|
662
|
+
this.Adapter = {
|
|
663
|
+
if: 'if',
|
|
664
|
+
else: 'else',
|
|
665
|
+
elseif: 'elif',
|
|
666
|
+
for: 'for',
|
|
667
|
+
forItem: 'for-item',
|
|
668
|
+
forIndex: 'for-index',
|
|
669
|
+
key: 'key',
|
|
670
|
+
type: 'harmony'
|
|
671
|
+
};
|
|
672
|
+
this.usedNativeComps = [];
|
|
673
|
+
this.patchVoidElements = [
|
|
674
|
+
'button',
|
|
675
|
+
'image',
|
|
676
|
+
'camera',
|
|
677
|
+
'video',
|
|
678
|
+
'web-view',
|
|
679
|
+
'picker',
|
|
680
|
+
'checkbox',
|
|
681
|
+
'rich-text'
|
|
682
|
+
];
|
|
683
|
+
this.buildHeaderTemplate = (componentConfig) => {
|
|
684
|
+
if (componentConfig.includeAll) {
|
|
685
|
+
this.usedNativeComps = [...this.nativeComps];
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
this.usedNativeComps = Array.from(componentConfig.includes).filter(name => this.nativeComps.includes(name));
|
|
689
|
+
}
|
|
690
|
+
const elements = this.usedNativeComps.reduce((str, name) => str + `<element name="taro-${name}" src="./components-harmony/${name}/index.hml"></element>\n`, '');
|
|
691
|
+
return `<element name="container" src="./index.hml"></element>
|
|
692
|
+
${elements}
|
|
693
|
+
|
|
694
|
+
<block>
|
|
695
|
+
`;
|
|
696
|
+
};
|
|
697
|
+
this.buildTemplate = (componentConfig) => {
|
|
698
|
+
let template = this.buildHeaderTemplate(componentConfig);
|
|
699
|
+
if (!this.miniComponents) {
|
|
700
|
+
this.componentsAlias = shared.getComponentsAlias(this.internalComponents);
|
|
701
|
+
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
702
|
+
}
|
|
703
|
+
const ZERO_FLOOR = 0;
|
|
704
|
+
const components = Object.keys(this.miniComponents)
|
|
705
|
+
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
706
|
+
template = components.reduce((current, nodeName) => {
|
|
707
|
+
const attributes = this.miniComponents[nodeName];
|
|
708
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
709
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
|
|
710
|
+
}, template);
|
|
711
|
+
template += this.buildPlainTextTemplate();
|
|
712
|
+
template += '\n</block>';
|
|
713
|
+
return template;
|
|
714
|
+
};
|
|
715
|
+
this.buildPageTemplate = (baseTempPath) => {
|
|
716
|
+
const containerPath = path.join(path.dirname(baseTempPath), 'container');
|
|
717
|
+
const containerTempPath = path.join(containerPath, 'index.hml');
|
|
718
|
+
const navbarTempPath = path.join(containerPath, 'components-harmony/navbar/index.hml');
|
|
719
|
+
const tabbarTempPath = path.join(containerPath, 'components-harmony/tabbar/index.hml');
|
|
720
|
+
const template = `<element name="container" src="${containerTempPath}"></element>
|
|
721
|
+
<element name="navbar" src="${navbarTempPath}"></element>
|
|
722
|
+
<element name="tabbar" src="${tabbarTempPath}"></element>
|
|
723
|
+
|
|
724
|
+
<div class="container">
|
|
725
|
+
<navbar if="{{taroNavBar}}" title="{{taroNavBar.title}}" background="{{taroNavBar.background}}" text-style="{{taroNavBar.textStyle}}" st="{{taroNavBar.style}}"></navbar>
|
|
726
|
+
<div class="body" style="padding-top: 44vp;padding-bottom: {{isShowTaroTabBar ? '56vp' : '0'}}">
|
|
727
|
+
<refresh if="{{enablePullDownRefresh}}" type="pulldown" refreshing="{{isRefreshing}}" onrefresh="onPullDownRefresh">
|
|
728
|
+
<block for="{{root.cn}}">
|
|
729
|
+
<container i="{{$item}}"></container>
|
|
730
|
+
</block>
|
|
731
|
+
</refresh>
|
|
732
|
+
<block else for="{{root.cn}}">
|
|
733
|
+
<container i="{{$item}}"></container>
|
|
734
|
+
</block>
|
|
735
|
+
</div>
|
|
736
|
+
<tabbar if="{{isShowTaroTabBar}}" tabbar-data="{{taroTabBar}}" selected="{{selected}}"></tabbar>
|
|
737
|
+
</div>
|
|
738
|
+
`;
|
|
739
|
+
return template;
|
|
740
|
+
};
|
|
741
|
+
const compsDir = path.resolve(__dirname, 'components-harmony');
|
|
742
|
+
this.patchVoidElements.forEach(item => {
|
|
743
|
+
this.voidElements.add(item);
|
|
744
|
+
});
|
|
745
|
+
this.nativeComps = helper.fs.readdirSync(compsDir).filter(name => helper.fs.pathExistsSync(path.resolve(compsDir, name, 'index.hml')));
|
|
746
|
+
}
|
|
747
|
+
createMiniComponents(components) {
|
|
748
|
+
components.Button.cn = '';
|
|
749
|
+
components.Button.bindtap = '';
|
|
750
|
+
components.Button.type = "'default'";
|
|
751
|
+
const result = super.createMiniComponents(components);
|
|
752
|
+
delete result['pure-view'];
|
|
753
|
+
delete result['static-view'];
|
|
754
|
+
delete result['static-text'];
|
|
755
|
+
delete result['static-image'];
|
|
756
|
+
return result;
|
|
757
|
+
}
|
|
758
|
+
buildFocusComponentTemplate(comp) {
|
|
759
|
+
return this.generateComponentTemplateSrc(comp);
|
|
760
|
+
}
|
|
761
|
+
buildStandardComponentTemplate(comp) {
|
|
762
|
+
let nodeName = '';
|
|
763
|
+
switch (comp.nodeName) {
|
|
764
|
+
case 'slot':
|
|
765
|
+
case 'slot-view':
|
|
766
|
+
case 'cover-view':
|
|
767
|
+
case 'view':
|
|
768
|
+
case 'swiper-item':
|
|
769
|
+
nodeName = 'div';
|
|
770
|
+
break;
|
|
771
|
+
case 'static-text':
|
|
772
|
+
nodeName = 'text';
|
|
773
|
+
break;
|
|
774
|
+
case 'static-image':
|
|
775
|
+
nodeName = 'image';
|
|
776
|
+
break;
|
|
777
|
+
default:
|
|
778
|
+
nodeName = comp.nodeName;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
return this.generateComponentTemplateSrc(comp, nodeName);
|
|
782
|
+
}
|
|
783
|
+
generateComponentTemplateSrc(comp, nodeName) {
|
|
784
|
+
const nodeAlias = comp.nodeAlias;
|
|
785
|
+
const children = this.voidElements.has(comp.nodeName)
|
|
786
|
+
? ''
|
|
787
|
+
: `<block for="{{i.cn}}">
|
|
788
|
+
<container i="{{$item}}"></container>
|
|
789
|
+
</block>`;
|
|
790
|
+
if (!nodeName) {
|
|
791
|
+
nodeName = comp.nodeName;
|
|
792
|
+
}
|
|
793
|
+
if (this.nativeComps.includes(nodeName)) {
|
|
794
|
+
nodeName = `taro-${nodeName}`;
|
|
795
|
+
}
|
|
796
|
+
const res = `
|
|
797
|
+
<block if="{{i.nn == '${nodeAlias}'}}">
|
|
798
|
+
<${nodeName} ${this.buildAttrs(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
|
|
799
|
+
${children}
|
|
800
|
+
</${nodeName}>
|
|
801
|
+
</block>
|
|
802
|
+
`;
|
|
803
|
+
return res;
|
|
804
|
+
}
|
|
805
|
+
buildPlainTextTemplate() {
|
|
806
|
+
return `
|
|
807
|
+
<block if="{{i.nn === '#text'}}">
|
|
808
|
+
<span>{{i.${"v" /* Shortcuts.Text */}}}</span>
|
|
809
|
+
</block>
|
|
810
|
+
`;
|
|
811
|
+
}
|
|
812
|
+
buildAttrs(attrs, nodeName) {
|
|
813
|
+
return Object.keys(attrs)
|
|
814
|
+
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
815
|
+
.join('');
|
|
816
|
+
}
|
|
817
|
+
replacePropName(name, value, componentName) {
|
|
818
|
+
if (value === 'eh')
|
|
819
|
+
return name.toLowerCase().replace(/^bind/, '@');
|
|
820
|
+
// 由于鸿蒙不支持for属性 需要修改for属性,需要改名
|
|
821
|
+
if (componentName === 'label' && name === 'for')
|
|
822
|
+
return 'target';
|
|
823
|
+
return name;
|
|
824
|
+
}
|
|
825
|
+
getEvents() {
|
|
826
|
+
return {
|
|
827
|
+
'@click': 'eh'
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
const EXPORT_PREFIX = 'var __webpack_exports__ = ';
|
|
833
|
+
class Harmony extends service.TaroPlatformBase {
|
|
834
|
+
/**
|
|
835
|
+
* 1. setupTransaction - init
|
|
836
|
+
* 2. setup
|
|
837
|
+
* 3. setupTransaction - close
|
|
838
|
+
* 4. buildTransaction - init
|
|
839
|
+
* 5. build
|
|
840
|
+
* 6. buildTransaction - close
|
|
841
|
+
*/
|
|
842
|
+
constructor(ctx, config) {
|
|
843
|
+
super(ctx, config);
|
|
844
|
+
this.platform = 'harmony';
|
|
845
|
+
this.globalObject = 'globalThis';
|
|
846
|
+
this.runtimePath = `${PACKAGE_NAME}/dist/runtime`;
|
|
847
|
+
this.taroComponentsPath = `${PACKAGE_NAME}/dist/components/components-react`;
|
|
848
|
+
this.fileType = {
|
|
849
|
+
templ: '.hml',
|
|
850
|
+
style: '.css',
|
|
851
|
+
config: '.json',
|
|
852
|
+
script: '.js'
|
|
853
|
+
};
|
|
854
|
+
this.template = new Template();
|
|
855
|
+
this.addEntry();
|
|
856
|
+
this.setupTransaction.addWrapper({
|
|
857
|
+
close() {
|
|
858
|
+
this.modifyComponents();
|
|
859
|
+
this.modifyPostcssConfigs(config);
|
|
860
|
+
this.modifyWebpackConfig();
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
this.modifyTaroExport();
|
|
864
|
+
this.modifyBuildAssets(ctx, config);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* 增加组件或修改组件属性
|
|
868
|
+
*/
|
|
869
|
+
modifyComponents() {
|
|
870
|
+
this.template.mergeComponents(this.ctx, components);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* 不需要转 rpx
|
|
874
|
+
*/
|
|
875
|
+
modifyPostcssConfigs(config) {
|
|
876
|
+
config.postcss || (config.postcss = {});
|
|
877
|
+
const postcssConfig = config.postcss;
|
|
878
|
+
postcssConfig.autoprefixer = {
|
|
879
|
+
enable: false
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* 模板自定义组件 js
|
|
884
|
+
* 等鸿蒙支持 template 后需要重构
|
|
885
|
+
*/
|
|
886
|
+
addEntry() {
|
|
887
|
+
this.ctx.onCompilerMake(({ compilation, plugin }) => __awaiter(this, void 0, void 0, function* () {
|
|
888
|
+
// container/index.hml
|
|
889
|
+
const filePath = path.resolve(__dirname, 'template/container');
|
|
890
|
+
plugin.addEntry(filePath, 'container/index', helper.META_TYPE.STATIC);
|
|
891
|
+
const dep = plugin.dependencies.get(filePath);
|
|
892
|
+
yield new Promise((resolve, reject) => {
|
|
893
|
+
compilation.addEntry(plugin.options.sourceDir, dep, dep.name, err => err ? reject(err) : resolve(null));
|
|
894
|
+
});
|
|
895
|
+
}));
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* 把 app、pages、自定义组件的 js 改造为鸿蒙的 export default 导出形式
|
|
899
|
+
*/
|
|
900
|
+
modifyTaroExport() {
|
|
901
|
+
this.ctx.onCompilerMake(({ compilation, compiler }) => {
|
|
902
|
+
const render = this.compiler === 'webpack5'
|
|
903
|
+
? compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render
|
|
904
|
+
: compilation.chunkTemplate.hooks.renderWithEntry;
|
|
905
|
+
render.tap(PLUGIN_NAME, (modules, renderContext) => {
|
|
906
|
+
var _a, _b;
|
|
907
|
+
const chunk = (_a = renderContext.chunk) !== null && _a !== void 0 ? _a : renderContext; // Webpack4 中 renderContext 实际为 chunk
|
|
908
|
+
const chunkEntryModule = this.getChunkEntryModule(compilation, chunk, this.compiler);
|
|
909
|
+
if (chunkEntryModule) {
|
|
910
|
+
const entryModule = (_b = chunkEntryModule.rootModule) !== null && _b !== void 0 ? _b : chunkEntryModule;
|
|
911
|
+
if (this.checkMetaType(entryModule)) {
|
|
912
|
+
const origin = modules._value ? modules._value.toString() : modules.source();
|
|
913
|
+
const editedOrigin = origin.replace(/\(globalThis/, 'var taroExport = (globalThis');
|
|
914
|
+
const source = new webpackSources.ConcatSource();
|
|
915
|
+
source.add(editedOrigin);
|
|
916
|
+
source.add(';');
|
|
917
|
+
source.add(`\nexport default taroExport ? taroExport.default${entryModule.miniType === helper.META_TYPE.STATIC ? '' : '()'} : {};`);
|
|
918
|
+
return source;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
return modules;
|
|
922
|
+
});
|
|
923
|
+
if (this.compiler === 'webpack5') {
|
|
924
|
+
compilation.hooks.optimizeChunks.tap(PLUGIN_NAME, (chunks) => {
|
|
925
|
+
var _a;
|
|
926
|
+
for (const chunk of chunks) {
|
|
927
|
+
const { chunkGraph, moduleGraph } = compilation;
|
|
928
|
+
const chunkEntryModule = this.getChunkEntryModule(compilation, chunk, this.compiler);
|
|
929
|
+
if (chunkEntryModule) {
|
|
930
|
+
const entryModule = (_a = chunkEntryModule.rootModule) !== null && _a !== void 0 ? _a : chunkEntryModule;
|
|
931
|
+
const modulesIterable = chunkGraph.getOrderedChunkModulesIterable(chunk, compiler.webpack.util.comparators.compareModulesByIdentifier);
|
|
932
|
+
if (this.checkMetaType(entryModule)) {
|
|
933
|
+
for (const module of modulesIterable) {
|
|
934
|
+
const moduleUsedExports = moduleGraph.getUsedExports(module, chunk.runtime);
|
|
935
|
+
if (moduleUsedExports instanceof Set) {
|
|
936
|
+
if (module.identifier().includes(chunk.name)) {
|
|
937
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
938
|
+
const used = exportsInfo.getUsedName('default', chunk.runtime);
|
|
939
|
+
if (used) {
|
|
940
|
+
exportsInfo.setUsedWithoutInfo(chunk.runtime);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
|
|
950
|
+
var _a, _b;
|
|
951
|
+
const chunk = (_a = renderContext.chunk) !== null && _a !== void 0 ? _a : renderContext;
|
|
952
|
+
const chunkEntryModule = this.getChunkEntryModule(compilation, chunk, this.compiler);
|
|
953
|
+
if (chunkEntryModule) {
|
|
954
|
+
const entryModule = (_b = chunkEntryModule.rootModule) !== null && _b !== void 0 ? _b : chunkEntryModule;
|
|
955
|
+
if (this.checkMetaType(entryModule)) {
|
|
956
|
+
// @ts-ignore
|
|
957
|
+
const origin = modules._value ? modules._value.toString() : modules.source();
|
|
958
|
+
const editedOrigin = origin.replace(EXPORT_PREFIX, 'return ');
|
|
959
|
+
const source = new webpackSources.ConcatSource();
|
|
960
|
+
source.add(editedOrigin);
|
|
961
|
+
return source;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return modules;
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* 修改最终的编译产物
|
|
971
|
+
* 1. 生成模板自定义组件的 xml、css 文件
|
|
972
|
+
* 2. 删除多余的文件
|
|
973
|
+
* 3. 把 components-harmony 中被使用到的组件移动到输出目录
|
|
974
|
+
*/
|
|
975
|
+
modifyBuildAssets(ctx, config) {
|
|
976
|
+
ctx.modifyBuildAssets(({ assets, miniPlugin }) => {
|
|
977
|
+
const scriptExt = miniPlugin.options.fileType.script;
|
|
978
|
+
const templateExt = miniPlugin.options.fileType.templ;
|
|
979
|
+
const styleExt = miniPlugin.options.fileType.style;
|
|
980
|
+
const configExt = miniPlugin.options.fileType.config;
|
|
981
|
+
// 模板自定义组件 xml
|
|
982
|
+
const base = `base${templateExt}`;
|
|
983
|
+
assets[`container/index${templateExt}`] = assets[base];
|
|
984
|
+
delete assets[base];
|
|
985
|
+
// 模板自定义组件 css
|
|
986
|
+
const styles = Object.keys(assets).filter(key => key.endsWith(styleExt));
|
|
987
|
+
const source = new webpackSources.ConcatSource();
|
|
988
|
+
styles.forEach(file => {
|
|
989
|
+
const re = path.relative('container', file);
|
|
990
|
+
source.add(`@import '${re}';\n`);
|
|
991
|
+
});
|
|
992
|
+
assets[`container/index${styleExt}`] =
|
|
993
|
+
this.compiler === 'webpack5'
|
|
994
|
+
? new webpackSources.RawSource(`${source.source()}`)
|
|
995
|
+
: {
|
|
996
|
+
size: () => source.source().length,
|
|
997
|
+
source: () => source.source()
|
|
998
|
+
};
|
|
999
|
+
// 不需要生成 json 配置文件
|
|
1000
|
+
miniPlugin.pages.forEach(page => {
|
|
1001
|
+
delete assets[`${page.name}${configExt}`];
|
|
1002
|
+
});
|
|
1003
|
+
const appConfig = `app${configExt}`;
|
|
1004
|
+
// 修改 harmony Hap 的配置文件 config.json,主要是注入路由配置
|
|
1005
|
+
const route = JSON.parse(assets[appConfig].source()).pages;
|
|
1006
|
+
this.modifyHarmonyConfig(route, config.harmony);
|
|
1007
|
+
// 不需要生成 app.json
|
|
1008
|
+
delete assets[appConfig];
|
|
1009
|
+
// 不需要生成 custom-wrapper
|
|
1010
|
+
delete assets[`custom-wrapper${scriptExt}`];
|
|
1011
|
+
delete assets[`custom-wrapper${templateExt}`];
|
|
1012
|
+
delete assets[`custom-wrapper${configExt}`];
|
|
1013
|
+
// 其他冗余文件
|
|
1014
|
+
delete assets[`container/global${scriptExt}`];
|
|
1015
|
+
});
|
|
1016
|
+
// 把 components-harmony 中被使用到的组件移动到输出目录
|
|
1017
|
+
ctx.onBuildFinish(() => {
|
|
1018
|
+
const outDir = path.resolve(process.cwd(), config.outputRoot);
|
|
1019
|
+
const compsDir = path.resolve(__dirname, '..', 'components', 'components-harmony');
|
|
1020
|
+
const compsOutDir = path.join(outDir, 'container/components-harmony');
|
|
1021
|
+
helper.fs.ensureDirSync(compsOutDir);
|
|
1022
|
+
[...this.template.usedNativeComps, 'navbar', 'tabbar', 'utils'].forEach(name => {
|
|
1023
|
+
const src = path.join(compsDir, name);
|
|
1024
|
+
const outDir = path.join(compsOutDir, name);
|
|
1025
|
+
helper.fs.copy(src, outDir);
|
|
1026
|
+
});
|
|
1027
|
+
this.modifyHostPackageDep(outDir);
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
modifyWebpackConfig() {
|
|
1031
|
+
this.ctx.modifyWebpackChain(({ chain }) => {
|
|
1032
|
+
const externals = ({ request }, callback) => {
|
|
1033
|
+
// Note: 判断引用的依赖是否是 Harmony 全局注入的依赖,如果是则 Webpack 不需要处理,直接 external 掉
|
|
1034
|
+
if (this.isHarmonyRequest(request)) {
|
|
1035
|
+
return callback(null, 'commonjs ' + request);
|
|
1036
|
+
}
|
|
1037
|
+
callback();
|
|
1038
|
+
};
|
|
1039
|
+
chain.merge({
|
|
1040
|
+
externals: [
|
|
1041
|
+
this.compiler === 'webpack5'
|
|
1042
|
+
? externals
|
|
1043
|
+
: (_context, request, callback) => externals({ request }, callback)
|
|
1044
|
+
]
|
|
1045
|
+
});
|
|
1046
|
+
chain.plugin('miniPlugin')
|
|
1047
|
+
.tap(args => {
|
|
1048
|
+
args[0].loaderMeta.modifyInstantiate = function (origin) {
|
|
1049
|
+
return origin.replace(/var inst = (App|Page)\(([A-Za-z]+)\(/, 'export default ($2.bind(null, ');
|
|
1050
|
+
};
|
|
1051
|
+
return args;
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
modifyHarmonyConfig(pages, { projectPath, hapName, name }) {
|
|
1056
|
+
var _a, _b;
|
|
1057
|
+
const designWidth = this.config.designWidth || ((_b = (_a = this.config.postcss.pxtransform) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.designWidth) || 750;
|
|
1058
|
+
const hapConfigPath = path.join(projectPath, hapName, 'src/main/config.json');
|
|
1059
|
+
helper.fs.readJson(hapConfigPath)
|
|
1060
|
+
.then(config => {
|
|
1061
|
+
var _a;
|
|
1062
|
+
(_a = config.module).js || (_a.js = []);
|
|
1063
|
+
const jsFAs = config.module.js;
|
|
1064
|
+
const target = jsFAs.find(item => item.name === name);
|
|
1065
|
+
if (target) {
|
|
1066
|
+
if (JSON.stringify(target.pages) === JSON.stringify(pages))
|
|
1067
|
+
return;
|
|
1068
|
+
target.pages = pages;
|
|
1069
|
+
target.window = {
|
|
1070
|
+
designWidth,
|
|
1071
|
+
autoDesignWidth: false
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
jsFAs.push({
|
|
1076
|
+
pages,
|
|
1077
|
+
name,
|
|
1078
|
+
window: {
|
|
1079
|
+
designWidth,
|
|
1080
|
+
autoDesignWidth: false
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
return helper.fs.writeJson(hapConfigPath, config, { spaces: 2 });
|
|
1085
|
+
})
|
|
1086
|
+
.catch(err => {
|
|
1087
|
+
console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
modifyHostPackageDep(dest) {
|
|
1091
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1092
|
+
const hmsDeps = {
|
|
1093
|
+
'@hmscore/hms-js-base': '^6.1.0-300',
|
|
1094
|
+
'@hmscore/hms-jsb-account': '^1.0.300'
|
|
1095
|
+
};
|
|
1096
|
+
const packageJsonFile = path.resolve(dest, '../../../../../package.json');
|
|
1097
|
+
const isExists = yield helper.fs.pathExists(packageJsonFile);
|
|
1098
|
+
if (!isExists)
|
|
1099
|
+
return;
|
|
1100
|
+
const data = yield helper.fs.readFile(packageJsonFile);
|
|
1101
|
+
let packageJson = data.toString();
|
|
1102
|
+
packageJson = JSON.parse(packageJson);
|
|
1103
|
+
if (!packageJson.dependencies) {
|
|
1104
|
+
packageJson.dependencies = hmsDeps;
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
for (const hmsDep in hmsDeps) {
|
|
1108
|
+
packageJson.dependencies[hmsDep] = hmsDeps[hmsDep];
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
packageJson = JSON.stringify(packageJson);
|
|
1112
|
+
yield helper.fs.writeFile(packageJsonFile, packageJson);
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {
|
|
1116
|
+
if (compiler === 'webpack5') {
|
|
1117
|
+
const chunkGraph = compilation.chunkGraph;
|
|
1118
|
+
const entryModules = Array.from(chunkGraph.getChunkEntryModulesIterable(chunk));
|
|
1119
|
+
if (entryModules.length) {
|
|
1120
|
+
return entryModules[0];
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
else {
|
|
1124
|
+
return chunk.entryModule;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
checkMetaType(entryModule) {
|
|
1128
|
+
const { miniType } = entryModule;
|
|
1129
|
+
return miniType === helper.META_TYPE.ENTRY ||
|
|
1130
|
+
miniType === helper.META_TYPE.PAGE ||
|
|
1131
|
+
(miniType === helper.META_TYPE.STATIC && entryModule.name === 'container/index');
|
|
1132
|
+
}
|
|
1133
|
+
isHarmonyRequest(request) {
|
|
1134
|
+
return HARMONY_SCOPES.some(scope => scope.test(request));
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
var index = (ctx, options = {}) => {
|
|
1139
|
+
// 合并 harmony 编译配置到 opts
|
|
1140
|
+
ctx.modifyRunnerOpts(({ opts }) => {
|
|
1141
|
+
if (opts.platform !== PLATFORM_NAME)
|
|
1142
|
+
return;
|
|
1143
|
+
const harmonyConfig = ctx.ctx.initialConfig.harmony;
|
|
1144
|
+
assertHarmonyConfig(ctx, harmonyConfig);
|
|
1145
|
+
harmonyConfig.name || (harmonyConfig.name = 'default');
|
|
1146
|
+
harmonyConfig.hapName || (harmonyConfig.hapName = 'entry');
|
|
1147
|
+
const { projectPath, hapName } = harmonyConfig;
|
|
1148
|
+
opts.outputRoot = path.join(projectPath, hapName, 'src/main', options.disableArkTS ? 'js' : 'ets');
|
|
1149
|
+
opts.harmony = harmonyConfig;
|
|
1150
|
+
ctx.paths.outputPath = opts.outputRoot;
|
|
1151
|
+
});
|
|
1152
|
+
const Harmony$2 = options.disableArkTS ? Harmony : Harmony$1;
|
|
1153
|
+
ctx.registerPlatform({
|
|
1154
|
+
name: PLATFORM_NAME,
|
|
1155
|
+
useConfigName: options.useConfigName || PLATFORM_NAME,
|
|
1156
|
+
fn({ config }) {
|
|
1157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1158
|
+
const program = new Harmony$2(ctx, config);
|
|
1159
|
+
yield program.start();
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
};
|
|
1164
|
+
function assertHarmonyConfig(ctx, config) {
|
|
1165
|
+
const NOTE_INVALID = helper.chalk.red('[✗] ');
|
|
1166
|
+
const errorChalk = helper.chalk.hex('#f00');
|
|
1167
|
+
const lineChalk = helper.chalk.hex('#fff');
|
|
1168
|
+
function throwError(err) {
|
|
1169
|
+
console.log(errorChalk(`Taro 配置有误,请检查! (${ctx.paths.configPath})`));
|
|
1170
|
+
console.log(` ${NOTE_INVALID}${lineChalk(err)}`);
|
|
1171
|
+
process.exit(0);
|
|
1172
|
+
}
|
|
1173
|
+
if (typeof config !== 'object' || !config) {
|
|
1174
|
+
throwError('请设置 harmony 编译配置');
|
|
1175
|
+
}
|
|
1176
|
+
if (!config.projectPath) {
|
|
1177
|
+
throwError('请设置 harmony.projectPath');
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
exports.HarmonyOS_JSUI = Harmony;
|
|
1182
|
+
exports.default = index;
|
|
1183
|
+
//# sourceMappingURL=index.js.map
|