@expo-harmony/cli 55.0.26-harmony.1 → 55.0.26-harmony.10

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.
Files changed (185) hide show
  1. package/README.md +87 -38
  2. package/build/args.d.ts +19 -0
  3. package/build/args.js +27 -0
  4. package/build/bin/expo-harmony.d.ts +2 -0
  5. package/build/bin/expo-harmony.js +1 -1
  6. package/build/buildHap/build.d.ts +18 -0
  7. package/build/buildHap/build.js +38 -0
  8. package/build/buildHap/index.d.ts +2 -0
  9. package/build/buildHap/index.js +19 -0
  10. package/build/buildHap/options.d.ts +7 -0
  11. package/build/buildHap/options.js +30 -0
  12. package/build/cli.d.ts +3 -0
  13. package/build/cli.js +40 -0
  14. package/build/command.d.ts +9 -0
  15. package/build/command.js +20 -0
  16. package/build/development/manifest.d.ts +1 -0
  17. package/build/development/manifest.js +100 -0
  18. package/build/development/protocol.d.ts +2 -0
  19. package/build/development/protocol.js +26 -0
  20. package/build/development/session.d.ts +5 -0
  21. package/build/development/session.js +66 -0
  22. package/build/doctor/doctor.d.ts +20 -0
  23. package/build/doctor/doctor.js +226 -0
  24. package/build/doctor/index.d.ts +2 -0
  25. package/build/doctor/index.js +16 -0
  26. package/build/doctor/options.d.ts +5 -0
  27. package/build/doctor/options.js +15 -0
  28. package/build/entry.d.ts +2 -0
  29. package/build/entry.js +47 -0
  30. package/build/errors.d.ts +12 -0
  31. package/build/errors.js +16 -0
  32. package/build/expo.d.ts +19 -0
  33. package/build/expo.js +53 -0
  34. package/build/exportEmbed/export.d.ts +18 -0
  35. package/build/exportEmbed/export.js +124 -0
  36. package/build/exportEmbed/index.d.ts +2 -0
  37. package/build/exportEmbed/index.js +19 -0
  38. package/build/exportEmbed/manifest.d.ts +44 -0
  39. package/build/exportEmbed/manifest.js +171 -0
  40. package/build/exportEmbed/options.d.ts +7 -0
  41. package/build/exportEmbed/options.js +22 -0
  42. package/build/file.d.ts +10 -0
  43. package/build/file.js +110 -0
  44. package/build/help.d.ts +1 -0
  45. package/build/help.js +44 -0
  46. package/build/index.d.ts +14 -0
  47. package/build/index.js +6 -5
  48. package/build/internal/development.d.ts +1 -0
  49. package/build/internal/development.js +8 -0
  50. package/build/internal/export.d.ts +1 -0
  51. package/build/internal/export.js +80 -0
  52. package/build/internal/prebuild.d.ts +3 -0
  53. package/build/internal/prebuild.js +9 -0
  54. package/build/log.d.ts +4 -0
  55. package/build/log.js +6 -0
  56. package/build/modules/index.d.ts +2 -0
  57. package/build/modules/index.js +16 -0
  58. package/build/modules/modules.d.ts +42 -0
  59. package/build/modules/modules.js +84 -0
  60. package/build/modules/options.d.ts +10 -0
  61. package/build/modules/options.js +45 -0
  62. package/build/native/bare.d.ts +4 -0
  63. package/build/native/bare.js +130 -0
  64. package/build/native/build.d.ts +15 -0
  65. package/build/native/build.js +69 -0
  66. package/build/native/cache.d.ts +11 -0
  67. package/build/native/cache.js +73 -0
  68. package/build/native/hvigor.d.ts +3 -0
  69. package/build/native/hvigor.js +83 -0
  70. package/build/native/install.d.ts +5 -0
  71. package/build/native/install.js +13 -0
  72. package/build/native/prepareProject.d.ts +11 -0
  73. package/build/native/prepareProject.js +68 -0
  74. package/build/native/project.d.ts +8 -0
  75. package/build/native/project.js +58 -0
  76. package/build/native/toolchain.d.ts +16 -0
  77. package/build/native/toolchain.js +172 -0
  78. package/build/native/types.d.ts +47 -0
  79. package/build/native/types.js +2 -0
  80. package/build/path.d.ts +4 -0
  81. package/build/path.js +27 -0
  82. package/build/prebuild/check.d.ts +10 -0
  83. package/build/prebuild/check.js +151 -0
  84. package/build/prebuild/clean.d.ts +2 -0
  85. package/build/prebuild/clean.js +50 -0
  86. package/build/prebuild/index.d.ts +2 -0
  87. package/build/prebuild/index.js +51 -0
  88. package/build/prebuild/options.d.ts +10 -0
  89. package/build/prebuild/options.js +50 -0
  90. package/build/prebuild/prebuild.d.ts +6 -0
  91. package/build/prebuild/prebuild.js +70 -0
  92. package/build/prebuild/template.d.ts +8 -0
  93. package/build/prebuild/template.js +86 -0
  94. package/build/process.d.ts +41 -0
  95. package/build/process.js +324 -0
  96. package/build/profile.d.ts +1 -0
  97. package/build/profile.js +12 -0
  98. package/build/project.d.ts +2 -0
  99. package/build/project.js +23 -0
  100. package/build/projectLock.d.ts +2 -0
  101. package/build/projectLock.js +185 -0
  102. package/build/run/devices.d.ts +29 -0
  103. package/build/run/devices.js +216 -0
  104. package/build/run/emulators.d.ts +13 -0
  105. package/build/run/emulators.js +82 -0
  106. package/build/run/index.d.ts +2 -0
  107. package/build/run/index.js +25 -0
  108. package/build/run/metro.d.ts +21 -0
  109. package/build/run/metro.js +162 -0
  110. package/build/run/options.d.ts +14 -0
  111. package/build/run/options.js +62 -0
  112. package/build/run/run.d.ts +46 -0
  113. package/build/run/run.js +135 -0
  114. package/build/runtime/config.d.ts +35 -0
  115. package/build/runtime/config.js +118 -0
  116. package/build/runtime/contract.d.ts +5 -0
  117. package/build/runtime/contract.js +108 -0
  118. package/build/runtime/fingerprint.d.ts +1 -0
  119. package/build/runtime/fingerprint.js +44 -0
  120. package/build/runtime/index.d.ts +2 -0
  121. package/build/runtime/index.js +50 -0
  122. package/build/start/index.d.ts +2 -0
  123. package/build/start/index.js +38 -0
  124. package/build/start/options.d.ts +9 -0
  125. package/build/start/options.js +38 -0
  126. package/build/updates/export.d.ts +14 -0
  127. package/build/updates/export.js +46 -0
  128. package/build/updates/index.d.ts +2 -0
  129. package/build/updates/index.js +96 -0
  130. package/build/upstream.d.ts +9 -0
  131. package/build/upstream.js +17 -0
  132. package/package.json +21 -5
  133. package/src/bin/expo-harmony.ts +2 -2
  134. package/src/buildHap/build.ts +13 -105
  135. package/src/buildHap/index.ts +19 -0
  136. package/src/cli.ts +27 -225
  137. package/src/command.ts +24 -0
  138. package/src/development/manifest.ts +106 -0
  139. package/src/development/protocol.ts +37 -0
  140. package/src/development/session.ts +83 -0
  141. package/src/doctor/doctor.ts +67 -62
  142. package/src/doctor/index.ts +16 -0
  143. package/src/exportEmbed/export.ts +73 -72
  144. package/src/exportEmbed/index.ts +17 -0
  145. package/src/file.ts +20 -11
  146. package/src/help.ts +41 -0
  147. package/src/index.ts +5 -3
  148. package/src/internal/development.ts +8 -0
  149. package/src/internal/export.ts +82 -0
  150. package/src/internal/prebuild.ts +3 -0
  151. package/src/log.ts +5 -0
  152. package/src/modules/index.ts +16 -0
  153. package/src/native/bare.ts +145 -0
  154. package/src/native/build.ts +83 -0
  155. package/src/{run → native}/cache.ts +10 -9
  156. package/src/native/hvigor.ts +88 -0
  157. package/src/native/install.ts +17 -0
  158. package/src/native/prepareProject.ts +99 -0
  159. package/src/native/project.ts +88 -0
  160. package/src/{tools.ts → native/toolchain.ts} +38 -140
  161. package/src/native/types.ts +44 -0
  162. package/src/prebuild/check.ts +56 -31
  163. package/src/prebuild/clean.ts +3 -3
  164. package/src/prebuild/index.ts +56 -0
  165. package/src/prebuild/prebuild.ts +11 -1
  166. package/src/prebuild/template.ts +2 -2
  167. package/src/process.ts +175 -64
  168. package/src/profile.ts +13 -0
  169. package/src/projectLock.ts +9 -1
  170. package/src/run/devices.ts +16 -11
  171. package/src/run/emulators.ts +4 -6
  172. package/src/run/index.ts +25 -0
  173. package/src/run/metro.ts +10 -1
  174. package/src/run/options.ts +2 -0
  175. package/src/run/run.ts +63 -129
  176. package/src/runtime/config.ts +150 -0
  177. package/src/runtime/contract.ts +165 -0
  178. package/src/runtime/fingerprint.ts +39 -0
  179. package/src/runtime/index.ts +54 -0
  180. package/src/start/index.ts +37 -0
  181. package/src/start/options.ts +12 -0
  182. package/src/updates/export.ts +60 -0
  183. package/src/updates/index.ts +89 -0
  184. package/src/buildHap/common.ts +0 -145
  185. package/src/run/install.ts +0 -41
