@react-native-oh/react-native-harmony-cli 0.77.48 → 0.77.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/assetResolver.js +31 -3
  2. package/dist/autolinking/Autolinking.js +8 -1
  3. package/dist/autolinking/JSON5Writer.js +61 -0
  4. package/dist/autolinking/index.js +6 -0
  5. package/dist/commands/bundle-harmony.js +15 -0
  6. package/dist/commands/init.js +0 -0
  7. package/harmony/{rnoh-hvigor-plugin-0.77.48.tgz → rnoh-hvigor-plugin-0.77.59.tgz} +0 -0
  8. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0271b9dd +0 -0
  9. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/07ba0208 +0 -0
  10. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/082dd09d +0 -0
  11. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0a9e1b0b +0 -0
  12. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/0c3d528a +0 -0
  13. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1014d3ff +0 -0
  14. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/1184678c +0 -0
  15. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/12621366 +0 -0
  16. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/19262852 +0 -0
  17. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/203fac53 +0 -0
  18. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/237b660a +0 -0
  19. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2528002d +0 -0
  20. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2587d041 +0 -0
  21. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2893bd11 +0 -0
  22. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2af6ff9d +0 -0
  23. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/2bf31f33 +0 -0
  24. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/333648cc +0 -0
  25. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/386f6df0 +0 -0
  26. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3b8c270e +0 -0
  27. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/3bcc34ba +0 -0
  28. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/444808bd +0 -0
  29. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/44a775e2 +0 -0
  30. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/46da3ccd +0 -0
  31. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/51f80e35 +0 -0
  32. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5203a2ca +0 -0
  33. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/52795646 +0 -0
  34. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/577f8208 +0 -0
  35. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5c2aafe7 +0 -0
  36. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/5c69bcfe +0 -0
  37. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62695b92 +0 -0
  38. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/62698102 +0 -0
  39. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6411ab00 +0 -0
  40. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6569ba92 +0 -0
  41. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/65e5133c +0 -0
  42. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/66029655 +0 -0
  43. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/69e85d0d +0 -0
  44. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6afcb99e +0 -0
  45. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/6de07367 +0 -0
  46. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/72498307 +0 -0
  47. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7babd1de +0 -0
  48. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/7fe56d21 +0 -0
  49. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/810cbd72 +0 -0
  50. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/812386d2 +0 -0
  51. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8448897d +0 -0
  52. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/84ab0a41 +0 -0
  53. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/853825e2 +0 -0
  54. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/862ad93a +0 -0
  55. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/86b14da6 +0 -0
  56. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/87f0fe62 +0 -0
  57. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/88ee8f74 +0 -0
  58. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8c5237c9 +0 -0
  59. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8c725800 +0 -0
  60. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8e83cbe1 +0 -0
  61. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/8f4085b9 +0 -0
  62. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/931f0b2e +0 -0
  63. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/940c8f92 +0 -0
  64. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/968191a3 +0 -0
  65. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/970780c0 +0 -0
  66. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/99a3b0b0 +0 -0
  67. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9c0ffa6b +0 -0
  68. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/9d9b42c2 +0 -0
  69. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a04266ef +0 -0
  70. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a18f78c5 +0 -0
  71. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a642fb0e +0 -0
  72. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/a97edf40 +0 -0
  73. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/aa672a20 +0 -0
  74. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ae25c61a +0 -0
  75. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/b2bebae6 +0 -0
  76. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/ba492422 +0 -0
  77. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bd3e6c21 +0 -0
  78. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/be9e564e +0 -0
  79. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/bfd71502 +0 -0
  80. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c342b18e +0 -0
  81. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c3993e7e +0 -0
  82. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c52ffd54 +0 -0
  83. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c7079ad4 +0 -0
  84. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/caee5d30 +0 -0
  85. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/cf039161 +0 -0
  86. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d0377c40 +0 -0
  87. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d262bc85 +0 -0
  88. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d287cb5c +0 -0
  89. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d716a608 +0 -0
  90. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d751012b +0 -0
  91. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e0873711 +0 -0
  92. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e1fcf77b +0 -0
  93. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/e8548d8a +0 -0
  94. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/eaedd71d +0 -0
  95. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/eca0019e +0 -0
  96. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f7189953 +0 -0
  97. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f75cb201 +0 -0
  98. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/f888164b +0 -0
  99. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/fdb9eb5a +0 -0
  100. package/package.json +2 -1
  101. package/src/assetResolver.ts +37 -3
  102. package/src/autolinking/Autolinking.test.ts +70 -17
  103. package/src/autolinking/Autolinking.ts +14 -9
  104. package/src/autolinking/JSON5Writer.ts +70 -0
  105. package/src/autolinking/index.ts +7 -0
  106. package/src/commands/bundle-harmony.ts +17 -0
  107. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/126d3e66 +0 -0
  108. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/98bc4394 +0 -0
  109. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/c8eb01c1 +0 -0
  110. package/node-compile-cache/v22.14.0-x64-efe9a9df-0/d64bff57 +0 -0
