@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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.commandVerifyPackageHarmony = void 0;
|
|
23
|
+
const cli_tools_1 = require("@react-native-community/cli-tools");
|
|
24
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
25
|
+
const core_1 = require("../core");
|
|
26
|
+
const io_1 = require("../io");
|
|
27
|
+
const package_verifier_1 = require("../package-verifier");
|
|
28
|
+
exports.commandVerifyPackageHarmony = {
|
|
29
|
+
name: 'verify-package-harmony',
|
|
30
|
+
description: 'Validates that a package is compliant with guidelines',
|
|
31
|
+
options: [
|
|
32
|
+
{
|
|
33
|
+
name: '--package-path <path>',
|
|
34
|
+
description: 'Path to the npm package',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: '--no-harmony-code [boolean]',
|
|
38
|
+
description: 'Disable har verification',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: '--skip-checks <string>',
|
|
42
|
+
description: 'Disable certain checks by their names separated by ";"',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
func: (argv, config, rawArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
var _a, e_1, _b, _c;
|
|
47
|
+
const loader = (0, cli_tools_1.getLoader)();
|
|
48
|
+
try {
|
|
49
|
+
const args = validateArgs(rawArgs);
|
|
50
|
+
loader.info(`Verifying RNOH package: ${args.packagePath.getValue()}`);
|
|
51
|
+
const checkResults = [];
|
|
52
|
+
try {
|
|
53
|
+
for (var _d = true, _e = __asyncValues((0, package_verifier_1.verifyRNOHPackage)({
|
|
54
|
+
npmPackagePath: args.packagePath,
|
|
55
|
+
hasHarmonyCode: args.hasHarmonyCode,
|
|
56
|
+
checkNamesToSkip: args.checkNamesToSkip,
|
|
57
|
+
})), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
58
|
+
_c = _f.value;
|
|
59
|
+
_d = false;
|
|
60
|
+
try {
|
|
61
|
+
const checkResult = _c;
|
|
62
|
+
if (checkResult.type === 'START_PROCESS') {
|
|
63
|
+
loader.start(chalk_1.default.gray(checkResult.name));
|
|
64
|
+
}
|
|
65
|
+
else if (checkResult.type === 'FINISHED_CHECKING') {
|
|
66
|
+
checkResults.push(checkResult);
|
|
67
|
+
logCheckResult(loader, checkResult);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
_d = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
76
|
+
finally {
|
|
77
|
+
try {
|
|
78
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
79
|
+
}
|
|
80
|
+
finally { if (e_1) throw e_1.error; }
|
|
81
|
+
}
|
|
82
|
+
if (checkResults.every((checkResult) => checkResult.status === 'pass' || checkResult.status === 'skip')) {
|
|
83
|
+
loader.info(chalk_1.default.bold('OK'));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
loader.info(chalk_1.default.red('Package verification failed. Please fix those checks before publishing your package.'));
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
if (err instanceof core_1.DescriptiveError) {
|
|
92
|
+
new io_1.Logger().descriptiveError(err);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
function validateArgs(args) {
|
|
100
|
+
var _a;
|
|
101
|
+
if (!args.packagePath) {
|
|
102
|
+
throw new core_1.DescriptiveError({
|
|
103
|
+
whatHappened: 'package-path is undefined',
|
|
104
|
+
whatCanUserDo: { default: ['Please provide --package-path'] },
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
packagePath: new core_1.AbsolutePath(args.packagePath),
|
|
109
|
+
hasHarmonyCode: args.harmonyCode,
|
|
110
|
+
checkNamesToSkip: ((_a = args.skipChecks) !== null && _a !== void 0 ? _a : '').split(';'),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function logCheckResult(loader, checkResult) {
|
|
114
|
+
const prefix = (() => {
|
|
115
|
+
switch (checkResult.status) {
|
|
116
|
+
case 'pass':
|
|
117
|
+
return `${chalk_1.default.green('PASS')}`;
|
|
118
|
+
case 'fail':
|
|
119
|
+
return `${chalk_1.default.red('FAIL')}`;
|
|
120
|
+
case 'skip':
|
|
121
|
+
return `${chalk_1.default.yellow('SKIP')}`;
|
|
122
|
+
}
|
|
123
|
+
})();
|
|
124
|
+
loader.info(checkResult.message
|
|
125
|
+
? `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}\n${checkResult.message}`
|
|
126
|
+
: `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}`);
|
|
127
|
+
}
|
|
@@ -26,6 +26,12 @@ class AbsolutePath {
|
|
|
26
26
|
}
|
|
27
27
|
return null;
|
|
28
28
|
}
|
|
29
|
+
getDirectoryPath() {
|
|
30
|
+
const dirPath = node_path_1.default.extname(this.value)
|
|
31
|
+
? node_path_1.default.dirname(this.value)
|
|
32
|
+
: this.value;
|
|
33
|
+
return new AbsolutePath(dirPath);
|
|
34
|
+
}
|
|
29
35
|
relativeTo(absolutePath) {
|
|
30
36
|
return new RelativePath(node_path_1.default.relative(absolutePath.getValue(), this.value));
|
|
31
37
|
}
|
|
@@ -9,7 +9,7 @@ const io_1 = require("../io");
|
|
|
9
9
|
const DescriptiveError_1 = require("./DescriptiveError");
|
|
10
10
|
class CodegenConfig {
|
|
11
11
|
static fromRawCodegenConfig(rawCodegenConfig, packageRootPath, projectRootPath, packageName) {
|
|
12
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
13
13
|
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
14
14
|
const specPaths = ((_a = rawCodegenConfig.specPaths) !== null && _a !== void 0 ? _a : []).map((rawSpecPath) => {
|
|
15
15
|
if (rawSpecPath.startsWith('~')) {
|
|
@@ -25,7 +25,7 @@ class CodegenConfig {
|
|
|
25
25
|
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
26
26
|
whatCanUserDo: {
|
|
27
27
|
default: [
|
|
28
|
-
`Please verify
|
|
28
|
+
`Please verify "${packageName}/package.json::harmony::codegenConfig". If you are not the maintainer of this package, please report this problem to the package maintainer.`,
|
|
29
29
|
],
|
|
30
30
|
},
|
|
31
31
|
});
|
|
@@ -41,13 +41,17 @@ class CodegenConfig {
|
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
return new CodegenConfig(specFilePaths);
|
|
44
|
+
return new CodegenConfig(specFilePaths, (_b = rawCodegenConfig.version) !== null && _b !== void 0 ? _b : 1);
|
|
45
45
|
}
|
|
46
|
-
constructor(specFilePaths) {
|
|
46
|
+
constructor(specFilePaths, version) {
|
|
47
47
|
this.specFilePaths = specFilePaths;
|
|
48
|
+
this.version = version;
|
|
48
49
|
}
|
|
49
50
|
getSpecFilePaths() {
|
|
50
51
|
return this.specFilePaths;
|
|
51
52
|
}
|
|
53
|
+
getVersion() {
|
|
54
|
+
return this.version;
|
|
55
|
+
}
|
|
52
56
|
}
|
|
53
57
|
exports.CodegenConfig = CodegenConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OHPackageJSON5 = void 0;
|
|
7
|
+
const json5_1 = __importDefault(require("json5"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
class OHPackageJSON5 {
|
|
10
|
+
static fromPath(ohPackageJson5Path) {
|
|
11
|
+
return new OHPackageJSON5(json5_1.default.parse(node_fs_1.default.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })));
|
|
12
|
+
}
|
|
13
|
+
constructor(rawData) {
|
|
14
|
+
this.rawData = rawData;
|
|
15
|
+
}
|
|
16
|
+
get name() {
|
|
17
|
+
return this.rawData['name'];
|
|
18
|
+
}
|
|
19
|
+
get version() {
|
|
20
|
+
return this.rawData['version'];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.OHPackageJSON5 = OHPackageJSON5;
|
package/dist/core/PackageJSON.js
CHANGED
|
@@ -35,7 +35,7 @@ class PackageJSON {
|
|
|
35
35
|
get version() {
|
|
36
36
|
return this.rawPackageJSON.version;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
getCodegenConfigs() {
|
|
39
39
|
var _a;
|
|
40
40
|
/**
|
|
41
41
|
* Shared codegenConfig is not used on purpose. Android, iOS and other platforms shouldn't
|
|
@@ -45,9 +45,14 @@ class PackageJSON {
|
|
|
45
45
|
*/
|
|
46
46
|
const rawCodegenConfig = (_a = this.rawPackageJSON.harmony) === null || _a === void 0 ? void 0 : _a.codegenConfig;
|
|
47
47
|
if (!rawCodegenConfig) {
|
|
48
|
-
return
|
|
48
|
+
return [];
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
if (Array.isArray(rawCodegenConfig)) {
|
|
51
|
+
return rawCodegenConfig.map((config) => CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(config, this.packageRootPath, this.projectRootPath, this.name));
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
CodegenConfig_1.CodegenConfig.fromRawCodegenConfig(rawCodegenConfig, this.packageRootPath, this.projectRootPath, this.name),
|
|
55
|
+
];
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
exports.PackageJSON = PackageJSON;
|
|
@@ -23,8 +23,8 @@ class ProjectDependency {
|
|
|
23
23
|
getRootPath() {
|
|
24
24
|
return this.packageRootPath;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
return this.readPackageJSON().
|
|
26
|
+
getCodegenConfigs() {
|
|
27
|
+
return this.readPackageJSON().getCodegenConfigs();
|
|
28
28
|
}
|
|
29
29
|
readPackageJSON() {
|
|
30
30
|
return PackageJSON_1.PackageJSON.fromProjectRootPath(this.packageRootPath, this.projectRootPath);
|
package/dist/core/index.js
CHANGED
package/dist/index.js
CHANGED
package/dist/io/TarGz.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unpackTarGz = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
9
|
+
const tar_1 = __importDefault(require("tar"));
|
|
10
|
+
function unpackTarGz(archivePath, outputDirPath) {
|
|
11
|
+
if (!node_fs_1.default.existsSync(outputDirPath.getValue())) {
|
|
12
|
+
node_fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
const readStream = node_fs_1.default.createReadStream(archivePath.getValue());
|
|
15
|
+
const writeStream = tar_1.default.extract({
|
|
16
|
+
cwd: outputDirPath.getValue(),
|
|
17
|
+
});
|
|
18
|
+
readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
writeStream.on('finish', () => {
|
|
21
|
+
resolve(undefined);
|
|
22
|
+
});
|
|
23
|
+
writeStream.on('error', (err) => {
|
|
24
|
+
reject(err);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.unpackTarGz = unpackTarGz;
|
package/dist/io/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Logger"), exports);
|
|
18
18
|
__exportStar(require("./fsUtils"), exports);
|
|
19
|
+
__exportStar(require("./TarGz"), exports);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createHarmonyDirContainsOnlyHarsCheck = void 0;
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
function createHarmonyDirContainsOnlyHarsCheck(npmPackagePath, hasNpmPackageNativeCode) {
|
|
18
|
+
return {
|
|
19
|
+
checkIf: 'harmony_directory_contains_only_one_har_file',
|
|
20
|
+
run: () => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
if (!hasNpmPackageNativeCode) {
|
|
22
|
+
return 'skip';
|
|
23
|
+
}
|
|
24
|
+
const harmonyPath = npmPackagePath
|
|
25
|
+
.copyWithNewSegment('harmony')
|
|
26
|
+
.getValue();
|
|
27
|
+
const fileOrDirNames = node_fs_1.default.readdirSync(harmonyPath);
|
|
28
|
+
if (fileOrDirNames.length !== 1) {
|
|
29
|
+
return { status: 'fail', message: JSON.stringify(fileOrDirNames) };
|
|
30
|
+
}
|
|
31
|
+
if (!fileOrDirNames[0].endsWith('.har')) {
|
|
32
|
+
return 'fail';
|
|
33
|
+
}
|
|
34
|
+
return 'pass';
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.createHarmonyDirContainsOnlyHarsCheck = createHarmonyDirContainsOnlyHarsCheck;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createHarmonyDirExistsCheck = void 0;
|
|
16
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
17
|
+
function createHarmonyDirExistsCheck(packagePath, hasNativeCode) {
|
|
18
|
+
return {
|
|
19
|
+
checkIf: 'package_has_harmony_dir',
|
|
20
|
+
run: () => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const harmonyDirExist = node_fs_1.default.existsSync(packagePath.copyWithNewSegment('harmony').getValue());
|
|
22
|
+
if (!hasNativeCode) {
|
|
23
|
+
return 'skip';
|
|
24
|
+
}
|
|
25
|
+
if (!harmonyDirExist) {
|
|
26
|
+
return 'fail';
|
|
27
|
+
}
|
|
28
|
+
return 'pass';
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.createHarmonyDirExistsCheck = createHarmonyDirExistsCheck;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createNpmAndOhPackageVersionsAreEqualCheck = void 0;
|
|
13
|
+
function createNpmAndOhPackageVersionsAreEqualCheck(npmPackageVersion, ohPackageVersion) {
|
|
14
|
+
return {
|
|
15
|
+
checkIf: 'npm_and_oh_package_versions_are_equal',
|
|
16
|
+
run: () => __awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
}
|
|
26
|
+
exports.createNpmAndOhPackageVersionsAreEqualCheck = createNpmAndOhPackageVersionsAreEqualCheck;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createOhPackageNameFollowsNamingConventionCheck = void 0;
|
|
13
|
+
function createOhPackageNameFollowsNamingConventionCheck(npmPackageName, ohPackageName) {
|
|
14
|
+
const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
|
|
15
|
+
return {
|
|
16
|
+
checkIf: 'oh_package_name_is_derived_from_npm_package_name',
|
|
17
|
+
run: () => __awaiter(this, void 0, void 0, function* () {
|
|
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
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.unscopedName}`;
|
|
29
|
+
return expectedOHPackageName === ohPackageName
|
|
30
|
+
? 'pass'
|
|
31
|
+
: {
|
|
32
|
+
status: 'fail',
|
|
33
|
+
message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.createOhPackageNameFollowsNamingConventionCheck = createOhPackageNameFollowsNamingConventionCheck;
|
|
40
|
+
function getPackageNameInfo(packageName) {
|
|
41
|
+
if (packageName.startsWith('@') && packageName.includes('/')) {
|
|
42
|
+
const [part1, part2] = packageName.split('/');
|
|
43
|
+
return {
|
|
44
|
+
organizationName: part1.replace('@', ''),
|
|
45
|
+
unscopedName: part2,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return { organizationName: null, unscopedName: packageName };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./HarmonyDirExistsCheck"), exports);
|
|
18
|
+
__exportStar(require("./HarmonyDirContainsOnlyHarsCheck"), exports);
|
|
19
|
+
__exportStar(require("./NpmAnAndOhPackageVersionsAreEqual"), exports);
|
|
20
|
+
__exportStar(require("./OhPackageNameFollowsNamingConventionCheck"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./verify-package"), exports);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
10
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
11
|
+
var i, p;
|
|
12
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
13
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
14
|
+
};
|
|
15
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
16
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
17
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
18
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
19
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
20
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
21
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
22
|
+
function fulfill(value) { resume("next", value); }
|
|
23
|
+
function reject(value) { resume("throw", value); }
|
|
24
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.verifyRNOHPackage = void 0;
|
|
31
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
32
|
+
const tmp_1 = __importDefault(require("tmp"));
|
|
33
|
+
const core_1 = require("../core");
|
|
34
|
+
const checks_1 = require("./checks");
|
|
35
|
+
const io_1 = require("../io");
|
|
36
|
+
function verifyRNOHPackage({ npmPackagePath, hasHarmonyCode, checkNamesToSkip, }) {
|
|
37
|
+
return __asyncGenerator(this, arguments, function* verifyRNOHPackage_1() {
|
|
38
|
+
const npmPackageJson = core_1.PackageJSON.fromProjectRootPath(npmPackagePath, npmPackagePath);
|
|
39
|
+
const initialChecks = [
|
|
40
|
+
(0, checks_1.createHarmonyDirExistsCheck)(npmPackagePath, hasHarmonyCode),
|
|
41
|
+
(0, checks_1.createHarmonyDirContainsOnlyHarsCheck)(npmPackagePath, hasHarmonyCode),
|
|
42
|
+
];
|
|
43
|
+
yield __await(yield* __asyncDelegator(__asyncValues(runChecks(initialChecks, checkNamesToSkip))));
|
|
44
|
+
if (hasHarmonyCode) {
|
|
45
|
+
const harPath = findHarPath(npmPackagePath);
|
|
46
|
+
if (!harPath) {
|
|
47
|
+
throw new core_1.DescriptiveError({
|
|
48
|
+
whatHappened: 'Attempted to verify har but no har was found',
|
|
49
|
+
whatCanUserDo: {
|
|
50
|
+
default: [
|
|
51
|
+
'Run this command without --no-harmony-code flag.',
|
|
52
|
+
'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.',
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const tmpDirPath = new core_1.AbsolutePath(tmp_1.default.dirSync().name);
|
|
58
|
+
yield yield __await({
|
|
59
|
+
type: 'START_PROCESS',
|
|
60
|
+
name: `Unpacking the har file to the tmpdir`,
|
|
61
|
+
});
|
|
62
|
+
yield __await((0, io_1.unpackTarGz)(harPath, tmpDirPath));
|
|
63
|
+
const ohPackageJson5 = core_1.OHPackageJSON5.fromPath(tmpDirPath.copyWithNewSegment('package', 'oh-package.json5'));
|
|
64
|
+
const harChecks = [
|
|
65
|
+
(0, checks_1.createOhPackageNameFollowsNamingConventionCheck)(npmPackageJson.name, ohPackageJson5.name),
|
|
66
|
+
(0, checks_1.createNpmAndOhPackageVersionsAreEqualCheck)(npmPackageJson.version, ohPackageJson5.version),
|
|
67
|
+
];
|
|
68
|
+
yield __await(yield* __asyncDelegator(__asyncValues(runChecks(harChecks, checkNamesToSkip))));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.verifyRNOHPackage = verifyRNOHPackage;
|
|
73
|
+
function runChecks(checks, checkNamesToSkip) {
|
|
74
|
+
return __asyncGenerator(this, arguments, function* runChecks_1() {
|
|
75
|
+
for (const { checkIf, run } of checks) {
|
|
76
|
+
if (checkNamesToSkip.includes(checkIf)) {
|
|
77
|
+
yield yield __await({
|
|
78
|
+
type: 'FINISHED_CHECKING',
|
|
79
|
+
name: checkIf,
|
|
80
|
+
status: 'skip',
|
|
81
|
+
message: '',
|
|
82
|
+
});
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const result = yield __await(run());
|
|
86
|
+
const status = typeof result === 'string' ? result : result.status;
|
|
87
|
+
const message = typeof result === 'string' ? '' : result.message;
|
|
88
|
+
yield yield __await({ type: 'FINISHED_CHECKING', name: checkIf, status, message });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function findHarPath(packagePath) {
|
|
93
|
+
const packageHarmonyPath = packagePath.copyWithNewSegment('harmony');
|
|
94
|
+
const fileOrDirNames = node_fs_1.default.readdirSync(packageHarmonyPath.getValue());
|
|
95
|
+
const harFilenames = fileOrDirNames.filter((fileOrDirName) => fileOrDirName.endsWith('.har'));
|
|
96
|
+
if (harFilenames.length != 1) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return packageHarmonyPath.copyWithNewSegment(harFilenames[0]);
|
|
100
|
+
}
|
package/jest.config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
};
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
};
|