@react-native-oh/react-native-harmony-cli 0.0.27 → 0.0.28

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 (140) hide show
  1. package/README.md +12 -0
  2. package/dist/assetResolver.js +6 -0
  3. package/dist/autolinking/Autolinking.js +275 -0
  4. package/dist/autolinking/index.js +23 -0
  5. package/dist/codegen/core/CodeGenerator.js +6 -0
  6. package/dist/codegen/core/CodegenError.js +6 -0
  7. package/dist/codegen/core/EventUtils.js +6 -0
  8. package/dist/codegen/core/TypeAnnotationToTS.js +6 -0
  9. package/dist/codegen/core/UberSchema.js +9 -3
  10. package/dist/codegen/core/index.js +6 -0
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +6 -0
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +6 -0
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +6 -0
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +6 -0
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +6 -0
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -0
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +6 -0
  18. package/dist/codegen/generators/UberGeneratorV1.js +6 -0
  19. package/dist/codegen/generators/UberGeneratorV2.js +6 -0
  20. package/dist/codegen/generators/index.js +6 -0
  21. package/dist/codegen/index.js +6 -0
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +6 -0
  23. package/dist/codegen/templates/BasePackageHTemplate.js +6 -0
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +6 -0
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +6 -0
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +6 -0
  27. package/dist/codegen/templates/IndexTSTemplate.js +6 -0
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +6 -0
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +6 -0
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +6 -0
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +6 -0
  32. package/dist/codegen/templates/index.js +6 -0
  33. package/dist/commands/bundle-harmony.js +6 -0
  34. package/dist/commands/codegen-harmony.js +16 -10
  35. package/dist/commands/codegen-lib-harmony.js +6 -0
  36. package/dist/commands/create-metro-host-constants.js +6 -0
  37. package/dist/commands/index.js +7 -0
  38. package/dist/commands/link-harmony.js +97 -0
  39. package/dist/commands/pack-harmony.js +6 -0
  40. package/dist/commands/unpack-harmony.js +10 -3
  41. package/dist/commands/verify-package-harmony.js +6 -0
  42. package/dist/core/AbsolutePath.js +12 -0
  43. package/dist/core/CodegenConfig.js +6 -0
  44. package/dist/core/DescriptiveError.js +6 -0
  45. package/dist/core/FileSystem.js +33 -0
  46. package/dist/core/OHPackageJSON5.js +6 -0
  47. package/dist/core/PackageJSON.js +15 -7
  48. package/dist/core/ProjectDependenciesManager.js +31 -18
  49. package/dist/core/ValidationError.js +6 -0
  50. package/dist/core/ValueObject.js +6 -0
  51. package/dist/core/fs.js +6 -0
  52. package/dist/core/index.js +7 -0
  53. package/dist/index.js +7 -0
  54. package/dist/io/CliExecutor.js +35 -0
  55. package/dist/io/Logger.js +9 -0
  56. package/dist/io/RealFS.js +68 -0
  57. package/dist/io/TarGz.js +6 -0
  58. package/dist/io/__fixtures__.js +127 -0
  59. package/dist/io/fsUtils.js +20 -6
  60. package/dist/io/index.js +7 -0
  61. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +6 -0
  62. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +6 -0
  63. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +6 -0
  64. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +6 -0
  65. package/dist/package-verifier/checks/index.js +6 -0
  66. package/dist/package-verifier/index.js +6 -0
  67. package/dist/package-verifier/types.js +6 -0
  68. package/dist/package-verifier/verify-package.js +7 -1
  69. package/jest.config.js +7 -0
  70. package/package.json +8 -2
  71. package/react-native.config.js +7 -0
  72. package/src/assetResolver.ts +7 -0
  73. package/src/autolinking/Autolinking.test.ts +483 -0
  74. package/src/autolinking/Autolinking.ts +384 -0
  75. package/src/autolinking/index.ts +8 -0
  76. package/src/codegen/core/CodeGenerator.ts +7 -0
  77. package/src/codegen/core/CodegenError.ts +7 -0
  78. package/src/codegen/core/EventUtils.ts +7 -0
  79. package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
  80. package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
  81. package/src/codegen/core/UberSchema.ts +11 -1
  82. package/src/codegen/core/index.ts +7 -0
  83. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +7 -0
  84. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +7 -0
  85. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +7 -0
  86. package/src/codegen/generators/CppComponentCodeGenerator.ts +7 -0
  87. package/src/codegen/generators/LibGlueCodeGenerator.ts +7 -0
  88. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -0
  89. package/src/codegen/generators/SharedComponentCodeGenerator.ts +7 -0
  90. package/src/codegen/generators/UberGeneratorV1.ts +7 -0
  91. package/src/codegen/generators/UberGeneratorV2.ts +7 -0
  92. package/src/codegen/generators/index.ts +7 -0
  93. package/src/codegen/index.ts +7 -0
  94. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +7 -0
  95. package/src/codegen/templates/BasePackageHTemplate.ts +7 -0
  96. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +7 -0
  97. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +7 -0
  98. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +7 -0
  99. package/src/codegen/templates/IndexTSTemplate.ts +7 -0
  100. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +7 -0
  101. package/src/codegen/templates/TurboModuleCppTemplate.ts +7 -0
  102. package/src/codegen/templates/TurboModuleHTemplate.ts +7 -0
  103. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +7 -0
  104. package/src/codegen/templates/index.ts +7 -0
  105. package/src/commands/bundle-harmony.ts +8 -1
  106. package/src/commands/codegen-harmony.ts +19 -6
  107. package/src/commands/codegen-lib-harmony.ts +7 -0
  108. package/src/commands/create-metro-host-constants.ts +7 -0
  109. package/src/commands/index.ts +8 -0
  110. package/src/commands/link-harmony.ts +102 -0
  111. package/src/commands/pack-harmony.ts +7 -0
  112. package/src/commands/unpack-harmony.ts +12 -3
  113. package/src/commands/verify-package-harmony.ts +7 -0
  114. package/src/core/AbsolutePath.ts +16 -0
  115. package/src/core/CodegenConfig.ts +7 -0
  116. package/src/core/DescriptiveError.ts +7 -0
  117. package/src/core/FileSystem.ts +57 -0
  118. package/src/core/OHPackageJSON5.ts +7 -0
  119. package/src/core/PackageJSON.ts +40 -8
  120. package/src/core/ProjectDependenciesManager.ts +40 -14
  121. package/src/core/ValidationError.ts +7 -0
  122. package/src/core/ValueObject.ts +7 -0
  123. package/src/core/fs.ts +7 -0
  124. package/src/core/index.ts +8 -0
  125. package/src/index.ts +9 -0
  126. package/src/io/CliExecutor.ts +47 -0
  127. package/src/io/Logger.ts +11 -0
  128. package/src/io/RealFS.ts +62 -0
  129. package/src/io/TarGz.ts +7 -0
  130. package/src/io/__fixtures__.ts +135 -0
  131. package/src/io/fsUtils.ts +26 -6
  132. package/src/io/index.ts +8 -0
  133. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
  134. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
  135. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
  136. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
  137. package/src/package-verifier/checks/index.ts +7 -0
  138. package/src/package-verifier/index.ts +7 -0
  139. package/src/package-verifier/types.ts +7 -0
  140. package/src/package-verifier/verify-package.ts +9 -1
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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);
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -13,7 +19,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
19
  };
