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

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 (73) hide show
  1. package/build/args.d.ts +19 -0
  2. package/build/args.js +27 -0
  3. package/build/bin/expo-harmony.d.ts +2 -0
  4. package/build/buildHap/build.d.ts +25 -0
  5. package/build/buildHap/build.js +96 -0
  6. package/build/buildHap/common.d.ts +24 -0
  7. package/build/buildHap/common.js +92 -0
  8. package/build/buildHap/options.d.ts +7 -0
  9. package/build/buildHap/options.js +30 -0
  10. package/build/cli.d.ts +3 -0
  11. package/build/cli.js +202 -0
  12. package/build/doctor/doctor.d.ts +20 -0
  13. package/build/doctor/doctor.js +217 -0
  14. package/build/doctor/options.d.ts +5 -0
  15. package/build/doctor/options.js +15 -0
  16. package/build/entry.d.ts +2 -0
  17. package/build/entry.js +47 -0
  18. package/build/errors.d.ts +12 -0
  19. package/build/errors.js +16 -0
  20. package/build/expo.d.ts +19 -0
  21. package/build/expo.js +53 -0
  22. package/build/exportEmbed/export.d.ts +16 -0
  23. package/build/exportEmbed/export.js +125 -0
  24. package/build/exportEmbed/manifest.d.ts +44 -0
  25. package/build/exportEmbed/manifest.js +171 -0
  26. package/build/exportEmbed/options.d.ts +7 -0
  27. package/build/exportEmbed/options.js +22 -0
  28. package/build/file.d.ts +9 -0
  29. package/build/file.js +100 -0
  30. package/build/index.d.ts +12 -0
  31. package/build/modules/modules.d.ts +42 -0
  32. package/build/modules/modules.js +84 -0
  33. package/build/modules/options.d.ts +10 -0
  34. package/build/modules/options.js +45 -0
  35. package/build/path.d.ts +4 -0
  36. package/build/path.js +27 -0
  37. package/build/prebuild/check.d.ts +6 -0
  38. package/build/prebuild/check.js +139 -0
  39. package/build/prebuild/clean.d.ts +2 -0
  40. package/build/prebuild/clean.js +50 -0
  41. package/build/prebuild/options.d.ts +10 -0
  42. package/build/prebuild/options.js +50 -0
  43. package/build/prebuild/prebuild.d.ts +6 -0
  44. package/build/prebuild/prebuild.js +62 -0
  45. package/build/prebuild/template.d.ts +8 -0
  46. package/build/prebuild/template.js +86 -0
  47. package/build/process.d.ts +31 -0
  48. package/build/process.js +236 -0
  49. package/build/project.d.ts +2 -0
  50. package/build/project.js +23 -0
  51. package/build/projectLock.d.ts +2 -0
  52. package/build/projectLock.js +180 -0
  53. package/build/run/cache.d.ts +11 -0
  54. package/build/run/cache.js +73 -0
  55. package/build/run/devices.d.ts +29 -0
  56. package/build/run/devices.js +211 -0
  57. package/build/run/emulators.d.ts +13 -0
  58. package/build/run/emulators.js +85 -0
  59. package/build/run/install.d.ts +7 -0
  60. package/build/run/install.js +26 -0
  61. package/build/run/metro.d.ts +17 -0
  62. package/build/run/metro.js +156 -0
  63. package/build/run/options.d.ts +13 -0
  64. package/build/run/options.js +60 -0
  65. package/build/run/run.d.ts +51 -0
  66. package/build/run/run.js +174 -0
  67. package/build/start/options.d.ts +7 -0
  68. package/build/start/options.js +31 -0
  69. package/build/tools.d.ts +39 -0
  70. package/build/tools.js +226 -0
  71. package/build/upstream.d.ts +9 -0
  72. package/build/upstream.js +17 -0
  73. package/package.json +1 -1