@@ -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
  }
@@ -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) {
@@ -18,6 +24,7 @@ const core_1 = require("../core");
18
24
  const mustache_1 = __importDefault(require("mustache"));
19
25
  const case_1 = __importDefault(require("case"));
20
26
  const node_path_1 = __importDefault(require("node:path"));
27
+ const JSON5Writer_1 = require("./JSON5Writer");
21
28
  const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
22
29
  /*
23
30
  * This file was generated by RNOH autolinking.
@@ -209,7 +216,7 @@ class Autolinking {
209
216
  ],
210
217
  ohPackagePathAndContent: [
211
218
  input.ohPackagePathAndContent[0],
212
- json5_1.default.stringify(Object.assign(Object.assign({}, ohPackage), { dependencies: Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName) }), { space: 2, quote: '"' }) + '\n',
219
+ JSON5Writer_1.JSON5Writer.updateDependenciesWithFallback(input.ohPackagePathAndContent[1], Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName)),
213
220
  ],
214
221
  };
215
222
  }
@@ -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;
@@ -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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
9
  if (k2 === undefined) k2 = k;
4
10
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -24,6 +24,13 @@ const child_process_1 = require("child_process");
24
24
  const io_1 = require("../io");
25
25
  const core_1 = require("../core");
26
26
  const node_crypto_1 = require("node:crypto");
27
+ const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
28
+ function debugLog(message) {
29
+ if (ENABLE_DEBUG_LOG) {
30
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
31
+ console.log(`[${timestamp}] ${message}`);
32
+ }
33
+ }
27
34
  const HERMESC_BIN_PATH = {
28
35
  darwin: path_1.default.normalize('osx-bin/hermesc'),
29
36
  linux: path_1.default.normalize('linux64-bin/hermesc'),
@@ -129,13 +136,17 @@ exports.commandBundleHarmony = {
129
136
  const bundle = yield createBundle(metroConfig, buildOptions);
130
137
  const assets = yield retrieveAssetsData(metroConfig, buildOptions);
131
138
  if (shouldGenerateHbcBundle) {
139
+ debugLog('Starting Hermes bytecode compilation...');
132
140
  yield saveHbcBundle(logger, bundle.code, bundleOutput, args.hermescDir, args.hermescOptions);
141
+ debugLog('Hermes bytecode compilation finished');
133
142
  }
134
143
  else {
135
144
  yield saveJSBundle(logger, bundle, bundleOutput);
136
145
  }
137
146
  maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
138
147
  yield (0, assetResolver_1.copyAssets)(logger, assets, assetsDest);
148
+ debugLog('Assets copy completed, cleaning up...');
149
+ debugLog('Bundle process finished, exiting');
139
150
  }
140
151
  catch (err) {
141
152
  if (err instanceof core_1.DescriptiveError) {
@@ -180,15 +191,19 @@ function saveHbcBundle(logger, bundleCode, bundleOutput, hermescPath, hermescOpt
180
191
  });
181
192
  }
182
193
  const tmpBundlePath = `${os_1.default.tmpdir()}${path_1.default.sep}b-${(0, node_crypto_1.randomUUID)()}.harmony.js`;
194
+ debugLog('Writing temporary JS bundle...');
183
195
  yield fs_extra_1.default.writeFile(tmpBundlePath, bundleCode);
184
196
  const hbcFilePath = bundleOutput.endsWith('.hbc')
185
197
  ? bundleOutput
186
198
  : path_1.default.join(path_1.default.dirname(bundleOutput), 'hermes_bundle.hbc');
187
199
  const hermescOptionsString = (hermescOptions === null || hermescOptions === void 0 ? void 0 : hermescOptions.map((e) => `-${e}`).join(' ')) || '';
200
+ debugLog(`Executing hermesc compiler: ${resolvedHermescPath}`);
188
201
  (0, child_process_1.execSync)(`${resolvedHermescPath} ${hermescOptionsString} --emit-binary -out ${hbcFilePath} ${tmpBundlePath}`, {
189
202
  stdio: 'inherit',
190
203
  });
204
+ debugLog('Hermesc execution completed, cleaning up temp file...');
191
205
  node_fs_1.default.unlinkSync(tmpBundlePath);
206
+ debugLog('Temp file deleted');
192
207
  logger.info((s) => `Created ${hbcFilePath}`);
193
208
  });
194
209
  }
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-oh/react-native-harmony-cli",
3
- "version": "0.77.48",
3
+ "version": "0.77.59",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -54,6 +54,7 @@
54
54
  "fs-extra": "^11.1.1",
55
55
  "inquirer": "^12.6.3",
56
56
  "json5": "^2.2.3",
57
+ "json5-writer": "^0.2.0",
57
58
  "memfs": "4.12.0",
58
59
  "mustache": "^4.2.0",
59
60
  "tar": "^6.1.15",
@@ -9,6 +9,15 @@ import pathUtils from 'path';
9
9
  import type { AssetData } from 'metro';
10
10
  import { Logger } from './io';
11
11
 
12
+ const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
13
+
14
+ function debugLog(message: string) {
15
+ if (ENABLE_DEBUG_LOG) {
16
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
17
+ console.log(`[${timestamp}] ${message}`);
18
+ }
19
+ }
20
+
12
21
  type Path = string;
13
22
  type CopiedFiles = Record<Path, Path>;
14
23
 
@@ -104,7 +113,9 @@ function copyFiles(logger: Logger, fileDestBySrc: CopiedFiles) {
104
113
  assetFilesCount === 1 ? 'asset' : 'assets'
105
114
  }`
106
115
  );
116
+ debugLog('All assets copied, resolving promise...');
107
117
  resolve();
118
+ debugLog('Assets copy promise resolved');
108
119
  } else {
109
120
  // fileSources.length === 0 is checked in previous branch, so this is string
110
121
  const src = fileSources.shift()!;
@@ -127,8 +138,31 @@ function copyFile(
127
138
  onFinished(err);
128
139
  return;
129
140
  }
130
- fs.createReadStream(src)
131
- .pipe(fs.createWriteStream(dest))
132
- .on('finish', onFinished);
141
+ const readStream = fs.createReadStream(src);
142
+ const writeStream = fs.createWriteStream(dest);
143
+
144
+ let finished = false;
145
+ const handleError = (err: Error) => {
146
+ if (!finished) {
147
+ finished = true;
148
+ console.error(`[Asset Copy Error] ${src} -> ${dest}:`, err.message);
149
+ readStream.destroy();
150
+ writeStream.destroy();
151
+ onFinished(err);
152
+ }
153
+ };
154
+
155
+ const handleFinish = () => {
156
+ if (!finished) {
157
+ finished = true;
158
+ onFinished();
159
+ }
160
+ };
161
+
162
+ readStream.on('error', handleError);
163
+ writeStream.on('error', handleError);
164
+ writeStream.on('finish', handleFinish);
165
+
166
+ readStream.pipe(writeStream);
133
167
  });
134
168
  }
@@ -1,8 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE-MIT file in the root directory of this source tree.
6
+ */
7
+
1
8
  import { Autolinking, AutolinkingConfig } from './Autolinking';
2
9
  import { NestedDirectoryJSON } from 'memfs';
3
10
  import { AbsolutePath, DescriptiveError } from '../core/';
4
11
  import { MockedLogger, MemFS } from '../io/__fixtures__';
5
- import pathUtils from "node:path"
12
+ import pathUtils from 'node:path';
6
13
 
7
14
  function createAutolinking({
8
15
  fsStructure,
@@ -91,16 +98,13 @@ it('should generate correct templates with scoped package default configuration'
91
98
 
92
99
  await runAutolinking();
93
100
 
94
- expect(
95
- memFS.readTextSync(new AbsolutePath('./harmony/oh-package.json5')).replace(/\\\\/g, '/')
96
- ).toBe(
97
- `
98
- {
99
- dependencies: {
100
- "@rnoh/rnoh--link-scoped": "file:../node_modules/@rnoh/link-scoped/harmony/link_scoped.har",
101
- },
102
- }
103
- `.trimStart()
101
+ const ohPackageContent = memFS.readTextSync(
102
+ new AbsolutePath('./harmony/oh-package.json5')
103
+ );
104
+ expect(ohPackageContent).toContain('dependencies');
105
+ expect(ohPackageContent).toContain('@rnoh/rnoh--link-scoped');
106
+ expect(ohPackageContent).toContain(
107
+ 'file:../node_modules/@rnoh/link-scoped/harmony/link_scoped.har'
104
108
  );
105
109
  expect(
106
110
  memFS.readTextSync(
@@ -323,14 +327,18 @@ it('should log updated files', async () => {
323
327
  const { logs } = await runAutolinking();
324
328
 
325
329
  const combinedLogs = logs.map((log) => log.msg).join('\n');
326
- expect(combinedLogs).toContain(pathUtils.normalize('harmony/entry/src/main/cpp/autolink.cmake'));
327
- expect(combinedLogs).toContain(pathUtils.normalize(
328
- 'harmony/entry/src/main/ets/RNOHPackageFactory.ets')
330
+ expect(combinedLogs).toContain(
331
+ pathUtils.normalize('harmony/entry/src/main/cpp/autolink.cmake')
332
+ );
333
+ expect(combinedLogs).toContain(
334
+ pathUtils.normalize('harmony/entry/src/main/ets/RNOHPackageFactory.ets')
329
335
  );
330
- expect(combinedLogs).toContain(pathUtils.normalize(
331
- 'harmony/entry/src/main/cpp/RNOHPackageFactory.h')
336
+ expect(combinedLogs).toContain(
337
+ pathUtils.normalize('harmony/entry/src/main/cpp/RNOHPackageFactory.h')
338
+ );
339
+ expect(combinedLogs).toContain(
340
+ pathUtils.normalize('harmony/oh-package.json5')
332
341
  );
333
- expect(combinedLogs).toContain(pathUtils.normalize('harmony/oh-package.json5'));
334
342
  });
335
343
 
336
344
  it('should log linked and skipped packages', async () => {
@@ -517,3 +525,48 @@ it('not delete packages with two hars', async () => {
517
525
  const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
518
526
  expect(ohPackageContent).toContain('@rnoh/multiple-har');
519
527
  });
528
+
529
+ it('should preserve comments in oh-package.json5', async () => {
530
+ const { runAutolinking, memFS } = createAutolinking({
531
+ fsStructure: {
532
+ ...baseFileStructure,
533
+ node_modules: {
534
+ 'test-package': {
535
+ harmony: {
536
+ 'test_package.har': '',
537
+ },
538
+ 'package.json': JSON.stringify({
539
+ name: 'test-package',
540
+ harmony: {
541
+ autolinking: true,
542
+ },
543
+ }),
544
+ },
545
+ },
546
+ harmony: {
547
+ ...baseFileStructure.harmony,
548
+ 'oh-package.json5': `{
549
+ // This is a top-level comment
550
+ "modelVersion": "5.0.0",
551
+ "license": "ISC",
552
+ /* This is a multi-line
553
+ comment */
554
+ "dependencies": {
555
+ // Existing dependency comment
556
+ "@rnoh/react-native-openharmony/": "./react_native_openharmony",
557
+ },
558
+ }`,
559
+ },
560
+ },
561
+ });
562
+
563
+ const output = await runAutolinking();
564
+
565
+ const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
566
+ // Verify comments are preserved
567
+ expect(ohPackageContent).toContain('// This is a top-level comment');
568
+ expect(ohPackageContent).toContain('/* This is a multi-line');
569
+ expect(ohPackageContent).toContain('// Existing dependency comment');
570
+ // Verify new dependency is added
571
+ expect(ohPackageContent).toContain('@rnoh/test-package');
572
+ });
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE-MIT file in the root directory of this source tree.
6
+ */
7
+
1
8
  import JSON5 from 'json5';
2
9
  import {
3
10
  AbsolutePath,
@@ -9,6 +16,7 @@ import Mustache from 'mustache';
9
16
  import Case from 'case';
10
17
  import { Logger } from '../io';
11
18
  import pathUtils from 'node:path';
19
+ import { JSON5Writer } from './JSON5Writer';
12
20
 
13
21
  type Version = string;
14
22
  type DependencySpecifier = `file:${string}` | Version;
@@ -299,16 +307,13 @@ export class Autolinking {
299
307
  ],
300
308
  ohPackagePathAndContent: [
301
309
  input.ohPackagePathAndContent[0],
302
- JSON5.stringify(
310
+ JSON5Writer.updateDependenciesWithFallback(
311
+ input.ohPackagePathAndContent[1],
303
312
  {
304
- ...ohPackage,
305
- dependencies: {
306
- ...unmanagedNativeDependencySpecifierByName,
307
- ...managedNativeDependencySpecifierByName,
308
- },
309
- },
310
- { space: 2, quote: '"' }
311
- ) + '\n',
313
+ ...unmanagedNativeDependencySpecifierByName,
314
+ ...managedNativeDependencySpecifierByName,
315
+ }
316
+ ),
312
317
  ],
313
318
  };
314
319
  }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE-MIT file in the root directory of this source tree.
6
+ */
7
+
8
+ import JSON5 from 'json5';
9
+
10
+ /**
11
+ * A utility class for modifying JSON5 content while preserving comments and formatting.
12
+ * Uses json5-writer's AST-based transformation to maintain the original structure.
13
+ */
14
+ export class JSON5Writer {
15
+ /**
16
+ * Updates the dependencies in a JSON5 string while preserving comments and formatting.
17
+ *
18
+ * @param content - The original JSON5 content
19
+ * @param newDependencies - The new dependencies object to set
20
+ * @returns The modified JSON5 content with preserved comments
21
+ */
22
+ static updateDependencies(content: string, newDependencies: Record<string, string>): string {
23
+ const json5Writer = require('json5-writer');
24
+
25
+ // Parse the original content to get all fields
26
+ const parsed = JSON5.parse(content);
27
+
28
+ // Create the new object with updated dependencies
29
+ const newObject = {
30
+ ...parsed,
31
+ dependencies: newDependencies,
32
+ };
33
+
34
+ // Load the original content into json5-writer to preserve comments
35
+ const writer = json5Writer.load(content);
36
+
37
+ // Write the new object, which will preserve comments
38
+ writer.write(newObject);
39
+
40
+ // Return the modified source with JSON5-style formatting
41
+ // Use double quotes for both keys and values, and trailing commas
42
+ // quoteKeys: true ensures keys with special characters (like @, /, -) are properly quoted
43
+ return writer.toSource({ quote: 'double', quoteKeys: true, trailingComma: true }) + '\n';
44
+ }
45
+
46
+ /**
47
+ * Updates dependencies with fallback to standard JSON5 stringify if preservation fails.
48
+ * This ensures backward compatibility.
49
+ *
50
+ * @param content - The original JSON5 content
51
+ * @param newDependencies - The new dependencies object to set
52
+ * @returns The modified JSON5 content
53
+ */
54
+ static updateDependenciesWithFallback(
55
+ content: string,
56
+ newDependencies: Record<string, string>
57
+ ): string {
58
+ try {
59
+ return this.updateDependencies(content, newDependencies);
60
+ } catch (error) {
61
+ // Fallback to JSON5 stringify if AST transformation fails
62
+ const parsed = JSON5.parse(content);
63
+ const result = {
64
+ ...parsed,
65
+ dependencies: newDependencies,
66
+ };
67
+ return JSON5.stringify(result, { space: 2, quote: '"' }) + '\n';
68
+ }
69
+ }
70
+ }
@@ -1 +1,8 @@
1
+ /**
2
+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE-MIT file in the root directory of this source tree.
6
+ */
7
+
1
8
  export * from './Autolinking';
@@ -12,6 +12,15 @@ import { Logger } from '../io';
12
12
  import { DescriptiveError } from '../core';
13
13
  import { randomUUID } from 'node:crypto';
14
14
 
15
+ const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
16
+
17
+ function debugLog(message: string) {
18
+ if (ENABLE_DEBUG_LOG) {
19
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
20
+ console.log(`[${timestamp}] ${message}`);
21
+ }
22
+ }
23
+
15
24
  type MetroConfig = Awaited<ReturnType<typeof Metro.loadConfig>>;
16
25
 
17
26
  const HERMESC_BIN_PATH = {
@@ -144,6 +153,7 @@ export const commandBundleHarmony: Command = {
144
153
  const assets = await retrieveAssetsData(metroConfig, buildOptions);
145
154
 
146
155
  if (shouldGenerateHbcBundle) {
156
+ debugLog('Starting Hermes bytecode compilation...');
147
157
  await saveHbcBundle(
148
158
  logger,
149
159
  bundle.code,
@@ -151,11 +161,14 @@ export const commandBundleHarmony: Command = {
151
161
  args.hermescDir,
152
162
  args.hermescOptions
153
163
  );
164
+ debugLog('Hermes bytecode compilation finished');
154
165
  } else {
155
166
  await saveJSBundle(logger, bundle, bundleOutput);
156
167
  }
157
168
  maybeSaveSourceMap(logger, bundle, args.sourcemapOutput);
158
169
  await copyAssets(logger, assets, assetsDest);
170
+ debugLog('Assets copy completed, cleaning up...');
171
+ debugLog('Bundle process finished, exiting');
159
172
  } catch (err) {
160
173
  if (err instanceof DescriptiveError) {
161
174
  logger.descriptiveError(err);
@@ -215,19 +228,23 @@ async function saveHbcBundle(
215
228
  }
216
229
 
217
230
  const tmpBundlePath = `${os.tmpdir()}${pathUtils.sep}b-${randomUUID()}.harmony.js`;
231
+ debugLog('Writing temporary JS bundle...');
218
232
  await fse.writeFile(tmpBundlePath, bundleCode);
219
233
  const hbcFilePath = bundleOutput.endsWith('.hbc')
220
234
  ? bundleOutput
221
235
  : pathUtils.join(pathUtils.dirname(bundleOutput), 'hermes_bundle.hbc');
222
236
  const hermescOptionsString =
223
237
  hermescOptions?.map((e) => `-${e}`).join(' ') || '';
238
+ debugLog(`Executing hermesc compiler: ${resolvedHermescPath}`);
224
239
  execSync(
225
240
  `${resolvedHermescPath} ${hermescOptionsString} --emit-binary -out ${hbcFilePath} ${tmpBundlePath}`,
226
241
  {
227
242
  stdio: 'inherit',
228
243
  }
229
244
  );
245
+ debugLog('Hermesc execution completed, cleaning up temp file...');
230
246
  fs.unlinkSync(tmpBundlePath);
247
+ debugLog('Temp file deleted');
231
248
  logger.info((s) => `Created ${hbcFilePath}`);
232
249
  }
233
250