14
20
  Object.defineProperty(exports, "__esModule", { value: true });
15
21
  exports.commandCodegenHarmony = void 0;
16
- const node_fs_1 = __importDefault(require("node:fs"));
17
22
  const node_path_1 = __importDefault(require("node:path"));
18
23
  const case_1 = __importDefault(require("case"));
19
24
  const core_1 = require("../core");
@@ -49,6 +54,7 @@ exports.commandCodegenHarmony = {
49
54
  ],
50
55
  func: (_argv, _config, args) => __awaiter(void 0, void 0, void 0, function* () {
51
56
  const logger = new io_1.Logger();
57
+ const fs = new io_1.RealFS();
52
58
  try {
53
59
  const MAX_SUPPORTED_CODEGEN_VERSION = 2;
54
60
  // prepare the input data
@@ -57,11 +63,11 @@ exports.commandCodegenHarmony = {
57
63
  const enableSafetyCheck = args.safetyCheck;
58
64
  const cppOutputPath = new core_1.AbsolutePath(args.cppOutputPath);
59
65
  const projectRootPath = new core_1.AbsolutePath(args.projectRootPath);
60
- const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(projectRootPath, (codegenVersion, packageName) => {
66
+ const uberSchemaFromArkTSLibraries = yield codegen_1.UberSchema.fromProject(fs, projectRootPath, (codegenVersion, packageName) => {
61
67
  throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
62
68
  return codegenVersion === 1;
63
69
  });
64
- const cApiLibrariesData = yield collectLibrariesData(projectRootPath, (codegenVersion, packageName) => {
70
+ const cApiLibrariesData = yield collectLibrariesData(fs, projectRootPath, (codegenVersion, packageName) => {
65
71
  throwErrorIfUnsupportedCodegenVersion(codegenVersion, MAX_SUPPORTED_CODEGEN_VERSION, packageName);
66
72
  return codegenVersion === 2;
67
73
  });
@@ -94,10 +100,10 @@ exports.commandCodegenHarmony = {
94
100
  .forEach(appendToFileContentByPath);
95
101
  // output the results
96
102
  if (args.debug) {
97
- const uberSchema = yield codegen_1.UberSchema.fromProject(projectRootPath);
103
+ const uberSchema = yield codegen_1.UberSchema.fromProject(fs, projectRootPath);
98
104
  logger.debug((styles) => styles.gray(JSON.stringify(uberSchema.getValue(), null, 2)));
99
105
  }
100
- saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
106
+ saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck);
101
107
  logCodegenResult(logger, fileContentByPath, projectRootPath);
102
108
  }
103
109
  catch (err) {
@@ -121,12 +127,12 @@ function validateArgs(args) {
121
127
  });
122
128
  }
123
129
  }
124
- function collectLibrariesData(projectRootPath, onShouldAcceptCodegenConfig) {
130
+ function collectLibrariesData(fs, projectRootPath, onShouldAcceptCodegenConfig) {
125
131
  return __awaiter(this, void 0, void 0, function* () {
126
132
  const packageJSONs = [
127
- core_1.PackageJSON.fromProjectRootPath(projectRootPath, projectRootPath),
133
+ core_1.PackageJSON.fromProjectRootPath(fs, projectRootPath, projectRootPath),
128
134
  ];
129
- yield new core_1.ProjectDependenciesManager(projectRootPath).forEachAsync((dependency) => {
135
+ yield new core_1.ProjectDependenciesManager(fs, projectRootPath).forEachAsync((dependency) => {
130
136
  packageJSONs.push(dependency.readPackageJSON());
131
137
  });
132
138
  const results = [];
@@ -158,7 +164,7 @@ function throwErrorIfUnsupportedCodegenVersion(codegenVersion, maxSupportedCodeg
158
164
  });
159
165
  }
160
166
  }
161
- function saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
167
+ function saveCodegenResult(fs, fileContentByPath, cppOutputPath, etsOutputPath, enableSafetyCheck) {
162
168
  prepareDirectory(cppOutputPath, enableSafetyCheck);
163
169
  prepareDirectory(etsOutputPath, enableSafetyCheck);
164
170
  prepareDirectory(etsOutputPath.copyWithNewSegment('components'), enableSafetyCheck);
@@ -167,7 +173,7 @@ function saveCodegenResult(fileContentByPath, cppOutputPath, etsOutputPath, enab
167
173
  prepareDirectory(path.getDirectoryPath(), enableSafetyCheck);
168
174
  });
169
175
  fileContentByPath.forEach((fileContent, path) => {
170
- node_fs_1.default.writeFileSync(path.getValue(), fileContent);
176
+ fs.writeTextSync(path, fileContent);
171
177
  });
172
178
  }
173
179
  function prepareDirectory(path, enableSafetyCheck) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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);
@@ -21,3 +27,4 @@ __exportStar(require("./create-metro-host-constants"), exports);
21
27
  __exportStar(require("./codegen-harmony"), exports);
22
28
  __exportStar(require("./verify-package-harmony"), exports);
23
29
  __exportStar(require("./codegen-lib-harmony"), exports);
30
+ __exportStar(require("./link-harmony"), exports);
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.commandLinkHarmony = void 0;
19
+ const core_1 = require("../core");
20
+ const io_1 = require("../io");
21
+ const autolinking_1 = require("../autolinking");
22
+ const COMMAND_NAME = 'link-harmony';
23
+ exports.commandLinkHarmony = {
24
+ name: COMMAND_NAME,
25
+ description: 'Handles the automatic linking of RNOH libraries. This command is meant to be used by the RNOH HvigorPlugin.',
26
+ options: [
27
+ {
28
+ name: '--harmony-project-path <path>',
29
+ description: 'Specifies the root of your OpenHarmony project.',
30
+ default: './harmony',
31
+ },
32
+ {
33
+ name: '--node-modules-path <path>',
34
+ description: 'Defines the path to the node_modules directory which holds npm packages.',
35
+ default: './node_modules',
36
+ },
37
+ {
38
+ name: '--cmake-autolink-path-relative-to-harmony <path>',
39
+ description: 'Path relative to the root of your OpenHarmony project for the generated CMake file involved in autolinking.',
40
+ default: './entry/src/main/cpp/autolinking.cmake',
41
+ },
42
+ {
43
+ name: '--cpp-rnoh-packages-factory-path-relative-to-harmony <path>',
44
+ description: 'Path relative to the root of your OpenHarmony project, for the generated file used to link packages on C++ side.',
45
+ default: './entry/src/main/cpp/RNOHPackagesFactory.h',
46
+ },
47
+ {
48
+ name: '--ets-rnoh-packages-factory-path-relative-to-harmony <path>',
49
+ description: 'Path relative to the root of your OpenHarmony project, for the generated file used to link packages on ETS side.',
50
+ default: './entry/src/main/ets/RNOHPackagesFactory.ets',
51
+ },
52
+ {
53
+ name: '--oh-package-path-relative-to-harmony <path>',
54
+ description: 'Path to the oh-package.json5 relative to the root of your OpenHarmony project.',
55
+ default: './oh-package.json5',
56
+ },
57
+ {
58
+ name: '--exclude-npm-packages [string]',
59
+ description: "Lists npm package names to be excluded from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --included-npm-packages.",
60
+ },
61
+ {
62
+ name: '--include-npm-packages [string]',
63
+ description: "Lists npm package names to be included from the autolinking process, separated by semicolons. By default every library is included. Can't be used with --excluded-npm-packages.",
64
+ },
65
+ ],
66
+ func: (_argv, _config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
67
+ var _a, _b;
68
+ const logger = new io_1.Logger();
69
+ const fs = new io_1.RealFS();
70
+ const autolinking = new autolinking_1.Autolinking(fs, logger);
71
+ try {
72
+ const config = yield autolinking.prepareInput({
73
+ harmonyProjectPath: new core_1.AbsolutePath(rawArgs.harmonyProjectPath),
74
+ nodeModulesPath: new core_1.AbsolutePath(rawArgs.nodeModulesPath),
75
+ cmakeAutolinkPathRelativeToHarmony: rawArgs.cmakeAutolinkPathRelativeToHarmony,
76
+ cppRNOHPackagesFactoryPathRelativeToHarmony: rawArgs.cppRnohPackagesFactoryPathRelativeToHarmony,
77
+ etsRNOHPackagesFactoryPathRelativeToHarmony: rawArgs.etsRnohPackagesFactoryPathRelativeToHarmony,
78
+ ohPackagePathRelativeToHarmony: rawArgs.ohPackagePathRelativeToHarmony,
79
+ excludedNpmPackageNames: new Set(rawArgs.excludeNpmPackages
80
+ ? ((_a = rawArgs.excludeNpmPackages) !== null && _a !== void 0 ? _a : '').split(';')
81
+ : undefined),
82
+ includedNpmPackageNames: new Set(rawArgs.includeNpmPackages
83
+ ? ((_b = rawArgs.includeNpmPackages) !== null && _b !== void 0 ? _b : '').split(';')
84
+ : undefined),
85
+ });
86
+ const result = autolinking.evaluate(config);
87
+ autolinking.saveAndLogOutput(result);
88
+ }
89
+ catch (err) {
90
+ if (err instanceof core_1.DescriptiveError && !err.isUnexpected()) {
91
+ logger.descriptiveError(err);
92
+ return;
93
+ }
94
+ throw err;
95
+ }
96
+ }),
97
+ };
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -53,7 +59,8 @@ exports.commandUnpackHarmony = {
53
59
  function unpack(projectRootPath, outputDirPath) {
54
60
  return __awaiter(this, void 0, void 0, function* () {
55
61
  const logger = new io_1.Logger();
56
- const projectDependenciesManager = new core_1.ProjectDependenciesManager(projectRootPath);
62
+ const fs = new io_1.RealFS();
63
+ const projectDependenciesManager = new core_1.ProjectDependenciesManager(fs, projectRootPath);
57
64
  logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
58
65
  prefix: true,
59
66
  });
@@ -74,7 +81,7 @@ function unpack(projectRootPath, outputDirPath) {
74
81
  .getValue();
75
82
  if (packageJSON.version &&
76
83
  shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
77
- if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue())) {
84
+ if (!fs.existsSync(pkgHarmonyDirPath)) {
78
85
  /**
79
86
  * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
80
87
  */
@@ -99,7 +106,7 @@ function unpack(projectRootPath, outputDirPath) {
99
106
  }
100
107
  }
101
108
  else {
102
- if (fs_1.default.existsSync(harmonyArchivePath.getValue())) {
109
+ if (fs.existsSync(harmonyArchivePath)) {
103
110
  skippedArchivesCount++;
104
111
  logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
105
112
  }
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -16,6 +22,9 @@ class AbsolutePath {
16
22
  getValue() {
17
23
  return this.value;
18
24
  }
25
+ toString() {
26
+ return this.value;
27
+ }
19
28
  copyWithNewSegment(...relativePath) {
20
29
  return new AbsolutePath(node_path_1.default.join(this.getValue(), ...relativePath));
21
30
  }
@@ -44,4 +53,7 @@ class RelativePath {
44
53
  getValue() {
45
54
  return this.value;
46
55
  }
56
+ toString() {
57
+ return this.value;
58
+ }
47
59
  }
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.DescriptiveError = void 0;
4
10
  class DescriptiveError extends Error {
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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.FS = exports.Dirent = void 0;
13
+ const node_path_1 = __importDefault(require("node:path"));
14
+ class Dirent {
15
+ }
16
+ exports.Dirent = Dirent;
17
+ class FS {
18
+ findFilePathsWithExtensions(dirPath, fileExtensions) {
19
+ let results = [];
20
+ const dirents = this.readDirentsSync(dirPath);
21
+ for (const dirent of dirents) {
22
+ const path = dirPath.copyWithNewSegment(dirent.name.toString());
23
+ if (dirent.isDirectory()) {
24
+ results = results.concat(this.findFilePathsWithExtensions(path, fileExtensions));
25
+ }
26
+ else if (fileExtensions.includes(node_path_1.default.extname(dirent.name.toString()).substring(1))) {
27
+ results.push(path);
28
+ }
29
+ }
30
+ return results;
31
+ }
32
+ }
33
+ exports.FS = FS;
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.PackageJSON = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
4
  const CodegenConfig_1 = require("./CodegenConfig");
9
5
  const DescriptiveError_1 = require("./DescriptiveError");
10
6
  class PackageJSON {
11
- static fromProjectRootPath(packageRootPath, projectRootPath) {
7
+ static fromProjectRootPath(fs, packageRootPath, projectRootPath) {
12
8
  const packageJSONPath = packageRootPath.copyWithNewSegment('package.json');
13
- if (!fs_1.default.existsSync(packageJSONPath.getValue())) {
9
+ if (!fs.existsSync(packageJSONPath)) {
14
10
  throw new DescriptiveError_1.DescriptiveError({
15
11
  whatHappened: "Couldn't find 'package.json'",
16
12
  whatCanUserDo: {
@@ -22,7 +18,16 @@ class PackageJSON {
22
18
  extraData: packageJSONPath.getValue(),
23
19
  });
24
20
  }
25
- return new PackageJSON(JSON.parse(fs_1.default.readFileSync(packageJSONPath.getValue()).toString()), packageRootPath, projectRootPath);
21
+ try {
22
+ return new PackageJSON(JSON.parse(fs.readTextSync(packageJSONPath).toString()), packageRootPath, projectRootPath);
23
+ }
24
+ catch (err) {
25
+ throw new DescriptiveError_1.DescriptiveError({
26
+ whatHappened: "Couldn't parse package.json",
27
+ whatCanUserDo: {},
28
+ extraData: { packageJSONPath, err },
29
+ });
30
+ }
26
31
  }
27
32
  constructor(rawPackageJSON, packageRootPath, projectRootPath) {
28
33
  this.rawPackageJSON = rawPackageJSON;
@@ -35,6 +40,9 @@ class PackageJSON {
35
40
  get version() {
36
41
  return this.rawPackageJSON.version;
37
42
  }
43
+ get harmony() {
44
+ return this.rawPackageJSON.harmony;
45
+ }
38
46
  getCodegenConfigs() {
39
47
  var _a;
40
48
  /**
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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) {
@@ -8,15 +14,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
14
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
15
  });
10
16
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
17
  Object.defineProperty(exports, "__esModule", { value: true });
15
18
  exports.ProjectDependenciesManager = exports.ProjectDependency = void 0;
16
- const node_fs_1 = __importDefault(require("node:fs"));
17
19
  const PackageJSON_1 = require("./PackageJSON");
18
20
  class ProjectDependency {
19
- constructor(packageRootPath, projectRootPath) {
21
+ constructor(fs, packageRootPath, projectRootPath) {
22
+ this.fs = fs;
20
23
  this.packageRootPath = packageRootPath;
21
24
  this.projectRootPath = projectRootPath;
22
25
  }
@@ -26,13 +29,25 @@ class ProjectDependency {
26
29
  getCodegenConfigs() {
27
30
  return this.readPackageJSON().getCodegenConfigs();
28
31
  }
32
+ getHarFilePath() {
33
+ const packageHarmonyPath = this.packageRootPath.copyWithNewSegment('harmony');
34
+ if (!this.fs.existsSync(packageHarmonyPath)) {
35
+ return null;
36
+ }
37
+ const harFilePaths = this.fs.findFilePathsWithExtensions(packageHarmonyPath, ['har']);
38
+ if (harFilePaths.length !== 1) {
39
+ return null;
40
+ }
41
+ return harFilePaths[0];
42
+ }
29
43
  readPackageJSON() {
30
- return PackageJSON_1.PackageJSON.fromProjectRootPath(this.packageRootPath, this.projectRootPath);
44
+ return PackageJSON_1.PackageJSON.fromProjectRootPath(this.fs, this.packageRootPath, this.projectRootPath);
31
45
  }
32
46
  }
33
47
  exports.ProjectDependency = ProjectDependency;
34
48
  class ProjectDependenciesManager {
35
- constructor(projectRootPath) {
49
+ constructor(fs, projectRootPath) {
50
+ this.fs = fs;
36
51
  this.projectRootPath = projectRootPath;
37
52
  }
38
53
  forEachAsync(cb) {
@@ -42,25 +57,23 @@ class ProjectDependenciesManager {
42
57
  }
43
58
  forEachDependencyInDirectory(cb, directoryPath) {
44
59
  return __awaiter(this, void 0, void 0, function* () {
45
- if (!node_fs_1.default.existsSync(directoryPath.getValue())) {
60
+ if (!this.fs.existsSync(directoryPath)) {
46
61
  return;
47
62
  }
48
- for (let dirOrFileName of node_fs_1.default.readdirSync(directoryPath.getValue())) {
49
- const potentialDependencyRootPath = directoryPath.copyWithNewSegment(dirOrFileName);
50
- if (node_fs_1.default.lstatSync(potentialDependencyRootPath.getValue()).isDirectory()) {
51
- if (dirOrFileName.startsWith('.')) {
63
+ for (let dirent of this.fs.readDirentsSync(directoryPath)) {
64
+ if (dirent.isDirectory()) {
65
+ if (dirent.name.startsWith('.')) {
52
66
  continue;
53
67
  }
54
- else if (dirOrFileName.startsWith('@')) {
55
- yield this.forEachDependencyInDirectory(cb, directoryPath.copyWithNewSegment(dirOrFileName));
68
+ else if (dirent.name.startsWith('@')) {
69
+ yield this.forEachDependencyInDirectory(cb, directoryPath.copyWithNewSegment(dirent.name));
56
70
  }
57
71
  else {
58
- if (!node_fs_1.default.existsSync(potentialDependencyRootPath
59
- .copyWithNewSegment('package.json')
60
- .getValue())) {
72
+ const potentialDependencyRootPath = directoryPath.copyWithNewSegment(dirent.name);
73
+ if (!this.fs.existsSync(potentialDependencyRootPath.copyWithNewSegment('package.json'))) {
61
74
  continue;
62
75
  }
63
- yield cb(new ProjectDependency(potentialDependencyRootPath, this.projectRootPath));
76
+ yield cb(new ProjectDependency(this.fs, potentialDependencyRootPath, this.projectRootPath));
64
77
  }
65
78
  }
66
79
  }
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.ValidationError = void 0;
4
10
  class ValidationError extends Error {
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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
  Object.defineProperty(exports, "__esModule", { value: true });
package/dist/core/fs.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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 __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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);
@@ -23,3 +29,4 @@ __exportStar(require("./ProjectDependenciesManager"), exports);
23
29
  __exportStar(require("./CodegenConfig"), exports);
24
30
  __exportStar(require("./fs"), exports);
25
31
  __exportStar(require("./OHPackageJSON5"), exports);
32
+ __exportStar(require("./FileSystem"), exports);
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Copyright (c) 2024 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
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.config = void 0;
4
10
  const commands_1 = require("./commands");
@@ -11,5 +17,6 @@ exports.config = {
11
17
  commands_1.commandCodegenHarmony,
12
18
  commands_1.commandVerifyPackageHarmony,
13
19
  commands_1.commandCodegenLibHarmony,
20
+ commands_1.commandLinkHarmony,
14
21
  ],
15
22
  };