@react-native-oh/react-native-harmony-cli 0.0.41 → 0.0.43-1

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.
@@ -21,6 +21,13 @@ exports.copyAssets = copyAssets;
21
21
  */
22
22
  const fs_1 = __importDefault(require("fs"));
23
23
  const path_1 = __importDefault(require("path"));
24
+ const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
25
+ function debugLog(message) {
26
+ if (ENABLE_DEBUG_LOG) {
27
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
28
+ console.log(`[${timestamp}] ${message}`);
29
+ }
30
+ }
24
31
  const ALLOWED_SCALES = [1, 2, 3, 4];
25
32
  function filterAssetScales(scales) {
26
33
  const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
@@ -94,7 +101,9 @@ function copyFiles(logger, fileDestBySrc) {
94
101
  }
95
102
  if (fileSources.length === 0) {
96
103
  logger.info(() => `Copied ${assetFilesCount} ${assetFilesCount === 1 ? 'asset' : 'assets'}`);
104
+ debugLog('All assets copied, resolving promise...');
97
105
  resolve();
106
+ debugLog('Assets copy promise resolved');
98
107
  }
99
108
  else {
100
109
  // fileSources.length === 0 is checked in previous branch, so this is string
@@ -113,8 +122,27 @@ function copyFile(src, dest, onFinished) {
113
122
  onFinished(err);
114
123
  return;
115
124
  }
116
- fs_1.default.createReadStream(src)
117
- .pipe(fs_1.default.createWriteStream(dest))
118
- .on('finish', onFinished);
125
+ const readStream = fs_1.default.createReadStream(src);
126
+ const writeStream = fs_1.default.createWriteStream(dest);
127
+ let finished = false;
128
+ const handleError = (err) => {
129
+ if (!finished) {
130
+ finished = true;
131
+ console.error(`[Asset Copy Error] ${src} -> ${dest}:`, err.message);
132
+ readStream.destroy();
133
+ writeStream.destroy();
134
+ onFinished(err);
135
+ }
136
+ };
137
+ const handleFinish = () => {
138
+ if (!finished) {
139
+ finished = true;
140
+ onFinished();
141
+ }
142
+ };
143
+ readStream.on('error', handleError);
144
+ writeStream.on('error', handleError);
145
+ writeStream.on('finish', handleFinish);
146
+ readStream.pipe(writeStream);
119
147
  });
120
148
  }
@@ -24,6 +24,7 @@ const core_1 = require("../core");
24
24
  const mustache_1 = __importDefault(require("mustache"));
25
25
  const case_1 = __importDefault(require("case"));
26
26
  const node_path_1 = __importDefault(require("node:path"));
27
+ const JSON5Writer_1 = require("./JSON5Writer");
27
28
  const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