@@ -0,0 +1,42 @@
1
+ import { type BuildType, type Diagnostic, type ModuleDescriptor, type ModuleSource } from '@expo-harmony/expo-modules-autolinking';
2
+ import type { ModulesAction } from './options';
3
+ interface ModulesCommandOptions {
4
+ action: ModulesAction;
5
+ nativeModulesDir?: string;
6
+ packageName?: string;
7
+ variant?: BuildType;
8
+ }
9
+ interface ListedModule {
10
+ packageName: string;
11
+ packageVersion: string;
12
+ source: ModuleSource;
13
+ supportsHarmony: boolean;
14
+ }
15
+ interface ModulesListResult {
16
+ action: 'list';
17
+ duplicates: ReadonlyArray<{
18
+ packageName: string;
19
+ revisions: ReadonlyArray<{
20
+ path: string;
21
+ version: string;
22
+ }>;
23
+ }>;
24
+ missingIncludes: ReadonlyArray<string>;
25
+ modules: ReadonlyArray<ListedModule>;
26
+ ok: boolean;
27
+ }
28
+ interface ModulesInspectResult {
29
+ action: 'inspect';
30
+ modules: ReadonlyArray<ModuleDescriptor>;
31
+ ok: boolean;
32
+ }
33
+ interface ModulesVerifyResult {
34
+ action: 'verify';
35
+ diagnostics: ReadonlyArray<Diagnostic>;
36
+ modules: ReadonlyArray<ModuleDescriptor>;
37
+ ok: boolean;
38
+ }
39
+ export type ModulesCommandResult = ModulesInspectResult | ModulesListResult | ModulesVerifyResult;
40
+ declare function runModulesCommandAsync(projectRoot: string, options: ModulesCommandOptions): Promise<ModulesCommandResult>;
41
+ declare function formatModulesResult(result: ModulesCommandResult): string;
42
+ export { formatModulesResult, runModulesCommandAsync };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatModulesResult = formatModulesResult;
4
+ exports.runModulesCommandAsync = runModulesCommandAsync;
5
+ const expo_modules_autolinking_1 = require("@expo-harmony/expo-modules-autolinking");
6
+ const errors_1 = require("../errors");
7
+ function apiOptions(projectRoot, options) {
8
+ return {
9
+ projectRoot,
10
+ platform: 'harmony',
11
+ ...(options.nativeModulesDir === undefined ? {} : { nativeModulesDir: options.nativeModulesDir }),
12
+ ...(options.variant === undefined ? {} : { buildType: options.variant }),
13
+ };
14
+ }
15
+ async function runModulesCommandAsync(projectRoot, options) {
16
+ const shared = apiOptions(projectRoot, options);
17
+ if (options.action === 'list') {
18
+ const result = await (0, expo_modules_autolinking_1.searchModulesAsync)(shared);
19
+ return {
20
+ action: 'list',
21
+ duplicates: result.duplicates,
22
+ missingIncludes: result.missingIncludes,
23
+ modules: result.modules.map(module => ({
24
+ packageName: module.packageName,
25
+ packageVersion: module.packageVersion,
26
+ source: module.source,
27
+ supportsHarmony: module.supportsHarmony,
28
+ })),
29
+ ok: result.missingIncludes.length === 0,
30
+ };
31
+ }
32
+ if (options.action === 'inspect') {
33
+ const modules = await (0, expo_modules_autolinking_1.resolveModulesAsync)(shared);
34
+ const selected = options.packageName === undefined
35
+ ? modules
36
+ : modules.filter(module => module.packageName === options.packageName);
37
+ if (options.packageName !== undefined && selected.length === 0) {
38
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_MODULE_NOT_FOUND', `Harmony module '${options.packageName}' was not discovered. Run 'expo-harmony modules list' to inspect candidates.`, { operation: 'modules-inspect' });
39
+ }
40
+ return { action: 'inspect', modules: selected, ok: true };
41
+ }
42
+ const result = await (0, expo_modules_autolinking_1.verifyModulesAsync)(shared);
43
+ return {
44
+ action: 'verify',
45
+ diagnostics: result.diagnostics,
46
+ modules: result.modules,
47
+ ok: result.valid,
48
+ };
49
+ }
50
+ function formatDiagnostic(diagnostic) {
51
+ const subject = diagnostic.packageName ? ` ${diagnostic.packageName}` : '';
52
+ return `${diagnostic.severity === 'error' ? '✗' : '!'} [${diagnostic.code}]${subject}: ${diagnostic.message}`;
53
+ }
54
+ function formatModulesResult(result) {
55
+ if (result.action === 'list') {
56
+ const lines = result.modules.map(module => (`${module.supportsHarmony ? '✓' : '-'} ${module.packageName}@${module.packageVersion} [${module.source}]`));
57
+ for (const packageName of result.missingIncludes) {
58
+ lines.push(`✗ missing required package ${packageName}`);
59
+ }
60
+ for (const duplicate of result.duplicates) {
61
+ lines.push(`! duplicate ${duplicate.packageName}: ${duplicate.revisions.map(item => item.version).join(', ')}`);
62
+ }
63
+ return lines.length === 0 ? 'No native module candidates were discovered.' : lines.join('\n');
64
+ }
65
+ if (result.action === 'verify') {
66
+ if (result.diagnostics.length === 0) {
67
+ return `✓ Verified ${result.modules.length} Harmony native module(s).`;
68
+ }
69
+ return result.diagnostics.map(formatDiagnostic).join('\n');
70
+ }
71
+ return result.modules.map((module) => {
72
+ const arkTsModules = module.harmony.modules.join(', ') || 'none';
73
+ const har = module.arkTs
74
+ ? `${module.arkTs.ohPackageName} <- ${module.arkTs.harPath}`
75
+ : 'none';
76
+ return [
77
+ `${module.packageName}@${module.packageVersion}`,
78
+ ` source: ${module.source}`,
79
+ ` packageRoot: ${module.packageRoot}`,
80
+ ` ArkTS modules: ${arkTsModules}`,
81
+ ` HAR: ${har}`,
82
+ ].join('\n');
83
+ }).join('\n');
84
+ }
@@ -0,0 +1,10 @@
1
+ export type ModulesAction = 'inspect' | 'list' | 'verify';
2
+ declare function parseModulesArgs(argv: string[]): {
3
+ action: ModulesAction;
4
+ help: boolean;
5
+ project: string;
6
+ packageName: string;
7
+ nativeModulesDir: string;
8
+ variant: "debug" | "release" | undefined;
9
+ };
10
+ export { parseModulesArgs };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseModulesArgs = parseModulesArgs;
4
+ const args_1 = require("../args");
5
+ const errors_1 = require("../errors");
6
+ const ModuleOptions = {
7
+ ...args_1.CommonOptions,
8
+ 'package': { short: 'p', type: 'string' },
9
+ 'variant': { type: 'string' },
10
+ 'native-modules-dir': { type: 'string' },
11
+ };
12
+ function parseModulesArgs(argv) {
13
+ const { positionals, values } = (0, args_1.parseArgs)(ModuleOptions, argv);
14
+ const action = positionals[0];
15
+ if (values.help && action === undefined) {
16
+ return {
17
+ action: 'list',
18
+ help: true,
19
+ project: undefined,
20
+ packageName: values.package,
21
+ nativeModulesDir: values['native-modules-dir'],
22
+ variant: values.variant,
23
+ };
24
+ }
25
+ if (!action || !['inspect', 'list', 'verify'].includes(action)) {
26
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_CONFIG_INVALID', 'modules requires one of: list, inspect, verify.', { operation: 'parse-arguments' });
27
+ }
28
+ if (positionals.length > 2) {
29
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_CONFIG_INVALID', `Unexpected modules positional argument: ${positionals[2]}`, { operation: 'parse-arguments' });
30
+ }
31
+ if (values.variant !== undefined && !['debug', 'release'].includes(values.variant)) {
32
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_CONFIG_INVALID', `--variant must be debug or release, received: ${values.variant}`, { operation: 'parse-arguments' });
33
+ }
34
+ if (values.package !== undefined && action !== 'inspect') {
35
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_CONFIG_INVALID', '--package is supported by modules inspect only.', { operation: 'parse-arguments' });
36
+ }
37
+ return {
38
+ action,
39
+ help: Boolean(values.help),
40
+ project: positionals[1],
41
+ packageName: values.package,
42
+ nativeModulesDir: values['native-modules-dir'],
43
+ variant: values.variant,
44
+ };
45
+ }
@@ -0,0 +1,4 @@
1
+ import type { BareHarmonyBuildPlan } from './types';
2
+ declare function isBareHarmonyProject(root: string): boolean;
3
+ declare function resolveBareHarmonyBuildPlan(root: string, mode: 'debug' | 'release'): BareHarmonyBuildPlan;
4
+ export { isBareHarmonyProject, resolveBareHarmonyBuildPlan };
@@ -0,0 +1,130 @@
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.isBareHarmonyProject = isBareHarmonyProject;
7
+ exports.resolveBareHarmonyBuildPlan = resolveBareHarmonyBuildPlan;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const json5_1 = __importDefault(require("json5"));
11
+ const errors_1 = require("../errors");
12
+ function isBareHarmonyProject(root) {
13
+ return node_fs_1.default.existsSync(node_path_1.default.join(root, 'harmony'))
14
+ && !node_fs_1.default.existsSync(node_path_1.default.join(root, 'harmony/.expo-harmony-template'))
15
+ && !node_fs_1.default.existsSync(node_path_1.default.join(root, '.expo/harmony/cng-manifest.json'));
16
+ }
17
+ function record(value, field) {
18
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
19
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Native ${field} must be an object.`, { operation: 'resolve-build' });
20
+ }
21
+ return value;
22
+ }
23
+ function records(value, field) {
24
+ if (!Array.isArray(value)) {
25
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Native ${field} must be an array.`, { operation: 'resolve-build' });
26
+ }
27
+ return value.map(item => record(item, field));
28
+ }
29
+ function readJson(file) {
30
+ try {
31
+ return record(json5_1.default.parse(node_fs_1.default.readFileSync(file, 'utf8')), file);
32
+ }
33
+ catch (cause) {
34
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Cannot read native project file ${file}: ${cause.message}`, { cause, operation: 'resolve-build' });
35
+ }
36
+ }
37
+ function identifier(value, field) {
38
+ if (typeof value !== 'string' || !/^[A-Za-z_][A-Za-z0-9_.]*$/.test(value)) {
39
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `The native project must specify a valid ${field}.`, { operation: 'resolve-build' });
40
+ }
41
+ return value;
42
+ }
43
+ function selectDefault(items, field) {
44
+ if (items.length === 0) {
45
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `No ${field} is defined in harmony/build-profile.json5.`, { operation: 'resolve-build' });
46
+ }
47
+ const defaults = items.filter(item => item.name === 'default');
48
+ if (defaults.length === 1)
49
+ return defaults[0];
50
+ if (items.length === 1)
51
+ return items[0];
52
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Multiple ${field} are defined; name the intended default "default" in harmony/build-profile.json5.`, { operation: 'resolve-build' });
53
+ }
54
+ function resolveBareHarmonyBuildPlan(root, mode) {
55
+ const harmony = node_path_1.default.join(root, 'harmony');
56
+ const entry = node_path_1.default.join(harmony, 'entry');
57
+ for (const directory of [harmony, entry]) {
58
+ if (!node_fs_1.default.existsSync(directory)
59
+ || !node_fs_1.default.lstatSync(directory).isDirectory() || node_fs_1.default.lstatSync(directory).isSymbolicLink()) {
60
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Bare Harmony projects require a regular directory at ${directory}.`, { operation: 'resolve-build' });
61
+ }
62
+ }
63
+ const profile = readJson(node_path_1.default.join(harmony, 'build-profile.json5'));
64
+ const app = record(readJson(node_path_1.default.join(harmony, 'AppScope/app.json5')).app, 'app');
65
+ const module = record(readJson(node_path_1.default.join(entry, 'src/main/module.json5')).module, 'module');
66
+ const name = identifier(module.name, 'module.name');
67
+ const registration = records(profile.modules, 'modules').find(item => item.name === name);
68
+ if (!registration || typeof registration.srcPath !== 'string'
69
+ || node_path_1.default.resolve(harmony, registration.srcPath) !== entry || module.type !== 'entry') {
70
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', 'Bare Harmony autolinking requires an entry module at harmony/entry, registered in build-profile.json5.', { operation: 'resolve-build' });
71
+ }
72
+ const config = record(profile.app, 'build-profile.app');
73
+ const selected = selectDefault(records(config.products, 'products'), 'products');
74
+ const product = identifier(selected.name, 'product name');
75
+ const targets = records(registration.targets, 'module targets').filter((item) => {
76
+ if (item.applyToProducts === undefined)
77
+ return true;
78
+ if (!Array.isArray(item.applyToProducts) || item.applyToProducts.some(value => typeof value !== 'string')) {
79
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', 'Native target.applyToProducts must be an array of product names.', { operation: 'resolve-build' });
80
+ }
81
+ return item.applyToProducts.includes(product);
82
+ });
83
+ const target = identifier(selectDefault(targets, 'module targets').name, 'target name');
84
+ const ability = identifier(module.mainElement, 'module.mainElement');
85
+ if (!records(module.abilities, 'abilities').some(item => item.name === ability)) {
86
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Ability ${ability} is missing from module.json5.`, { operation: 'resolve-build' });
87
+ }
88
+ const bundle = identifier(app.bundleName, 'app.bundleName');
89
+ const signed = Boolean(selected.signingConfig);
90
+ if (signed && !records(config.signingConfigs, 'signingConfigs').some(item => item.name === selected.signingConfig)) {
91
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_PROJECT', `Signing config ${selected.signingConfig} is referenced by the product but is not defined.`, { operation: 'resolve-build' });
92
+ }
93
+ const rawfile = node_path_1.default.join(entry, 'src/main/resources/rawfile');
94
+ const metadata = node_path_1.default.join(root, '.expo/harmony/export');
95
+ return {
96
+ workflow: 'bare',
97
+ abilityName: ability,
98
+ buildMode: mode,
99
+ bundleName: bundle,
100
+ harmonyRoot: harmony,
101
+ moduleName: name,
102
+ moduleRoot: entry,
103
+ productName: product,
104
+ targetName: target,
105
+ expectedHap: node_path_1.default.join(entry, `build/${target}/outputs/${target}/${name}-${target}-${signed ? 'signed' : 'unsigned'}.hap`),
106
+ hvigorArgs: ['--mode', 'module', '-p', `module=${name}@${target}`, '-p', `product=${product}`, '-p', `buildMode=${mode}`, '--no-daemon', 'assembleHap'],
107
+ exportPaths: {
108
+ bundle: node_path_1.default.join(rawfile, 'hermes_bundle.hbc'),
109
+ manifest: node_path_1.default.join(root, '.expo/harmony/export-manifest.json'),
110
+ metadataRoot: metadata,
111
+ rawfileRoot: rawfile,
112
+ sourceMap: node_path_1.default.join(metadata, 'hermes_bundle.hbc.map'),
113
+ },
114
+ nativeCache: {
115
+ invalidationRoots: [node_path_1.default.join(entry, '.cxx'), node_path_1.default.join(entry, 'build')],
116
+ stateFile: node_path_1.default.join(entry, '.cxx/.expo-harmony-native-dependencies.json'),
117
+ },
118
+ nativeInputs: {
119
+ lockfile: node_path_1.default.join(harmony, 'oh-package-lock.json5'),
120
+ manifest: node_path_1.default.join(harmony, 'oh-package.json5'),
121
+ },
122
+ projectFiles: {
123
+ hvigorConfig: node_path_1.default.join(harmony, 'hvigor/hvigor-config.json5'),
124
+ moduleHvigor: node_path_1.default.join(entry, 'hvigorfile.ts'),
125
+ moduleJson: node_path_1.default.join(entry, 'src/main/module.json5'),
126
+ projectBuildProfile: node_path_1.default.join(harmony, 'build-profile.json5'),
127
+ rootHvigor: node_path_1.default.join(harmony, 'hvigorfile.ts'),
128
+ },
129
+ };
130
+ }
@@ -0,0 +1,15 @@
1
+ import type { HarmonyToolchain } from './toolchain';
2
+ import type { HarmonyBuildPlan } from './types';
3
+ import { type Log } from '../log';
4
+ export interface NativeBuildResult {
5
+ export: null | {
6
+ assetCount: number;
7
+ bundleSha256: string;
8
+ sourceMapSha256: string;
9
+ };
10
+ hapPath: string;
11
+ }
12
+ export declare function buildNativeAsync(root: string, plan: HarmonyBuildPlan, tools: HarmonyToolchain, options: {
13
+ io?: Log;
14
+ resetCache?: boolean;
15
+ }, steps: Record<string, number>): Promise<NativeBuildResult>;
@@ -0,0 +1,69 @@
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.buildNativeAsync = buildNativeAsync;
7
+ const config_1 = require("@expo/config");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const cache_1 = require("./cache");
10
+ const install_1 = require("./install");
11
+ const errors_1 = require("../errors");
12
+ const export_1 = require("../exportEmbed/export");
13
+ const file_1 = require("../file");
14
+ const log_1 = require("../log");
15
+ const path_1 = require("../path");
16
+ const process_1 = require("../process");
17
+ const profile_1 = require("../profile");
18
+ async function buildNativeAsync(root, plan, tools, options, steps) {
19
+ let exported = null;
20
+ const embedded = plan.buildMode === 'release' || (0, config_1.getConfig)(root).exp.updates?.useNativeDebug === true;
21
+ if (embedded) {
22
+ (0, log_1.progress)(options, 'Exporting the release Hermes bundle');
23
+ const manifest = await (0, profile_1.timedAsync)(steps, 'export', () => (0, export_1.exportEmbedAsync)(root, {
24
+ resetCache: options.resetCache,
25
+ skipDoctor: true,
26
+ }));
27
+ exported = {
28
+ assetCount: manifest.assets.length,
29
+ bundleSha256: manifest.bundle.sha256,
30
+ sourceMapSha256: manifest.sourceMap.sha256,
31
+ };
32
+ }
33
+ else {
34
+ steps.export = 0;
35
+ }
36
+ (0, log_1.progress)(options, 'Installing Harmony project dependencies');
37
+ await (0, profile_1.timedAsync)(steps, 'ohpm', () => (0, install_1.installHarmonyDependenciesAsync)(plan, tools));
38
+ (0, log_1.progress)(options, 'Checking Harmony native dependency cache');
39
+ const cache = await (0, profile_1.timedAsync)(steps, 'nativeCache', () => (0, cache_1.prepareHarmonyNativeBuildCacheAsync)(root, plan));
40
+ if (cache.changed)
41
+ (0, log_1.progress)(options, 'Invalidated stale Harmony native build objects');
42
+ (0, log_1.progress)(options, `Building the ${plan.buildMode} HAP`);
43
+ await (0, profile_1.timedAsync)(steps, 'build', () => (0, process_1.runCheckedAsync)(tools.hvigor.command, [
44
+ ...tools.hvigor.args,
45
+ ...plan.hvigorArgs,
46
+ ], {
47
+ code: 'ERR_HARMONY_BUILD_FAILED',
48
+ cwd: plan.harmonyRoot,
49
+ env: {
50
+ ...process.env,
51
+ EXPO_HARMONY_NODE: process.env.EXPO_HARMONY_NODE || process.execPath,
52
+ EXPO_METRO_TARGET: 'harmony',
53
+ HERMES_V1_ENABLED: 'true',
54
+ ...(plan.workflow === 'bare' ? { EXPO_HARMONY_NATIVE_PREPARED: '1' } : {}),
55
+ ...(embedded ? { EXPO_HARMONY_BUNDLE_PREBUILT: '1' } : {}),
56
+ ...(tools.sdkHome && !process.env.DEVECO_SDK_HOME
57
+ ? { DEVECO_SDK_HOME: tools.sdkHome }
58
+ : {}),
59
+ },
60
+ message: 'Hvigor build',
61
+ operation: 'hvigor-build',
62
+ timeoutMs: 15 * 60_000,
63
+ }));
64
+ if (!(0, file_1.isNonEmptyRegularFile)(plan.expectedHap)) {
65
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_HAP_MISSING', 'Hvigor completed without producing the expected non-empty regular HAP.', { operation: 'verify-hap' });
66
+ }
67
+ await (0, profile_1.timedAsync)(steps, 'nativeCacheCommit', () => (0, cache_1.commitHarmonyNativeBuildCacheAsync)(cache));
68
+ return { export: exported, hapPath: (0, path_1.toPosixPath)(node_path_1.default.relative(root, plan.expectedHap)) };
69
+ }
@@ -0,0 +1,11 @@
1
+ import { type HarmonyBuildPlan } from './types';
2
+ export interface HarmonyNativeBuildCacheState {
3
+ artifactCount: number;
4
+ cacheFile: string;
5
+ changed: boolean;
6
+ fingerprint: string;
7
+ fingerprintVersion: number;
8
+ }
9
+ declare function prepareHarmonyNativeBuildCacheAsync(root: string, plan: HarmonyBuildPlan): Promise<HarmonyNativeBuildCacheState>;
10
+ declare function commitHarmonyNativeBuildCacheAsync(state: HarmonyNativeBuildCacheState): Promise<void>;
11
+ export { commitHarmonyNativeBuildCacheAsync, prepareHarmonyNativeBuildCacheAsync, };
@@ -0,0 +1,73 @@
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.commitHarmonyNativeBuildCacheAsync = commitHarmonyNativeBuildCacheAsync;
7
+ exports.prepareHarmonyNativeBuildCacheAsync = prepareHarmonyNativeBuildCacheAsync;
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const native_inputs_1 = require("@expo-harmony/config-plugins/internal/native-inputs");
11
+ const errors_1 = require("../errors");
12
+ const SchemaVersion = 1;
13
+ async function readOptionalFile(file) {
14
+ try {
15
+ return await node_fs_1.default.promises.readFile(file);
16
+ }
17
+ catch (error) {
18
+ if (error?.code === 'ENOENT')
19
+ return null;
20
+ throw new errors_1.HarmonyCliError(error.code || 'ERR_HARMONY_NATIVE_CACHE', error.message || `Cannot read a Harmony native cache input: ${file}`, { cause: error, exitCode: error.exitCode, operation: error.operation });
21
+ }
22
+ }
23
+ async function resolveNativeDependencyFingerprintAsync(root, plan) {
24
+ try {
25
+ return (0, native_inputs_1.fingerprintHarmonyNativeInputsSync)({
26
+ lockfile: plan.nativeInputs.lockfile,
27
+ manifest: plan.nativeInputs.manifest,
28
+ projectRoot: root,
29
+ });
30
+ }
31
+ catch (cause) {
32
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_CACHE', `Cannot fingerprint generated Harmony native dependencies: ${cause.message}`, { cause, operation: 'native-cache' });
33
+ }
34
+ }
35
+ async function prepareHarmonyNativeBuildCacheAsync(root, plan) {
36
+ const current = await resolveNativeDependencyFingerprintAsync(root, plan);
37
+ const file = plan.nativeCache.stateFile;
38
+ const source = await readOptionalFile(file);
39
+ let saved = null;
40
+ if (source) {
41
+ try {
42
+ saved = JSON.parse(source.toString('utf8'));
43
+ }
44
+ catch {
45
+ saved = null;
46
+ }
47
+ }
48
+ const changed = saved?.schemaVersion !== SchemaVersion
49
+ || saved?.fingerprintVersion !== native_inputs_1.HarmonyNativeInputsFingerprintVersion
50
+ || saved?.fingerprint !== current.fingerprint;
51
+ if (changed) {
52
+ for (const root of plan.nativeCache.invalidationRoots) {
53
+ await node_fs_1.default.promises.rm(root, { force: true, recursive: true });
54
+ }
55
+ }
56
+ return {
57
+ ...current,
58
+ cacheFile: file,
59
+ changed,
60
+ };
61
+ }
62
+ async function commitHarmonyNativeBuildCacheAsync(state) {
63
+ const root = node_path_1.default.dirname(state.cacheFile);
64
+ const temp = `${state.cacheFile}.${process.pid}.tmp`;
65
+ await node_fs_1.default.promises.mkdir(root, { recursive: true });
66
+ await node_fs_1.default.promises.writeFile(temp, `${JSON.stringify({
67
+ artifactCount: state.artifactCount,
68
+ fingerprint: state.fingerprint,
69
+ fingerprintVersion: state.fingerprintVersion,
70
+ schemaVersion: SchemaVersion,
71
+ }, null, 2)}\n`);
72
+ await node_fs_1.default.promises.rename(temp, state.cacheFile);
73
+ }
@@ -0,0 +1,3 @@
1
+ export declare function prepareHarmonyNativeBuild(root: string, mode: 'debug' | 'release'): void;
2
+ export declare function bundleHarmonyNativeBuild(root: string): void;
3
+ export declare function publishHarmonyNativeRuntime(root: string, mode: 'debug' | 'release'): void;
@@ -0,0 +1,83 @@
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.prepareHarmonyNativeBuild = prepareHarmonyNativeBuild;
7
+ exports.bundleHarmonyNativeBuild = bundleHarmonyNativeBuild;
8
+ exports.publishHarmonyNativeRuntime = publishHarmonyNativeRuntime;
9
+ const node_crypto_1 = __importDefault(require("node:crypto"));
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const node_module_1 = require("node:module");
12
+ const node_path_1 = __importDefault(require("node:path"));
13
+ const node_child_process_1 = require("node:child_process");
14
+ const native_inputs_1 = require("@expo-harmony/config-plugins/internal/native-inputs");
15
+ const errors_1 = require("../errors");
16
+ const toolchain_1 = require("./toolchain");
17
+ function nodeExecutable() {
18
+ const candidates = process.env.EXPO_HARMONY_NODE
19
+ ? [process.env.EXPO_HARMONY_NODE]
20
+ : [
21
+ process.execPath,
22
+ ...(process.env.PATH || '').split(node_path_1.default.delimiter).filter(Boolean)
23
+ .map(directory => node_path_1.default.join(directory, process.platform === 'win32' ? 'node.exe' : 'node')),
24
+ ];
25
+ for (const candidate of new Set(candidates)) {
26
+ const result = (0, node_child_process_1.spawnSync)(candidate, ['-p', 'process.versions.node'], { encoding: 'utf8', timeout: 5_000 });
27
+ if (result.status === 0 && Number.parseInt(result.stdout, 10) >= 20)
28
+ return candidate;
29
+ }
30
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NODE', 'Harmony native builds require Node.js 20 or newer. Set EXPO_HARMONY_NODE to its executable.', { operation: 'native-build' });
31
+ }
32
+ function run(command, args, cwd) {
33
+ const result = (0, node_child_process_1.spawnSync)(command, args, {
34
+ cwd,
35
+ env: { ...(0, toolchain_1.createHarmonyToolchainEnv)(), EXPO_HARMONY: '1', EXPO_METRO_TARGET: 'harmony', HERMES_V1_ENABLED: 'true' },
36
+ stdio: 'inherit',
37
+ timeout: 10 * 60_000,
38
+ });
39
+ if (result.error || result.status !== 0) {
40
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_NATIVE_BUILD', `Harmony build command failed: ${command} (${result.error?.message || result.status}).`, { cause: result.error, exitCode: result.status || 1, operation: 'native-build' });
41
+ }
42
+ }
43
+ // Hvigor configuration is synchronous; linking must finish before task execution.
44
+ function prepareHarmonyNativeBuild(root, mode) {
45
+ const harmony = node_path_1.default.join(root, 'harmony');
46
+ if (process.env.EXPO_HARMONY_NATIVE_PREPARED !== '1') {
47
+ const require = (0, node_module_1.createRequire)(node_path_1.default.join(root, 'package.json'));
48
+ const manifest = node_path_1.default.resolve(node_path_1.default.dirname(require.resolve('@expo-harmony/expo-modules-autolinking')), '../package.json');
49
+ const bin = node_path_1.default.resolve(node_path_1.default.dirname(manifest), require(manifest).bin['expo-harmony-autolinking']);
50
+ run(nodeExecutable(), [bin, 'link', '--project-root', root, '--harmony-project-path', harmony, '--build-type', mode], root);
51
+ const { ohpm } = (0, toolchain_1.resolveHarmonyToolchain)();
52
+ run(ohpm.command, [...ohpm.args, 'install', '--all'], harmony);
53
+ }
54
+ publishHarmonyNativeRuntime(root, mode);
55
+ const { fingerprint } = (0, native_inputs_1.fingerprintHarmonyNativeInputsSync)({
56
+ projectRoot: root,
57
+ manifest: node_path_1.default.join(harmony, 'oh-package.json5'),
58
+ lockfile: node_path_1.default.join(harmony, 'oh-package-lock.json5'),
59
+ });
60
+ const file = node_path_1.default.join(harmony, '.hvigor/expo-harmony/native-inputs.cmake');
61
+ const content = `# Generated native dependency fingerprint.\nadd_compile_definitions(EXPO_HARMONY_NATIVE_INPUTS_SHA256_${fingerprint}=1)\n`;
62
+ if (node_fs_1.default.existsSync(file) && node_fs_1.default.readFileSync(file, 'utf8') === content)
63
+ return;
64
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
65
+ const temp = `${file}.${node_crypto_1.default.randomUUID()}.tmp`;
66
+ try {
67
+ node_fs_1.default.writeFileSync(temp, content);
68
+ node_fs_1.default.renameSync(temp, file);
69
+ }
70
+ finally {
71
+ node_fs_1.default.rmSync(temp, { force: true });
72
+ }
73
+ }
74
+ function bundleHarmonyNativeBuild(root) {
75
+ if (process.env.EXPO_HARMONY_BUNDLE_PREBUILT === '1')
76
+ return;
77
+ const require = (0, node_module_1.createRequire)(node_path_1.default.join(root, 'package.json'));
78
+ run(nodeExecutable(), [require.resolve('@expo-harmony/cli/bin/expo-harmony'), 'export:embed', root], root);
79
+ }
80
+ function publishHarmonyNativeRuntime(root, mode) {
81
+ const require = (0, node_module_1.createRequire)(node_path_1.default.join(root, 'package.json'));
82
+ run(nodeExecutable(), [require.resolve('@expo-harmony/cli/bin/expo-harmony'), 'runtime', root, '--publish', '--variant', mode], root);
83
+ }
@@ -0,0 +1,5 @@
1
+ import type { HarmonyBuildPlan } from './types';
2
+ import type { HarmonyToolchain } from './toolchain';
3
+ export declare function installHarmonyDependenciesAsync(plan: Pick<HarmonyBuildPlan, 'harmonyRoot'>, tools: HarmonyToolchain, options?: {
4
+ timeoutMs?: number;
5
+ }): Promise<void>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installHarmonyDependenciesAsync = installHarmonyDependenciesAsync;
4
+ const process_1 = require("../process");
5
+ async function installHarmonyDependenciesAsync(plan, tools, options = {}) {
6
+ await (0, process_1.runCheckedAsync)(tools.ohpm.command, [...tools.ohpm.args, 'install', '--all'], {
7
+ code: 'ERR_HARMONY_OHPM_FAILED',
8
+ cwd: plan.harmonyRoot,
9
+ message: 'OHPM install',
10
+ operation: 'ohpm-install',
11
+ timeoutMs: options.timeoutMs || 5 * 60_000,
12
+ });
13
+ }
@@ -0,0 +1,11 @@
1
+ import { type Log } from '../log';
2
+ import type { HarmonyBuildPlan } from './types';
3
+ interface PrepareProjectOptions {
4
+ io?: Log;
5
+ requireDeviceTools?: boolean;
6
+ check?: boolean;
7
+ sync: boolean;
8
+ variant: 'debug' | 'release';
9
+ }
10
+ declare function prepareNativeProjectAsync(root: string, options: PrepareProjectOptions, steps: Record<string, number>): Promise<HarmonyBuildPlan>;
11
+ export { prepareNativeProjectAsync };