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

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 (138) hide show
  1. package/README.md +11 -11
  2. package/dist/assetResolver.js +74 -43
  3. package/dist/autolinking/Autolinking.js +183 -179
  4. package/dist/codegen/core/CodegenError.js +23 -3
  5. package/dist/codegen/core/EventUtils.js +3 -3
  6. package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
  7. package/dist/codegen/core/UberSchema.js +96 -57
  8. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
  9. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
  10. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
  11. package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
  12. package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
  13. package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
  14. package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
  15. package/dist/codegen/generators/UberGeneratorV1.js +24 -18
  16. package/dist/codegen/generators/UberGeneratorV2.js +36 -28
  17. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
  18. package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
  19. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
  20. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
  21. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
  22. package/dist/codegen/templates/IndexTSTemplate.js +17 -37
  23. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
  24. package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
  25. package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
  26. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
  27. package/dist/commands/bundle-harmony.js +138 -53
  28. package/dist/commands/codegen-harmony.js +175 -104
  29. package/dist/commands/codegen-lib-harmony.js +116 -76
  30. package/dist/commands/create-metro-host-constants.js +47 -18
  31. package/dist/commands/init.js +961 -537
  32. package/dist/commands/link-harmony.js +71 -33
  33. package/dist/commands/pack-harmony.js +108 -47
  34. package/dist/commands/run-harmony.js +518 -374
  35. package/dist/commands/unpack-harmony.js +198 -105
  36. package/dist/commands/verify-package-harmony.js +108 -54
  37. package/dist/core/AbsolutePath.js +47 -31
  38. package/dist/core/CodegenConfig.js +22 -24
  39. package/dist/core/DescriptiveError.js +37 -18
  40. package/dist/core/FileSystem.js +18 -14
  41. package/dist/core/OHPackageJSON5.js +23 -17
  42. package/dist/core/PackageJSON.js +42 -26
  43. package/dist/core/ProjectDependenciesManager.js +96 -46
  44. package/dist/core/ValidationError.js +22 -2
  45. package/dist/core/fs.js +6 -9
  46. package/dist/index.js +1 -1
  47. package/dist/io/CliExecutor.js +98 -46
  48. package/dist/io/Logger.js +46 -40
  49. package/dist/io/RealFS.js +88 -35
  50. package/dist/io/TarGz.js +8 -11
  51. package/dist/io/__fixtures__.js +141 -79
  52. package/dist/io/fsUtils.js +12 -13
  53. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
  54. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
  55. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
  56. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
  57. package/dist/package-verifier/verify-package.js +132 -55
  58. package/dist/simulator/LaunchSimulator.js +301 -217
  59. package/jest.config.js +12 -12
  60. package/package.json +78 -70
  61. package/react-native.config.js +17 -17
  62. package/tsconfig.build.json +6 -6
  63. package/tsconfig.json +2 -2
  64. package/.prettierrc +0 -6
  65. package/src/assetResolver.ts +0 -134
  66. package/src/autolinking/Autolinking.test.ts +0 -483
  67. package/src/autolinking/Autolinking.ts +0 -382
  68. package/src/autolinking/index.ts +0 -8
  69. package/src/codegen/core/CodeGenerator.ts +0 -16
  70. package/src/codegen/core/CodegenError.ts +0 -10
  71. package/src/codegen/core/EventUtils.ts +0 -23
  72. package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
  73. package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
  74. package/src/codegen/core/UberSchema.ts +0 -152
  75. package/src/codegen/core/index.ts +0 -12
  76. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
  77. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
  78. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
  79. package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
  80. package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
  81. package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
  82. package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
  83. package/src/codegen/generators/UberGeneratorV1.ts +0 -75
  84. package/src/codegen/generators/UberGeneratorV2.ts +0 -114
  85. package/src/codegen/generators/index.ts +0 -15
  86. package/src/codegen/index.ts +0 -9
  87. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
  88. package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
  89. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
  90. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
  91. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
  92. package/src/codegen/templates/IndexTSTemplate.ts +0 -62
  93. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
  94. package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
  95. package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
  96. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
  97. package/src/codegen/templates/index.ts +0 -16
  98. package/src/commands/bundle-harmony.ts +0 -134
  99. package/src/commands/codegen-harmony.ts +0 -297
  100. package/src/commands/codegen-lib-harmony.ts +0 -389
  101. package/src/commands/create-metro-host-constants.ts +0 -55
  102. package/src/commands/index.ts +0 -16
  103. package/src/commands/init.ts +0 -755
  104. package/src/commands/link-harmony.ts +0 -102
  105. package/src/commands/pack-harmony.ts +0 -128
  106. package/src/commands/run-harmony.ts +0 -506
  107. package/src/commands/types.ts +0 -21
  108. package/src/commands/unpack-harmony.ts +0 -238
  109. package/src/commands/verify-package-harmony.ts +0 -113
  110. package/src/core/AbsolutePath.ts +0 -66
  111. package/src/core/CodegenConfig.ts +0 -67
  112. package/src/core/DescriptiveError.ts +0 -68
  113. package/src/core/FileSystem.ts +0 -57
  114. package/src/core/OHPackageJSON5.ts +0 -30
  115. package/src/core/PackageJSON.ts +0 -104
  116. package/src/core/ProjectDependenciesManager.ts +0 -103
  117. package/src/core/ValidationError.ts +0 -8
  118. package/src/core/ValueObject.ts +0 -9
  119. package/src/core/fs.ts +0 -38
  120. package/src/core/index.ts +0 -17
  121. package/src/index.ts +0 -33
  122. package/src/io/CliExecutor.ts +0 -69
  123. package/src/io/Logger.ts +0 -112
  124. package/src/io/RealFS.ts +0 -62
  125. package/src/io/TarGz.ts +0 -33
  126. package/src/io/__fixtures__.ts +0 -139
  127. package/src/io/fsUtils.ts +0 -44
  128. package/src/io/index.ts +0 -11
  129. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
  130. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
  131. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
  132. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
  133. package/src/package-verifier/checks/index.ts +0 -11
  134. package/src/package-verifier/index.ts +0 -9
  135. package/src/package-verifier/types.ts +0 -19
  136. package/src/package-verifier/verify-package.ts +0 -123
  137. package/src/simulator/LaunchSimulator.ts +0 -352
  138. package/src/simulator/index.ts +0 -8