28
29
  /*
29
30
  * This file was generated by RNOH autolinking.
@@ -112,33 +113,38 @@ class Autolinking {
112
113
  const skippedLibraryNpmPackageNames = [];
113
114
  yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
114
115
  var _a;
115
- const harFilePaths = dependency.getHarFilePaths();
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);
116
125
  if (harFilePaths.length === 0) {
117
126
  return;
118
127
  }
119
128
  nodeModuleHarPaths.push(...harFilePaths);
120
- const packageJson = dependency.readPackageJSON();
121
- const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
129
+ // 检查是否应该跳过该包
122
130
  if (providedAutolinkingConfig === undefined ||
123
131
  providedAutolinkingConfig === null ||
124
132
  (config.excludedNpmPackageNames.has(packageJson.name) &&
125
133
  config.excludedNpmPackageNames.size > 0) ||
126
134
  (!config.includedNpmPackageNames.has(packageJson.name) &&
127
- config.includedNpmPackageNames.size > 0) ||
128
- harFilePaths.length !== 1) {
135
+ config.includedNpmPackageNames.size > 0)) {
129
136
  skippedLibraryNpmPackageNames.push(packageJson.name);
130
137
  return;
131
138
  }
132
- const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
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);
133
142
  autolinkableLibraries.push({
134
143
  npmPackageName: packageJson.name,
144
+ resolvedHars,
135
145
  etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
136
146
  cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
137
147
  cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
138
- ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
139
- harFilePathRelativeToHarmony: harFilePaths[0]
140
- .relativeTo(harmonyProjectPath)
141
- .toString(),
142
148
  });
143
149
  });
144
150
  const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
@@ -157,10 +163,68 @@ class Autolinking {
157
163
  };
158
164
  });
159
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
+ }
160
222
  evaluate(input) {
223
+ var _a;
224
+ // 处理库配置,应用默认值
161
225
  const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
162
- var _a, _b, _c, _d;
163
- 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), ohPackageName: (_d = lib.ohPackageName) !== null && _d !== void 0 ? _d : this.npmPackageNameToOHPackageName(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 });
164
228
  });
165
229
  autolinkableLibraries.sort((a, b) => {
166
230
  if (a.npmPackageName < b.npmPackageName)
@@ -170,27 +234,51 @@ class Autolinking {
170
234
  return 0;
171
235
  });
172
236
  const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
173
- const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
174
237
  const unmanagedNativeDependencySpecifierByName = {};
238
+ // 收集所有配置了 autolinking 的 npm 包名
239
+ const autolinkedNpmPackageNames = new Set(autolinkableLibraries.map(lib => lib.npmPackageName));
175
240
  Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
176
241
  if (!(dependencySpecifier.includes('file:') &&
177
242
  dependencySpecifier.includes('node_modules'))) {
243
+ // 不是 file:node_modules 格式 → 非托管,保留
178
244
  unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
179
245
  }
180
246
  else {
181
- const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
182
- if (!autolinkableHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony)) &&
183
- input.nodeModuleHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony))) {
184
- unmanagedNativeDependencySpecifierByName[name] =
185
- dependencySpecifier;
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 文件不存在 → 不保留(清理无效依赖)
186
261
  }
262
+ // 如果配置了 autolinking → 不保留(后面会用新生成的值替换)
187
263
  }
188
264
  });
265
+ // 为每个 HAR 生成依赖条目
189
266
  const managedNativeDependencySpecifierByName = {};
190
267
  for (const library of autolinkableLibraries) {
191
- managedNativeDependencySpecifierByName[library.ohPackageName] =
192
- `file:${library.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
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
+ }
193
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
+ });
194
282
  return {
195
283
  skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
196
284
  linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
@@ -198,24 +286,24 @@ class Autolinking {
198
286
  cppRNOHPackagesFactoryPathAndContent: [
199
287
  input.cppRNOHPackagesFactoryPath,
200
288
  mustache_1.default.render(CPP_RNOH_PACKAGES_FACTORY_TEMPLATE, {
201
- libraries: autolinkableLibraries,
289
+ libraries: templateLibraries,
202
290
  }),
203
291
  ],
204
292
  etsRNOHPackagesFactoryPathAndContent: [
205
293
  input.etsRNOHPackagesFactoryPath,
206
294
  mustache_1.default.render(ETS_RNOH_PACKAGES_FACTORY_TEMPLATE, {
207
- libraries: autolinkableLibraries,
295
+ libraries: templateLibraries,
208
296
  }),
209
297
  ],
210
298
  cmakeAutolinkingPathAndContent: [
211
299
  input.cmakeAutolinkingPath,
212
300
  mustache_1.default.render(CMAKE_AUTOLINKING_TEMPLATE, {
213
- libraries: autolinkableLibraries,
301
+ libraries: templateLibraries,
214
302
  }),
215
303
  ],
216
304
  ohPackagePathAndContent: [
217
305
  input.ohPackagePathAndContent[0],
218
- json5_1.default.stringify(Object.assign(Object.assign({}, ohPackage), { dependencies: Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName) }), { space: 2, quote: '"' }) + '\n',
306
+ JSON5Writer_1.JSON5Writer.updateDependenciesWithFallback(input.ohPackagePathAndContent[1], Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName)),
219
307
  ],
220
308
  };
221
309
  }
@@ -246,6 +334,37 @@ class Autolinking {
246
334
  }
247
335
  return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
248
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
+ }
249
368
  saveAndLogOutput(output) {
250
369
  const pathAndContentPairs = [];
251
370
  pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
@@ -0,0 +1,61 @@
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
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JSON5Writer = void 0;
13
+ const json5_1 = __importDefault(require("json5"));
14
+ /**
15
+ * A utility class for modifying JSON5 content while preserving comments and formatting.
16
+ * Uses json5-writer's AST-based transformation to maintain the original structure.
17
+ */
18
+ class JSON5Writer {
19
+ /**
20
+ * Updates the dependencies in a JSON5 string while preserving comments and formatting.
21
+ *
22
+ * @param content - The original JSON5 content
23
+ * @param newDependencies - The new dependencies object to set
24
+ * @returns The modified JSON5 content with preserved comments
25
+ */
26
+ static updateDependencies(content, newDependencies) {
27
+ const json5Writer = require('json5-writer');
28
+ // Parse the original content to get all fields
29
+ const parsed = json5_1.default.parse(content);
30
+ // Create the new object with updated dependencies
31
+ const newObject = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
32
+ // Load the original content into json5-writer to preserve comments
33
+ const writer = json5Writer.load(content);
34
+ // Write the new object, which will preserve comments
35
+ writer.write(newObject);
36
+ // Return the modified source with JSON5-style formatting
37
+ // Use double quotes for both keys and values, and trailing commas
38
+ // quoteKeys: true ensures keys with special characters (like @, /, -) are properly quoted
39
+ return writer.toSource({ quote: 'double', quoteKeys: true, trailingComma: true }) + '\n';
40
+ }
41
+ /**
42
+ * Updates dependencies with fallback to standard JSON5 stringify if preservation fails.
43
+ * This ensures backward compatibility.
44
+ *
45
+ * @param content - The original JSON5 content
46
+ * @param newDependencies - The new dependencies object to set
47
+ * @returns The modified JSON5 content
48
+ */
49
+ static updateDependenciesWithFallback(content, newDependencies) {
50
+ try {
51
+ return this.updateDependencies(content, newDependencies);
52
+ }
53
+ catch (error) {
54
+ // Fallback to JSON5 stringify if AST transformation fails
55
+ const parsed = json5_1.default.parse(content);
56
+ const result = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
57
+ return json5_1.default.stringify(result, { space: 2, quote: '"' }) + '\n';
58
+ }
59
+ }
60
+ }
61
+ exports.JSON5Writer = JSON5Writer;
@@ -26,6 +26,13 @@ const Server_1 = __importDefault(require("metro/src/Server"));
26
26
  const path_1 = __importDefault(require("path"));
