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