@react-native-oh/react-native-harmony-cli 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/assetResolver.js +74 -77
- package/dist/autolinking/Autolinking.js +179 -179
- package/dist/autolinking/JSON5Writer.js +61 -0
- package/dist/codegen/core/CodegenError.js +3 -23
- package/dist/codegen/core/EventUtils.js +3 -3
- package/dist/codegen/core/TypeAnnotationToTS.js +24 -28
- package/dist/codegen/core/UberSchema.js +57 -96
- package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +28 -41
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +27 -34
- package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +25 -33
- package/dist/codegen/generators/CppComponentCodeGenerator.js +23 -28
- package/dist/codegen/generators/LibGlueCodeGenerator.js +26 -29
- package/dist/codegen/generators/NativeModuleCodeGenerator.js +25 -30
- package/dist/codegen/generators/SharedComponentCodeGenerator.js +15 -15
- package/dist/codegen/generators/UberGeneratorV1.js +24 -23
- package/dist/codegen/generators/UberGeneratorV2.js +34 -35
- package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +50 -24
- package/dist/codegen/templates/BasePackageHTemplate.js +120 -21
- package/dist/codegen/templates/ComponentDescriptorHTemplate.js +53 -8
- package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +75 -27
- package/dist/codegen/templates/ComponentUtilsTSTemplate.js +162 -29
- package/dist/codegen/templates/IndexTSTemplate.js +37 -17
- package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +119 -24
- package/dist/codegen/templates/TurboModuleCppTemplate.js +38 -15
- package/dist/codegen/templates/TurboModuleHTemplate.js +32 -11
- package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +52 -19
- package/dist/commands/bundle-harmony.js +65 -138
- package/dist/commands/codegen-harmony.js +105 -165
- package/dist/commands/codegen-lib-harmony.js +76 -116
- package/dist/commands/create-metro-host-constants.js +18 -47
- package/dist/commands/init.js +537 -961
- package/dist/commands/link-harmony.js +33 -71
- package/dist/commands/pack-harmony.js +47 -108
- package/dist/commands/run-harmony.js +372 -518
- package/dist/commands/unpack-harmony.js +105 -198
- package/dist/commands/verify-package-harmony.js +54 -108
- package/dist/core/AbsolutePath.js +31 -47
- package/dist/core/CodegenConfig.js +24 -22
- package/dist/core/DescriptiveError.js +18 -37
- package/dist/core/FileSystem.js +14 -18
- package/dist/core/OHPackageJSON5.js +17 -23
- package/dist/core/PackageJSON.js +26 -42
- package/dist/core/ProjectDependenciesManager.js +40 -92
- package/dist/core/ValidationError.js +2 -22
- package/dist/core/fs.js +9 -6
- package/dist/index.js +1 -1
- package/dist/io/CliExecutor.js +46 -98
- package/dist/io/Logger.js +40 -46
- package/dist/io/RealFS.js +35 -88
- package/dist/io/TarGz.js +11 -8
- package/dist/io/__fixtures__.js +79 -141
- package/dist/io/fsUtils.js +13 -12
- package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +19 -47
- package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +13 -41
- package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +8 -38
- package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +22 -54
- package/dist/package-verifier/verify-package.js +55 -132
- package/dist/simulator/LaunchSimulator.js +224 -301
- package/harmony/rnoh-hvigor-plugin-0.3.0.tgz +0 -0
- package/jest.config.js +12 -12
- package/package.json +79 -78
- package/react-native.config.js +17 -17
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +2 -2
|
@@ -5,17 +5,6 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
var __assign = (this && this.__assign) || function () {
|
|
9
|
-
__assign = Object.assign || function(t) {
|
|
10
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
-
s = arguments[i];
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
}
|
|
15
|
-
return t;
|
|
16
|
-
};
|
|
17
|
-
return __assign.apply(this, arguments);
|
|
18
|
-
};
|
|
19
8
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
9
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
10
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -25,152 +14,172 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
14
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
15
|
});
|
|
27
16
|
};
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
31
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
32
|
-
function step(op) {
|
|
33
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
34
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
35
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
36
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
37
|
-
switch (op[0]) {
|
|
38
|
-
case 0: case 1: t = op; break;
|
|
39
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
40
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
41
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
42
|
-
default:
|
|
43
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
44
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
45
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
46
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
47
|
-
if (t[2]) _.ops.pop();
|
|
48
|
-
_.trys.pop(); continue;
|
|
49
|
-
}
|
|
50
|
-
op = body.call(thisArg, _);
|
|
51
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
52
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
53
|
-
}
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
19
|
};
|
|
55
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
21
|
exports.Autolinking = void 0;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
22
|
+
const json5_1 = __importDefault(require("json5"));
|
|
23
|
+
const core_1 = require("../core");
|
|
24
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
25
|
+
const case_1 = __importDefault(require("case"));
|
|
26
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
27
|
+
const JSON5Writer_1 = require("./JSON5Writer");
|
|
28
|
+
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
29
|
+
/*
|
|
30
|
+
* This file was generated by RNOH autolinking.
|
|
31
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
32
|
+
*/
|
|
33
|
+
import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
|
|
34
|
+
{{#libraries}}
|
|
35
|
+
import {{etsRNOHPackageClassName}} from '{{{ohPackageName}}}';
|
|
36
|
+
{{/libraries}}
|
|
37
|
+
|
|
38
|
+
export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
|
|
39
|
+
return [
|
|
40
|
+
{{#libraries}}
|
|
41
|
+
new {{etsRNOHPackageClassName}}(ctx),
|
|
42
|
+
{{/libraries}}
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
`.trimStart();
|
|
46
|
+
const CPP_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
47
|
+
/*
|
|
48
|
+
* This file was generated by RNOH autolinking.
|
|
49
|
+
* DO NOT modify it manually, your changes WILL be overwritten.
|
|
50
|
+
*/
|
|
51
|
+
// clang-format off
|
|
52
|
+
#pragma once
|
|
53
|
+
#include "RNOH/Package.h"
|
|
54
|
+
{{#libraries}}
|
|
55
|
+
#include "{{cppRNOHPackageClassName}}.h"
|
|
56
|
+
{{/libraries}}
|
|
57
|
+
|
|
58
|
+
std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
|
|
59
|
+
return {
|
|
60
|
+
{{#libraries}}
|
|
61
|
+
std::make_shared<rnoh::{{cppRNOHPackageClassName}}>(ctx),
|
|
62
|
+
{{/libraries}}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
`.trimStart();
|
|
66
|
+
const CMAKE_AUTOLINKING_TEMPLATE = `
|
|
67
|
+
# This file was generated by RNOH autolinking.
|
|
68
|
+
# DO NOT modify it manually, your changes WILL be overwritten.
|
|
69
|
+
cmake_minimum_required(VERSION 3.5)
|
|
70
|
+
|
|
71
|
+
# @actor RNOH_APP
|
|
72
|
+
function(autolink_libraries target)
|
|
73
|
+
{{#libraries}}
|
|
74
|
+
add_subdirectory("\${OH_MODULES_DIR}/{{{ohPackageName}}}/src/main/cpp" ./{{cmakeLibraryTargetName}})
|
|
75
|
+
{{/libraries}}
|
|
76
|
+
|
|
77
|
+
set(AUTOLINKED_LIBRARIES
|
|
78
|
+
{{#libraries}}
|
|
79
|
+
{{cmakeLibraryTargetName}}
|
|
80
|
+
{{/libraries}}
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
foreach(lib \${AUTOLINKED_LIBRARIES})
|
|
84
|
+
target_link_libraries(\${target} PUBLIC \${lib})
|
|
85
|
+
endforeach()
|
|
86
|
+
endfunction()
|
|
87
|
+
`.trimStart();
|
|
88
|
+
class Autolinking {
|
|
89
|
+
constructor(fs, logger) {
|
|
67
90
|
this.fs = fs;
|
|
68
91
|
this.logger = logger;
|
|
69
92
|
}
|
|
70
|
-
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var harmonyProjectPath, nodeModuleHarPaths, autolinkableLibraries, projectRootPath, skippedLibraryNpmPackageNames, ohPackagePath, ohPackageContent, cppRNOHPackagesFactoryPath, cmakeAutolinkingPath;
|
|
93
|
+
prepareInput(config) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
95
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
harFilePaths.length !== 1) {
|
|
111
|
-
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
var autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
115
|
-
autolinkableLibraries.push({
|
|
116
|
-
npmPackageName: packageJson.name,
|
|
117
|
-
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
118
|
-
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
119
|
-
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
120
|
-
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
121
|
-
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
122
|
-
.relativeTo(harmonyProjectPath)
|
|
123
|
-
.toString(),
|
|
124
|
-
});
|
|
125
|
-
})];
|
|
126
|
-
case 1:
|
|
127
|
-
_b.sent();
|
|
128
|
-
ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
129
|
-
return [4 /*yield*/, this.fs.readText(ohPackagePath)];
|
|
130
|
-
case 2:
|
|
131
|
-
ohPackageContent = _b.sent();
|
|
132
|
-
cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
|
|
133
|
-
cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
|
|
134
|
-
return [2 /*return*/, {
|
|
135
|
-
projectRootPath: projectRootPath,
|
|
136
|
-
skippedLibraryNpmPackageNames: skippedLibraryNpmPackageNames,
|
|
137
|
-
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
|
|
138
|
-
cppRNOHPackagesFactoryPath: cppRNOHPackagesFactoryPath,
|
|
139
|
-
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
140
|
-
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
141
|
-
autolinkableLibraries: autolinkableLibraries,
|
|
142
|
-
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map(function (p) {
|
|
143
|
-
return p.relativeTo(harmonyProjectPath).toString();
|
|
144
|
-
}),
|
|
145
|
-
}];
|
|
96
|
+
if (config.includedNpmPackageNames.size > 0 &&
|
|
97
|
+
config.excludedNpmPackageNames.size > 0) {
|
|
98
|
+
throw new core_1.DescriptiveError({
|
|
99
|
+
whatHappened: 'Tried to exclude and include npm packages.',
|
|
100
|
+
whatCanUserDo: ['Include or exclude npm packages, but not both.'],
|
|
101
|
+
extraData: {
|
|
102
|
+
includedNpmPackageNamesCount: config.includedNpmPackageNames.size,
|
|
103
|
+
excludedNpmPackageNamesCount: config.excludedNpmPackageNames.size,
|
|
104
|
+
includedNpmPackageNames: config.includedNpmPackageNames,
|
|
105
|
+
excludedNpmPackageNames: config.excludedNpmPackageNames,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const harmonyProjectPath = (_a = config.harmonyProjectPath) !== null && _a !== void 0 ? _a : new core_1.AbsolutePath('./');
|
|
110
|
+
const nodeModuleHarPaths = [];
|
|
111
|
+
const autolinkableLibraries = [];
|
|
112
|
+
const projectRootPath = config.nodeModulesPath.copyWithNewSegment('..');
|
|
113
|
+
const skippedLibraryNpmPackageNames = [];
|
|
114
|
+
yield new core_1.ProjectDependenciesManager(this.fs, projectRootPath).forEachAsync((dependency) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const harFilePaths = dependency.getHarFilePaths();
|
|
117
|
+
if (harFilePaths.length === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
nodeModuleHarPaths.push(...harFilePaths);
|
|
121
|
+
const packageJson = dependency.readPackageJSON();
|
|
122
|
+
const providedAutolinkingConfig = (_a = packageJson.harmony) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
123
|
+
if (providedAutolinkingConfig === undefined ||
|
|
124
|
+
providedAutolinkingConfig === null ||
|
|
125
|
+
(config.excludedNpmPackageNames.has(packageJson.name) &&
|
|
126
|
+
config.excludedNpmPackageNames.size > 0) ||
|
|
127
|
+
(!config.includedNpmPackageNames.has(packageJson.name) &&
|
|
128
|
+
config.includedNpmPackageNames.size > 0) ||
|
|
129
|
+
harFilePaths.length !== 1) {
|
|
130
|
+
skippedLibraryNpmPackageNames.push(packageJson.name);
|
|
131
|
+
return;
|
|
146
132
|
}
|
|
133
|
+
const autolinkingConfig = providedAutolinkingConfig === true ? {} : providedAutolinkingConfig;
|
|
134
|
+
autolinkableLibraries.push({
|
|
135
|
+
npmPackageName: packageJson.name,
|
|
136
|
+
etsRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.etsPackageClassName,
|
|
137
|
+
cppRNOHPackageClassName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cppPackageClassName,
|
|
138
|
+
cmakeLibraryTargetName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.cmakeLibraryTargetName,
|
|
139
|
+
ohPackageName: autolinkingConfig === null || autolinkingConfig === void 0 ? void 0 : autolinkingConfig.ohPackageName,
|
|
140
|
+
harFilePathRelativeToHarmony: harFilePaths[0]
|
|
141
|
+
.relativeTo(harmonyProjectPath)
|
|
142
|
+
.toString(),
|
|
143
|
+
});
|
|
147
144
|
});
|
|
145
|
+
const ohPackagePath = harmonyProjectPath.copyWithNewSegment(config.ohPackagePathRelativeToHarmony);
|
|
146
|
+
const ohPackageContent = yield this.fs.readText(ohPackagePath);
|
|
147
|
+
const cppRNOHPackagesFactoryPath = harmonyProjectPath.copyWithNewSegment(config.cppRNOHPackagesFactoryPathRelativeToHarmony);
|
|
148
|
+
const cmakeAutolinkingPath = harmonyProjectPath.copyWithNewSegment(config.cmakeAutolinkPathRelativeToHarmony);
|
|
149
|
+
return {
|
|
150
|
+
projectRootPath,
|
|
151
|
+
skippedLibraryNpmPackageNames,
|
|
152
|
+
etsRNOHPackagesFactoryPath: harmonyProjectPath.copyWithNewSegment(config.etsRNOHPackagesFactoryPathRelativeToHarmony),
|
|
153
|
+
cppRNOHPackagesFactoryPath,
|
|
154
|
+
cmakeAutolinkingPath: cmakeAutolinkingPath,
|
|
155
|
+
ohPackagePathAndContent: [ohPackagePath, ohPackageContent],
|
|
156
|
+
autolinkableLibraries,
|
|
157
|
+
nodeModuleHarFilePathsRelativeToHarmony: nodeModuleHarPaths.map((p) => p.relativeTo(harmonyProjectPath).toString()),
|
|
158
|
+
};
|
|
148
159
|
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var autolinkableLibraries = input.autolinkableLibraries.map(function (lib) {
|
|
160
|
+
}
|
|
161
|
+
evaluate(input) {
|
|
162
|
+
const autolinkableLibraries = input.autolinkableLibraries.map((lib) => {
|
|
153
163
|
var _a, _b, _c, _d;
|
|
154
|
-
return
|
|
164
|
+
return Object.assign(Object.assign({}, lib), { etsRNOHPackageClassName: (_a = lib.etsRNOHPackageClassName) !== null && _a !== void 0 ? _a : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cppRNOHPackageClassName: (_b = lib.cppRNOHPackageClassName) !== null && _b !== void 0 ? _b : this.npmPackageNameToRNOHPackageClassName(lib.npmPackageName), cmakeLibraryTargetName: (_c = lib.cmakeLibraryTargetName) !== null && _c !== void 0 ? _c : this.npmPackageNameToCMakeLibraryTargetName(lib.npmPackageName), ohPackageName: (_d = lib.ohPackageName) !== null && _d !== void 0 ? _d : this.npmPackageNameToOHPackageName(lib.npmPackageName) });
|
|
155
165
|
});
|
|
156
|
-
autolinkableLibraries.sort(
|
|
166
|
+
autolinkableLibraries.sort((a, b) => {
|
|
157
167
|
if (a.npmPackageName < b.npmPackageName)
|
|
158
168
|
return -1;
|
|
159
169
|
if (a.npmPackageName > b.npmPackageName)
|
|
160
170
|
return 1;
|
|
161
171
|
return 0;
|
|
162
172
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Object.entries(ohPackage.dependencies).forEach(
|
|
167
|
-
var name = _a[0], dependencySpecifier = _a[1];
|
|
173
|
+
const ohPackage = json5_1.default.parse(input.ohPackagePathAndContent[1]);
|
|
174
|
+
const autolinkableHarFilePathsRelativeToHarmony = autolinkableLibraries.map((lib) => lib.harFilePathRelativeToHarmony);
|
|
175
|
+
const unmanagedNativeDependencySpecifierByName = {};
|
|
176
|
+
Object.entries(ohPackage.dependencies).forEach(([name, dependencySpecifier]) => {
|
|
168
177
|
if (!(dependencySpecifier.includes('file:') &&
|
|
169
178
|
dependencySpecifier.includes('node_modules'))) {
|
|
170
179
|
unmanagedNativeDependencySpecifierByName[name] = dependencySpecifier;
|
|
171
180
|
}
|
|
172
181
|
else {
|
|
173
|
-
|
|
182
|
+
const harFilePathRelativeToHarmony = dependencySpecifier.replace('file:', '');
|
|
174
183
|
if (!autolinkableHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony)) &&
|
|
175
184
|
input.nodeModuleHarFilePathsRelativeToHarmony.includes(node_path_1.default.normalize(harFilePathRelativeToHarmony))) {
|
|
176
185
|
unmanagedNativeDependencySpecifierByName[name] =
|
|
@@ -178,15 +187,14 @@ var Autolinking = /** @class */ (function () {
|
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
});
|
|
181
|
-
|
|
182
|
-
for (
|
|
183
|
-
var library = autolinkableLibraries_1[_i];
|
|
190
|
+
const managedNativeDependencySpecifierByName = {};
|
|
191
|
+
for (const library of autolinkableLibraries) {
|
|
184
192
|
managedNativeDependencySpecifierByName[library.ohPackageName] =
|
|
185
|
-
|
|
193
|
+
`file:${library.harFilePathRelativeToHarmony}`.split(node_path_1.default.sep).join('/');
|
|
186
194
|
}
|
|
187
195
|
return {
|
|
188
196
|
skippedLibraryNpmPackageNames: input.skippedLibraryNpmPackageNames,
|
|
189
|
-
linkedLibraryNpmPackageNames: autolinkableLibraries.map(
|
|
197
|
+
linkedLibraryNpmPackageNames: autolinkableLibraries.map((lib) => lib.npmPackageName),
|
|
190
198
|
projectRootPath: input.projectRootPath,
|
|
191
199
|
cppRNOHPackagesFactoryPathAndContent: [
|
|
192
200
|
input.cppRNOHPackagesFactoryPath,
|
|
@@ -208,70 +216,62 @@ var Autolinking = /** @class */ (function () {
|
|
|
208
216
|
],
|
|
209
217
|
ohPackagePathAndContent: [
|
|
210
218
|
input.ohPackagePathAndContent[0],
|
|
211
|
-
|
|
219
|
+
JSON5Writer_1.JSON5Writer.updateDependenciesWithFallback(input.ohPackagePathAndContent[1], Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName)),
|
|
212
220
|
],
|
|
213
221
|
};
|
|
214
|
-
}
|
|
215
|
-
|
|
222
|
+
}
|
|
223
|
+
npmPackageNameToRNOHPackageClassName(fullNpmPackageName) {
|
|
216
224
|
if (fullNpmPackageName.startsWith('@')) {
|
|
217
|
-
|
|
225
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
218
226
|
.replace('@', '')
|
|
219
|
-
.split('/')
|
|
227
|
+
.split('/');
|
|
220
228
|
return case_1.default.pascal(scopeName) + case_1.default.pascal(packageName) + 'Package';
|
|
221
229
|
}
|
|
222
230
|
return case_1.default.pascal(fullNpmPackageName) + 'Package';
|
|
223
|
-
}
|
|
224
|
-
|
|
231
|
+
}
|
|
232
|
+
npmPackageNameToCMakeLibraryTargetName(fullNpmPackageName) {
|
|
225
233
|
if (fullNpmPackageName.startsWith('@')) {
|
|
226
|
-
|
|
234
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
227
235
|
.replace('@', '')
|
|
228
|
-
.split('/')
|
|
236
|
+
.split('/');
|
|
229
237
|
return 'rnoh__' + case_1.default.snake(scopeName) + '__' + case_1.default.snake(packageName);
|
|
230
238
|
}
|
|
231
239
|
return 'rnoh__' + case_1.default.snake(fullNpmPackageName);
|
|
232
|
-
}
|
|
233
|
-
|
|
240
|
+
}
|
|
241
|
+
npmPackageNameToOHPackageName(fullNpmPackageName) {
|
|
234
242
|
if (fullNpmPackageName.startsWith('@')) {
|
|
235
|
-
|
|
243
|
+
const [scopeName, packageName] = fullNpmPackageName
|
|
236
244
|
.replace('@', '')
|
|
237
|
-
.split('/')
|
|
245
|
+
.split('/');
|
|
238
246
|
return '@rnoh/' + case_1.default.kebab(scopeName) + '--' + case_1.default.kebab(packageName);
|
|
239
247
|
}
|
|
240
248
|
return '@rnoh/' + case_1.default.kebab(fullNpmPackageName);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var pathAndContentPairs = [];
|
|
249
|
+
}
|
|
250
|
+
saveAndLogOutput(output) {
|
|
251
|
+
const pathAndContentPairs = [];
|
|
245
252
|
pathAndContentPairs.push(output.etsRNOHPackagesFactoryPathAndContent);
|
|
246
253
|
pathAndContentPairs.push(output.cppRNOHPackagesFactoryPathAndContent);
|
|
247
254
|
pathAndContentPairs.push(output.cmakeAutolinkingPathAndContent);
|
|
248
255
|
pathAndContentPairs.push(output.ohPackagePathAndContent);
|
|
249
|
-
pathAndContentPairs.forEach(
|
|
250
|
-
|
|
251
|
-
_this.fs.writeTextSync(path, content);
|
|
256
|
+
pathAndContentPairs.forEach(([path, content]) => {
|
|
257
|
+
this.fs.writeTextSync(path, content);
|
|
252
258
|
});
|
|
253
|
-
output.linkedLibraryNpmPackageNames.forEach(
|
|
254
|
-
|
|
259
|
+
output.linkedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
260
|
+
this.logger.debug((styles) => `[${styles.green(styles.bold('link'))}] ${npmPackageName}`);
|
|
255
261
|
});
|
|
256
|
-
output.skippedLibraryNpmPackageNames.forEach(
|
|
257
|
-
|
|
262
|
+
output.skippedLibraryNpmPackageNames.forEach((npmPackageName) => {
|
|
263
|
+
this.logger.debug((styles) => `[${styles.yellow(styles.bold('skip'))}] ${npmPackageName}`);
|
|
258
264
|
});
|
|
259
|
-
this.logger.debug(
|
|
260
|
-
|
|
261
|
-
.map(
|
|
262
|
-
var path = _a[0];
|
|
263
|
-
return path.relativeTo(output.projectRootPath).toString();
|
|
264
|
-
})
|
|
265
|
+
this.logger.debug(() => '');
|
|
266
|
+
const sortedPathsRelativeToRoot = pathAndContentPairs
|
|
267
|
+
.map(([path]) => path.relativeTo(output.projectRootPath).toString())
|
|
265
268
|
.sort();
|
|
266
|
-
sortedPathsRelativeToRoot.forEach(
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
this.logger.debug(function () { return ''; });
|
|
270
|
-
this.logger.info(function (styles) {
|
|
271
|
-
return "updated ".concat(styles.green(styles.bold(sortedPathsRelativeToRoot.length)), " file(s), linked ").concat(styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length)), " libraries, skipped ").concat(styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length)), " libraries");
|
|
269
|
+
sortedPathsRelativeToRoot.forEach((pathStr) => {
|
|
270
|
+
this.logger.debug((styles) => styles.gray(`• ${pathStr}`));
|
|
272
271
|
});
|
|
273
|
-
this.logger.debug(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
272
|
+
this.logger.debug(() => '');
|
|
273
|
+
this.logger.info((styles) => `updated ${styles.green(styles.bold(sortedPathsRelativeToRoot.length))} file(s), linked ${styles.green(styles.bold(output.linkedLibraryNpmPackageNames.length))} libraries, skipped ${styles.yellow(styles.bold(output.skippedLibraryNpmPackageNames.length))} libraries`);
|
|
274
|
+
this.logger.debug(() => '');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
277
|
exports.Autolinking = Autolinking;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JSON5Writer = void 0;
|
|
13
|
+
const json5_1 = __importDefault(require("json5"));
|
|
14
|
+
/**
|
|
15
|
+
* A utility class for modifying JSON5 content while preserving comments and formatting.
|
|
16
|
+
* Uses json5-writer's AST-based transformation to maintain the original structure.
|
|
17
|
+
*/
|
|
18
|
+
class JSON5Writer {
|
|
19
|
+
/**
|
|
20
|
+
* Updates the dependencies in a JSON5 string while preserving comments and formatting.
|
|
21
|
+
*
|
|
22
|
+
* @param content - The original JSON5 content
|
|
23
|
+
* @param newDependencies - The new dependencies object to set
|
|
24
|
+
* @returns The modified JSON5 content with preserved comments
|
|
25
|
+
*/
|
|
26
|
+
static updateDependencies(content, newDependencies) {
|
|
27
|
+
const json5Writer = require('json5-writer');
|
|
28
|
+
// Parse the original content to get all fields
|
|
29
|
+
const parsed = json5_1.default.parse(content);
|
|
30
|
+
// Create the new object with updated dependencies
|
|
31
|
+
const newObject = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
|
|
32
|
+
// Load the original content into json5-writer to preserve comments
|
|
33
|
+
const writer = json5Writer.load(content);
|
|
34
|
+
// Write the new object, which will preserve comments
|
|
35
|
+
writer.write(newObject);
|
|
36
|
+
// Return the modified source with JSON5-style formatting
|
|
37
|
+
// Use double quotes for both keys and values, and trailing commas
|
|
38
|
+
// quoteKeys: true ensures keys with special characters (like @, /, -) are properly quoted
|
|
39
|
+
return writer.toSource({ quote: 'double', quoteKeys: true, trailingComma: true }) + '\n';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Updates dependencies with fallback to standard JSON5 stringify if preservation fails.
|
|
43
|
+
* This ensures backward compatibility.
|
|
44
|
+
*
|
|
45
|
+
* @param content - The original JSON5 content
|
|
46
|
+
* @param newDependencies - The new dependencies object to set
|
|
47
|
+
* @returns The modified JSON5 content
|
|
48
|
+
*/
|
|
49
|
+
static updateDependenciesWithFallback(content, newDependencies) {
|
|
50
|
+
try {
|
|
51
|
+
return this.updateDependencies(content, newDependencies);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// Fallback to JSON5 stringify if AST transformation fails
|
|
55
|
+
const parsed = json5_1.default.parse(content);
|
|
56
|
+
const result = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
|
|
57
|
+
return json5_1.default.stringify(result, { space: 2, quote: '"' }) + '\n';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.JSON5Writer = JSON5Writer;
|
|
@@ -5,29 +5,9 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
var __extends = (this && this.__extends) || (function () {
|
|
9
|
-
var extendStatics = function (d, b) {
|
|
10
|
-
extendStatics = Object.setPrototypeOf ||
|
|
11
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
12
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
13
|
-
return extendStatics(d, b);
|
|
14
|
-
};
|
|
15
|
-
return function (d, b) {
|
|
16
|
-
if (typeof b !== "function" && b !== null)
|
|
17
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
18
|
-
extendStatics(d, b);
|
|
19
|
-
function __() { this.constructor = d; }
|
|
20
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
-
};
|
|
22
|
-
})();
|
|
23
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
9
|
exports.CodegenError = void 0;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function CodegenError() {
|
|
29
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
-
}
|
|
31
|
-
return CodegenError;
|
|
32
|
-
}(core_1.DescriptiveError));
|
|
10
|
+
const core_1 = require("../../core");
|
|
11
|
+
class CodegenError extends core_1.DescriptiveError {
|
|
12
|
+
}
|
|
33
13
|
exports.CodegenError = CodegenError;
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createEventNameFromEventHandlerName = createEventNameFromEventHandlerName;
|
|
10
|
-
|
|
10
|
+
const CodegenError_1 = require("./CodegenError");
|
|
11
11
|
function createEventNameFromEventHandlerName(eventHandlerName) {
|
|
12
|
-
|
|
12
|
+
const eventName = eventHandlerName.replace('on', '');
|
|
13
13
|
if (eventName.length === 0) {
|
|
14
14
|
throw new CodegenError_1.CodegenError({
|
|
15
|
-
whatHappened:
|
|
15
|
+
whatHappened: `Received invalid event handler name: ${eventHandlerName}`,
|
|
16
16
|
whatCanUserDo: [
|
|
17
17
|
'Change your event listener name to match naming convention "onEventName" e.g. "onPress"',
|
|
18
18
|
],
|