@@ -1,139 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { AbsolutePath, DescriptiveError, Dirent, FS } from '../core';
9
- import { CliExecutor, CliOptions } from './CliExecutor';
10
- import { IFs, memfs, NestedDirectoryJSON } from 'memfs';
11
- import RawMemDirent from 'memfs/lib/Dirent';
12
- import { Logger } from './Logger';
13
- import chalk from 'chalk';
14
-
15
- export class FakeCliExecutor extends CliExecutor {
16
- private commands: string[] = [];
17
-
18
- constructor(private onRun: (command: string) => Promise<string>) {
19
- super();
20
- }
21
-
22
- run(command: string, options: CliOptions): Promise<string> {
23
- let commandWithArgs = command;
24
- if (options.args) {
25
- commandWithArgs += options.args.join(' ');
26
- }
27
- this.commands.push(commandWithArgs);
28
- return this.onRun(commandWithArgs);
29
- }
30
-
31
- getCommands() {
32
- return this.commands;
33
- }
34
- }
35
-
36
- class MemFSDirent extends Dirent {
37
- constructor(private rawDirent: RawMemDirent) {
38
- super();
39
- }
40
-
41
- isDirectory(): boolean {
42
- return this.rawDirent.isDirectory();
43
- }
44
-
45
- isSymbolicLink(): boolean {
46
- return false;
47
- }
48
-
49
- get name(): string {
50
- return this.rawDirent.name.toString();
51
- }
52
-
53
- get path(): AbsolutePath {
54
- return new AbsolutePath(this.rawDirent.path).copyWithNewSegment(
55
- this.rawDirent.name.toString()
56
- );
57
- }
58
- }
59
- export class MemFS extends FS {
60
- private fs: IFs;
61
-
62
- constructor(initialFileStructure: NestedDirectoryJSON) {
63
- super();
64
- this.fs = memfs(initialFileStructure, './').fs;
65
- }
66
-
67
- existsSync(path: AbsolutePath): boolean {
68
- return this.fs.existsSync(path.toString());
69
- }
70
-
71
- readTextSync(path: AbsolutePath): string {
72
- return this.fs.readFileSync(path.toString()).toString();
73
- }
74
-
75
- async readText(path: AbsolutePath): Promise<string> {
76
- return new Promise((resolve, reject) => {
77
- this.fs.readFile(path.toString(), {}, (err, data) => {
78
- if (err) {
79
- reject(err);
80
- return;
81
- }
82
- resolve(data?.toString() ?? '');
83
- });
84
- });
85
- }
86
-
87
- writeTextSync(path: AbsolutePath, data: string): void {
88
- return this.fs.writeFileSync(path.toString(), data);
89
- }
90
-
91
- readDirentsSync(
92
- path: AbsolutePath,
93
- options?: { recursive?: boolean | undefined } | undefined
94
- ): Dirent[] {
95
- return this.fs
96
- .readdirSync(path.toString(), {
97
- withFileTypes: true,
98
- recursive: options?.recursive,
99
- })
100
- .flatMap((dataOutOrDirent) => {
101
- if (!(dataOutOrDirent instanceof RawMemDirent)) {
102
- return [];
103
- }
104
- return [new MemFSDirent(dataOutOrDirent)];
105
- });
106
- }
107
- }
108
-
109
- export class MockedLogger extends Logger {
110
- private logs: { type: 'debug' | 'info' | 'warn' | 'error'; msg: string }[] =
111
- [];
112
-
113
- debug(prepareMsg: (styles: typeof import('chalk')) => string): void {
114
- chalk.level = 0;
115
- this.logs.push({ type: 'debug', msg: prepareMsg(chalk) });
116
- }
117
-
118
- info(
119
- prepareMsg: (styles: typeof import('chalk')) => string,
120
- options?: { prefix?: boolean }
121
- ): void {
122
- chalk.level = 0;
123
- this.logs.push({ type: 'info', msg: prepareMsg(chalk) });
124
- }
125
-
126
- warn(prepareMsg: (styles: typeof chalk) => string): void {
127
- chalk.level = 0;
128
- this.logs.push({ type: 'warn', msg: prepareMsg(chalk) });
129
- }
130
-
131
- descriptiveError(error: DescriptiveError): void {
132
- chalk.level = 0;
133
- this.logs.push({ type: 'error', msg: error.getMessage() });
134
- }
135
-
136
- getLogs() {
137
- return this.logs;
138
- }
139
- }
package/src/io/fsUtils.ts DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import pathUtils from 'node:path';
9
- import { AbsolutePath } from '../core';
10
- import { IFs } from 'memfs';
11
- import MemDirent from 'memfs/lib/Dirent';
12
- import nodeFS from 'node:fs';
13
- import { Dirent } from 'node:fs';
14
-
15
- export function findFilePathsWithExtensions(
16
- dirPath: AbsolutePath,
17
- fileExtensions: readonly string[],
18
- options: { fs?: IFs | typeof nodeFS } = {}
19
- ): AbsolutePath[] {
20
- const fs = (options?.fs ?? nodeFS) as typeof nodeFS;
21
- let results: AbsolutePath[] = [];
22
- const files = fs.readdirSync(dirPath.getValue(), { withFileTypes: true });
23
- for (const file of files) {
24
- if (
25
- !(file instanceof Dirent) &&
26
- !((file as MemDirent) instanceof MemDirent)
27
- ) {
28
- continue;
29
- }
30
- const path = dirPath.copyWithNewSegment(file.name.toString());
31
- if (fs.lstatSync(path.toString()).isDirectory()) {
32
- results = results.concat(
33
- findFilePathsWithExtensions(path, fileExtensions, options)
34
- );
35
- } else if (
36
- fileExtensions.includes(
37
- pathUtils.extname(file.name.toString()).substring(1)
38
- )
39
- ) {
40
- results.push(path);
41
- }
42
- }
43
- return results;
44
- }
package/src/io/index.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export * from './Logger';
9
- export * from './fsUtils';
10
- export * from './TarGz';
11
- export * from './RealFS';
@@ -1,35 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import fs from 'node:fs';
9
- import { AbsolutePath } from '../../core';
10
- import { Check } from '../types';
11
-
12
- export function createHarmonyDirContainsOnlyHarsCheck(
13
- npmPackagePath: AbsolutePath,
14
- hasNpmPackageNativeCode: boolean
15
- ): Check {
16
- return {
17
- checkIf: 'harmony_directory_contains_only_one_har_file',
18
- run: async () => {
19
- if (!hasNpmPackageNativeCode) {
20
- return 'skip';
21
- }
22
- const harmonyPath = npmPackagePath
23
- .copyWithNewSegment('harmony')
24
- .getValue();
25
- const fileOrDirNames = fs.readdirSync(harmonyPath);
26
- if (fileOrDirNames.length !== 1) {
27
- return { status: 'fail', message: JSON.stringify(fileOrDirNames) };
28
- }
29
- if (!fileOrDirNames[0].endsWith('.har')) {
30
- return 'fail';
31
- }
32
- return 'pass';
33
- },
34
- };
35
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import fs from 'node:fs';
9
- import { AbsolutePath } from '../../core';
10
- import { Check } from '../types';
11
-
12
- export function createHarmonyDirExistsCheck(
13
- packagePath: AbsolutePath,
14
- hasNativeCode: boolean
15
- ): Check {
16
- return {
17
- checkIf: 'package_has_harmony_dir',
18
- run: async () => {
19
- const harmonyDirExist = fs.existsSync(
20
- packagePath.copyWithNewSegment('harmony').getValue()
21
- );
22
- if (!hasNativeCode) {
23
- return 'skip';
24
- }
25
- if (!harmonyDirExist) {
26
- return 'fail';
27
- }
28
- return 'pass';
29
- },
30
- };
31
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { Check } from '../types';
9
-
10
- export function createNpmAndOhPackageVersionsAreEqualCheck(
11
- npmPackageVersion: string,
12
- ohPackageVersion: string
13
- ): Check {
14
- return {
15
- checkIf: 'npm_and_oh_package_versions_are_equal',
16
- run: async () => {
17
- return npmPackageVersion === ohPackageVersion
18
- ? 'pass'
19
- : {
20
- status: 'fail',
21
- message: `expected OH package version (${ohPackageVersion}) to match NPM version (${npmPackageVersion})`,
22
- };
23
- },
24
- };
25
- }
@@ -1,54 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import { Check } from '../types';
9
-
10
- export function createOhPackageNameFollowsNamingConventionCheck(
11
- npmPackageName: string,
12
- ohPackageName: string
13
- ): Check {
14
- const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
15
- return {
16
- checkIf: 'oh_package_name_is_derived_from_npm_package_name',
17
- run: async () => {
18
- if (npmPackageNameInfo.organizationName) {
19
- const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.organizationName}--${npmPackageNameInfo.unscopedName}`;
20
- return expectedOHPackageName === ohPackageName
21
- ? 'pass'
22
- : {
23
- status: 'fail',
24
- message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
25
- };
26
- } else {
27
- const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.unscopedName}`;
28
- return expectedOHPackageName === ohPackageName
29
- ? 'pass'
30
- : {
31
- status: 'fail',
32
- message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
33
- };
34
- }
35
- },
36
- };
37
- }
38
-
39
- type PackageNameInfo = {
40
- organizationName: string | null;
41
- unscopedName: string;
42
- };
43
-
44
- function getPackageNameInfo(packageName: string): PackageNameInfo {
45
- if (packageName.startsWith('@') && packageName.includes('/')) {
46
- const [part1, part2] = packageName.split('/');
47
- return {
48
- organizationName: part1.replace('@', ''),
49
- unscopedName: part2,
50
- };
51
- } else {
52
- return { organizationName: null, unscopedName: packageName };
53
- }
54
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export * from './HarmonyDirExistsCheck';
9
- export * from './HarmonyDirContainsOnlyHarsCheck';
10
- export * from './NpmAnAndOhPackageVersionsAreEqual';
11
- export * from './OhPackageNameFollowsNamingConventionCheck';
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export * from './types';
9
- export * from './verify-package';
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- export type CheckStatus = 'pass' | 'fail' | 'skip';
9
-
10
- export type Check = {
11
- checkIf: string;
12
- run: () => Promise<CheckStatus | { status: CheckStatus; message: string }>;
13
- };
14
-
15
- export type CheckResult = {
16
- name: string;
17
- status: CheckStatus;
18
- message: string;
19
- };
@@ -1,123 +0,0 @@
1
- /**
2
- * Copyright (c) 2024-2025 Huawei Technologies Co., Ltd.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE-MIT file in the root directory of this source tree.
6
- */
7
-
8
- import fs from 'node:fs';
9
- import tmp from 'tmp';
10
- import {
11
- AbsolutePath,
12
- DescriptiveError,
13
- OHPackageJSON5,
14
- PackageJSON,
15
- } from '../core';
16
- import {
17
- createHarmonyDirContainsOnlyHarsCheck,
18
- createHarmonyDirExistsCheck,
19
- createOhPackageNameFollowsNamingConventionCheck,
20
- createNpmAndOhPackageVersionsAreEqualCheck,
21
- } from './checks';
22
- import { Check, CheckStatus } from './types';
23
- import { RealFS, unpackTarGz } from '../io';
24
-
25
- type StartProcessMessage = {
26
- type: 'START_PROCESS';
27
- name: string;
28
- };
29
-
30
- type FinishedCheckingMessage = {
31
- type: 'FINISHED_CHECKING';
32
- name: string;
33
- status: CheckStatus;
34
- message: string;
35
- };
36
-
37
- type VerificationMessage = StartProcessMessage | FinishedCheckingMessage;
38
-
39
- export async function* verifyRNOHPackage({
40
- npmPackagePath,
41
- hasHarmonyCode,
42
- checkNamesToSkip,
43
- }: {
44
- npmPackagePath: AbsolutePath;
45
- hasHarmonyCode: boolean;
46
- checkNamesToSkip: string[];
47
- }): AsyncGenerator<VerificationMessage, void, unknown> {
48
- const npmPackageJson = PackageJSON.fromProjectRootPath(
49
- new RealFS(),
50
- npmPackagePath,
51
- npmPackagePath
52
- );
53
- const initialChecks: Check[] = [
54
- createHarmonyDirExistsCheck(npmPackagePath, hasHarmonyCode),
55
- createHarmonyDirContainsOnlyHarsCheck(npmPackagePath, hasHarmonyCode),
56
- ];
57
- yield* runChecks(initialChecks, checkNamesToSkip);
58
- if (hasHarmonyCode) {
59
- const harPath = findHarPath(npmPackagePath);
60
- if (!harPath) {
61
- throw new DescriptiveError({
62
- whatHappened: 'Attempted to verify har but no har was found',
63
- whatCanUserDo: [
64
- 'Run this command without --no-harmony-code flag.',
65
- 'Create har files by running DevEco Studio > Build > Make Module (MODULE_NAME). The har file can be later found in MODULE_NAME/build/default/outputs/default/MODULE_NAME.har. Copy that file to the PACKAGE_ROOT/harmony directory.',
66
- ],
67
- });
68
- }
69
- const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
70
- yield {
71
- type: 'START_PROCESS',
72
- name: `Unpacking the har file to the tmpdir`,
73
- };
74
- await unpackTarGz(harPath, tmpDirPath);
75
- const ohPackageJson5 = OHPackageJSON5.fromPath(
76
- tmpDirPath.copyWithNewSegment('package', 'oh-package.json5')
77
- );
78
- const harChecks: Check[] = [
79
- createOhPackageNameFollowsNamingConventionCheck(
80
- npmPackageJson.name,
81
- ohPackageJson5.name
82
- ),
83
- createNpmAndOhPackageVersionsAreEqualCheck(
84
- npmPackageJson.version,
85
- ohPackageJson5.version
86
- ),
87
- ];
88
- yield* runChecks(harChecks, checkNamesToSkip);
89
- }
90
- }
91
-
92
- async function* runChecks(
93
- checks: Check[],
94
- checkNamesToSkip: string[]
95
- ): AsyncGenerator<VerificationMessage, void, unknown> {
96
- for (const { checkIf, run } of checks) {
97
- if (checkNamesToSkip.includes(checkIf)) {
98
- yield {
99
- type: 'FINISHED_CHECKING',
100
- name: checkIf,
101
- status: 'skip' as CheckStatus,
102
- message: '',
103
- };
104
- continue;
105
- }
106
- const result = await run();
107
- const status = typeof result === 'string' ? result : result.status;
108
- const message = typeof result === 'string' ? '' : result.message;
109
- yield { type: 'FINISHED_CHECKING', name: checkIf, status, message };
110
- }
111
- }
112
-
113
- function findHarPath(packagePath: AbsolutePath): AbsolutePath | null {
114
- const packageHarmonyPath = packagePath.copyWithNewSegment('harmony');
115
- const fileOrDirNames = fs.readdirSync(packageHarmonyPath.getValue());
116
- const harFilenames = fileOrDirNames.filter((fileOrDirName) =>
117
- fileOrDirName.endsWith('.har')
118
- );
119
- if (harFilenames.length != 1) {
120
- return null;
121
- }
122
- return packageHarmonyPath.copyWithNewSegment(harFilenames[0]);
123
- }