@react-native-oh/react-native-harmony-cli 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assetResolver.js +19 -0
- package/dist/codegen/core/CodeGenerator.js +2 -0
- package/dist/codegen/core/CodegenError.js +7 -0
- package/dist/codegen/core/EventUtils.js +19 -0
- package/dist/codegen/core/TypeAnnotationToTS.js +132 -0
- package/dist/codegen/core/UberSchema.js +103 -0
- package/dist/codegen/core/index.js +21 -0
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +61 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +76 -0
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +74 -0
- package/dist/codegen/generators/CppComponentCodeGenerator.js +56 -0
- package/dist/codegen/generators/LibGlueCodeGenerator.js +50 -0
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +73 -0
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +34 -0
- package/dist/codegen/generators/UberGeneratorV1.js +50 -0
- package/dist/codegen/generators/UberGeneratorV2.js +71 -0
- package/dist/codegen/generators/index.js +24 -0
- package/dist/codegen/index.js +18 -0
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +105 -0
- package/dist/codegen/templates/BasePackageHTemplate.js +130 -0
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +62 -0
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +85 -0
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +192 -0
- package/dist/codegen/templates/IndexTSTemplate.js +52 -0
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +124 -0
- package/dist/codegen/templates/TurboModuleCppTemplate.js +53 -0
- package/dist/codegen/templates/TurboModuleHTemplate.js +42 -0
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +75 -0
- package/dist/codegen/templates/index.js +25 -0
- package/dist/commands/bundle-harmony.js +179 -0
- package/dist/commands/codegen-harmony.js +201 -0
- package/dist/commands/codegen-lib-harmony.js +253 -0
- package/dist/commands/create-metro-host-constants.js +61 -0
- package/dist/commands/index.js +23 -0
- package/dist/commands/pack-harmony.js +100 -0
- package/dist/commands/unpack-harmony.js +184 -0
- package/dist/commands/verify-package-harmony.js +122 -0
- package/dist/core/AbsolutePath.js +47 -0
- package/dist/core/CodegenConfig.js +57 -0
- package/dist/core/DescriptiveError.js +49 -0
- package/dist/core/OHPackageJSON5.js +23 -0
- package/dist/core/PackageJSON.js +58 -0
- package/dist/core/ProjectDependenciesManager.js +70 -0
- package/dist/core/ValidationError.js +6 -0
- package/dist/core/ValueObject.js +2 -0
- package/dist/core/fs.js +36 -0
- package/dist/core/index.js +25 -0
- package/dist/index.js +15 -0
- package/dist/io/Logger.js +71 -0
- package/dist/io/TarGz.js +28 -0
- package/dist/io/fsUtils.js +23 -0
- package/dist/io/index.js +19 -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 +101 -0
- package/package.json +1 -1
- package/src/codegen/core/UberSchema.ts +4 -0
- package/src/codegen/generators/{GlueCodeGenerator.ts → AppBuildTimeGlueCodeGenerator.ts} +13 -9
- package/src/codegen/generators/{ComponentCodeGeneratorArkTS.ts → ArkTSComponentCodeGeneratorArkTS.ts} +11 -5
- package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +112 -0
- package/src/codegen/generators/{ComponentCodeGeneratorCAPI.ts → CppComponentCodeGenerator.ts} +14 -43
- package/src/codegen/generators/LibGlueCodeGenerator.ts +91 -0
- package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -5
- package/src/codegen/generators/SharedComponentCodeGenerator.ts +50 -0
- package/src/codegen/generators/UberGeneratorV1.ts +12 -8
- package/src/codegen/generators/UberGeneratorV2.ts +32 -16
- package/src/codegen/generators/index.ts +5 -3
- package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +12 -7
- package/src/codegen/templates/{GeneratedPackageHTemplate.ts → BasePackageHTemplate.ts} +45 -12
- package/src/codegen/templates/ComponentDescriptorHTemplate.ts +2 -1
- package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +8 -10
- package/src/codegen/templates/ComponentUtilsTSTemplate.ts +13 -8
- package/src/codegen/templates/IndexTSTemplate.ts +11 -9
- package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +1 -0
- package/src/codegen/templates/TurboModuleCppTemplate.ts +9 -9
- package/src/codegen/templates/TurboModuleHTemplate.ts +9 -9
- package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +13 -9
- package/src/commands/codegen-harmony.ts +24 -7
- package/src/commands/codegen-lib-harmony.ts +387 -0
- package/src/commands/index.ts +1 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,61 @@
|
|
|
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.commandCreateMetroConstantsHarmony = void 0;
|
|
16
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
17
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
+
exports.commandCreateMetroConstantsHarmony = {
|
|
20
|
+
name: 'create-metro-host-constants-harmony',
|
|
21
|
+
description: 'Creates a Typescript file that exports constant with IP of the host machine. That IP is later used to connect to the Metro server from a physical device.',
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
name: '--output <string>',
|
|
25
|
+
description: 'Output file',
|
|
26
|
+
default: './harmony/entry/src/main/ets/codegen/MetroHostConstants.ts',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
createMetroHostConstants(node_path_1.default.resolve(args.output));
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
function createMetroHostConstants(outputPath) {
|
|
34
|
+
const networkInterfacesByName = node_os_1.default.networkInterfaces();
|
|
35
|
+
const getIP = () => {
|
|
36
|
+
var _a;
|
|
37
|
+
for (let name of Object.keys(networkInterfacesByName)) {
|
|
38
|
+
for (let net of (_a = networkInterfacesByName[name]) !== null && _a !== void 0 ? _a : []) {
|
|
39
|
+
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
|
|
40
|
+
if (net.family === 'IPv4' && !net.internal) {
|
|
41
|
+
return net.address;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
};
|
|
47
|
+
const ip = getIP();
|
|
48
|
+
const tsCode = [
|
|
49
|
+
'// This file is autogenerated. Do not modify it manually.',
|
|
50
|
+
'',
|
|
51
|
+
`export const METRO_SERVER_IP = '${ip}';\n`,
|
|
52
|
+
];
|
|
53
|
+
node_fs_1.default.writeFile(outputPath, tsCode.join('\n'), (err) => {
|
|
54
|
+
if (err) {
|
|
55
|
+
console.error(`Error writing to ${outputPath}:`, err);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log(`Created file at ${outputPath}`);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./bundle-harmony"), exports);
|
|
18
|
+
__exportStar(require("./pack-harmony"), exports);
|
|
19
|
+
__exportStar(require("./unpack-harmony"), exports);
|
|
20
|
+
__exportStar(require("./create-metro-host-constants"), exports);
|
|
21
|
+
__exportStar(require("./codegen-harmony"), exports);
|
|
22
|
+
__exportStar(require("./verify-package-harmony"), exports);
|
|
23
|
+
__exportStar(require("./codegen-lib-harmony"), exports);
|
|
@@ -0,0 +1,100 @@
|
|
|
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.commandPackHarmony = void 0;
|
|
16
|
+
const glob_1 = require("glob");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const tar_1 = __importDefault(require("tar"));
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const core_1 = require("../core");
|
|
21
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
22
|
+
const json5_1 = __importDefault(require("json5"));
|
|
23
|
+
exports.commandPackHarmony = {
|
|
24
|
+
name: 'pack-harmony',
|
|
25
|
+
description: 'Pack native code. Used for package development.',
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
name: '--oh-module-path <string>',
|
|
29
|
+
description: 'Path to the OH module',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: '--harmony-dir-path <string>',
|
|
33
|
+
description: 'Path to the harmony dir',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: '--package-json-path <string>',
|
|
37
|
+
description: 'Path to the package.json',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
try {
|
|
42
|
+
yield pack(path_1.default.resolve(args.harmonyDirPath), path_1.default.resolve(args.ohModulePath), path_1.default.resolve(args.packageJsonPath));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (err instanceof core_1.ValidationError) {
|
|
46
|
+
console.error('[ERROR]', err.message);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
function pack(harmonyDirPath, ohModuleDirPath, packageJSONPath) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
syncVersions(packageJSONPath, path_1.default.join(ohModuleDirPath, 'oh-package.json5'));
|
|
58
|
+
if (!fs_1.default.existsSync(harmonyDirPath)) {
|
|
59
|
+
fs_1.default.mkdirSync(harmonyDirPath, { recursive: true });
|
|
60
|
+
}
|
|
61
|
+
yield createTGZFromDir(ohModuleDirPath, path_1.default.join(harmonyDirPath, `${path_1.default.parse(ohModuleDirPath).name}.tar.gz`));
|
|
62
|
+
yield createTGZFromDir(harmonyDirPath, path_1.default.join(path_1.default.dirname(harmonyDirPath), 'harmony.tar.gz'));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function syncVersions(packageJSONFilePath, ohPackageJSONFilePath) {
|
|
66
|
+
const packageJSONFileContent = JSON.parse(fs_1.default.readFileSync(packageJSONFilePath, { encoding: 'utf-8' }));
|
|
67
|
+
if (fs_1.default.existsSync(ohPackageJSONFilePath)) {
|
|
68
|
+
const ohPackageJSONFileContent = json5_1.default.parse(fs_1.default.readFileSync(ohPackageJSONFilePath, { encoding: 'utf-8' }));
|
|
69
|
+
ohPackageJSONFileContent['version'] = packageJSONFileContent['version'];
|
|
70
|
+
fs_1.default.writeFileSync(ohPackageJSONFilePath, json5_1.default.stringify(ohPackageJSONFileContent, null, 2));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function createTGZFromDir(dirPath, outputFilePath) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const ig = getIgnoreUtil(path_1.default.join(dirPath, '.tarignore'));
|
|
76
|
+
const filesToInclude = (0, glob_1.globSync)('**', {
|
|
77
|
+
cwd: dirPath,
|
|
78
|
+
nodir: true,
|
|
79
|
+
}).filter((path) => !ig.ignores(path));
|
|
80
|
+
yield createArchive(outputFilePath, dirPath, filesToInclude);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function getIgnoreUtil(tarignorePath) {
|
|
84
|
+
if (!fs_1.default.existsSync(tarignorePath)) {
|
|
85
|
+
return (0, ignore_1.default)();
|
|
86
|
+
}
|
|
87
|
+
return (0, ignore_1.default)().add(fs_1.default.readFileSync(tarignorePath).toString());
|
|
88
|
+
}
|
|
89
|
+
function createArchive(outputFilePath, packageDirPath, filesToInclude) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
if (filesToInclude.length === 0) {
|
|
92
|
+
throw new core_1.ValidationError('Nothing to pack');
|
|
93
|
+
}
|
|
94
|
+
yield tar_1.default.c({
|
|
95
|
+
gzip: true,
|
|
96
|
+
file: outputFilePath,
|
|
97
|
+
cwd: packageDirPath,
|
|
98
|
+
}, filesToInclude);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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.commandUnpackHarmony = void 0;
|
|
16
|
+
const io_1 = require("../io");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
20
|
+
const tar_1 = __importDefault(require("tar"));
|
|
21
|
+
const json5_1 = __importDefault(require("json5"));
|
|
22
|
+
const core_1 = require("../core");
|
|
23
|
+
exports.commandUnpackHarmony = {
|
|
24
|
+
name: 'unpack-harmony',
|
|
25
|
+
description: 'Unpacks native code.',
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
name: '--project-root-path <path>',
|
|
29
|
+
description: 'Relative path to package root',
|
|
30
|
+
default: '.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: '--output-dir <string>',
|
|
34
|
+
description: 'Output directory to which OH modules should be unpacked to',
|
|
35
|
+
default: './harmony/rnoh_modules',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
yield unpack(new core_1.AbsolutePath(args.projectRootPath), new core_1.AbsolutePath(args.outputDir));
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (err instanceof core_1.ValidationError) {
|
|
44
|
+
console.error('[ERROR]', err.message);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
};
|
|
53
|
+
function unpack(projectRootPath, outputDirPath) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const logger = new io_1.Logger();
|
|
56
|
+
const projectDependenciesManager = new core_1.ProjectDependenciesManager(projectRootPath);
|
|
57
|
+
logger.info((styles) => styles.bold(`Unpacking RNOH modules`), {
|
|
58
|
+
prefix: true,
|
|
59
|
+
});
|
|
60
|
+
let unpackedArchivesCount = 0;
|
|
61
|
+
let skippedArchivesCount = 0;
|
|
62
|
+
yield projectDependenciesManager.forEachAsync((dependency) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const packageJSON = dependency.readPackageJSON();
|
|
64
|
+
const harmonyArchivePath = dependency
|
|
65
|
+
.getRootPath()
|
|
66
|
+
.copyWithNewSegment('harmony.tar.gz');
|
|
67
|
+
const pkgHarmonyDirPath = dependency
|
|
68
|
+
.getRootPath()
|
|
69
|
+
.copyWithNewSegment('harmony');
|
|
70
|
+
const harmonyTarGzPathStr = dependency
|
|
71
|
+
.getRootPath()
|
|
72
|
+
.copyWithNewSegment('harmony.tar.gz')
|
|
73
|
+
.relativeTo(projectRootPath)
|
|
74
|
+
.getValue();
|
|
75
|
+
if (packageJSON.version &&
|
|
76
|
+
shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, packageJSON.version)) {
|
|
77
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue())) {
|
|
78
|
+
/**
|
|
79
|
+
* After fresh install, harmony.tar.gz wasn't unpacked to harmony. Updating npm package should remove unpacked harmony dir.
|
|
80
|
+
*/
|
|
81
|
+
logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
82
|
+
yield unpackTarGz(harmonyArchivePath, pkgHarmonyDirPath);
|
|
83
|
+
unpackedArchivesCount++;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
skippedArchivesCount++;
|
|
87
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
88
|
+
}
|
|
89
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
90
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
91
|
+
const moduleArchivePathStr = dependency
|
|
92
|
+
.getRootPath()
|
|
93
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
94
|
+
.relativeTo(projectRootPath)
|
|
95
|
+
.getValue();
|
|
96
|
+
logger.info((styles) => `[${styles.cyan('unpacking')}] ${styles.gray(moduleArchivePathStr)}`);
|
|
97
|
+
unpackedArchivesCount++;
|
|
98
|
+
yield unpackTarGz(ohModuleInfo.archivePath, ohModuleInfo.computedModulePath);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (fs_1.default.existsSync(harmonyArchivePath.getValue())) {
|
|
103
|
+
skippedArchivesCount++;
|
|
104
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(harmonyTarGzPathStr)}`);
|
|
105
|
+
}
|
|
106
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
107
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
108
|
+
const moduleArchivePathStr = dependency
|
|
109
|
+
.getRootPath()
|
|
110
|
+
.copyWithNewSegment('harmony', ohModuleInfo.archiveFileName)
|
|
111
|
+
.relativeTo(projectRootPath)
|
|
112
|
+
.getValue();
|
|
113
|
+
skippedArchivesCount++;
|
|
114
|
+
logger.info((styles) => `[${styles.yellow('skipped')}] ${styles.gray(moduleArchivePathStr)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
logger.info((styles) => `\nUnpacked: ${styles.cyan(unpackedArchivesCount)}, Skipped: ${styles.yellow(skippedArchivesCount)}`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function shouldUnpack(harmonyArchivePath, pkgHarmonyDirPath, outputDirPath, nodePackageVersion) {
|
|
122
|
+
if (!fs_1.default.existsSync(harmonyArchivePath.getValue()))
|
|
123
|
+
return false;
|
|
124
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
|
|
125
|
+
return true;
|
|
126
|
+
const ohModulesInfo = getOhModulesInfo(pkgHarmonyDirPath, outputDirPath);
|
|
127
|
+
for (const ohModuleInfo of ohModulesInfo) {
|
|
128
|
+
if (!fs_1.default.existsSync(ohModuleInfo.computedModulePath.getValue()) ||
|
|
129
|
+
getOhPackageVersion(ohModuleInfo.computedModulePath) !==
|
|
130
|
+
nodePackageVersion) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
function getOhPackageVersion(modulePath) {
|
|
137
|
+
const ohPackagePath = modulePath.copyWithNewSegment('oh-package.json5');
|
|
138
|
+
if (!fs_1.default.existsSync(ohPackagePath.getValue()))
|
|
139
|
+
return null;
|
|
140
|
+
const content = fs_1.default.readFileSync(ohPackagePath.getValue(), {
|
|
141
|
+
encoding: 'utf-8',
|
|
142
|
+
});
|
|
143
|
+
return json5_1.default.parse(content)['version'];
|
|
144
|
+
}
|
|
145
|
+
function getOhModulesInfo(pkgHarmonyDirPath, outputDirPath) {
|
|
146
|
+
const results = [];
|
|
147
|
+
if (!fs_1.default.existsSync(pkgHarmonyDirPath.getValue()))
|
|
148
|
+
return [];
|
|
149
|
+
const names = fs_1.default.readdirSync(pkgHarmonyDirPath.getValue());
|
|
150
|
+
for (const name of names) {
|
|
151
|
+
if (name.endsWith('.tar.gz')) {
|
|
152
|
+
const archivePath = pkgHarmonyDirPath.copyWithNewSegment(name);
|
|
153
|
+
const computedModuleName = path_1.default
|
|
154
|
+
.parse(archivePath.getValue())
|
|
155
|
+
.name.split('.')[0];
|
|
156
|
+
const computedModulePath = outputDirPath.copyWithNewSegment(computedModuleName);
|
|
157
|
+
results.push({
|
|
158
|
+
archivePath,
|
|
159
|
+
archiveFileName: name,
|
|
160
|
+
computedModulePath,
|
|
161
|
+
computedModuleName,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return results;
|
|
166
|
+
}
|
|
167
|
+
function unpackTarGz(archivePath, outputDirPath) {
|
|
168
|
+
if (!fs_1.default.existsSync(outputDirPath.getValue())) {
|
|
169
|
+
fs_1.default.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
170
|
+
}
|
|
171
|
+
const readStream = fs_1.default.createReadStream(archivePath.getValue());
|
|
172
|
+
const writeStream = tar_1.default.extract({
|
|
173
|
+
cwd: outputDirPath.getValue(),
|
|
174
|
+
});
|
|
175
|
+
readStream.pipe(zlib_1.default.createGunzip()).pipe(writeStream);
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
writeStream.on('finish', () => {
|
|
178
|
+
resolve(undefined);
|
|
179
|
+
});
|
|
180
|
+
writeStream.on('error', (err) => {
|
|
181
|
+
reject(err);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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; _d = true) {
|
|
58
|
+
_c = _f.value;
|
|
59
|
+
_d = false;
|
|
60
|
+
const checkResult = _c;
|
|
61
|
+
if (checkResult.type === 'START_PROCESS') {
|
|
62
|
+
loader.start(chalk_1.default.gray(checkResult.name));
|
|
63
|
+
}
|
|
64
|
+
else if (checkResult.type === 'FINISHED_CHECKING') {
|
|
65
|
+
checkResults.push(checkResult);
|
|
66
|
+
logCheckResult(loader, checkResult);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e_1) throw e_1.error; }
|
|
76
|
+
}
|
|
77
|
+
if (checkResults.every((checkResult) => checkResult.status === 'pass' || checkResult.status === 'skip')) {
|
|
78
|
+
loader.info(chalk_1.default.bold('OK'));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
loader.info(chalk_1.default.red('Package verification failed. Please fix those checks before publishing your package.'));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (err instanceof core_1.DescriptiveError) {
|
|
87
|
+
new io_1.Logger().descriptiveError(err);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
function validateArgs(args) {
|
|
95
|
+
var _a;
|
|
96
|
+
if (!args.packagePath) {
|
|
97
|
+
throw new core_1.DescriptiveError({
|
|
98
|
+
whatHappened: 'package-path is undefined',
|
|
99
|
+
whatCanUserDo: { default: ['Please provide --package-path'] },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
packagePath: new core_1.AbsolutePath(args.packagePath),
|
|
104
|
+
hasHarmonyCode: args.harmonyCode,
|
|
105
|
+
checkNamesToSkip: ((_a = args.skipChecks) !== null && _a !== void 0 ? _a : '').split(';'),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function logCheckResult(loader, checkResult) {
|
|
109
|
+
const prefix = (() => {
|
|
110
|
+
switch (checkResult.status) {
|
|
111
|
+
case 'pass':
|
|
112
|
+
return `${chalk_1.default.green('PASS')}`;
|
|
113
|
+
case 'fail':
|
|
114
|
+
return `${chalk_1.default.red('FAIL')}`;
|
|
115
|
+
case 'skip':
|
|
116
|
+
return `${chalk_1.default.yellow('SKIP')}`;
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
loader.info(checkResult.message
|
|
120
|
+
? `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}\n${checkResult.message}`
|
|
121
|
+
: `[${chalk_1.default.bold(prefix)}] ${chalk_1.default.bold(checkResult.name)}`);
|
|
122
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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.AbsolutePath = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
class AbsolutePath {
|
|
9
|
+
static fromSegments(...segments) {
|
|
10
|
+
return new AbsolutePath(node_path_1.default.join(...segments));
|
|
11
|
+
}
|
|
12
|
+
constructor(path) {
|
|
13
|
+
this.value = '';
|
|
14
|
+
this.value = node_path_1.default.resolve(path);
|
|
15
|
+
}
|
|
16
|
+
getValue() {
|
|
17
|
+
return this.value;
|
|
18
|
+
}
|
|
19
|
+
copyWithNewSegment(...relativePath) {
|
|
20
|
+
return new AbsolutePath(node_path_1.default.join(this.getValue(), ...relativePath));
|
|
21
|
+
}
|
|
22
|
+
getExtension() {
|
|
23
|
+
const maybeExtWithDot = node_path_1.default.extname(this.value);
|
|
24
|
+
if (maybeExtWithDot) {
|
|
25
|
+
return maybeExtWithDot.substring(1);
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
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
|
+
}
|
|
35
|
+
relativeTo(absolutePath) {
|
|
36
|
+
return new RelativePath(node_path_1.default.relative(absolutePath.getValue(), this.value));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.AbsolutePath = AbsolutePath;
|
|
40
|
+
class RelativePath {
|
|
41
|
+
constructor(value) {
|
|
42
|
+
this.value = value;
|
|
43
|
+
}
|
|
44
|
+
getValue() {
|
|
45
|
+
return this.value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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.CodegenConfig = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const io_1 = require("../io");
|
|
9
|
+
const DescriptiveError_1 = require("./DescriptiveError");
|
|
10
|
+
class CodegenConfig {
|
|
11
|
+
static fromRawCodegenConfig(rawCodegenConfig, packageRootPath, projectRootPath, packageName) {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const SUPPORTED_SPEC_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
|
|
14
|
+
const specPaths = ((_a = rawCodegenConfig.specPaths) !== null && _a !== void 0 ? _a : []).map((rawSpecPath) => {
|
|
15
|
+
if (rawSpecPath.startsWith('~')) {
|
|
16
|
+
return projectRootPath.copyWithNewSegment(rawSpecPath.replace('~', ''));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return packageRootPath.copyWithNewSegment(rawSpecPath);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const specFilePaths = specPaths.flatMap((specPath) => {
|
|
23
|
+
if (!node_fs_1.default.existsSync(specPath.getValue())) {
|
|
24
|
+
throw new DescriptiveError_1.DescriptiveError({
|
|
25
|
+
whatHappened: `No such file or directory: ${specPath.getValue()}`,
|
|
26
|
+
whatCanUserDo: {
|
|
27
|
+
default: [
|
|
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
|
+
],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (node_fs_1.default.lstatSync(specPath.getValue()).isDirectory()) {
|
|
34
|
+
return (0, io_1.findFilePathsWithExtensions)(specPath, SUPPORTED_SPEC_EXTENSIONS);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const ext = specPath.getExtension();
|
|
38
|
+
if (ext && SUPPORTED_SPEC_EXTENSIONS.includes(ext)) {
|
|
39
|
+
return [specPath];
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return new CodegenConfig(specFilePaths, (_b = rawCodegenConfig.version) !== null && _b !== void 0 ? _b : 1);
|
|
45
|
+
}
|
|
46
|
+
constructor(specFilePaths, version) {
|
|
47
|
+
this.specFilePaths = specFilePaths;
|
|
48
|
+
this.version = version;
|
|
49
|
+
}
|
|
50
|
+
getSpecFilePaths() {
|
|
51
|
+
return this.specFilePaths;
|
|
52
|
+
}
|
|
53
|
+
getVersion() {
|
|
54
|
+
return this.version;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CodegenConfig = CodegenConfig;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DescriptiveError = void 0;
|
|
4
|
+
class DescriptiveError extends Error {
|
|
5
|
+
constructor(data) {
|
|
6
|
+
super(data.whatHappened);
|
|
7
|
+
this.data = data;
|
|
8
|
+
}
|
|
9
|
+
isUnexpected() {
|
|
10
|
+
return 'unexpected' in this.data;
|
|
11
|
+
}
|
|
12
|
+
getMessage() {
|
|
13
|
+
return this.data.whatHappened;
|
|
14
|
+
}
|
|
15
|
+
getSuggestionsByRole() {
|
|
16
|
+
if ('whatCanUserDo' in this.data) {
|
|
17
|
+
return this.data.whatCanUserDo;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getDetails() {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!this.data.extraData) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
if (typeof this.data.extraData === 'string') {
|
|
29
|
+
return this.data.extraData.trim();
|
|
30
|
+
}
|
|
31
|
+
if (this.data.extraData instanceof Error) {
|
|
32
|
+
let lines = [
|
|
33
|
+
`${this.data.extraData.name}: ${this.data.extraData.message}`,
|
|
34
|
+
];
|
|
35
|
+
for (let stackEntry of ((_a = this.data.extraData.stack) !== null && _a !== void 0 ? _a : '').split('\n')) {
|
|
36
|
+
lines.push('');
|
|
37
|
+
lines.push(stackEntry);
|
|
38
|
+
}
|
|
39
|
+
return lines.join('\n');
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return JSON.stringify(this.data.extraData, null, 2);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.DescriptiveError = DescriptiveError;
|
|
@@ -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;
|