@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.42

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 (65) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -77
  3. package/dist/autolinking/Autolinking.js +179 -179
  4. package/dist/autolinking/JSON5Writer.js +61 -0
  5. package/dist/codegen/core/CodegenError.js +3 -23
  6. package/dist/codegen/core/EventUtils.js +3 -3
  7. package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
  8. package/dist/codegen/core/UberSchema.js +57 -96
  9. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
  11. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
  12. package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
  13. package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
  14. package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
  15. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  16. package/dist/codegen/generators/UberGeneratorV1.js +24 -23
  17. package/dist/codegen/generators/UberGeneratorV2.js +34 -35
  18. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
  19. package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
  20. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
  21. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
  22. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
  23. package/dist/codegen/templates/IndexTSTemplate.js +37 -17
  24. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
  25. package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
  26. package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
  27. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
  28. package/dist/commands/bundle-harmony.js +65 -138
  29. package/dist/commands/codegen-harmony.js +105 -165
  30. package/dist/commands/codegen-lib-harmony.js +76 -116
  31. package/dist/commands/create-metro-host-constants.js +18 -47
  32. package/dist/commands/init.js +537 -961
  33. package/dist/commands/link-harmony.js +33 -71
  34. package/dist/commands/pack-harmony.js +47 -108
  35. package/dist/commands/run-harmony.js +372 -518
  36. package/dist/commands/unpack-harmony.js +105 -198
  37. package/dist/commands/verify-package-harmony.js +54 -108
  38. package/dist/core/AbsolutePath.js +31 -47
  39. package/dist/core/CodegenConfig.js +24 -22
  40. package/dist/core/DescriptiveError.js +18 -37
  41. package/dist/core/FileSystem.js +14 -18
  42. package/dist/core/OHPackageJSON5.js +17 -23
  43. package/dist/core/PackageJSON.js +26 -42
  44. package/dist/core/ProjectDependenciesManager.js +40 -92
  45. package/dist/core/ValidationError.js +2 -22
  46. package/dist/core/fs.js +9 -6
  47. package/dist/index.js +1 -1
  48. package/dist/io/CliExecutor.js +46 -98
  49. package/dist/io/Logger.js +40 -46
  50. package/dist/io/RealFS.js +35 -88
  51. package/dist/io/TarGz.js +11 -8
  52. package/dist/io/__fixtures__.js +79 -141
  53. package/dist/io/fsUtils.js +13 -12
  54. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
  55. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
  56. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
  57. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
  58. package/dist/package-verifier/verify-package.js +55 -132
  59. package/dist/simulator/LaunchSimulator.js +224 -301
  60. package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
  61. package/jest.config.js +12 -12
  62. package/package.json +79 -78
  63. package/react-native.config.js +17 -17
  64. package/tsconfig.build.json +6 -6
  65. package/tsconfig.json +2 -2
@@ -5,17 +5,6 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE-MIT file in the root directory of this source tree.
7
7
  */
8
- var __assign = (this && this.__assign) || function () {
9
- __assign = Object.assign || function(t) {
10
- for (var s, i = 1, n = arguments.length; i < n; i++) {
11
- s = arguments[i];
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13
- t[p] = s[p];
14
- }
15
- return t;
16
- };
17
- return __assign.apply(this, arguments);
18
- };
19
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
20
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
10
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -25,152 +14,172 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
25
14
  step((generator = generator.apply(thisArg, _arguments || [])).next());
26
15
  });
27
16
  };
28
- var __generator = (this && this.__generator) || function (thisArg, body) {
29
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
30
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
31
- function verb(n) { return function (v) { return step([n, v]); }; }
32
- function step(op) {
33
- if (f) throw new TypeError("Generator is already executing.");
34
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
35
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
36
- if (y = 0, t) op = [op[0] & 2, t.value];
37
- switch (op[0]) {
38
- case 0: case 1: t = op; break;
39
- case 4: _.label++; return { value: op[1], done: false };
40
- case 5: _.label++; y = op[1]; op = [0]; continue;
41
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
42
- default:
43
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
44
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
45
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
46
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
47
- if (t[2]) _.ops.pop();
48
- _.trys.pop(); continue;
49
- }
50
- op = body.call(thisArg, _);
51
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
52
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
53
- }
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
54
19
  };
