@react-native-oh/react-native-harmony-cli 0.82.18 → 0.82.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/autolinking/Autolinking.js +141 -23
- package/dist/commands/init.js +0 -0
- package/dist/core/ProjectDependenciesManager.js +20 -1
- package/harmony/rnoh-hvigor-plugin-0.82.29.tgz +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/00a68392 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0544a6cc +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0f36b2db +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12f23f1e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/13d95d98 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1629e86b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/180c8379 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a697147 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1a8271b1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1b7fa689 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/255a9f13 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/268d155b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/27db9aa4 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/28db79ed +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2dc2bbcb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2df5f8c5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2f88aedb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/31b3a7ea +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/36335b1c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/38fca641 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397722eb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/397b6432 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3b17421f +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/454f5e18 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/45ec6cce +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/482d51b1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4ac5cd67 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4d40499a +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4dcad919 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/4fc31929 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/54edc8f5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/558a5405 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/58d2b670 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5ec7feca +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62180f3e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/63981360 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64096c89 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/64af560b +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6585e783 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6954304f +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/69fd6235 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6d3a0478 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6e131db7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/778cd8f1 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/788206b6 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7882dc26 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7b3c14f7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7cdfe667 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8048c487 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8332d9a3 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/84e5b603 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/854d8127 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/88c97376 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/90d5f644 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/967e25ac +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/969896c2 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9790193e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/97ae40c5 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9a5bf482 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a07adeb9 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a427f355 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9dd7eb7 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a9e9d79e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab920855 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ab9e3038 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/af054988 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/afe03e51 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b3b83913 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b4db7b4d +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b5225355 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b8c00f06 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b917a081 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b9e2f3bd +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bd70db0e +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bdbda648 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/be1e5469 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c9462295 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ca6e5efa +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/caf52beb +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cb268960 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cca16b15 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cfc1c937 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d10e6e05 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d172fc04 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d4e94e50 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d59f8d2c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/da964053 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e0bb712a +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e3e6ca34 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e50f7385 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f1a1d282 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f2514c3c +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f66207cf +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f8d129ce +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fb1e9558 +0 -0
- package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ff7e3608 +0 -0
- package/package.json +1 -1
- package/src/autolinking/Autolinking.test.ts +237 -0
- package/src/autolinking/Autolinking.ts +223 -39
- package/src/core/PackageJSON.ts +19 -1
- package/src/core/ProjectDependenciesManager.ts +25 -7
- package/harmony/rnoh-hvigor-plugin-0.82.18.tgz +0 -0
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Please refer to: [RNOH repo](https://gitcode.com/openharmony-sig/ohos_react_nati
|
|
|
4
4
|
|
|
5
5
|
# Documentation
|
|
6
6
|
|
|
7
|
-
- [中文](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.
|
|
8
|
-
- [English](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.
|
|
7
|
+
- [中文](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.82/docs/zh-cn/README.md)
|
|
8
|
+
- [English](https://gitcode.com/openharmony-sig/ohos_react_native/blob/0.82/docs/en/README.md)
|
|
9
9
|
|
|
10
10
|
# License
|
|
11
11
|
|
|
12
|
-
This library is licensed under The [MIT License (MIT)](https://gitcode.com/openharmony-sig/ohos_react_native)
|
|
12
|
+
This library is licensed under The [MIT License (MIT)](https://gitcode.com/openharmony-sig/ohos_react_native)
|
|
@@ -113,33 +113,38 @@ class Autolinking {
|
|
|
113
113
|
const skippedLibraryNpmPackageNames = [];
|
|
114
114
|
yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
|
|
115
115
|
var _a;
|
|
116
|
-
|
|
116
|
+
// 读取 package.json 配置
|
|
117
|
+
const packageJson = dependency.readPackageJSON();
|
|
118
|
+
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
119
|
+
// 解析 autolinking 配置
|
|
120
|
+
const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
121
|
+
// 获取自定义的 HAR 扫描路径
|
|
122
|
+
const mainHarPath = autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.mainHarPath;
|
|
123
|
+
// 扫描 HAR 文件
|
|
124
|
+
const harFilePaths = dependency.getHarFilePaths(mainHarPath);
|
|
117
125
|
if (harFilePaths.length === 0) {
|
|
118
126
|
return;
|
|
119
127
|
}
|
|
120
128
|
nodeModuleHarPaths.push(...harFilePaths);
|
|
121
|
-
|
|
122
|
-
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
129
|
+
// 检查是否应该跳过该包
|
|
123
130
|
if (providedAutolinkingConfig === undefined ||
|
|
124
131
|
providedAutolinkingConfig === null ||
|
|
125
132
|
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
126
133
|
config.excludedNpmPackageNames.size > 0) ||
|
|
127
134
|
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
128
|
-
config.includedNpmPackageNames.size > 0)
|
|
129
|
-
harFilePaths.length !== 1) {
|
|
135
|
+
config.includedNpmPackageNames.size > 0)) {
|
|
130
136
|
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
131
137
|
return;
|
|
132
138
|
}
|
|
133
|
-
|
|
139
|
+
// 解析 ohPackageName 配置,生成每个 HAR 对应的包名
|
|
140
|
+
const ohPackageNameConfig = autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName;
|
|
141
|
+
const resolvedHars = this.resolveHarPackageNames(harFilePaths, ohPackageNameConfig, packageJson.name, harmonyProjectPath);
|
|
134
142
|
autolinkableLibraries.push({
|
|
135
143
|
npmPackageName: packageJson.name,
|
|
144
|
+
resolvedHars,
|
|
136
145
|
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
137
146
|
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
138
147
|
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
139
|
-
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
140
|
-
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
141
|
-
.relativeTo(harmonyProjectPath)
|
|
142
|
-
.toString(),
|
|
143
148
|
});
|
|
144
149
|
});
|
|
145
150
|
const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
@@ -158,10 +163,68 @@ class Autolinking {
|
|
|
158
163
|
};
|
|
159
164
|
});
|
|
160
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* 解析 HAR 文件的 ohPackage 名称
|
|
168
|
+
* @param harFilePaths HAR 文件路径列表
|
|
169
|
+
* @param ohPackageNameConfig ohPackageName 配置(字符串或数组)
|
|
170
|
+
* @param npmPackageName npm 包名
|
|
171
|
+
* @param harmonyProjectPath Harmony 项目路径
|
|
172
|
+
*/
|
|
173
|
+
resolveHarPackageNames(harFilePaths, ohPackageNameConfig, npmPackageName, harmonyProjectPath) {
|
|
174
|
+
// 默认的 ohPackage 名称
|
|
175
|
+
const defaultOhPackageName = this.npmPackageNameToOHPackageName(npmPackageName);
|
|
176
|
+
// 构建 HAR 文件名到路径的映射
|
|
177
|
+
const harPathMap = new Map();
|
|
178
|
+
for (const harPath of harFilePaths) {
|
|
179
|
+
const harFileName = node_path_1.default.basename(harPath.toString());
|
|
180
|
+
harPathMap.set(harFileName, harPath);
|
|
181
|
+
}
|
|
182
|
+
// 辅助函数:创建 ResolvedHar
|
|
183
|
+
const createResolvedHar = (harPath, ohPkgName, version) => ({
|
|
184
|
+
harFilePathRelativeToHarmony: harPath.relativeTo(harmonyProjectPath).toString(),
|
|
185
|
+
ohPackageName: ohPkgName,
|
|
186
|
+
version,
|
|
187
|
+
});
|
|
188
|
+
const result = [];
|
|
189
|
+
const processedHarNames = new Set();
|
|
190
|
+
// 1. 如果是数组配置,按照配置顺序处理
|
|
191
|
+
if (Array.isArray(ohPackageNameConfig)) {
|
|
192
|
+
for (const mapping of ohPackageNameConfig) {
|
|
193
|
+
const harPath = harPathMap.get(mapping.harName);
|
|
194
|
+
if (harPath) {
|
|
195
|
+
result.push(createResolvedHar(harPath, mapping.packageName, mapping.version));
|
|
196
|
+
processedHarNames.add(mapping.harName);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// 2. 处理未在配置中指定的 HAR(按文件系统扫描顺序)
|
|
201
|
+
for (const harPath of harFilePaths) {
|
|
202
|
+
const harFileName = node_path_1.default.basename(harPath.toString());
|
|
203
|
+
if (processedHarNames.has(harFileName)) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// 如果是字符串格式,所有 HAR 共用
|
|
207
|
+
if (typeof ohPackageNameConfig === 'string') {
|
|
208
|
+
const suffix = harFilePaths.length > 1
|
|
209
|
+
? '--' + node_path_1.default.basename(harFileName, '.har')
|
|
210
|
+
: '';
|
|
211
|
+
result.push(createResolvedHar(harPath, ohPackageNameConfig + suffix));
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
// 默认命名规则
|
|
215
|
+
const suffix = harFilePaths.length > 1
|
|
216
|
+
? '--' + node_path_1.default.basename(harFileName, '.har')
|
|
217
|
+
: '';
|
|
218
|
+
result.push(createResolvedHar(harPath, defaultOhPackageName + suffix));
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
161
222
|
evaluate(input) {
|
|
223
|
+
var _a;
|
|
224
|
+
// 处理库配置,应用默认值
|
|
162
225
|
const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
|
|
163
|
-
var _a, _b, _c
|
|
164
|
-
return Object.assign(Object.assign({}, lib), { etsRNOHPackageClassName: (_a = lib.etsRNOHPackageClassName) !== null && _a !== void 0 ? _a : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cppRNOHPackageClassName: (_b = lib.cppRNOHPackageClassName) !== null && _b !== void 0 ? _b : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cmakeLibraryTargetName: (_c = lib.cmakeLibraryTargetName) !== null && _c !== void 0 ? _c : this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName),
|
|
226
|
+
var _a, _b, _c;
|
|
227
|
+
return Object.assign(Object.assign({}, lib), { etsRNOHPackageClassName: (_a = lib.etsRNOHPackageClassName) !== null && _a !== void 0 ? _a : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cppRNOHPackageClassName: (_b = lib.cppRNOHPackageClassName) !== null && _b !== void 0 ? _b : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cmakeLibraryTargetName: (_c = lib.cmakeLibraryTargetName) !== null && _c !== void 0 ? _c : this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName), resolvedHars: lib.resolvedHars });
|
|
165
228
|
});
|
|
166
229
|
autolinkableLibraries.sort((a, b) => {
|
|
167
230
|
if (a.npmPackageName < b.npmPackageName)
|
|
@@ -171,27 +234,51 @@ class Autolinking {
|
|
|
171
234
|
return 0;
|
|
172
235
|
});
|
|
173
236
|
const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
|
|
174
|
-
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
|
|
175
237
|
const unmanagedNativeDependencySpecifierByName = {};
|
|
238
|
+
// 收集所有配置了 autolinking 的 npm 包名
|
|
239
|
+
const autolinkedNpmPackageNames = new Set(autolinkableLibraries.map(lib => lib.npmPackageName));
|
|
176
240
|
Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
|
|
177
241
|
if (!(dependencySpecifier.includes('file:') &&
|
|
178
242
|
dependencySpecifier.includes('node_modules'))) {
|
|
243
|
+
// 不是 file:node_modules 格式 → 非托管,保留
|
|
179
244
|
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
180
245
|
}
|
|
181
246
|
else {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
247
|
+
// 是 file:node_modules 格式,判断对应的 npm 包是否配置了 autolinking
|
|
248
|
+
const npmPackageName = this.extractNpmPackageNameFromPath(dependencySpecifier);
|
|
249
|
+
if (!npmPackageName || !autolinkedNpmPackageNames.has(npmPackageName)) {
|
|
250
|
+
// 没有配置 autolinking → 需要检查 HAR 文件是否实际存在
|
|
251
|
+
const harPath = dependencySpecifier.replace('file:', '');
|
|
252
|
+
const normalizedHarPath = node_path_1.default.normalize(harPath);
|
|
253
|
+
// 依赖路径是相对于 harmony 项目的,oh-package.json5 所在目录就是 harmony 项目目录
|
|
254
|
+
const harmonyProjectPath = input.ohPackagePathAndContent[0].getDirectoryPath();
|
|
255
|
+
const absoluteHarPath = harmonyProjectPath.copyWithNewSegment(normalizedHarPath);
|
|
256
|
+
if (this.fs.existsSync(absoluteHarPath)) {
|
|
257
|
+
// HAR 文件存在 → 非托管,保留原依赖
|
|
258
|
+
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
259
|
+
}
|
|
260
|
+
// HAR 文件不存在 → 不保留(清理无效依赖)
|
|
187
261
|
}
|
|
262
|
+
// 如果配置了 autolinking → 不保留(后面会用新生成的值替换)
|
|
188
263
|
}
|
|
189
264
|
});
|
|
265
|
+
// 为每个 HAR 生成依赖条目
|
|
190
266
|
const managedNativeDependencySpecifierByName = {};
|
|
191
267
|
for (const library of autolinkableLibraries) {
|
|
192
|
-
|
|
193
|
-
|
|
268
|
+
for (const har of library.resolvedHars) {
|
|
269
|
+
// 如果有 version 字段,使用版本号(远程依赖);否则使用 file: 路径(本地依赖)
|
|
270
|
+
managedNativeDependencySpecifierByName[har.ohPackageName] =
|
|
271
|
+
(_a = har.version) !== null && _a !== void 0 ? _a : `file:${har.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
|
|
272
|
+
}
|
|
194
273
|
}
|
|
274
|
+
// 为模板准备数据:每个库需要生成 import 语句
|
|
275
|
+
// 由于所有 HAR 共享同一个 Package 类名,每个库只需要一个 import
|
|
276
|
+
const templateLibraries = autolinkableLibraries.map((lib) => {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
// 使用第一个 HAR 的 ohPackageName 作为 import 来源
|
|
279
|
+
const primaryOhPackageName = (_b = (_a = lib.resolvedHars[0]) === null || _a === void 0 ? void 0 : _a.ohPackageName) !== null && _b !== void 0 ? _b : '';
|
|
280
|
+
return Object.assign(Object.assign({}, lib), { ohPackageName: primaryOhPackageName });
|
|
281
|
+
});
|
|
195
282
|
return {
|
|
196
283
|
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
197
284
|
linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
|
|
@@ -199,19 +286,19 @@ class Autolinking {
|
|
|
199
286
|
cppRNOHPackagesFactoryPathAndContent: [
|
|
200
287
|
input.cppRNOHPackagesFactoryPath,
|
|
201
288
|
mustache_1.default.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
202
|
-
libraries:
|
|
289
|
+
libraries: templateLibraries,
|
|
203
290
|
}),
|
|
204
291
|
],
|
|
205
292
|
etsRNOHPackagesFactoryPathAndContent: [
|
|
206
293
|
input.etsRNOHPackagesFactoryPath,
|
|
207
294
|
mustache_1.default.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
|
|
208
|
-
libraries:
|
|
295
|
+
libraries: templateLibraries,
|
|
209
296
|
}),
|
|
210
297
|
],
|
|
211
298
|
cmakeAutolinkingPathAndContent: [
|
|
212
299
|
input.cmakeAutolinkingPath,
|
|
213
300
|
mustache_1.default.render(CMAKE_AUTOLINKING_TEMPLATE, {
|
|
214
|
-
libraries:
|
|
301
|
+
libraries: templateLibraries,
|
|
215
302
|
}),
|
|
216
303
|
],
|
|
217
304
|
ohPackagePathAndContent: [
|
|
@@ -247,6 +334,37 @@ class Autolinking {
|
|
|
247
334
|
}
|
|
248
335
|
return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
|
|
249
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* 从依赖路径中提取 npm 包名
|
|
339
|
+
* @param dependencySpecifier 依赖路径,如 "file:../node_modules/@scope/package/harmony/xxx.har"
|
|
340
|
+
* @returns npm 包名,如 "@scope/package";如果无法解析则返回 null
|
|
341
|
+
*/
|
|
342
|
+
extractNpmPackageNameFromPath(dependencySpecifier) {
|
|
343
|
+
// 移除 file: 前缀
|
|
344
|
+
const path = dependencySpecifier.replace(/^file:/, '');
|
|
345
|
+
// 查找 node_modules 后面的部分
|
|
346
|
+
const nodeModulesIndex = path.indexOf('node_modules/');
|
|
347
|
+
if (nodeModulesIndex === -1) {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
const afterNodeModules = path.substring(nodeModulesIndex + 'node_modules/'.length);
|
|
351
|
+
// 检查是否是 scoped package (@scope/package)
|
|
352
|
+
if (afterNodeModules.startsWith('@')) {
|
|
353
|
+
const parts = afterNodeModules.split('/');
|
|
354
|
+
if (parts.length >= 2) {
|
|
355
|
+
return `${parts[0]}/${parts[1]}`; // @scope/package
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
// 非 scoped package
|
|
360
|
+
const firstSlash = afterNodeModules.indexOf('/');
|
|
361
|
+
if (firstSlash !== -1) {
|
|
362
|
+
return afterNodeModules.substring(0, firstSlash);
|
|
363
|
+
}
|
|
364
|
+
return afterNodeModules || null;
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
250
368
|
saveAndLogOutput(output) {
|
|
251
369
|
const pathAndContentPairs = [];
|
|
252
370
|
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
package/dist/commands/init.js
CHANGED
|
File without changes
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
2
8
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
9
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
10
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,7 +29,20 @@ class ProjectDependency {
|
|
|
23
29
|
getCodegenConfigs() {
|
|
24
30
|
return this.readPackageJSON().getCodegenConfigs();
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
/**
|
|
33
|
+
* 获取 HAR 文件路径列表
|
|
34
|
+
* @param mainHarPath 自定义的 HAR 扫描根目录(相对于包根目录),默认为 'harmony'
|
|
35
|
+
*/
|
|
36
|
+
getHarFilePaths(mainHarPath) {
|
|
37
|
+
// 如果指定了 mainHarPath,使用自定义路径
|
|
38
|
+
if (mainHarPath) {
|
|
39
|
+
const customPath = this.packageRootPath.copyWithNewSegment(mainHarPath);
|
|
40
|
+
if (this.fs.existsSync(customPath)) {
|
|
41
|
+
return this.fs.findFilePathsWithExtensions(customPath, ['har']);
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
// 默认行为:优先查找 harmony/ 目录,否则查找包根目录
|
|
27
46
|
const packageHarmonyPath = this.packageRootPath.copyWithNewSegment('harmony');
|
|
28
47
|
if (this.fs.existsSync(packageHarmonyPath)) {
|
|
29
48
|
return this.fs.findFilePathsWithExtensions(packageHarmonyPath, ['har']);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|