@@ -0,0 +1,236 @@
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.formatDiagnostics = formatDiagnostics;
7
+ exports.spawnAsync = spawnAsync;
8
+ exports.startManagedProcess = startManagedProcess;
9
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
10
+ const errors_1 = require("./errors");
11
+ const DefaultOutputLimit = 1024 * 1024;
12
+ const DefaultStopGraceMs = 3_000;
13
+ class BoundedCapture {
14
+ limit;
15
+ buffers = [];
16
+ head = 0;
17
+ length = 0;
18
+ constructor(limit) {
19
+ this.limit = limit;
20
+ }
21
+ append(value) {
22
+ const buffer = typeof value === 'string' ? new TextEncoder().encode(value) : Uint8Array.from(value);
23
+ if (buffer.length >= this.limit) {
24
+ this.buffers = [buffer.subarray(buffer.length - this.limit)];
25
+ this.head = 0;
26
+ this.length = this.limit;
27
+ return;
28
+ }
29
+ while (this.length + buffer.length > this.limit && this.head < this.buffers.length) {
30
+ const first = this.buffers[this.head];
31
+ const excess = this.length + buffer.length - this.limit;
32
+ if (first.length > excess) {
33
+ this.buffers[this.head] = first.subarray(excess);
34
+ this.length -= excess;
35
+ break;
36
+ }
37
+ this.length -= first.length;
38
+ this.head += 1;
39
+ }
40
+ this.buffers.push(buffer);
41
+ this.length += buffer.length;
42
+ if (this.head > 128 && this.head * 2 > this.buffers.length) {
43
+ this.buffers = this.buffers.slice(this.head);
44
+ this.head = 0;
45
+ }
46
+ }
47
+ toString() {
48
+ return Buffer.concat(this.buffers.slice(this.head), this.length).toString('utf8');
49
+ }
50
+ }
51
+ function formatDiagnostics(result, limit = 4_000) {
52
+ return (result.stderr || result.stdout || '').slice(-limit).trim();
53
+ }
54
+ function spawnAsync(command, args, options = {}) {
55
+ return new Promise((resolve, reject) => {
56
+ const piped = Boolean(options.capture || options.onStdout || options.onStderr);
57
+ const outputLimit = options.outputLimit || DefaultOutputLimit;
58
+ const child = (0, cross_spawn_1.default)(command, args, {
59
+ cwd: options.cwd,
60
+ env: options.env || process.env,
61
+ shell: false,
62
+ stdio: piped ? ['ignore', 'pipe', 'pipe'] : 'inherit',
63
+ windowsHide: true,
64
+ });
65
+ const stdout = new BoundedCapture(outputLimit);
66
+ const stderr = new BoundedCapture(outputLimit);
67
+ let timedOut = false;
68
+ let settled = false;
69
+ let forceKillTimer = null;
70
+ if (piped) {
71
+ child.stdout.on('data', (chunk) => {
72
+ stdout.append(chunk);
73
+ options.onStdout?.(chunk);
74
+ });
75
+ child.stderr.on('data', (chunk) => {
76
+ stderr.append(chunk);
77
+ options.onStderr?.(chunk);
78
+ });
79
+ }
80
+ const stopChild = (signal = 'SIGTERM') => {
81
+ child.kill(signal);
82
+ if (forceKillTimer === null) {
83
+ forceKillTimer = setTimeout(() => child.kill('SIGKILL'), options.stopGraceMs || DefaultStopGraceMs);
84
+ forceKillTimer.unref?.();
85
+ }
86
+ };
87
+ const forwardSigint = () => stopChild('SIGINT');
88
+ const forwardSigterm = () => stopChild('SIGTERM');
89
+ process.once('SIGINT', forwardSigint);
90
+ process.once('SIGTERM', forwardSigterm);
91
+ const timeout = options.timeoutMs
92
+ ? setTimeout(() => {
93
+ timedOut = true;
94
+ stopChild('SIGTERM');
95
+ }, options.timeoutMs)
96
+ : null;
97
+ timeout?.unref?.();
98
+ const cleanup = () => {
99
+ if (timeout)
100
+ clearTimeout(timeout);
101
+ if (forceKillTimer)
102
+ clearTimeout(forceKillTimer);
103
+ process.removeListener('SIGINT', forwardSigint);
104
+ process.removeListener('SIGTERM', forwardSigterm);
105
+ options.signal?.removeEventListener('abort', abort);
106
+ };
107
+ const abort = () => stopChild('SIGTERM');
108
+ if (options.signal?.aborted)
109
+ abort();
110
+ else
111
+ options.signal?.addEventListener('abort', abort, { once: true });
112
+ child.once('error', (cause) => {
113
+ if (settled)
114
+ return;
115
+ settled = true;
116
+ cleanup();
117
+ reject(new errors_1.HarmonyCliError('ERR_HARMONY_PROCESS_FAILED', `Cannot launch ${command}: ${cause.message}`, {
118
+ cause,
119
+ operation: options.operation || 'spawn',
120
+ }));
121
+ });
122
+ // `close` runs after stdout/stderr have closed, so captured diagnostics are
123
+ // complete. `exit` can fire while pipe data is still pending.
124
+ child.once('close', (code, signal) => {
125
+ if (settled)
126
+ return;
127
+ settled = true;
128
+ cleanup();
129
+ resolve({
130
+ code: code === null ? 1 : code,
131
+ signal,
132
+ stderr: stderr.toString(),
133
+ stdout: stdout.toString(),
134
+ timedOut,
135
+ });
136
+ });
137
+ });
138
+ }
139
+ function startManagedProcess(command, args, options = {}) {
140
+ const outputLimit = options.outputLimit || DefaultOutputLimit;
141
+ const piped = options.stdio !== 'inherit';
142
+ const child = (0, cross_spawn_1.default)(command, args, {
143
+ cwd: options.cwd,
144
+ env: options.env || process.env,
145
+ shell: false,
146
+ stdio: piped ? ['ignore', 'pipe', 'pipe'] : 'inherit',
147
+ windowsHide: true,
148
+ });
149
+ const stdout = new BoundedCapture(outputLimit);
150
+ const stderr = new BoundedCapture(outputLimit);
151
+ let spawnError = null;
152
+ let closed = false;
153
+ let stopRequested = false;
154
+ if (piped) {
155
+ child.stdout.on('data', (chunk) => {
156
+ stdout.append(chunk);
157
+ options.onStdout?.(chunk);
158
+ });
159
+ child.stderr.on('data', (chunk) => {
160
+ stderr.append(chunk);
161
+ options.onStderr?.(chunk);
162
+ });
163
+ }
164
+ const forwardSigint = () => {
165
+ void stop('SIGINT');
166
+ };
167
+ const forwardSigterm = () => {
168
+ void stop('SIGTERM');
169
+ };
170
+ const abort = () => {
171
+ void stop('SIGTERM');
172
+ };
173
+ const cleanup = () => {
174
+ process.removeListener('SIGINT', forwardSigint);
175
+ process.removeListener('SIGTERM', forwardSigterm);
176
+ options.signal?.removeEventListener('abort', abort);
177
+ };
178
+ const completion = new Promise((resolve, reject) => {
179
+ child.once('error', (cause) => {
180
+ spawnError = new errors_1.HarmonyCliError('ERR_HARMONY_PROCESS_FAILED', `Cannot launch ${command}: ${cause.message}`, {
181
+ cause,
182
+ operation: options.operation || 'spawn',
183
+ });
184
+ });
185
+ child.once('close', (code, signal) => {
186
+ closed = true;
187
+ cleanup();
188
+ if (spawnError)
189
+ reject(spawnError);
190
+ else
191
+ resolve({
192
+ code: code === null ? 1 : code,
193
+ signal,
194
+ stderr: stderr.toString(),
195
+ stdout: stdout.toString(),
196
+ timedOut: false,
197
+ });
198
+ });
199
+ });
200
+ // A readiness probe may be the first consumer. Keep early spawn failures from
201
+ // becoming unhandled rejections while the probe is still polling.
202
+ completion.catch(() => { });
203
+ async function stop(signal = 'SIGTERM', graceMs = DefaultStopGraceMs) {
204
+ if (closed)
205
+ return completion;
206
+ stopRequested = true;
207
+ child.kill(signal);
208
+ let timer;
209
+ await Promise.race([
210
+ completion.catch(() => undefined),
211
+ new Promise((resolve) => {
212
+ timer = setTimeout(resolve, graceMs);
213
+ timer.unref?.();
214
+ }),
215
+ ]);
216
+ if (timer)
217
+ clearTimeout(timer);
218
+ if (!closed)
219
+ child.kill('SIGKILL');
220
+ return completion.catch(() => undefined);
221
+ }
222
+ process.once('SIGINT', forwardSigint);
223
+ process.once('SIGTERM', forwardSigterm);
224
+ if (options.signal?.aborted)
225
+ abort();
226
+ else
227
+ options.signal?.addEventListener('abort', abort, { once: true });
228
+ return {
229
+ child,
230
+ completion,
231
+ getStderr: () => stderr.toString(),
232
+ getStdout: () => stdout.toString(),
233
+ stop,
234
+ wasStopped: () => stopRequested,
235
+ };
236
+ }
@@ -0,0 +1,2 @@
1
+ declare function resolveProject(start?: string): string;
2
+ export { resolveProject };
@@ -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.resolveProject = resolveProject;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const errors_1 = require("./errors");
10
+ function resolveProject(start = process.cwd()) {
11
+ let current = node_path_1.default.resolve(start);
12
+ if (node_fs_1.default.existsSync(current) && node_fs_1.default.statSync(current).isFile())
13
+ current = node_path_1.default.dirname(current);
14
+ while (true) {
15
+ if (node_fs_1.default.existsSync(node_path_1.default.join(current, 'package.json')))
16
+ return node_fs_1.default.realpathSync(current);
17
+ const parent = node_path_1.default.dirname(current);
18
+ if (parent === current)
19
+ break;
20
+ current = parent;
21
+ }
22
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_CONFIG_INVALID', `No package.json was found from ${start}.`, { operation: 'resolve-project' });
23
+ }
@@ -0,0 +1,2 @@
1
+ declare function withHarmonyProjectLockAsync<T>(projectRoot: string, operation: string, callback: () => Promise<T> | T): Promise<T>;
2
+ export { withHarmonyProjectLockAsync };
@@ -0,0 +1,180 @@
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.withHarmonyProjectLockAsync = withHarmonyProjectLockAsync;
7
+ const node_async_hooks_1 = require("node:async_hooks");
8
+ const node_crypto_1 = __importDefault(require("node:crypto"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const errors_1 = require("./errors");
12
+ const DefaultMalformedLockGraceMs = 30_000;
13
+ const DefaultPollIntervalMs = 100;
14
+ const DefaultWaitTimeoutMs = 5_000;
15
+ const LockRelativePath = '.expo/harmony/native-operation.lock';
16
+ const ActiveLock = new node_async_hooks_1.AsyncLocalStorage();
17
+ async function canonicalProjectRootAsync(projectRoot) {
18
+ try {
19
+ return await node_fs_1.default.promises.realpath(node_path_1.default.resolve(projectRoot));
20
+ }
21
+ catch (cause) {
22
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_PROJECT_LOCK', 'Cannot resolve the application project before acquiring its Harmony native operation lock.', { cause, operation: 'project-lock' });
23
+ }
24
+ }
25
+ function projectLockPath(projectRoot) {
26
+ return node_path_1.default.join(projectRoot, ...LockRelativePath.split('/'));
27
+ }
28
+ async function processIsAliveAsync(pid) {
29
+ if (!Number.isInteger(pid) || Number(pid) <= 0)
30
+ return false;
31
+ try {
32
+ process.kill(Number(pid), 0);
33
+ return true;
34
+ }
35
+ catch (cause) {
36
+ return cause?.code !== 'ESRCH';
37
+ }
38
+ }
39
+ async function readLockOwnerAsync(lockPath) {
40
+ try {
41
+ const candidate = JSON.parse(await node_fs_1.default.promises.readFile(lockPath, 'utf8'));
42
+ if (!candidate
43
+ || typeof candidate !== 'object'
44
+ || !Number.isInteger(candidate.pid)
45
+ || candidate.pid <= 0
46
+ || typeof candidate.createdAt !== 'string'
47
+ || typeof candidate.operation !== 'string'
48
+ || typeof candidate.projectRoot !== 'string'
49
+ || typeof candidate.token !== 'string') {
50
+ return null;
51
+ }
52
+ return candidate;
53
+ }
54
+ catch (_cause) {
55
+ return null;
56
+ }
57
+ }
58
+ async function removeStaleProjectLockAsync(lockPath) {
59
+ let observed;
60
+ try {
61
+ observed = await node_fs_1.default.promises.lstat(lockPath);
62
+ }
63
+ catch (_cause) {
64
+ return false;
65
+ }
66
+ if (!observed.isFile() || observed.isSymbolicLink())
67
+ return false;
68
+ const owner = await readLockOwnerAsync(lockPath);
69
+ if (owner) {
70
+ if (await processIsAliveAsync(owner.pid))
71
+ return false;
72
+ }
73
+ else if (Date.now() - observed.mtimeMs < DefaultMalformedLockGraceMs) {
74
+ return false;
75
+ }
76
+ try {
77
+ const current = await node_fs_1.default.promises.lstat(lockPath);
78
+ if (!current.isFile() || current.isSymbolicLink()
79
+ || current.dev !== observed.dev
80
+ || current.ino !== observed.ino
81
+ || current.mtimeMs !== observed.mtimeMs
82
+ || current.size !== observed.size) {
83
+ return false;
84
+ }
85
+ await node_fs_1.default.promises.unlink(lockPath);
86
+ return true;
87
+ }
88
+ catch (_cause) {
89
+ return false;
90
+ }
91
+ }
92
+ async function releaseOwnedLockAsync(handle, lockPath, owned) {
93
+ await handle.close().catch(() => { });
94
+ if (!owned)
95
+ return false;
96
+ try {
97
+ const current = await node_fs_1.default.promises.lstat(lockPath);
98
+ if (!current.isFile() || current.isSymbolicLink()
99
+ || current.dev !== owned.dev || current.ino !== owned.ino) {
100
+ return false;
101
+ }
102
+ await node_fs_1.default.promises.unlink(lockPath);
103
+ return true;
104
+ }
105
+ catch (_cause) {
106
+ return false;
107
+ }
108
+ }
109
+ function delayAsync(milliseconds) {
110
+ return new Promise(resolve => setTimeout(resolve, milliseconds));
111
+ }
112
+ async function acquireHarmonyProjectLockAsync(projectRoot, operation) {
113
+ const canonicalRoot = await canonicalProjectRootAsync(projectRoot);
114
+ const lockPath = projectLockPath(canonicalRoot);
115
+ const deadline = Date.now() + DefaultWaitTimeoutMs;
116
+ await node_fs_1.default.promises.mkdir(node_path_1.default.dirname(lockPath), { recursive: true });
117
+ while (true) {
118
+ try {
119
+ const handle = await node_fs_1.default.promises.open(lockPath, 'wx', 0o600);
120
+ let owned;
121
+ const owner = {
122
+ createdAt: new Date().toISOString(),
123
+ operation,
124
+ pid: process.pid,
125
+ projectRoot: canonicalRoot,
126
+ token: node_crypto_1.default.randomUUID(),
127
+ };
128
+ try {
129
+ owned = await handle.stat();
130
+ await handle.writeFile(`${JSON.stringify(owner)}\n`);
131
+ await handle.sync();
132
+ }
133
+ catch (cause) {
134
+ await releaseOwnedLockAsync(handle, lockPath, owned);
135
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_PROJECT_LOCK', 'Cannot initialize the Harmony native operation lock.', { cause, operation: 'project-lock' });
136
+ }
137
+ let released = false;
138
+ return {
139
+ async releaseAsync() {
140
+ if (released)
141
+ return;
142
+ released = true;
143
+ if (await releaseOwnedLockAsync(handle, lockPath, owned))
144
+ return;
145
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_PROJECT_LOCK', 'The Harmony native operation lock changed before it could be released safely.', { operation: 'project-lock' });
146
+ },
147
+ };
148
+ }
149
+ catch (cause) {
150
+ if (cause instanceof errors_1.HarmonyCliError)
151
+ throw cause;
152
+ if (cause?.code !== 'EEXIST') {
153
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_PROJECT_LOCK', 'Cannot acquire the Harmony native operation lock.', { cause, operation: 'project-lock' });
154
+ }
155
+ if (await removeStaleProjectLockAsync(lockPath))
156
+ continue;
157
+ if (Date.now() >= deadline) {
158
+ const owner = await readLockOwnerAsync(lockPath);
159
+ const detail = owner?.operation ? ` (${owner.operation}, pid ${owner.pid})` : '';
160
+ throw new errors_1.HarmonyCliError('ERR_HARMONY_PROJECT_BUSY', `Another Harmony native operation is using this project${detail}. Retry after it finishes.`, { operation });
161
+ }
162
+ await delayAsync(Math.min(DefaultPollIntervalMs, Math.max(1, deadline - Date.now())));
163
+ }
164
+ }
165
+ }
166
+ async function withHarmonyProjectLockAsync(projectRoot, operation, callback) {
167
+ const canonicalRoot = await canonicalProjectRootAsync(projectRoot);
168
+ const active = ActiveLock.getStore();
169
+ if (active?.projectRoot === canonicalRoot && !active.released)
170
+ return await callback();
171
+ const lease = await acquireHarmonyProjectLockAsync(canonicalRoot, operation);
172
+ const context = { projectRoot: canonicalRoot, released: false };
173
+ try {
174
+ return await ActiveLock.run(context, callback);
175
+ }
176
+ finally {
177
+ context.released = true;
178
+ await lease.releaseAsync();
179
+ }
180
+ }
@@ -0,0 +1,11 @@
1
+ import type { HarmonyBuildPlan } from '../tools';
2
+ export interface HarmonyNativeBuildCacheState {
3
+ artifactCount: number;
4
+ cacheFile: string;
5
+ changed: boolean;
6
+ fingerprint: string;
7
+ fingerprintVersion: number;
8
+ }
9
+ declare function prepareHarmonyNativeBuildCacheAsync(projectRoot: 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/native-inputs");
11
+ const errors_1 = require("../errors");
12
+ const CacheSchemaVersion = 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(projectRoot, plan) {
24
+ try {
25
+ return (0, native_inputs_1.fingerprintHarmonyNativeInputsSync)({
26
+ lockfile: plan.nativeInputs.lockfile,
27
+ manifest: plan.nativeInputs.manifest,
28
+ projectRoot,
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(projectRoot, plan) {
36
+ const current = await resolveNativeDependencyFingerprintAsync(projectRoot, 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 !== CacheSchemaVersion
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: CacheSchemaVersion,
71
+ }, null, 2)}\n`);
72
+ await node_fs_1.default.promises.rename(temp, state.cacheFile);
73
+ }
@@ -0,0 +1,29 @@
1
+ import type { HarmonyTool } from '../tools';
2
+ interface Device {
3
+ aliases: string[];
4
+ connectTool: string | null;
5
+ id: string;
6
+ location: string | null;
7
+ state: string;
8
+ transport: string;
9
+ }
10
+ interface HdcOptions {
11
+ allowFailure?: boolean;
12
+ code?: string;
13
+ cwd?: string;
14
+ devicePort?: number;
15
+ message?: string;
16
+ operation?: string;
17
+ outputLimit?: number;
18
+ timeoutMs?: number;
19
+ }
20
+ interface DeviceSelectionOptions extends HdcOptions {
21
+ emulator?: HarmonyTool;
22
+ emulatorLogFile?: string;
23
+ onProgress?: (message: string) => void;
24
+ }
25
+ declare function selectDeviceAsync(hdc: HarmonyTool, requested?: string, options?: DeviceSelectionOptions): Promise<Device>;
26
+ declare function installHapAsync(hdc: HarmonyTool, device: Device, hap: string, options?: HdcOptions): Promise<void>;
27
+ declare function configureMetroPortAsync(hdc: HarmonyTool, device: Device, port: number, options?: HdcOptions): Promise<void>;
28
+ declare function launchAppAsync(hdc: HarmonyTool, device: Device, bundleName: string, abilityName: string, options?: HdcOptions): Promise<void>;
29
+ export { configureMetroPortAsync, installHapAsync, launchAppAsync, selectDeviceAsync, };