27
27
  const assetResolver_1 = require("../assetResolver");
28
28
  const io_1 = require("../io");
29
+ const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
30
+ function debugLog(message) {
31
+ if (ENABLE_DEBUG_LOG) {
32
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
33
+ console.log(`[${timestamp}] ${message}`);
34
+ }
35
+ }
29
36
  const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
30
37
  const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
31
38
  exports.commandBundleHarmony = {
@@ -69,6 +76,7 @@ exports.commandBundleHarmony = {
69
76
  ],
70
77
  func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
71
78
  const logger = new io_1.Logger();
79
+ debugLog('Starting bundle-harmony process...');
72
80
  const buildOptions = {
73
81
  entry: args.entryFile,
74
82
  platform: 'harmony',
@@ -78,10 +86,14 @@ exports.commandBundleHarmony = {
78
86
  sourceMapUrl: args.sourcemapOutput,
79
87
  };
80
88
  const metroConfig = yield loadMetroConfig(args.config);
89
+ debugLog('Creating bundle...');
81
90
  const bundle = yield createBundle(metroConfig, buildOptions);
82
91
  yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
83
92
  const assets = yield retrieveAssetsData(metroConfig, buildOptions);
84
- (0, assetResolver_1.copyAssets)(logger, assets, args.assetsDest);
93
+ debugLog('Copying assets...');
94
+ yield (0, assetResolver_1.copyAssets)(logger, assets, args.assetsDest);
95
+ debugLog('Assets copy completed, cleaning up...');
96
+ debugLog('Bundle process finished, exiting');
85
97
  }),
86
98
  };
87
99
  function loadMetroConfig(configPath) {
@@ -29,7 +29,20 @@ class ProjectDependency {
29
29
  getCodegenConfigs() {
30
30
  return this.readPackageJSON().getCodegenConfigs();
31
31
  }
32
- getHarFilePaths() {
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/ 目录,否则查找包根目录
33
46
  const packageHarmonyPath = this.packageRootPath.copyWithNewSegment('harmony');
34
47
  if (this.fs.existsSync(packageHarmonyPath)) {
35
48
  return this.fs.findFilePathsWithExtensions(packageHarmonyPath, ['har']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-oh/react-native-harmony-cli",
3
- "version": "0.0.41",
3
+ "version": "0.0.43-1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -64,6 +64,7 @@
64
64
  "ignore": "^5.2.4",
65
65
  "inquirer": "^12.7.0",
66
66
  "json5": "^2.2.3",
67
+ "json5-writer": "^0.2.0",
67
68
  "memfs": "4.12.0",
68
69
  "mustache": "^4.2.0",
69
70
  "tar": "^6.1.15",