@react-native-oh/react-native-harmony-cli 0.0.37 → 0.0.40-1
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.
- package/dist/autolinking/Autolinking.js +14 -11
- package/dist/codegen/generators/UberGeneratorV1.js +9 -2
- package/dist/codegen/generators/UberGeneratorV2.js +8 -1
- package/dist/commands/codegen-harmony.js +16 -5
- package/dist/commands/run-harmony.js +0 -2
- package/dist/core/ProjectDependenciesManager.js +5 -7
- package/dist/simulator/LaunchSimulator.js +9 -2
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/package.json +10 -2
- package/.prettierrc +0 -6
- package/src/assetResolver.ts +0 -134
- package/src/autolinking/Autolinking.test.ts +0 -483
- package/src/autolinking/Autolinking.ts +0 -382
- package/src/autolinking/index.ts +0 -8
- package/src/codegen/core/CodeGenerator.ts +0 -16
- package/src/codegen/core/CodegenError.ts +0 -10
- package/src/codegen/core/EventUtils.ts +0 -23
- package/src/codegen/core/TypeAnnotationToTS.test.ts +0 -82
- package/src/codegen/core/TypeAnnotationToTS.ts +0 -195
- package/src/codegen/core/UberSchema.ts +0 -152
- package/src/codegen/core/index.ts +0 -12
- package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +0 -124
- package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +0 -128
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +0 -122
- package/src/codegen/generators/CppComponentCodeGenerator.ts +0 -95
- package/src/codegen/generators/LibGlueCodeGenerator.ts +0 -98
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +0 -124
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +0 -57
- package/src/codegen/generators/UberGeneratorV1.ts +0 -75
- package/src/codegen/generators/UberGeneratorV2.ts +0 -114
- package/src/codegen/generators/index.ts +0 -15
- package/src/codegen/index.ts +0 -9
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +0 -128
- package/src/codegen/templates/BasePackageHTemplate.ts +0 -159
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +0 -63
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +0 -121
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +0 -222
- package/src/codegen/templates/IndexTSTemplate.ts +0 -62
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +0 -150
- package/src/codegen/templates/TurboModuleCppTemplate.ts +0 -61
- package/src/codegen/templates/TurboModuleHTemplate.ts +0 -42
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +0 -101
- package/src/codegen/templates/index.ts +0 -16
- package/src/commands/bundle-harmony.ts +0 -134
- package/src/commands/codegen-harmony.ts +0 -297
- package/src/commands/codegen-lib-harmony.ts +0 -389
- package/src/commands/create-metro-host-constants.ts +0 -55
- package/src/commands/index.ts +0 -16
- package/src/commands/init.ts +0 -755
- package/src/commands/link-harmony.ts +0 -102
- package/src/commands/pack-harmony.ts +0 -128
- package/src/commands/run-harmony.ts +0 -506
- package/src/commands/types.ts +0 -21
- package/src/commands/unpack-harmony.ts +0 -238
- package/src/commands/verify-package-harmony.ts +0 -113
- package/src/core/AbsolutePath.ts +0 -66
- package/src/core/CodegenConfig.ts +0 -67
- package/src/core/DescriptiveError.ts +0 -68
- package/src/core/FileSystem.ts +0 -57
- package/src/core/OHPackageJSON5.ts +0 -30
- package/src/core/PackageJSON.ts +0 -104
- package/src/core/ProjectDependenciesManager.ts +0 -103
- package/src/core/ValidationError.ts +0 -8
- package/src/core/ValueObject.ts +0 -9
- package/src/core/fs.ts +0 -38
- package/src/core/index.ts +0 -17
- package/src/index.ts +0 -33
- package/src/io/CliExecutor.ts +0 -69
- package/src/io/Logger.ts +0 -112
- package/src/io/RealFS.ts +0 -62
- package/src/io/TarGz.ts +0 -33
- package/src/io/__fixtures__.ts +0 -139
- package/src/io/fsUtils.ts +0 -44
- package/src/io/index.ts +0 -11
- package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +0 -35
- package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +0 -31
- package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +0 -25
- package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +0 -54
- package/src/package-verifier/checks/index.ts +0 -11
- package/src/package-verifier/index.ts +0 -9
- package/src/package-verifier/types.ts +0 -19
- package/src/package-verifier/verify-package.ts +0 -123
- package/src/simulator/LaunchSimulator.ts +0 -352
- package/src/simulator/index.ts +0 -8
package/src/io/__fixtures__.ts
DELETED
|
@@ -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,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
|
-
}
|