@react-native-oh/react-native-harmony-cli 0.0.26 → 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 +25 -0
  3. package/dist/autolinking/Autolinking.js +275 -0
  4. package/dist/autolinking/index.js +23 -0
  5. package/dist/codegen/core/CodeGenerator.js +8 -0
  6. package/dist/codegen/core/CodegenError.js +13 -0
  7. package/dist/codegen/core/EventUtils.js +25 -0
  8. package/dist/codegen/core/TypeAnnotationToTS.js +138 -0
  9. package/dist/codegen/core/UberSchema.js +109 -0
  10. package/dist/codegen/core/index.js +27 -0
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +67 -0
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +82 -0
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +80 -0
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +62 -0
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +56 -0
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +79 -0
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +40 -0
  18. package/dist/codegen/generators/UberGeneratorV1.js +56 -0
  19. package/dist/codegen/generators/UberGeneratorV2.js +77 -0
  20. package/dist/codegen/generators/index.js +30 -0
  21. package/dist/codegen/index.js +24 -0
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +111 -0
  23. package/dist/codegen/templates/BasePackageHTemplate.js +136 -0
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +68 -0
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +91 -0
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +198 -0
  27. package/dist/codegen/templates/IndexTSTemplate.js +58 -0
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +130 -0
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +59 -0
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +48 -0
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +81 -0
  32. package/dist/codegen/templates/index.js +31 -0
  33. package/dist/commands/bundle-harmony.js +185 -0
  34. package/dist/commands/codegen-harmony.js +207 -0
  35. package/dist/commands/codegen-lib-harmony.js +259 -0
  36. package/dist/commands/create-metro-host-constants.js +67 -0
  37. package/dist/commands/index.js +30 -0
  38. package/dist/commands/link-harmony.js +97 -0
  39. package/dist/commands/pack-harmony.js +106 -0
  40. package/dist/commands/unpack-harmony.js +191 -0
  41. package/dist/commands/verify-package-harmony.js +128 -0
  42. package/dist/core/AbsolutePath.js +59 -0
  43. package/dist/core/CodegenConfig.js +63 -0
  44. package/dist/core/DescriptiveError.js +55 -0
  45. package/dist/core/FileSystem.js +33 -0
  46. package/dist/core/OHPackageJSON5.js +29 -0
  47. package/dist/core/PackageJSON.js +66 -0
  48. package/dist/core/ProjectDependenciesManager.js +83 -0
  49. package/dist/core/ValidationError.js +12 -0
  50. package/dist/core/ValueObject.js +8 -0
  51. package/dist/core/fs.js +42 -0
  52. package/dist/core/index.js +32 -0
  53. package/dist/index.js +22 -0
  54. package/dist/io/CliExecutor.js +35 -0
  55. package/dist/io/Logger.js +80 -0
  56. package/dist/io/RealFS.js +68 -0
  57. package/dist/io/TarGz.js +34 -0
  58. package/dist/io/__fixtures__.js +127 -0
  59. package/dist/io/fsUtils.js +37 -0
  60. package/dist/io/index.js +26 -0
  61. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +44 -0
  62. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +38 -0
  63. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +32 -0
  64. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +57 -0
  65. package/dist/package-verifier/checks/index.js +26 -0
  66. package/dist/package-verifier/index.js +24 -0
  67. package/dist/package-verifier/types.js +8 -0
  68. package/dist/package-verifier/verify-package.js +107 -0
  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 +15 -1
  82. package/src/codegen/core/index.ts +7 -0
  83. package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +20 -9
  84. package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +18 -5
  85. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +119 -0
  86. package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +21 -43
  87. package/src/codegen/generators/LibGlueCodeGenerator.ts +98 -0
  88. package/src/codegen/generators/NativeModuleCodeGenerator.ts +14 -5
  89. package/src/codegen/generators/SharedComponentCodeGenerator.ts +57 -0
  90. package/src/codegen/generators/UberGeneratorV1.ts +19 -8
  91. package/src/codegen/generators/UberGeneratorV2.ts +39 -16
  92. package/src/codegen/generators/index.ts +12 -3
  93. package/src/codegen/index.ts +7 -0
  94. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +19 -7
  95. package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +52 -12
  96. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +9 -1
  97. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +15 -10
  98. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +20 -8
  99. package/src/codegen/templates/IndexTSTemplate.ts +18 -9
  100. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +8 -0
  101. package/src/codegen/templates/TurboModuleCppTemplate.ts +16 -9
  102. package/src/codegen/templates/TurboModuleHTemplate.ts +16 -9
  103. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +20 -9
  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 +43 -13
  107. package/src/commands/codegen-lib-harmony.ts +394 -0
  108. package/src/commands/create-metro-host-constants.ts +7 -0
  109. package/src/commands/index.ts +9 -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 +11 -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
