@react-native-oh/react-native-harmony-cli 0.0.24 → 0.0.25
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/commands/index.js +1 -0
- package/dist/commands/verify-package-harmony.js +127 -0
- package/dist/core/OHPackageJSON5.js +23 -0
- 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/package.json +7 -3
- package/src/commands/bundle-harmony.ts +2 -1
- package/src/commands/index.ts +1 -0
- package/src/commands/verify-package-harmony.ts +106 -0
- package/src/core/OHPackageJSON5.ts +23 -0
- package/src/core/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/io/TarGz.ts +26 -0
- package/src/io/index.ts +1 -0
- 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/dist/commands/index.js
CHANGED
|
@@ -19,3 +19,4 @@ __exportStar(require("./pack-harmony"), exports);
|
|
|
19
19
|
__exportStar(require("./unpack-harmony"), exports);
|
|
20
20
|
__exportStar(require("./create-metro-host-constants"), exports);
|
|
21
21
|
__exportStar(require("./codegen-harmony"), exports);
|
|
22
|
+
__exportStar(require("./verify-package-harmony"), exports);
|
|
@@ -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
|
+
}
|
|
@@ -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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -24,8 +24,10 @@
|
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@react-native-community/cli-types": "^11.3.0",
|
|
27
|
+
"@types/adm-zip": "^0.5.5",
|
|
27
28
|
"@types/fs-extra": "^11.0.1",
|
|
28
29
|
"@types/jest": "^29.5.1",
|
|
30
|
+
"@types/jszip": "^3.4.1",
|
|
29
31
|
"@types/mustache": "^4.2.5",
|
|
30
32
|
"@types/tar": "^6.1.5",
|
|
31
33
|
"@types/tmp": "^0.2.3",
|
|
@@ -33,20 +35,22 @@
|
|
|
33
35
|
"execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
|
|
34
36
|
"jest": "^29.5.0",
|
|
35
37
|
"react-native": "^0.72.0",
|
|
36
|
-
"tmp": "^0.2.1",
|
|
37
38
|
"ts-jest": "^29.1.0",
|
|
38
39
|
"ts-node": "^10.9.1",
|
|
39
40
|
"typescript": "^5.0.4"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
43
|
+
"@react-native-community/cli-tools": "^13.6.5",
|
|
42
44
|
"@react-native/codegen": "0.74.0",
|
|
43
45
|
"@tsconfig/recommended": "^1.0.2",
|
|
46
|
+
"adm-zip": "^0.5.12",
|
|
44
47
|
"chalk": "^4",
|
|
45
48
|
"fs-extra": "^11.1.1",
|
|
46
49
|
"glob": "^10.2.6",
|
|
47
50
|
"ignore": "^5.2.4",
|
|
48
51
|
"json5": "^2.2.3",
|
|
49
52
|
"mustache": "^4.2.0",
|
|
50
|
-
"tar": "^6.1.15"
|
|
53
|
+
"tar": "^6.1.15",
|
|
54
|
+
"tmp": "^0.2.1"
|
|
51
55
|
}
|
|
52
56
|
}
|
|
@@ -9,7 +9,8 @@ import { getAssetDestRelativePath } from '../assetResolver';
|
|
|
9
9
|
import { ConfigT as MetroConfig } from 'metro-config';
|
|
10
10
|
|
|
11
11
|
const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
|
|
12
|
-
const ASSETS_DEFAULT_DEST_PATH =
|
|
12
|
+
const ASSETS_DEFAULT_DEST_PATH =
|
|
13
|
+
'./harmony/entry/src/main/resources/rawfile/assets';
|
|
13
14
|
|
|
14
15
|
type AssetData = Metro.AssetData;
|
|
15
16
|
type Bundle = { code: string; map: string };
|
package/src/commands/index.ts
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import json5 from 'json5';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { AbsolutePath } from './AbsolutePath';
|
|
4
|
+
|
|
5
|
+
export class OHPackageJSON5 {
|
|
6
|
+
static fromPath(ohPackageJson5Path: AbsolutePath) {
|
|
7
|
+
return new OHPackageJSON5(
|
|
8
|
+
json5.parse(
|
|
9
|
+
fs.readFileSync(ohPackageJson5Path.getValue(), { encoding: 'utf-8' })
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private constructor(private rawData: Record<string, any>) {}
|
|
15
|
+
|
|
16
|
+
get name(): string {
|
|
17
|
+
return this.rawData['name'];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get version(): string {
|
|
21
|
+
return this.rawData['version'];
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/core/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
commandUnpackHarmony,
|
|
6
6
|
commandCreateMetroConstantsHarmony,
|
|
7
7
|
commandCodegenHarmony,
|
|
8
|
+
commandVerifyPackageHarmony,
|
|
8
9
|
} from './commands';
|
|
9
10
|
|
|
10
11
|
export const config = {
|
|
@@ -14,5 +15,6 @@ export const config = {
|
|
|
14
15
|
commandUnpackHarmony,
|
|
15
16
|
commandCreateMetroConstantsHarmony,
|
|
16
17
|
commandCodegenHarmony,
|
|
18
|
+
commandVerifyPackageHarmony,
|
|
17
19
|
],
|
|
18
20
|
} satisfies Partial<Config>;
|
package/src/io/TarGz.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import zlib from 'zlib';
|
|
3
|
+
import tar from 'tar';
|
|
4
|
+
import { AbsolutePath } from '../core';
|
|
5
|
+
|
|
6
|
+
export function unpackTarGz(
|
|
7
|
+
archivePath: AbsolutePath,
|
|
8
|
+
outputDirPath: AbsolutePath
|
|
9
|
+
) {
|
|
10
|
+
if (!fs.existsSync(outputDirPath.getValue())) {
|
|
11
|
+
fs.mkdirSync(outputDirPath.getValue(), { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
const readStream = fs.createReadStream(archivePath.getValue());
|
|
14
|
+
const writeStream = tar.extract({
|
|
15
|
+
cwd: outputDirPath.getValue(),
|
|
16
|
+
});
|
|
17
|
+
readStream.pipe(zlib.createGunzip()).pipe(writeStream);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
writeStream.on('finish', () => {
|
|
20
|
+
resolve(undefined);
|
|
21
|
+
});
|
|
22
|
+
writeStream.on('error', (err) => {
|
|
23
|
+
reject(err);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
package/src/io/index.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { AbsolutePath } from '../../core';
|
|
3
|
+
import { Check } from '../types';
|
|
4
|
+
|
|
5
|
+
export function createHarmonyDirContainsOnlyHarsCheck(
|
|
6
|
+
npmPackagePath: AbsolutePath,
|
|
7
|
+
hasNpmPackageNativeCode: boolean
|
|
8
|
+
): Check {
|
|
9
|
+
return {
|
|
10
|
+
checkIf: 'harmony_directory_contains_only_one_har_file',
|
|
11
|
+
run: async () => {
|
|
12
|
+
if (!hasNpmPackageNativeCode) {
|
|
13
|
+
return 'skip';
|
|
14
|
+
}
|
|
15
|
+
const harmonyPath = npmPackagePath
|
|
16
|
+
.copyWithNewSegment('harmony')
|
|
17
|
+
.getValue();
|
|
18
|
+
const fileOrDirNames = fs.readdirSync(harmonyPath);
|
|
19
|
+
if (fileOrDirNames.length !== 1) {
|
|
20
|
+
return { status: 'fail', message: JSON.stringify(fileOrDirNames) };
|
|
21
|
+
}
|
|
22
|
+
if (!fileOrDirNames[0].endsWith('.har')) {
|
|
23
|
+
return 'fail';
|
|
24
|
+
}
|
|
25
|
+
return 'pass';
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { AbsolutePath } from '../../core';
|
|
3
|
+
import { Check } from '../types';
|
|
4
|
+
|
|
5
|
+
export function createHarmonyDirExistsCheck(
|
|
6
|
+
packagePath: AbsolutePath,
|
|
7
|
+
hasNativeCode: boolean
|
|
8
|
+
): Check {
|
|
9
|
+
return {
|
|
10
|
+
checkIf: 'package_has_harmony_dir',
|
|
11
|
+
run: async () => {
|
|
12
|
+
const harmonyDirExist = fs.existsSync(
|
|
13
|
+
packagePath.copyWithNewSegment('harmony').getValue()
|
|
14
|
+
);
|
|
15
|
+
if (!hasNativeCode) {
|
|
16
|
+
return 'skip';
|
|
17
|
+
}
|
|
18
|
+
if (!harmonyDirExist) {
|
|
19
|
+
return 'fail';
|
|
20
|
+
}
|
|
21
|
+
return 'pass';
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Check } from '../types';
|
|
2
|
+
|
|
3
|
+
export function createNpmAndOhPackageVersionsAreEqualCheck(
|
|
4
|
+
npmPackageVersion: string,
|
|
5
|
+
ohPackageVersion: string
|
|
6
|
+
): Check {
|
|
7
|
+
return {
|
|
8
|
+
checkIf: 'npm_and_oh_package_versions_are_equal',
|
|
9
|
+
run: async () => {
|
|
10
|
+
return npmPackageVersion === ohPackageVersion
|
|
11
|
+
? 'pass'
|
|
12
|
+
: {
|
|
13
|
+
status: 'fail',
|
|
14
|
+
message: `expected OH package version (${ohPackageVersion}) to match NPM version (${npmPackageVersion})`,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Check } from '../types';
|
|
2
|
+
|
|
3
|
+
export function createOhPackageNameFollowsNamingConventionCheck(
|
|
4
|
+
npmPackageName: string,
|
|
5
|
+
ohPackageName: string
|
|
6
|
+
): Check {
|
|
7
|
+
const npmPackageNameInfo = getPackageNameInfo(npmPackageName);
|
|
8
|
+
return {
|
|
9
|
+
checkIf: 'oh_package_name_is_derived_from_npm_package_name',
|
|
10
|
+
run: async () => {
|
|
11
|
+
if (npmPackageNameInfo.organizationName) {
|
|
12
|
+
const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.organizationName}--${npmPackageNameInfo.unscopedName}`;
|
|
13
|
+
return expectedOHPackageName === ohPackageName
|
|
14
|
+
? 'pass'
|
|
15
|
+
: {
|
|
16
|
+
status: 'fail',
|
|
17
|
+
message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
|
|
18
|
+
};
|
|
19
|
+
} else {
|
|
20
|
+
const expectedOHPackageName = `@rnoh/${npmPackageNameInfo.unscopedName}`;
|
|
21
|
+
return expectedOHPackageName === ohPackageName
|
|
22
|
+
? 'pass'
|
|
23
|
+
: {
|
|
24
|
+
status: 'fail',
|
|
25
|
+
message: `expected '${expectedOHPackageName}', got: ${ohPackageName}`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type PackageNameInfo = {
|
|
33
|
+
organizationName: string | null;
|
|
34
|
+
unscopedName: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function getPackageNameInfo(packageName: string): PackageNameInfo {
|
|
38
|
+
if (packageName.startsWith('@') && packageName.includes('/')) {
|
|
39
|
+
const [part1, part2] = packageName.split('/');
|
|
40
|
+
return {
|
|
41
|
+
organizationName: part1.replace('@', ''),
|
|
42
|
+
unscopedName: part2,
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
return { organizationName: null, unscopedName: packageName };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CheckStatus = 'pass' | 'fail' | 'skip';
|
|
2
|
+
|
|
3
|
+
export type Check = {
|
|
4
|
+
checkIf: string;
|
|
5
|
+
run: () => Promise<CheckStatus | { status: CheckStatus; message: string }>;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type CheckResult = {
|
|
9
|
+
name: string;
|
|
10
|
+
status: CheckStatus;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import tmp from 'tmp';
|
|
3
|
+
import {
|
|
4
|
+
AbsolutePath,
|
|
5
|
+
DescriptiveError,
|
|
6
|
+
OHPackageJSON5,
|
|
7
|
+
PackageJSON,
|
|
8
|
+
} from '../core';
|
|
9
|
+
import {
|
|
10
|
+
createHarmonyDirContainsOnlyHarsCheck,
|
|
11
|
+
createHarmonyDirExistsCheck,
|
|
12
|
+
createOhPackageNameFollowsNamingConventionCheck,
|
|
13
|
+
createNpmAndOhPackageVersionsAreEqualCheck,
|
|
14
|
+
} from './checks';
|
|
15
|
+
import { Check, CheckStatus } from './types';
|
|
16
|
+
import { unpackTarGz } from '../io';
|
|
17
|
+
|
|
18
|
+
type StartProcessMessage = {
|
|
19
|
+
type: 'START_PROCESS';
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type FinishedCheckingMessage = {
|
|
24
|
+
type: 'FINISHED_CHECKING';
|
|
25
|
+
name: string;
|
|
26
|
+
status: CheckStatus;
|
|
27
|
+
message: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type VerificationMessage = StartProcessMessage | FinishedCheckingMessage;
|
|
31
|
+
|
|
32
|
+
export async function* verifyRNOHPackage({
|
|
33
|
+
npmPackagePath,
|
|
34
|
+
hasHarmonyCode,
|
|
35
|
+
checkNamesToSkip,
|
|
36
|
+
}: {
|
|
37
|
+
npmPackagePath: AbsolutePath;
|
|
38
|
+
hasHarmonyCode: boolean;
|
|
39
|
+
checkNamesToSkip: string[];
|
|
40
|
+
}): AsyncGenerator<VerificationMessage, void, unknown> {
|
|
41
|
+
const npmPackageJson = PackageJSON.fromProjectRootPath(
|
|
42
|
+
npmPackagePath,
|
|
43
|
+
npmPackagePath
|
|
44
|
+
);
|
|
45
|
+
const initialChecks: Check[] = [
|
|
46
|
+
createHarmonyDirExistsCheck(npmPackagePath, hasHarmonyCode),
|
|
47
|
+
createHarmonyDirContainsOnlyHarsCheck(npmPackagePath, hasHarmonyCode),
|
|
48
|
+
];
|
|
49
|
+
yield* runChecks(initialChecks, checkNamesToSkip);
|
|
50
|
+
if (hasHarmonyCode) {
|
|
51
|
+
const harPath = findHarPath(npmPackagePath);
|
|
52
|
+
if (!harPath) {
|
|
53
|
+
throw new DescriptiveError({
|
|
54
|
+
whatHappened: 'Attempted to verify har but no har was found',
|
|
55
|
+
whatCanUserDo: {
|
|
56
|
+
default: [
|
|
57
|
+
'Run this command without --no-harmony-code flag.',
|
|
58
|
+
'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.',
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const tmpDirPath = new AbsolutePath(tmp.dirSync().name);
|
|
64
|
+
yield {
|
|
65
|
+
type: 'START_PROCESS',
|
|
66
|
+
name: `Unpacking the har file to the tmpdir`,
|
|
67
|
+
};
|
|
68
|
+
await unpackTarGz(harPath, tmpDirPath);
|
|
69
|
+
const ohPackageJson5 = OHPackageJSON5.fromPath(
|
|
70
|
+
tmpDirPath.copyWithNewSegment('package', 'oh-package.json5')
|
|
71
|
+
);
|
|
72
|
+
const harChecks: Check[] = [
|
|
73
|
+
createOhPackageNameFollowsNamingConventionCheck(
|
|
74
|
+
npmPackageJson.name,
|
|
75
|
+
ohPackageJson5.name
|
|
76
|
+
),
|
|
77
|
+
createNpmAndOhPackageVersionsAreEqualCheck(
|
|
78
|
+
npmPackageJson.version,
|
|
79
|
+
ohPackageJson5.version
|
|
80
|
+
),
|
|
81
|
+
];
|
|
82
|
+
yield* runChecks(harChecks, checkNamesToSkip);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function* runChecks(
|
|
87
|
+
checks: Check[],
|
|
88
|
+
checkNamesToSkip: string[]
|
|
89
|
+
): AsyncGenerator<VerificationMessage, void, unknown> {
|
|
90
|
+
for (const { checkIf, run } of checks) {
|
|
91
|
+
if (checkNamesToSkip.includes(checkIf)) {
|
|
92
|
+
yield {
|
|
93
|
+
type: 'FINISHED_CHECKING',
|
|
94
|
+
name: checkIf,
|
|
95
|
+
status: 'skip' as CheckStatus,
|
|
96
|
+
message: '',
|
|
97
|
+
};
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const result = await run();
|
|
101
|
+
const status = typeof result === 'string' ? result : result.status;
|
|
102
|
+
const message = typeof result === 'string' ? '' : result.message;
|
|
103
|
+
yield { type: 'FINISHED_CHECKING', name: checkIf, status, message };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function findHarPath(packagePath: AbsolutePath): AbsolutePath | null {
|
|
108
|
+
const packageHarmonyPath = packagePath.copyWithNewSegment('harmony');
|
|
109
|
+
const fileOrDirNames = fs.readdirSync(packageHarmonyPath.getValue());
|
|
110
|
+
const harFilenames = fileOrDirNames.filter((fileOrDirName) =>
|
|
111
|
+
fileOrDirName.endsWith('.har')
|
|
112
|
+
);
|
|
113
|
+
if (harFilenames.length != 1) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return packageHarmonyPath.copyWithNewSegment(harFilenames[0]);
|
|
117
|
+
}
|