@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.
- package/README.md +11 -11
- package/dist/assetResolver.js +74 -43
- package/dist/autolinking/Autolinking.js +183 -179
- package/dist/codegen/core/CodegenError.js +23 -3
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +28 -24
- package/dist/codegen/core/UberSchema.js +96 -57
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +41 -28
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +34 -27
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +33 -25
- package/dist/codegen/generators/CppComponentCodeGenerator.js +28 -23
- package/dist/codegen/generators/LibGlueCodeGenerator.js +29 -26
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +30 -25
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -18
- package/dist/codegen/generators/UberGeneratorV2.js +36 -28
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +24 -50
- package/dist/codegen/templates/BasePackageHTemplate.js +21 -120
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +8 -53
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +27 -75
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +29 -162
- package/dist/codegen/templates/IndexTSTemplate.js +17 -37
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +24 -119
- package/dist/codegen/templates/TurboModuleCppTemplate.js +15 -38
- package/dist/codegen/templates/TurboModuleHTemplate.js +11 -32
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +19 -52
- package/dist/commands/bundle-harmony.js +138 -53
- package/dist/commands/codegen-harmony.js +175 -104
- package/dist/commands/codegen-lib-harmony.js +116 -76
- package/dist/commands/create-metro-host-constants.js +47 -18
- package/dist/commands/init.js +961 -537
- package/dist/commands/link-harmony.js +71 -33
- package/dist/commands/pack-harmony.js +108 -47
- package/dist/commands/run-harmony.js +518 -374
- package/dist/commands/unpack-harmony.js +198 -105
- package/dist/commands/verify-package-harmony.js +108 -54
- package/dist/core/AbsolutePath.js +47 -31
- package/dist/core/CodegenConfig.js +22 -24
- package/dist/core/DescriptiveError.js +37 -18
- package/dist/core/FileSystem.js +18 -14
- package/dist/core/OHPackageJSON5.js +23 -17
- package/dist/core/PackageJSON.js +42 -26
- package/dist/core/ProjectDependenciesManager.js +96 -46
- package/dist/core/ValidationError.js +22 -2
- package/dist/core/fs.js +6 -9
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +98 -46
- package/dist/io/Logger.js +46 -40
- package/dist/io/RealFS.js +88 -35
- package/dist/io/TarGz.js +8 -11
- package/dist/io/__fixtures__.js +141 -79
- package/dist/io/fsUtils.js +12 -13
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +47 -19
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +41 -13
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +38 -8
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +54 -22
- package/dist/package-verifier/verify-package.js +132 -55
- package/dist/simulator/LaunchSimulator.js +301 -217
- package/jest.config.js +12 -12
- package/package.json +78 -70
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -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
|
@@ -1,238 +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 { Command } from './types';
|
|
9
|
-
import { Logger, RealFS } from '../io';
|
|
10
|
-
|
|
11
|
-
import pathUtils from 'path';
|
|
12
|
-
import fs from 'fs';
|
|
13
|
-
import zlib from 'zlib';
|
|
14
|
-
import tar from 'tar';
|
|
15
|
-
import JSON5 from 'json5';
|
|
16
|
-
import {
|
|
17
|
-
ValidationError,
|
|
18
|
-
AbsolutePath,
|
|
19
|
-
ProjectDependenciesManager,
|
|
20
|
-
} from '../core';
|
|
21
|
-
|
|
22
|
-
export const commandUnpackHarmony: Command = {
|
|
23
|
-
name: 'unpack-harmony',
|
|
24
|
-
description: 'Unpacks native code.',
|
|
25
|
-
options: [
|
|
26
|
-
{
|
|
27
|
-
name: '--project-root-path <path>',
|
|
28
|
-
description: 'Relative path to package root',
|
|
29
|
-
default: '.',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: '--output-dir <string>',
|
|
33
|
-
description: 'Output directory to which OH modules should be unpacked to',
|
|
34
|
-
default: './harmony/rnoh_modules',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
func: async (argv, config, args: any) => {
|
|
38
|
-
try {
|
|
39
|
-
await unpack(
|
|
40
|
-
new AbsolutePath(args.projectRootPath),
|
|
41
|
-
new AbsolutePath(args.outputDir)
|
|
42
|
-
);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
if (err instanceof ValidationError) {
|
|
45
|
-
console.error('[ERROR]', err.message);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
} else {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
async function unpack(
|
|
55
|
-
projectRootPath: AbsolutePath,
|
|
56
|
-
outputDirPath: AbsolutePath
|
|
57
|
-
) {
|
|
58
|
-
const logger = new Logger();
|
|
59
|
-
const fs = new RealFS();
|
|
60
|
-
const projectDependenciesManager = new ProjectDependenciesManager(
|
|
61
|
-
fs,
|
|
62
|
-
projectRootPath
|
|
63
|
-
);
|
|
64
|
-
logger.info((styles) => styles.bold(`Unpacking RNOH modules`));
|
|
65
|
-
let unpackedArchivesCount = 0;
|
|
66
|
-
let skippedArchivesCount = 0;
|
|
67
|
-
await projectDependenciesManager.forEachAsync(async (dependency) => {
|
|
68
|
-
const packageJSON = dependency.readPackageJSON();
|
|
69
|
-
const harmonyArchivePath = dependency
|
|
70
|
-
.getRootPath()
|
|
71
|
-
.copyWithNewSegment('harmony.tar.gz');
|
|
72
|
-
const pkgHarmonyDirPath = dependency
|
|
73
|
-
.getRootPath()
|
|
74
|
-
.copyWithNewSegment('harmony');
|
|
75
|
-
const harmonyTarGzPathStr = dependency
|
|
76
|
-
.getRootPath()
|
|
77
|
-
.copyWithNewSegment('harmony.tar.gz')
|
|
78
|
-
.relativeTo(projectRootPath)
|
|
79
|
-
.getValue();
|
|
80
|
-
if (
|
|
81
|
-
packageJSON.version &&
|
|
82
|
-
shouldUnpack(
|
|
83
|
-
harmonyArchivePath,
|
|
84
|
-
pkgHarmonyDirPath,
|
|
85
|
-
outputDirPath,
|
|
86
|
-
packageJSON.version
|
|
87
|
-
)
|
|
88
|
-
) {
|
|
89
|
-
if (!fs.existsSync(pkgHarmonyDirPath)) {
|
|
90
|
-
/**
|
|
91
|
-
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
92
|
-
*/
|
|
93
|
-
logger.info(
|
|
94
|
-
(styles) =>
|
|
95
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`
|
|
96
|
-
);
|
|
97
|
-
await unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
98
|
-
unpackedArchivesCount++;
|
|
99
|
-
} else {
|
|
100
|
-
skippedArchivesCount++;
|
|
101
|
-
logger.info(
|
|
102
|
-
(styles) =>
|
|
103
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
104
|
-
harmonyTarGzPathStr
|
|
105
|
-
)}`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
109
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
110
|
-
const moduleArchivePathStr = dependency
|
|
111
|
-
.getRootPath()
|
|
112
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
113
|
-
.relativeTo(projectRootPath)
|
|
114
|
-
.getValue();
|
|
115
|
-
logger.info(
|
|
116
|
-
(styles) =>
|
|
117
|
-
`[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`
|
|
118
|
-
);
|
|
119
|
-
unpackedArchivesCount++;
|
|
120
|
-
await unpackTarGz(
|
|
121
|
-
ohModuleInfo.archivePath,
|
|
122
|
-
ohModuleInfo.computedModulePath
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
if (fs.existsSync(harmonyArchivePath)) {
|
|
127
|
-
skippedArchivesCount++;
|
|
128
|
-
logger.info(
|
|
129
|
-
(styles) =>
|
|
130
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
131
|
-
harmonyTarGzPathStr
|
|
132
|
-
)}`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
136
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
137
|
-
const moduleArchivePathStr = dependency
|
|
138
|
-
.getRootPath()
|
|
139
|
-
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
140
|
-
.relativeTo(projectRootPath)
|
|
141
|
-
.getValue();
|
|
142
|
-
skippedArchivesCount++;
|
|
143
|
-
logger.info(
|
|
144
|
-
(styles) =>
|
|
145
|
-
`[${styles.yellow('skipped')}] ${styles.gray(
|
|
146
|
-
moduleArchivePathStr
|
|
147
|
-
)}`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
logger.info(
|
|
153
|
-
(styles) =>
|
|
154
|
-
`\nUnpacked: ${styles.cyan(
|
|
155
|
-
unpackedArchivesCount
|
|
156
|
-
)}, Skipped: ${styles.yellow(skippedArchivesCount)}`
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function shouldUnpack(
|
|
161
|
-
harmonyArchivePath: AbsolutePath,
|
|
162
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
163
|
-
outputDirPath: AbsolutePath,
|
|
164
|
-
nodePackageVersion: string
|
|
165
|
-
) {
|
|
166
|
-
if (!fs.existsSync(harmonyArchivePath.getValue())) return false;
|
|
167
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return true;
|
|
168
|
-
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
169
|
-
for (const ohModuleInfo of ohModulesInfo) {
|
|
170
|
-
if (
|
|
171
|
-
!fs.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
172
|
-
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
173
|
-
nodePackageVersion
|
|
174
|
-
) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getOhPackageVersion(modulePath: AbsolutePath) {
|
|
182
|
-
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
183
|
-
if (!fs.existsSync(ohPackagePath.getValue())) return null;
|
|
184
|
-
const content = fs.readFileSync(ohPackagePath.getValue(), {
|
|
185
|
-
encoding: 'utf-8',
|
|
186
|
-
});
|
|
187
|
-
return JSON5.parse(content)['version'];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function getOhModulesInfo(
|
|
191
|
-
pkgHarmonyDirPath: AbsolutePath,
|
|
192
|
-
outputDirPath: AbsolutePath
|
|
193
|
-
) {
|
|
194
|
-
const results: {
|
|
195
|
-
archivePath: AbsolutePath;
|
|
196
|
-
archiveFileName: string;
|
|
197
|
-
computedModulePath: AbsolutePath;
|
|
198
|
-
computedModuleName: string;
|
|
199
|
-
}[] = [];
|
|
200
|
-
if (!fs.existsSync(pkgHarmonyDirPath.getValue())) return [];
|
|
201
|
-
const names = fs.readdirSync(pkgHarmonyDirPath.getValue());
|
|
202
|
-
for (const name of names) {
|
|
203
|
-
if (name.endsWith('.tar.gz')) {
|
|
204
|
-
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
205
|
-
const computedModuleName = pathUtils
|
|
206
|
-
.parse(archivePath.getValue())
|
|
207
|
-
.name.split('.')[0];
|
|
208
|
-
const computedModulePath =
|
|
209
|
-
outputDirPath.copyWithNewSegment(computedModuleName);
|
|
210
|
-
results.push({
|
|
211
|
-
archivePath,
|
|
212
|
-
archiveFileName: name,
|
|
213
|
-
computedModulePath,
|
|
214
|
-
computedModuleName,
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return results;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function unpackTarGz(archivePath: AbsolutePath, outputDirPath: AbsolutePath) {
|
|
222
|
-
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
223
|
-
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
224
|
-
}
|
|
225
|
-
const readStream = fs.createReadStream(archivePath.getValue());
|
|
226
|
-
const writeStream = tar.extract({
|
|
227
|
-
cwd: outputDirPath.getValue(),
|
|
228
|
-
});
|
|
229
|
-
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
230
|
-
return new Promise((resolve, reject) => {
|
|
231
|
-
writeStream.on('finish', () => {
|
|
232
|
-
resolve(undefined);
|
|
233
|
-
});
|
|
234
|
-
writeStream.on('error', (err) => {
|
|
235
|
-
reject(err);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
}
|
|
@@ -1,113 +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 { Command } from './types';
|
|
9
|
-
import { getLoader, Loader } from '@react-native-community/cli-tools';
|
|
10
|
-
import chalk from 'chalk';
|
|
11
|
-
import { DescriptiveError, AbsolutePath } from '../core';
|
|
12
|
-
import { Logger } from '../io';
|
|
13
|
-
import { CheckResult, verifyRNOHPackage } from '../package-verifier';
|
|
14
|
-
|
|
15
|
-
export const commandVerifyPackageHarmony: Command = {
|
|
16
|
-
name: 'verify-package-harmony',
|
|
17
|
-
description: 'Validates that a package is compliant with guidelines',
|
|
18
|
-
options: [
|
|
19
|
-
{
|
|
20
|
-
name: '--package-path <path>',
|
|
21
|
-
description: 'Path to the npm package',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: '--no-harmony-code [boolean]',
|
|
25
|
-
description: 'Disable har verification',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: '--skip-checks <string>',
|
|
29
|
-
description: 'Disable certain checks by their names separated by ";"',
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
func: async (argv, config, rawArgs: any) => {
|
|
33
|
-
const loader = getLoader();
|
|
34
|
-
try {
|
|
35
|
-
const args = validateArgs(rawArgs);
|
|
36
|
-
loader.info(`Verifying RNOH package: ${args.packagePath.getValue()}`);
|
|
37
|
-
const checkResults: CheckResult[] = [];
|
|
38
|
-
for await (const checkResult of verifyRNOHPackage({
|
|
39
|
-
npmPackagePath: args.packagePath,
|
|
40
|
-
hasHarmonyCode: args.hasHarmonyCode,
|
|
41
|
-
checkNamesToSkip: args.checkNamesToSkip,
|
|
42
|
-
})) {
|
|
43
|
-
if (checkResult.type === 'START_PROCESS') {
|
|
44
|
-
loader.start(chalk.gray(checkResult.name));
|
|
45
|
-
} else if (checkResult.type === 'FINISHED_CHECKING') {
|
|
46
|
-
checkResults.push(checkResult);
|
|
47
|
-
logCheckResult(loader, checkResult);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (
|
|
51
|
-
checkResults.every(
|
|
52
|
-
(checkResult) =>
|
|
53
|
-
checkResult.status === 'pass' || checkResult.status === 'skip'
|
|
54
|
-
)
|
|
55
|
-
) {
|
|
56
|
-
loader.info(chalk.bold('OK'));
|
|
57
|
-
} else {
|
|
58
|
-
loader.info(
|
|
59
|
-
chalk.red(
|
|
60
|
-
'Package verification failed. Please fix those checks before publishing your package.'
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
} catch (err) {
|
|
66
|
-
if (err instanceof DescriptiveError) {
|
|
67
|
-
new Logger().descriptiveError(err);
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
throw err;
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type Args = {
|
|
76
|
-
packagePath: AbsolutePath;
|
|
77
|
-
hasHarmonyCode: boolean;
|
|
78
|
-
checkNamesToSkip: string[];
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
function validateArgs(args: any): Args {
|
|
82
|
-
if (!args.packagePath) {
|
|
83
|
-
throw new DescriptiveError({
|
|
84
|
-
whatHappened: 'package-path is undefined',
|
|
85
|
-
whatCanUserDo: ['Please provide --package-path'],
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
packagePath: new AbsolutePath(args.packagePath),
|
|
90
|
-
hasHarmonyCode: args.harmonyCode,
|
|
91
|
-
checkNamesToSkip: ((args.skipChecks ?? '') as string).split(';'),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function logCheckResult(loader: Loader, checkResult: CheckResult) {
|
|
96
|
-
const prefix = (() => {
|
|
97
|
-
switch (checkResult.status) {
|
|
98
|
-
case 'pass':
|
|
99
|
-
return `${chalk.green('PASS')}`;
|
|
100
|
-
case 'fail':
|
|
101
|
-
return `${chalk.red('FAIL')}`;
|
|
102
|
-
case 'skip':
|
|
103
|
-
return `${chalk.yellow('SKIP')}`;
|
|
104
|
-
}
|
|
105
|
-
})();
|
|
106
|
-
loader.info(
|
|
107
|
-
checkResult.message
|
|
108
|
-
? `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}\n${
|
|
109
|
-
checkResult.message
|
|
110
|
-
}`
|
|
111
|
-
: `[${chalk.bold(prefix)}] ${chalk.bold(checkResult.name)}`
|
|
112
|
-
);
|
|
113
|
-
}
|
package/src/core/AbsolutePath.ts
DELETED
|
@@ -1,66 +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 { ValueObject } from './ValueObject';
|
|
10
|
-
|
|
11
|
-
export class AbsolutePath implements ValueObject {
|
|
12
|
-
static fromSegments(...segments: string[]) {
|
|
13
|
-
return new AbsolutePath(pathUtils.join(...segments));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
private value: string = '';
|
|
17
|
-
|
|
18
|
-
constructor(path: string) {
|
|
19
|
-
this.value = pathUtils.resolve(path);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getValue(): string {
|
|
23
|
-
return this.value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
toString(): string {
|
|
27
|
-
return this.value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
copyWithNewSegment(...relativePath: string[]): AbsolutePath {
|
|
31
|
-
return new AbsolutePath(pathUtils.join(this.getValue(), ...relativePath));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getExtension(): string | null {
|
|
35
|
-
const maybeExtWithDot = pathUtils.extname(this.value);
|
|
36
|
-
if (maybeExtWithDot) {
|
|
37
|
-
return maybeExtWithDot.substring(1);
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getDirectoryPath(): AbsolutePath {
|
|
43
|
-
const dirPath = pathUtils.extname(this.value)
|
|
44
|
-
? pathUtils.dirname(this.value)
|
|
45
|
-
: this.value;
|
|
46
|
-
return new AbsolutePath(dirPath);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
relativeTo(absolutePath: AbsolutePath): RelativePath {
|
|
50
|
-
return new RelativePath(
|
|
51
|
-
pathUtils.relative(absolutePath.getValue(), this.value)
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class RelativePath implements ValueObject {
|
|
57
|
-
constructor(private value: string) {}
|
|
58
|
-
|
|
59
|
-
getValue() {
|
|
60
|
-
return this.value;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
toString() {
|
|
64
|
-
return this.value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,67 +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 { AbsolutePath } from './AbsolutePath';
|
|
10
|
-
import { findFilePathsWithExtensions } from '../io';
|
|
11
|
-
import { DescriptiveError } from './DescriptiveError';
|
|
12
|
-
|
|
13
|
-
export type RawCodegenConfig = {
|
|
14
|
-
specPaths: string[];
|
|
15
|
-
version?: number;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export class CodegenConfig {
|
|
19
|
-
static fromRawCodegenConfig(
|
|
20
|
-
rawCodegenConfig: RawCodegenConfig,
|
|
21
|
-
packageRootPath: AbsolutePath,
|
|
22
|
-
projectRootPath: AbsolutePath,
|
|
23
|
-
packageName: string
|
|
24
|
-
) {
|
|
25
|
-
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
26
|
-
const specPaths = (rawCodegenConfig.specPaths ?? []).map((rawSpecPath) => {
|
|
27
|
-
if (rawSpecPath.startsWith('~')) {
|
|
28
|
-
return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
|
|
29
|
-
} else {
|
|
30
|
-
return packageRootPath.copyWithNewSegment(rawSpecPath);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const specFilePaths = specPaths.flatMap((specPath) => {
|
|
34
|
-
if (!fs.existsSync(specPath.getValue())) {
|
|
35
|
-
throw new DescriptiveError({
|
|
36
|
-
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
37
|
-
whatCanUserDo: [
|
|
38
|
-
`Please verify "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (fs.lstatSync(specPath.getValue()).isDirectory()) {
|
|
43
|
-
return findFilePathsWithExtensions(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
44
|
-
} else {
|
|
45
|
-
const ext = specPath.getExtension();
|
|
46
|
-
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
47
|
-
return [specPath];
|
|
48
|
-
}
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return new CodegenConfig(specFilePaths, rawCodegenConfig.version ?? 1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private constructor(
|
|
56
|
-
private specFilePaths: AbsolutePath[],
|
|
57
|
-
private version: number
|
|
58
|
-
) {}
|
|
59
|
-
|
|
60
|
-
getSpecFilePaths(): AbsolutePath[] {
|
|
61
|
-
return this.specFilePaths;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getVersion(): number {
|
|
65
|
-
return this.version;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,68 +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
|
-
export class DescriptiveError extends Error {
|
|
9
|
-
constructor(
|
|
10
|
-
private data:
|
|
11
|
-
| {
|
|
12
|
-
whatHappened: string;
|
|
13
|
-
whatCanUserDo?: string[];
|
|
14
|
-
extraData?: any;
|
|
15
|
-
}
|
|
16
|
-
| {
|
|
17
|
-
whatHappened: string;
|
|
18
|
-
unexpected: true;
|
|
19
|
-
extraData?: any;
|
|
20
|
-
}
|
|
21
|
-
) {
|
|
22
|
-
super(data.whatHappened);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
isUnexpected(): boolean {
|
|
26
|
-
return 'unexpected' in this.data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getMessage(): string {
|
|
30
|
-
return this.data.whatHappened;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getSuggestions() {
|
|
34
|
-
if ('whatCanUserDo' in this.data) {
|
|
35
|
-
return this.data.whatCanUserDo ?? [];
|
|
36
|
-
} else {
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getRawData() {
|
|
42
|
-
return this.data;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getDetails(): string {
|
|
46
|
-
if (!this.data.extraData) {
|
|
47
|
-
return '';
|
|
48
|
-
}
|
|
49
|
-
if (typeof this.data.extraData === 'string') {
|
|
50
|
-
return this.data.extraData.trim();
|
|
51
|
-
}
|
|
52
|
-
if (this.data.extraData instanceof Error) {
|
|
53
|
-
let lines = [
|
|
54
|
-
`${this.data.extraData.name}: ${this.data.extraData.message}`,
|
|
55
|
-
];
|
|
56
|
-
for (let stackEntry of (this.data.extraData.stack ?? '').split('\n')) {
|
|
57
|
-
lines.push('');
|
|
58
|
-
lines.push(stackEntry);
|
|
59
|
-
}
|
|
60
|
-
return lines.join('\n');
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
return JSON.stringify(this.data.extraData, null, 2);
|
|
64
|
-
} catch (err) {
|
|
65
|
-
return '';
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/core/FileSystem.ts
DELETED
|
@@ -1,57 +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 { AbsolutePath } from './AbsolutePath';
|
|
9
|
-
import pathUtils from 'node:path';
|
|
10
|
-
|
|
11
|
-
export abstract class Dirent {
|
|
12
|
-
abstract isDirectory(): boolean;
|
|
13
|
-
|
|
14
|
-
abstract get name(): string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export abstract class FS {
|
|
18
|
-
abstract writeTextSync(path: AbsolutePath, data: string): void;
|
|
19
|
-
|
|
20
|
-
abstract readTextSync(path: AbsolutePath): string;
|
|
21
|
-
|
|
22
|
-
abstract readText(path: AbsolutePath): Promise<string>;
|
|
23
|
-
|
|
24
|
-
abstract existsSync(path: AbsolutePath): boolean;
|
|
25
|
-
|
|
26
|
-
abstract readDirentsSync(
|
|
27
|
-
path: AbsolutePath,
|
|
28
|
-
options?:
|
|
29
|
-
| {
|
|
30
|
-
recursive?: boolean | undefined;
|
|
31
|
-
}
|
|
32
|
-
| undefined
|
|
33
|
-
): Dirent[];
|
|
34
|
-
|
|
35
|
-
findFilePathsWithExtensions(
|
|
36
|
-
dirPath: AbsolutePath,
|
|
37
|
-
fileExtensions: readonly string[]
|
|
38
|
-
): AbsolutePath[] {
|
|
39
|
-
let results: AbsolutePath[] = [];
|
|
40
|
-
const dirents = this.readDirentsSync(dirPath);
|
|
41
|
-
for (const dirent of dirents) {
|
|
42
|
-
const path = dirPath.copyWithNewSegment(dirent.name.toString());
|
|
43
|
-
if (dirent.isDirectory()) {
|
|
44
|
-
results = results.concat(
|
|
45
|
-
this.findFilePathsWithExtensions(path, fileExtensions)
|
|
46
|
-
);
|
|
47
|
-
} else if (
|
|
48
|
-
fileExtensions.includes(
|
|
49
|
-
pathUtils.extname(dirent.name.toString()).substring(1)
|
|
50
|
-
)
|
|
51
|
-
) {
|
|
52
|
-
results.push(path);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return results;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,30 +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 json5 from 'json5';
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import { AbsolutePath } from './AbsolutePath';
|
|
11
|
-
|
|
12
|
-
export class OHPackageJSON5 {
|
|
13
|
-
static fromPath(ohPackageJson5Path: AbsolutePath) {
|
|
14
|
-
return new OHPackageJSON5(
|
|
15
|
-
json5.parse(
|
|
16
|
-
fs.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private constructor(private rawData: Record<string, any>) {}
|
|
22
|
-
|
|
23
|
-
get name(): string {
|
|
24
|
-
return this.rawData['name'];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get version(): string {
|
|
28
|
-
return this.rawData['version'];
|
|
29
|
-
}
|
|
30
|
-
}
|