55
20
  Object.defineProperty(exports, "__esModule", { value: true });
56
21
  exports.Autolinking = void 0;
57
- var json5_1 = require("json5");
58
- var core_1 = require("../core");
59
- var mustache_1 = require("mustache");
60
- var case_1 = require("case");
61
- var node_path_1 = require("node:path");
62
- var ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = "\n/*\n * This file was generated by RNOH autolinking.\n * DO NOT modify it manually, your changes WILL be overwritten.\n */\nimport type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';\n{{#libraries}}\nimport {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';\n{{/libraries}}\n\nexport function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {\n return [\n{{#libraries}}\n new {{etsRNOHPackageClassName}}(ctx),\n{{/libraries}}\n ];\n}\n".trimStart();
63
- var CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = "\n/*\n * This file was generated by RNOH autolinking.\n * DO NOT modify it manually, your changes WILL be overwritten.\n */\n// clang-format off\n#pragma once\n#include \"RNOH/Package.h\"\n{{#libraries}}\n#include \"{{cppRNOHPackageClassName}}.h\"\n{{/libraries}}\n\nstd::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {\n return {\n{{#libraries}}\n std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),\n{{/libraries}}\n };\n}\n".trimStart();
64
- var CMAKE_AUTOLINKING_TEMPLATE = "\n# This file was generated by RNOH autolinking.\n# DO NOT modify it manually, your changes WILL be overwritten.\ncmake_minimum_required(VERSION 3.5)\n\n# @actor RNOH_APP\nfunction(autolink_libraries target)\n{{#libraries}}\n add_subdirectory(\"${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp\" ./{{cmakeLibraryTargetName}})\n{{/libraries}}\n\n set(AUTOLINKED_LIBRARIES\n{{#libraries}}\n {{cmakeLibraryTargetName}}\n{{/libraries}}\n )\n\n foreach(lib ${AUTOLINKED_LIBRARIES})\n target_link_libraries(${target} PUBLIC ${lib})\n endforeach()\nendfunction()\n".trimStart();
65
- var Autolinking = /** @class */ (function () {
66
- function Autolinking(fs, logger) {
22
+ const json5_1 = __importDefault(require("json5"));
23
+ const core_1 = require("../core");
24
+ const mustache_1 = __importDefault(require("mustache"));
25
+ const case_1 = __importDefault(require("case"));
26
+ const node_path_1 = __importDefault(require("node:path"));
27
+ const JSON5Writer_1 = require("./JSON5Writer");
28
+ const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
29
+ /*
30
+ * This file was generated by RNOH autolinking.
31
+ * DO NOT modify it manually, your changes WILL be overwritten.
32
+ */
33
+ import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
34
+ {{#libraries}}
35
+ import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
36
+ {{/libraries}}
37
+
38
+ export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
39
+ return [
40
+ {{#libraries}}
41
+ new {{etsRNOHPackageClassName}}(ctx),
42
+ {{/libraries}}
43
+ ];
44
+ }
45
+ `.trimStart();
46
+ const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
47
+ /*
48
+ * This file was generated by RNOH autolinking.
49
+ * DO NOT modify it manually, your changes WILL be overwritten.
50
+ */
51
+ // clang-format off
52
+ #pragma once
53
+ #include "RNOH/Package.h"
54
+ {{#libraries}}
55
+ #include "{{cppRNOHPackageClassName}}.h"
56
+ {{/libraries}}
57
+
58
+ std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
59
+ return {
60
+ {{#libraries}}
61
+ std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
62
+ {{/libraries}}
63
+ };
64
+ }
65
+ `.trimStart();
66
+ const CMAKE_AUTOLINKING_TEMPLATE = `
67
+ # This file was generated by RNOH autolinking.
68
+ # DO NOT modify it manually, your changes WILL be overwritten.
69
+ cmake_minimum_required(VERSION 3.5)
70
+
71
+ # @actor RNOH_APP
72
+ function(autolink_libraries target)
73
+ {{#libraries}}
74
+ add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
75
+ {{/libraries}}
76
+
77
+ set(AUTOLINKED_LIBRARIES
78
+ {{#libraries}}
79
+ {{cmakeLibraryTargetName}}
80
+ {{/libraries}}
81
+ )
82
+
83
+ foreach(lib \${AUTOLINKED_LIBRARIES})
84
+ target_link_libraries(\${target} PUBLIC \${lib})
85
+ endforeach()
86
+ endfunction()
87
+ `.trimStart();
88
+ class Autolinking {
89
+ constructor(fs, logger) {
67
90
  this.fs = fs;
68
91
  this.logger = logger;
69
92
  }
70
- Autolinking.prototype.prepareInput = function (config) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var harmonyProjectPath, nodeModuleHarPaths, autolinkableLibraries, projectRootPath, skippedLibraryNpmPackageNames, ohPackagePath, ohPackageContent, cppRNOHPackagesFactoryPath, cmakeAutolinkingPath;
93
+ prepareInput(config) {
94
+ return __awaiter(this, void 0, void 0, function* () {
73
95
  var _a;
74
- return __generator(this, function (_b) {
75
- switch (_b.label) {
76
- case 0:
77
- if (config.includedNpmPackageNames.size > 0 &&
78
- config.excludedNpmPackageNames.size > 0) {
79
- throw new core_1.DescriptiveError({
80
- whatHappened: 'Tried to exclude and include npm packages.',
81
- whatCanUserDo: ['Include or exclude npm packages, but not both.'],
82
- extraData: {
83
- includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
84
- excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
85
- includedNpmPackageNames: config.includedNpmPackageNames,
86
- excludedNpmPackageNames: config.excludedNpmPackageNames,
87
- },
88
- });
89
- }
90
- harmonyProjectPath = (_a = config.harmonyProjectPath) !== null && _a !== void 0 ? _a : new core_1.AbsolutePath('./');
91
- nodeModuleHarPaths = [];
92
- autolinkableLibraries = [];
93
- projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
94
- skippedLibraryNpmPackageNames = [];
95
- return [4 /*yield*/, new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync(function (dependency) {
96
- var _a;
97
- var harFilePaths = dependency.getHarFilePaths();
98
- if (harFilePaths.length === 0) {
99
- return;
100
- }
101
- nodeModuleHarPaths.push.apply(nodeModuleHarPaths, harFilePaths);
102
- var packageJson = dependency.readPackageJSON();
103
- var providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
104
- if (providedAutolinkingConfig === undefined ||
105
- providedAutolinkingConfig === null ||
106
- (config.excludedNpmPackageNames.has(packageJson.name) &&
107
- config.excludedNpmPackageNames.size > 0) ||
108
- (!config.includedNpmPackageNames.has(packageJson.name) &&
109
- config.includedNpmPackageNames.size > 0) ||
110
- harFilePaths.length !== 1) {
111
- skippedLibraryNpmPackageNames.push(packageJson.name);
112
- return;
113
- }
114
- var autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
115
- autolinkableLibraries.push({
116
- npmPackageName: packageJson.name,
117
- etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
118
- cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
119
- cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
120
- ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
121
- harFilePathRelativeToHarmony: harFilePaths[0]
122
- .relativeTo(harmonyProjectPath)
123
- .toString(),
124
- });
125
- })];
126
- case 1:
127
- _b.sent();
128
- ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
129
- return [4 /*yield*/, this.fs.readText(ohPackagePath)];
130
- case 2:
131
- ohPackageContent = _b.sent();
132
- cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
133
- cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
134
- return [2 /*return*/, {
135
- projectRootPath: projectRootPath,
136
- skippedLibraryNpmPackageNames: skippedLibraryNpmPackageNames,
137
- etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
138
- cppRNOHPackagesFactoryPath: cppRNOHPackagesFactoryPath,
139
- cmakeAutolinkingPath: cmakeAutolinkingPath,
140
- ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
141
- autolinkableLibraries: autolinkableLibraries,
142
- nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map(function (p) {
143
- return p.relativeTo(harmonyProjectPath).toString();
144
- }),
145
- }];
96
+ if (config.includedNpmPackageNames.size > 0 &&
97
+ config.excludedNpmPackageNames.size > 0) {
98
+ throw new core_1.DescriptiveError({
99
+ whatHappened: 'Tried to exclude and include npm packages.',
100
+ whatCanUserDo: ['Include or exclude npm packages, but not both.'],
101
+ extraData: {
102
+ includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
103
+ excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
104
+ includedNpmPackageNames: config.includedNpmPackageNames,
105
+ excludedNpmPackageNames: config.excludedNpmPackageNames,
106
+ },
107
+ });
108
+ }
109
+ const harmonyProjectPath = (_a = config.harmonyProjectPath) !== null && _a !== void 0 ? _a : new core_1.AbsolutePath('./');
110
+ const nodeModuleHarPaths = [];
111
+ const autolinkableLibraries = [];
112
+ const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
113
+ const skippedLibraryNpmPackageNames = [];
114
+ yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
115
+ var _a;
116
+ const harFilePaths = dependency.getHarFilePaths();
117
+ if (harFilePaths.length === 0) {
118
+ return;
119
+ }
120
+ nodeModuleHarPaths.push(...harFilePaths);
121
+ const packageJson = dependency.readPackageJSON();
122
+ const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
123
+ if (providedAutolinkingConfig === undefined ||
124
+ providedAutolinkingConfig === null ||
125
+ (config.excludedNpmPackageNames.has(packageJson.name) &&
126
+ config.excludedNpmPackageNames.size > 0) ||
127
+ (!config.includedNpmPackageNames.has(packageJson.name) &&
128
+ config.includedNpmPackageNames.size > 0) ||
129
+ harFilePaths.length !== 1) {
130
+ skippedLibraryNpmPackageNames.push(packageJson.name);
131
+ return;
146
132
  }
133
+ const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
134
+ autolinkableLibraries.push({
135
+ npmPackageName: packageJson.name,
136
+ etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
137
+ cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
138
+ 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
+ });
147
144
  });
145
+ const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
146
+ const ohPackageContent = yield this.fs.readText(ohPackagePath);
147
+ const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
148
+ const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
149
+ return {
150
+ projectRootPath,
151
+ skippedLibraryNpmPackageNames,
152
+ etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
153
+ cppRNOHPackagesFactoryPath,
154
+ cmakeAutolinkingPath: cmakeAutolinkingPath,
155
+ ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
156
+ autolinkableLibraries,
157
+ nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) => p.relativeTo(harmonyProjectPath).toString()),
158
+ };
148
159
  });
149
- };
150
- Autolinking.prototype.evaluate = function (input) {
151
- var _this = this;
152
- var autolinkableLibraries = input.autolinkableLibraries.map(function (lib) {
160
+ }
161
+ evaluate(input) {
162
+ const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
153
163
  var _a, _b, _c, _d;
154
- return __assign(__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) });
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), ohPackageName: (_d = lib.ohPackageName) !== null && _d !== void 0 ? _d : this.npmPackageNameToOHPackageName(lib.npmPackageName) });
155
165
  });
156
- autolinkableLibraries.sort(function (a, b) {
166
+ autolinkableLibraries.sort((a, b) => {
157
167
  if (a.npmPackageName < b.npmPackageName)
158
168
  return -1;
159
169
  if (a.npmPackageName > b.npmPackageName)
160
170
  return 1;
161
171
  return 0;
162
172
  });
163
- var ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
164
- var autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map(function (lib) { return lib.harFilePathRelativeToHarmony; });
165
- var unmanagedNativeDependencySpecifierByName = {};
166
- Object.entries(ohPackage.dependencies).forEach(function (_a) {
167
- var name = _a[0], dependencySpecifier = _a[1];
173
+ const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
174
+ const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
175
+ const unmanagedNativeDependencySpecifierByName = {};
176
+ Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
168
177
  if (!(dependencySpecifier.includes('file:') &&
169
178
  dependencySpecifier.includes('node_modules'))) {
170
179
  unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
171
180
  }
172
181
  else {
173
- var harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
182
+ const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
174
183
  if (!autolinkableHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony)) &&
175
184
  input.nodeModuleHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony))) {
176
185
  unmanagedNativeDependencySpecifierByName[name] =
@@ -178,15 +187,14 @@ var Autolinking = /** @class */ (function () {
178
187
  }
179
188
  }
180
189
  });
181
- var managedNativeDependencySpecifierByName = {};
182
- for (var _i = 0, autolinkableLibraries_1 = autolinkableLibraries; _i < autolinkableLibraries_1.length; _i++) {
183
- var library = autolinkableLibraries_1[_i];
190
+ const managedNativeDependencySpecifierByName = {};
191
+ for (const library of autolinkableLibraries) {
184
192
  managedNativeDependencySpecifierByName[library.ohPackageName] =
185
- "file:".concat(library.harFilePathRelativeToHarmony).split(node_path_1.default.sep).join('/');
193
+ `file:${library.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
186
194
  }
187
195
  return {
188
196
  skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
189
- linkedLibraryNpmPackageNames: autolinkableLibraries.map(function (lib) { return lib.npmPackageName; }),
197
+ linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
190
198
  projectRootPath: input.projectRootPath,
191
199
  cppRNOHPackagesFactoryPathAndContent: [
192
200
  input.cppRNOHPackagesFactoryPath,
@@ -208,70 +216,62 @@ var Autolinking = /** @class */ (function () {
208
216
  ],
209
217
  ohPackagePathAndContent: [
210
218
  input.ohPackagePathAndContent[0],
211
- json5_1.default.stringify(__assign(__assign({}, ohPackage), { dependencies: __assign(__assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName) }), { space: 2, quote: '"' }) + '\n',
219
+ JSON5Writer_1.JSON5Writer.updateDependenciesWithFallback(input.ohPackagePathAndContent[1], Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName)),
212
220
  ],
213
221
  };
214
- };
215
- Autolinking.prototype.npmPackageNameToRNOHPackageClassName = function (fullNpmPackageName) {
222
+ }
223
+ npmPackageNameToRNOHPackageClassName(fullNpmPackageName) {
216
224
  if (fullNpmPackageName.startsWith('@')) {
217
- var _a = fullNpmPackageName
225
+ const [scopeName, packageName] = fullNpmPackageName
218
226
  .replace('@', '')
219
- .split('/'), scopeName = _a[0], packageName = _a[1];
227
+ .split('/');
220
228
  return case_1.default.pascal(scopeName) + case_1.default.pascal(packageName) + 'Package';
221
229
  }
222
230
  return case_1.default.pascal(fullNpmPackageName) + 'Package';
223
- };
224
- Autolinking.prototype.npmPackageNameToCMakeLibraryTargetName = function (fullNpmPackageName) {
231
+ }
232
+ npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName) {
225
233
  if (fullNpmPackageName.startsWith('@')) {
226
- var _a = fullNpmPackageName
234
+ const [scopeName, packageName] = fullNpmPackageName
227
235
  .replace('@', '')
228
- .split('/'), scopeName = _a[0], packageName = _a[1];
236
+ .split('/');
229
237
  return 'rnoh__' + case_1.default.snake(scopeName) + '__' + case_1.default.snake(packageName);
230
238
  }
231
239
  return 'rnoh__' + case_1.default.snake(fullNpmPackageName);
232
- };
233
- Autolinking.prototype.npmPackageNameToOHPackageName = function (fullNpmPackageName) {
240
+ }
241
+ npmPackageNameToOHPackageName(fullNpmPackageName) {
234
242
  if (fullNpmPackageName.startsWith('@')) {
235
- var _a = fullNpmPackageName
243
+ const [scopeName, packageName] = fullNpmPackageName
236
244
  .replace('@', '')
237
- .split('/'), scopeName = _a[0], packageName = _a[1];
245
+ .split('/');
238
246
  return '@rnoh/' + case_1.default.kebab(scopeName) + '--' + case_1.default.kebab(packageName);
239
247
  }
240
248
  return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
241
- };
242
- Autolinking.prototype.saveAndLogOutput = function (output) {
243
- var _this = this;
244
- var pathAndContentPairs = [];
249
+ }
250
+ saveAndLogOutput(output) {
251
+ const pathAndContentPairs = [];
245
252
  pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
246
253
  pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
247
254
  pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
248
255
  pathAndContentPairs.push(output.ohPackagePathAndContent);
249
- pathAndContentPairs.forEach(function (_a) {
250
- var path = _a[0], content = _a[1];
251
- _this.fs.writeTextSync(path, content);
256
+ pathAndContentPairs.forEach(([path, content]) => {
257
+ this.fs.writeTextSync(path, content);
252
258
  });
253
- output.linkedLibraryNpmPackageNames.forEach(function (npmPackageName) {
254
- _this.logger.debug(function (styles) { return "[".concat(styles.green(styles.bold('link')), "] ").concat(npmPackageName); });
259
+ output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
260
+ this.logger.debug((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
255
261
  });
256
- output.skippedLibraryNpmPackageNames.forEach(function (npmPackageName) {
257
- _this.logger.debug(function (styles) { return "[".concat(styles.yellow(styles.bold('skip')), "] ").concat(npmPackageName); });
262
+ output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
263
+ this.logger.debug((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
258
264
  });
259
- this.logger.debug(function () { return ''; });
260
- var sortedPathsRelativeToRoot = pathAndContentPairs
261
- .map(function (_a) {
262
- var path = _a[0];
263
- return path.relativeTo(output.projectRootPath).toString();
264
- })
265
+ this.logger.debug(() => '');
266
+ const sortedPathsRelativeToRoot = pathAndContentPairs
267
+ .map(([path]) => path.relativeTo(output.projectRootPath).toString())
265
268
  .sort();
266
- sortedPathsRelativeToRoot.forEach(function (pathStr) {
267
- _this.logger.debug(function (styles) { return styles.gray("\u2022 ".concat(pathStr)); });
268
- });
269
- this.logger.debug(function () { return ''; });
270
- this.logger.info(function (styles) {
271
- return "updated ".concat(styles.green(styles.bold(sortedPathsRelativeToRoot.length)), " file(s), linked ").concat(styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length)), " libraries, skipped ").concat(styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length)), " libraries");
269
+ sortedPathsRelativeToRoot.forEach((pathStr) => {
270
+ this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
272
271
  });
273
- this.logger.debug(function () { return ''; });
274
- };
275
- return Autolinking;
276
- }());
272
+ this.logger.debug(() => '');
273
+ this.logger.info((styles) => `updated ${styles.green(styles.bold(sortedPathsRelativeToRoot.length))} file(s), linked ${styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length))} libraries, skipped ${styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length))} libraries`);
274
+ this.logger.debug(() => '');
275
+ }
276
+ }
277
277
  exports.Autolinking = Autolinking;
@@ -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;
@@ -5,29 +5,9 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE-MIT file in the root directory of this source tree.
7
7
  */
8
- var __extends = (this && this.__extends) || (function () {
9
- var extendStatics = function (d, b) {
10
- extendStatics = Object.setPrototypeOf ||
11
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
12
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
13
- return extendStatics(d, b);
14
- };
15
- return function (d, b) {
16
- if (typeof b !== "function" && b !== null)
17
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
18
- extendStatics(d, b);
19
- function __() { this.constructor = d; }
20
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
21
- };
22
- })();
23
8
  Object.defineProperty(exports, "__esModule", { value: true });
24
9
  exports.CodegenError = void 0;
25
- var core_1 = require("../../core");
26
- var CodegenError = /** @class */ (function (_super) {
27
- __extends(CodegenError, _super);
28
- function CodegenError() {
29
- return _super !== null && _super.apply(this, arguments) || this;
30
- }
31
- return CodegenError;
32
- }(core_1.DescriptiveError));
10
+ const core_1 = require("../../core");
11
+ class CodegenError extends core_1.DescriptiveError {
12
+ }
33
13
  exports.CodegenError = CodegenError;
@@ -7,12 +7,12 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
10
- var CodegenError_1 = require("./CodegenError");
10
+ const CodegenError_1 = require("./CodegenError");
11
11
  function createEventNameFromEventHandlerName(eventHandlerName) {
12
- var eventName = eventHandlerName.replace('on', '');
12
+ const eventName = eventHandlerName.replace('on', '');
13
13
  if (eventName.length === 0) {
14
14
  throw new CodegenError_1.CodegenError({
15
- whatHappened: "Received invalid event handler name: ".concat(eventHandlerName),
15
+ whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
16
16
  whatCanUserDo: [
17
17
  'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
18
18
  ],