@@ -0,0 +1,106 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.commandPackHarmony = void 0;
22
+ const glob_1 = require("glob");
23
+ const path_1 = __importDefault(require("path"));
24
+ const tar_1 = __importDefault(require("tar"));
25
+ const fs_1 = __importDefault(require("fs"));
26
+ const core_1 = require("../core");
27
+ const ignore_1 = __importDefault(require("ignore"));
28
+ const json5_1 = __importDefault(require("json5"));
29
+ exports.commandPackHarmony = {
30
+ name: 'pack-harmony',
31
+ description: 'Pack native code. Used for package development.',
32
+ options: [
33
+ {
34
+ name: '--oh-module-path <string>',
35
+ description: 'Path to the OH module',
36
+ },
37
+ {
38
+ name: '--harmony-dir-path <string>',
39
+ description: 'Path to the harmony dir',
40
+ },
41
+ {
42
+ name: '--package-json-path <string>',
43
+ description: 'Path to the package.json',
44
+ },
45
+ ],
46
+ func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
47
+ try {
48
+ yield pack(path_1.default.resolve(args.harmonyDirPath), path_1.default.resolve(args.ohModulePath), path_1.default.resolve(args.packageJsonPath));
49
+ }
50
+ catch (err) {
51
+ if (err instanceof core_1.ValidationError) {
52
+ console.error('[ERROR]', err.message);
53
+ process.exit(1);
54
+ }
55
+ else {
56
+ throw err;
57
+ }
58
+ }
59
+ }),
60
+ };
61
+ function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
64
+ if (!fs_1.default.existsSync(harmonyDirPath)) {
65
+ fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
66
+ }
67
+ yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
68
+ yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
69
+ });
70
+ }
71
+ function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
72
+ const packageJSONFileContent = JSON.parse(fs_1.default.readFileSync(packageJSONFilePath, { encoding: 'utf-8' }));
73
+ if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
74
+ const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
75
+ ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
76
+ fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
77
+ }
78
+ }
79
+ function createTGZFromDir(dirPath, outputFilePath) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const ig = getIgnoreUtil(path_1.default.join(dirPath, '.tarignore'));
82
+ const filesToInclude = (0, glob_1.globSync)('**', {
83
+ cwd: dirPath,
84
+ nodir: true,
85
+ }).filter((path) => !ig.ignores(path));
86
+ yield createArchive(outputFilePath, dirPath, filesToInclude);
87
+ });
88
+ }
89
+ function getIgnoreUtil(tarignorePath) {
90
+ if (!fs_1.default.existsSync(tarignorePath)) {
91
+ return (0, ignore_1.default)();
92
+ }
93
+ return (0, ignore_1.default)().add(fs_1.default.readFileSync(tarignorePath).toString());
94
+ }
95
+ function createArchive(outputFilePath, packageDirPath, filesToInclude) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ if (filesToInclude.length === 0) {
98
+ throw new core_1.ValidationError('Nothing to pack');
99
+ }
100
+ yield tar_1.default.c({
101
+ gzip: true,
102
+ file: outputFilePath,
103
+ cwd: packageDirPath,
104
+ }, filesToInclude);
105
+ });
106
+ }
@@ -0,0 +1,191 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.commandUnpackHarmony = void 0;
22
+ const io_1 = require("../io");
23
+ const path_1 = __importDefault(require("path"));
24
+ const fs_1 = __importDefault(require("fs"));
25
+ const zlib_1 = __importDefault(require("zlib"));
26
+ const tar_1 = __importDefault(require("tar"));
27
+ const json5_1 = __importDefault(require("json5"));
28
+ const core_1 = require("../core");
29
+ exports.commandUnpackHarmony = {
30
+ name: 'unpack-harmony',
31
+ description: 'Unpacks native code.',
32
+ options: [
33
+ {
34
+ name: '--project-root-path <path>',
35
+ description: 'Relative path to package root',
36
+ default: '.',
37
+ },
38
+ {
39
+ name: '--output-dir <string>',
40
+ description: 'Output directory to which OH modules should be unpacked to',
41
+ default: './harmony/rnoh_modules',
42
+ },
43
+ ],
44
+ func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
45
+ try {
46
+ yield unpack(new core_1.AbsolutePath(args.projectRootPath), new core_1.AbsolutePath(args.outputDir));
47
+ }
48
+ catch (err) {
49
+ if (err instanceof core_1.ValidationError) {
50
+ console.error('[ERROR]', err.message);
51
+ process.exit(1);
52
+ }
53
+ else {
54
+ throw err;
55
+ }
56
+ }
57
+ }),
58
+ };
59
+ function unpack(projectRootPath, outputDirPath) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const logger = new io_1.Logger();
62
+ const fs = new io_1.RealFS();
63
+ const projectDependenciesManager = new core_1.ProjectDependenciesManager(fs, projectRootPath);
64
+ logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
65
+ prefix: true,
66
+ });
67
+ let unpackedArchivesCount = 0;
68
+ let skippedArchivesCount = 0;
69
+ yield projectDependenciesManager.forEachAsync((dependency) => __awaiter(this, void 0, void 0, function* () {
70
+ const packageJSON = dependency.readPackageJSON();
71
+ const harmonyArchivePath = dependency
72
+ .getRootPath()
73
+ .copyWithNewSegment('harmony.tar.gz');
74
+ const pkgHarmonyDirPath = dependency
75
+ .getRootPath()
76
+ .copyWithNewSegment('harmony');
77
+ const harmonyTarGzPathStr = dependency
78
+ .getRootPath()
79
+ .copyWithNewSegment('harmony.tar.gz')
80
+ .relativeTo(projectRootPath)
81
+ .getValue();
82
+ if (packageJSON.version &&
83
+ shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
84
+ if (!fs.existsSync(pkgHarmonyDirPath)) {
85
+ /**
86
+ * After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
87
+ */
88
+ logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`);
89
+ yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
90
+ unpackedArchivesCount++;
91
+ }
92
+ else {
93
+ skippedArchivesCount++;
94
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
95
+ }
96
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
97
+ for (const ohModuleInfo of ohModulesInfo) {
98
+ const moduleArchivePathStr = dependency
99
+ .getRootPath()
100
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
101
+ .relativeTo(projectRootPath)
102
+ .getValue();
103
+ logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`);
104
+ unpackedArchivesCount++;
105
+ yield unpackTarGz(ohModuleInfo.archivePath, ohModuleInfo.computedModulePath);
106
+ }
107
+ }
108
+ else {
109
+ if (fs.existsSync(harmonyArchivePath)) {
110
+ skippedArchivesCount++;
111
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
112
+ }
113
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
114
+ for (const ohModuleInfo of ohModulesInfo) {
115
+ const moduleArchivePathStr = dependency
116
+ .getRootPath()
117
+ .copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
118
+ .relativeTo(projectRootPath)
119
+ .getValue();
120
+ skippedArchivesCount++;
121
+ logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(moduleArchivePathStr)}`);
122
+ }
123
+ }
124
+ }));
125
+ logger.info((styles) => `\nUnpacked: ${styles.cyan(unpackedArchivesCount)}, Skipped: ${styles.yellow(skippedArchivesCount)}`);
126
+ });
127
+ }
128
+ function shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
129
+ if (!fs_1.default.existsSync(harmonyArchivePath.getValue()))
130
+ return false;
131
+ if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
132
+ return true;
133
+ const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
134
+ for (const ohModuleInfo of ohModulesInfo) {
135
+ if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
136
+ getOhPackageVersion(ohModuleInfo.computedModulePath) !==
137
+ nodePackageVersion) {
138
+ return true;
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+ function getOhPackageVersion(modulePath) {
144
+ const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
145
+ if (!fs_1.default.existsSync(ohPackagePath.getValue()))
146
+ return null;
147
+ const content = fs_1.default.readFileSync(ohPackagePath.getValue(), {
148
+ encoding: 'utf-8',
149
+ });
150
+ return json5_1.default.parse(content)['version'];
151
+ }
152
+ function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
153
+ const results = [];
154
+ if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
155
+ return [];
156
+ const names = fs_1.default.readdirSync(pkgHarmonyDirPath.getValue());
157
+ for (const name of names) {
158
+ if (name.endsWith('.tar.gz')) {
159
+ const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
160
+ const computedModuleName = path_1.default
161
+ .parse(archivePath.getValue())
162
+ .name.split('.')[0];
163
+ const computedModulePath = outputDirPath.copyWithNewSegment(computedModuleName);
164
+ results.push({
165
+ archivePath,
166
+ archiveFileName: name,
167
+ computedModulePath,
168
+ computedModuleName,
169
+ });
170
+ }
171
+ }
172
+ return results;
173
+ }
174
+ function unpackTarGz(archivePath, outputDirPath) {
175
+ if (!fs_1.default.existsSync(outputDirPath.getValue())) {
176
+ fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
177
+ }
178
+ const readStream = fs_1.default.createReadStream(archivePath.getValue());
179
+ const writeStream = tar_1.default.extract({
180
+ cwd: outputDirPath.getValue(),
181
+ });
182
+ readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
183
+ return new Promise((resolve, reject) => {
184
+ writeStream.on('finish', () => {
185
+ resolve(undefined);
186
+ });
187
+ writeStream.on('error', (err) => {
188
+ reject(err);
189
+ });
190
+ });
191
+ }
@@ -0,0 +1,128 @@
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
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
18
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
19
+ var m = o[Symbol.asyncIterator], i;
20
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
21
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
22
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.commandVerifyPackageHarmony = void 0;
29
+ const cli_tools_1 = require("@react-native-community/cli-tools");
30
+ const chalk_1 = __importDefault(require("chalk"));
31
+ const core_1 = require("../core");
32
+ const io_1 = require("../io");
33
+ const package_verifier_1 = require("../package-verifier");
34
+ exports.commandVerifyPackageHarmony = {
35
+ name: 'verify-package-harmony',
36
+ description: 'Validates that a package is compliant with guidelines',
37
+ options: [
38
+ {
39
+ name: '--package-path <path>',
40
+ description: 'Path to the npm package',
41
+ },
42
+ {
43
+ name: '--no-harmony-code [boolean]',
44
+ description: 'Disable har verification',
45
+ },
46
+ {
47
+ name: '--skip-checks <string>',
48
+ description: 'Disable certain checks by their names separated by ";"',
49
+ },
50
+ ],
51
+ func: (argv, config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
52
+ var _a, e_1, _b, _c;
53
+ const loader = (0, cli_tools_1.getLoader)();
54
+ try {
55
+ const args = validateArgs(rawArgs);
56
+ loader.info(`Verifying RNOH package: ${args.packagePath.getValue()}`);
57
+ const checkResults = [];
58
+ try {
59
+ for (var _d = true, _e = __asyncValues((0, package_verifier_1.verifyRNOHPackage)({
60
+ npmPackagePath: args.packagePath,
61
+ hasHarmonyCode: args.hasHarmonyCode,
62
+ checkNamesToSkip: args.checkNamesToSkip,
63
+ })), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
64
+ _c = _f.value;
65
+ _d = false;
66
+ const checkResult = _c;
67
+ if (checkResult.type === 'START_PROCESS') {
68
+ loader.start(chalk_1.default.gray(checkResult.name));
69
+ }
70
+ else if (checkResult.type === 'FINISHED_CHECKING') {
71
+ checkResults.push(checkResult);
72
+ logCheckResult(loader, checkResult);
73
+ }
74
+ }
75
+ }
76
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
+ finally {
78
+ try {
79
+ if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
80
+ }
81
+ finally { if (e_1) throw e_1.error; }
82
+ }
83
+ if (checkResults.every((checkResult) => checkResult.status === 'pass' || checkResult.status === 'skip')) {
84
+ loader.info(chalk_1.default.bold('OK'));
85
+ }
86
+ else {
87
+ loader.info(chalk_1.default.red('Package verification failed. Please fix those checks before publishing your package.'));
88
+ process.exit(1);
89
+ }
90
+ }
91
+ catch (err) {
92
+ if (err instanceof core_1.DescriptiveError) {
93
+ new io_1.Logger().descriptiveError(err);
94
+ process.exit(1);
95
+ }
96
+ throw err;
97
+ }
98
+ }),
99
+ };
100
+ function validateArgs(args) {
101
+ var _a;
102
+ if (!args.packagePath) {
103
+ throw new core_1.DescriptiveError({
104
+ whatHappened: 'package-path is undefined',
105
+ whatCanUserDo: { default: ['Please provide --package-path'] },
106
+ });
107
+ }
108
+ return {
109
+ packagePath: new core_1.AbsolutePath(args.packagePath),
110
+ hasHarmonyCode: args.harmonyCode,
111
+ checkNamesToSkip: ((_a = args.skipChecks) !== null && _a !== void 0 ? _a : '').split(';'),
112
+ };
113
+ }
114
+ function logCheckResult(loader, checkResult) {
115
+ const prefix = (() => {
116
+ switch (checkResult.status) {
117
+ case 'pass':
118
+ return `${chalk_1.default.green('PASS')}`;
119
+ case 'fail':
120
+ return `${chalk_1.default.red('FAIL')}`;
121
+ case 'skip':
122
+ return `${chalk_1.default.yellow('SKIP')}`;
123
+ }
124
+ })();
125
+ loader.info(checkResult.message
126
+ ? `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}\n${checkResult.message}`
127
+ : `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}`);
128
+ }
@@ -0,0 +1,59 @@
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.AbsolutePath = void 0;
13
+ const node_path_1 = __importDefault(require("node:path"));
14
+ class AbsolutePath {
15
+ static fromSegments(...segments) {
16
+ return new AbsolutePath(node_path_1.default.join(...segments));
17
+ }
18
+ constructor(path) {
19
+ this.value = '';
20
+ this.value = node_path_1.default.resolve(path);
21
+ }
22
+ getValue() {
23
+ return this.value;
24
+ }
25
+ toString() {
26
+ return this.value;
27
+ }
28
+ copyWithNewSegment(...relativePath) {
29
+ return new AbsolutePath(node_path_1.default.join(this.getValue(), ...relativePath));
30
+ }
31
+ getExtension() {
32
+ const maybeExtWithDot = node_path_1.default.extname(this.value);
33
+ if (maybeExtWithDot) {
34
+ return maybeExtWithDot.substring(1);
35
+ }
36
+ return null;
37
+ }
38
+ getDirectoryPath() {
39
+ const dirPath = node_path_1.default.extname(this.value)
40
+ ? node_path_1.default.dirname(this.value)
41
+ : this.value;
42
+ return new AbsolutePath(dirPath);
43
+ }
44
+ relativeTo(absolutePath) {
45
+ return new RelativePath(node_path_1.default.relative(absolutePath.getValue(), this.value));
46
+ }
47
+ }
48
+ exports.AbsolutePath = AbsolutePath;
49
+ class RelativePath {
50
+ constructor(value) {
51
+ this.value = value;
52
+ }
53
+ getValue() {
54
+ return this.value;
55
+ }
56
+ toString() {
57
+ return this.value;
58
+ }
59
+ }
@@ -0,0 +1,63 @@
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.CodegenConfig = void 0;
13
+ const node_fs_1 = __importDefault(require("node:fs"));
14
+ const io_1 = require("../io");
15
+ const DescriptiveError_1 = require("./DescriptiveError");
16
+ class CodegenConfig {
17
+ static fromRawCodegenConfig(rawCodegenConfig, packageRootPath, projectRootPath, packageName) {
18
+ var _a, _b;
19
+ const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
20
+ const specPaths = ((_a = rawCodegenConfig.specPaths) !== null && _a !== void 0 ? _a : []).map((rawSpecPath) => {
21
+ if (rawSpecPath.startsWith('~')) {
22
+ return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
23
+ }
24
+ else {
25
+ return packageRootPath.copyWithNewSegment(rawSpecPath);
26
+ }
27
+ });
28
+ const specFilePaths = specPaths.flatMap((specPath) => {
29
+ if (!node_fs_1.default.existsSync(specPath.getValue())) {
30
+ throw new DescriptiveError_1.DescriptiveError({
31
+ whatHappened: `No such file or directory: ${specPath.getValue()}`,
32
+ whatCanUserDo: {
33
+ default: [
34
+ `Please verify "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
35
+ ],
36
+ },
37
+ });
38
+ }
39
+ if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
40
+ return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
41
+ }
42
+ else {
43
+ const ext = specPath.getExtension();
44
+ if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
45
+ return [specPath];
46
+ }
47
+ return [];
48
+ }
49
+ });
50
+ return new CodegenConfig(specFilePaths, (_b = rawCodegenConfig.version) !== null && _b !== void 0 ? _b : 1);
51
+ }
52
+ constructor(specFilePaths, version) {
53
+ this.specFilePaths = specFilePaths;
54
+ this.version = version;
55
+ }
56
+ getSpecFilePaths() {
57
+ return this.specFilePaths;
58
+ }
59
+ getVersion() {
60
+ return this.version;
61
+ }
62
+ }
63
+ exports.CodegenConfig = CodegenConfig;
@@ -0,0 +1,55 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DescriptiveError = void 0;
10
+ class DescriptiveError extends Error {
11
+ constructor(data) {
12
+ super(data.whatHappened);
13
+ this.data = data;
14
+ }
15
+ isUnexpected() {
16
+ return 'unexpected' in this.data;
17
+ }
18
+ getMessage() {
19
+ return this.data.whatHappened;
20
+ }
21
+ getSuggestionsByRole() {
22
+ if ('whatCanUserDo' in this.data) {
23
+ return this.data.whatCanUserDo;
24
+ }
25
+ else {
26
+ return null;
27
+ }
28
+ }
29
+ getDetails() {
30
+ var _a;
31
+ if (!this.data.extraData) {
32
+ return '';
33
+ }
34
+ if (typeof this.data.extraData === 'string') {
35
+ return this.data.extraData.trim();
36
+ }
37
+ if (this.data.extraData instanceof Error) {
38
+ let lines = [
39
+ `${this.data.extraData.name}: ${this.data.extraData.message}`,
40
+ ];
41
+ for (let stackEntry of ((_a = this.data.extraData.stack) !== null && _a !== void 0 ? _a : '').split('\n')) {
42
+ lines.push('');
43
+ lines.push(stackEntry);
44
+ }
45
+ return lines.join('\n');
46
+ }
47
+ try {
48
+ return JSON.stringify(this.data.extraData, null, 2);
49
+ }
50
+ catch (err) {
51
+ return '';
52
+ }
53
+ }
54
+ }
55
+ exports.DescriptiveError = DescriptiveError;
@@ -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;
@@ -0,0 +1,29 @@
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.OHPackageJSON5 = void 0;
13
+ const json5_1 = __importDefault(require("json5"));
14
+ const node_fs_1 = __importDefault(require("node:fs"));
15
+ class OHPackageJSON5 {
16
+ static fromPath(ohPackageJson5Path) {
17
+ return new OHPackageJSON5(json5_1.default.parse(node_fs_1.default.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })));
18
+ }
19
+ constructor(rawData) {
20
+ this.rawData = rawData;
21
+ }
22
+ get name() {
23
+ return this.rawData['name'];
24
+ }
25
+ get version() {
26
+ return this.rawData['version'];
27
+ }
28
+ }
29
+ exports.OHPackageJSON5 = OHPackageJSON5;