@oniroproject/core 0.6.1 → 0.7.0
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 +255 -7
- package/dist/index.cjs +1723 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +907 -21
- package/dist/index.d.ts +907 -21
- package/dist/index.js +1665 -274
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @oniroproject/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The library that powers the Oniro/OpenHarmony app-development toolchain. It wraps SDK installation, command-line-tools setup, project scaffolding, signing-config generation, `hvigorw` builds, emulator lifecycle, and the full `hdc` device surface (install/launch, files, input, screenshot, UI-layout dump, hilog, reboot/wait) — behind a **vscode-agnostic, non-interactive API** that runs on Linux, macOS, and Windows.
|
|
4
4
|
|
|
5
|
-
This package backs [`@oniroproject/oniro-app`](https://www.npmjs.com/package/@oniroproject/oniro-app) (the `oniro-app` CLI). If you just want to build
|
|
5
|
+
This package backs [`@oniroproject/oniro-app`](https://www.npmjs.com/package/@oniroproject/oniro-app) (the `oniro-app` CLI) and the same functionality embedded in editor extensions and MCP servers. If you just want to build and run Oniro apps from a shell, install the CLI; install this library to embed the functionality in your own tool.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -10,16 +10,264 @@ This package backs [`@oniroproject/oniro-app`](https://www.npmjs.com/package/@on
|
|
|
10
10
|
npm install @oniroproject/core
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Requires Node.js 20
|
|
13
|
+
Requires **Node.js 20+**. The package is ESM-first and ships CommonJS + `.d.ts` (`import` and `require` both resolve). External tools are still required at runtime for the operations that shell out to them: `java`/`keytool` for signing, and the OpenHarmony command-line tools (`hvigorw`, `ohpm`, `hdc`, `codelinter`) for building and device operations — both of which the library can also install for you.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Design
|
|
16
|
+
|
|
17
|
+
Core has no dependency on VS Code, a TTY, or `console`. Frontends inject the environment through a few small **ports**, and every function returns data (or throws a typed error) rather than printing or calling `process.exit`.
|
|
18
|
+
|
|
19
|
+
- **`ConfigProvider`** supplies paths and URLs (SDK root, tools path, mirror URLs). The CLI reads these from `ONIRO_*` env vars; tests use `staticConfig({...})`.
|
|
20
|
+
- **`Logger`** / **`ProgressReporter`** are optional injectables — default to no-ops, so nothing is written unless you wire them up (`consoleLogger` is provided for quick use).
|
|
21
|
+
- Most functions take a **single options object** whose first field is `config`, plus an optional `logger`. Device operations add `deviceSerial?`, `timeoutMs?`, and `abortSignal?`.
|
|
22
|
+
- Results are **JSON-safe values**; screenshots return **raw JPEG bytes** (no image decoding, no heavy dependencies).
|
|
23
|
+
- Long-running operations accept an **`AbortSignal`** and reject with `CancelledError` when aborted.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
Build and deploy an app:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import {
|
|
31
|
+
staticConfig,
|
|
32
|
+
consoleLogger,
|
|
33
|
+
buildHap,
|
|
34
|
+
installApp,
|
|
35
|
+
launchApp,
|
|
36
|
+
} from '@oniroproject/core';
|
|
37
|
+
|
|
38
|
+
// A ConfigProvider tells core where the SDK / tools / emulator live.
|
|
39
|
+
// staticConfig is the simplest one; the CLI reads these from ONIRO_* env vars.
|
|
40
|
+
const config = staticConfig({
|
|
41
|
+
sdkRootDir: '${userHome}/setup-ohos-sdk',
|
|
42
|
+
cmdToolsPath: '${userHome}/command-line-tools',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const build = await buildHap({ config, projectDir: '/path/to/app', logger: consoleLogger });
|
|
46
|
+
console.log(build.discoveredHaps); // { entry: { signed: [...], unsigned: [...] } }
|
|
47
|
+
|
|
48
|
+
await installApp({ config, projectDir: '/path/to/app', logger: consoleLogger });
|
|
49
|
+
await launchApp({ config, projectDir: '/path/to/app', logger: consoleLogger });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Drive a connected device:
|
|
16
53
|
|
|
17
54
|
```ts
|
|
18
|
-
import {
|
|
55
|
+
import { staticConfig, takeScreenshot, dumpLayout, sendInput, waitForLog } from '@oniroproject/core';
|
|
56
|
+
import { writeFile } from 'node:fs/promises';
|
|
57
|
+
|
|
58
|
+
const config = staticConfig();
|
|
59
|
+
|
|
60
|
+
const shot = await takeScreenshot({ config }); // { pixels: Buffer, width, height }
|
|
61
|
+
await writeFile('shot.jpeg', shot.pixels);
|
|
62
|
+
|
|
63
|
+
const { tree } = await dumpLayout({ config }); // pruned, 0–1-normalized UI tree
|
|
64
|
+
await sendInput({ config, type: 'click', pxX: 200, pxY: 400 });
|
|
65
|
+
|
|
66
|
+
const entry = await waitForLog({ config, pattern: /ability launched/i, timeoutMs: 10_000 });
|
|
67
|
+
console.log(entry.tag, entry.message);
|
|
19
68
|
```
|
|
20
69
|
|
|
21
|
-
|
|
70
|
+
## API reference
|
|
71
|
+
|
|
72
|
+
`import { … } from '@oniroproject/core'` — everything below is a named export. `VERSION` is the package version string.
|
|
73
|
+
|
|
74
|
+
### Runtime seams (ports)
|
|
75
|
+
|
|
76
|
+
The injection points every frontend implements, plus their defaults.
|
|
77
|
+
|
|
78
|
+
| Export | Description |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `interface ConfigProvider` / `type ConfigKey` | `get(key, fallback)`. Keys: `sdkRootDir`, `cmdToolsPath`, `emulatorDir`, `hapPath`, `cmdToolsUrlLinux/Windows/Mac`, `emulatorUrl`, `sdkUrlBase`, `applicationCertPath`. |
|
|
81
|
+
| `staticConfig(values?)` | An in-memory `ConfigProvider` (expands `${userHome}`). For tests and as a base for frontend impls. |
|
|
82
|
+
| `defaultPaths` | The fallback values core uses when a key is unset. |
|
|
83
|
+
| `interface Logger` / `noopLogger` / `consoleLogger` | 4-level logger (`debug`/`info`/`warn`/`error`). Defaults to no-op. |
|
|
84
|
+
| `scopedLogger(logger, scope)` | Wrap a logger so every message is prefixed `[<scope>] `. |
|
|
85
|
+
| `interface ProgressReporter` / `ProgressUpdate` / `noopProgress` | `report({ message?, increment? })` for download/extract progress. |
|
|
86
|
+
| `interface Prompter` / `nonInteractivePrompter` | Interactive-prompt port; the non-interactive one throws on any prompt. |
|
|
87
|
+
| `interface OniroContext` / `defaultContext(overrides?)` | Bundles `{ logger, config }` for callers that prefer a context object. |
|
|
88
|
+
|
|
89
|
+
**Errors** — all extend `OniroError` (which carries an optional `cause`):
|
|
90
|
+
|
|
91
|
+
`OniroError` · `SdkNotInstalledError` · `CmdToolsNotInstalledError` · `UnsupportedPlatformError` · `ChecksumMismatchError` · `CancelledError` · `CommandFailedError` (carries `command`, `exitCode`, `stderr`).
|
|
92
|
+
|
|
93
|
+
### SDK management
|
|
94
|
+
|
|
95
|
+
| Export | Signature | Description |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `downloadAndInstallSdk` | `(InstallSdkOptions) => Promise<void>` | Download + install an SDK release into `<sdkRootDir>/<os>/<api>`, reporting progress. |
|
|
98
|
+
| `getSupportedSdksForUi` | `(config) => SdkInfo[]` | Known SDKs annotated with `installed`, newest first. |
|
|
99
|
+
| `getInstalledSdks` | `(config) => string[]` | Versions with at least one OS-folder install. |
|
|
100
|
+
| `removeSdk` | `(config, api) => boolean` | Remove an installed SDK by API level across OS folders. |
|
|
101
|
+
| `detectProjectSdkVersion` | `(projectRoot, logger?) => number \| undefined` | Read `compileSdkVersion` from a project's `build-profile.json5`. |
|
|
102
|
+
| `ALL_SDKS` / `SdkRelease` | — | Catalog of known releases (`version`, `api`, `tarballStrip`). |
|
|
103
|
+
| `OHOS_URL_BASE` | — | Default SDK mirror base URL. |
|
|
104
|
+
| `getOsFolder()` / `getSdkFilename(version?)` | — | Map the host platform to its OS folder / SDK archive (`SdkArchiveInfo`). |
|
|
105
|
+
|
|
106
|
+
**Path resolvers** (all take `config`): `getSdkRootDir`, `getOhosBaseSdkHome`, `getCmdToolsPath`, `getEmulatorDir`, `getHdcPath`, `getOhpmPath`, `getCmdToolsBin(config, name?)`, `getHvigorwPath(config, projectDir)` (prefers the project-local wrapper only when it is structurally complete, else the bundled one).
|
|
107
|
+
|
|
108
|
+
**Download/archive primitives**: `downloadFile(DownloadOptions)`, `verifySha256(file, sha256File)`, `extractZipWithProgress(ExtractZipOptions)` (Zip-Slip-safe), `extractTarball(tar, dest, strip?)`.
|
|
109
|
+
|
|
110
|
+
### Command-line tools
|
|
111
|
+
|
|
112
|
+
| Export | Signature | Description |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| `installCmdTools` | `(InstallCmdToolsOptions) => Promise<void>` | Install the tools by download or from a local zip (`localZipPath`). |
|
|
115
|
+
| `getCmdToolsStatus` | `(config) => CmdToolsStatus` | `{ installed, status }` (version when present). |
|
|
116
|
+
| `isCmdToolsInstalled` | `(config) => boolean` | — |
|
|
117
|
+
| `removeCmdTools` | `(config) => void` | Delete the install. |
|
|
118
|
+
| `getCmdToolsDownloadUrl` | `(config, platform?) => string` | Per-platform download URL (only Linux is public on the mirror). |
|
|
119
|
+
| `findCmdToolsSourceDir` | `(extractPath) => string` | Locate the tools root inside an extraction folder. |
|
|
120
|
+
|
|
121
|
+
### Signing
|
|
122
|
+
|
|
123
|
+
`java` must be on `PATH` (the OpenHarmony hap-sign-tool ships as a `.jar`).
|
|
124
|
+
|
|
125
|
+
| Export | Signature | Description |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| `generateSigningConfigs` | `(GenerateSigningConfigsOptions) => void` | Generate keys/certs/material and write the `signingConfigs` block into `build-profile.json5`. |
|
|
128
|
+
| `pickSigningKind` | `(apl) => SigningKind` | `'profile-release'` for `normal`, `'application-release'` for `system_basic`/`system_core`. |
|
|
129
|
+
| `detectSigningConfigNames` | `(projectDir) => string[]` | The `products[*].signingConfig` names (falls back to `['default']`). |
|
|
130
|
+
| `createMaterial` / `getKey` / `encryptPwd` / `decryptPwd` | — | Signing-material key derivation + password encryption used in the profile. |
|
|
131
|
+
| `APL_VALUES` / `APP_FEATURE_VALUES` | — | Allowed values for `Apl` (`normal`/`system_basic`/`system_core`) and `AppFeature` (`hos_normal_app`/`hos_system_app`). |
|
|
132
|
+
| types | `GenerateSigningConfigsOptions`, `SigningPasswords`, `SigningKind`, `Apl`, `AppFeature` | `apl`, `appFeature`, `acls`, `passwords`, and `applicationCertPath` all default to the SDK's dev cert / `123456` keystore. |
|
|
133
|
+
|
|
134
|
+
### Emulator
|
|
135
|
+
|
|
136
|
+
| Export | Signature | Description |
|
|
137
|
+
| --- | --- | --- |
|
|
138
|
+
| `installEmulator` | `(InstallEmulatorOptions) => Promise<void>` | Download + extract the QEMU emulator into `emulatorDir`. |
|
|
139
|
+
| `isEmulatorInstalled` / `removeEmulator` | `(config) => boolean` / `void` | — |
|
|
140
|
+
| `startEmulator` | `(StartEmulatorOptions) => Promise<void>` | Launch detached via `run.sh`/`run.bat`; optional `headless`, `logFile`, `connect`, and `waitForHdcSeconds`. |
|
|
141
|
+
| `stopEmulator` | `(logger?) => Promise<void>` | Kill running emulator processes. |
|
|
142
|
+
| `attemptHdcConnection` | `(config, address?, logger?) => Promise<boolean>` | Try to connect `hdc` (default `127.0.0.1:55555`). |
|
|
143
|
+
|
|
144
|
+
### hdc — process execution
|
|
145
|
+
|
|
146
|
+
The injection-safe primitives every device operation builds on (`spawn` with `shell: false`; args are arrays, never interpolated into a shell string).
|
|
147
|
+
|
|
148
|
+
| Export | Signature | Description |
|
|
149
|
+
| --- | --- | --- |
|
|
150
|
+
| `runProcess` | `(RunProcessOptions) => Promise<HdcExecResult>` | Spawn any process and collect `{ code, stdout, stderr }`. Resolves for **any** exit code. |
|
|
151
|
+
| `hdcExec` | `(HdcExecOptions) => Promise<HdcExecResult>` | Run `hdc [-t <serial>] <args…>`. |
|
|
152
|
+
| `shell` | `(HdcShellOptions) => Promise<HdcExecResult>` | Convenience wrapper for `hdc shell <command>`. |
|
|
153
|
+
| `ensureOk` | `(result, command) => HdcExecResult` | Throw `CommandFailedError` when `code !== 0`; otherwise pass through. |
|
|
154
|
+
| `type OutputSink` | — | `(chunk, 'stdout'\|'stderr') => void`, for streaming output. |
|
|
155
|
+
|
|
156
|
+
### hdc — devices & system properties
|
|
157
|
+
|
|
158
|
+
| Export | Signature | Description |
|
|
159
|
+
| --- | --- | --- |
|
|
160
|
+
| `listDevices` | `(config, opts?) => Promise<DeviceInfo[]>` | Parse `hdc list targets -v`. |
|
|
161
|
+
| `selectDevice` | `(config, serial?, opts?) => Promise<string>` | Resolve the target: explicit serial → `ONIRO_DEVICE_SERIAL`/`DEVICE_SERIAL` env → the single connected device (throws on ambiguity). |
|
|
162
|
+
| `parseDeviceList` | `(stdout) => DeviceInfo[]` | Pure parser (unit-testable). |
|
|
163
|
+
| `paramGet` / `paramSet` | `(config, key[, value], opts?) => Promise<…>` | Read/write system properties via `param get`/`set`. |
|
|
164
|
+
|
|
165
|
+
### hdc — files
|
|
166
|
+
|
|
167
|
+
`sendFile(SendFileOptions)` / `recvFile(RecvFileOptions)` — push/pull a file via `hdc file send`/`recv`.
|
|
168
|
+
|
|
169
|
+
### hdc — lifecycle & waiting
|
|
170
|
+
|
|
171
|
+
| Export | Signature | Description |
|
|
172
|
+
| --- | --- | --- |
|
|
173
|
+
| `reboot` | `(RebootOptions) => Promise<void>` | `system` (via `param set ohos.startup.powerctrl reboot`), `bootloader`, or `recovery`. Optionally waits for a bundle to return (and reconnects a TCP target across the reboot). |
|
|
174
|
+
| `waitForBundle` | `(WaitForBundleOptions) => Promise<void>` | Poll `pidof <bundle>` until it has a clean numeric pid. |
|
|
175
|
+
| `waitForBoot` | `(WaitForBootOptions) => Promise<void>` | Poll until reachable (and optionally `untilPidOf` has a pid). Tolerant of the reboot disconnect. |
|
|
176
|
+
| `waitForCondition` | `(WaitForConditionOptions) => Promise<void>` | Generic deadline + poll + heartbeat loop. A throwing probe counts as "not yet". |
|
|
177
|
+
|
|
178
|
+
### hdc — app install, launch & process
|
|
179
|
+
|
|
180
|
+
| Export | Signature | Description |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `installApp` | `(InstallAppOptions) => Promise<InstallAppResult>` | Install the signed `.hap` (resolves the path from `hapPath` / config / default). |
|
|
183
|
+
| `launchApp` | `(LaunchAppOptions) => Promise<void>` | `aa start` the entry ability (or an explicit `abilityName`). |
|
|
184
|
+
| `uninstallApp` / `forceStop` | `(BundleOptions) => Promise<void>` | Uninstall / force-stop by bundle name. |
|
|
185
|
+
| `findRunningProcess` | `(BundleOptions) => Promise<RunningProcess \| null>` | Non-throwing `pidof` check. |
|
|
186
|
+
| `listRunningProcesses` / `findAppProcessId` | — | `track-jpid`-based process listing / project-PID resolution. |
|
|
187
|
+
| `detectAaStartFailure` | `(output) => string \| null` | Detect a refused launch (`aa start` exits 0 even on failure). |
|
|
188
|
+
| `getBundleName` / `getMainAbility` | `(projectDir[, module?, ability?]) => string` | Read the bundle / resolve the launch ability from project manifests. |
|
|
189
|
+
|
|
190
|
+
### hdc — capture, display & UI dump
|
|
191
|
+
|
|
192
|
+
| Export | Signature | Description |
|
|
193
|
+
| --- | --- | --- |
|
|
194
|
+
| `takeScreenshot` | `(ScreenshotOptions) => Promise<Screenshot>` | `{ pixels: Buffer, width, height }` — raw JPEG, no decode. |
|
|
195
|
+
| `captureBurst` | `(CaptureBurstOptions) => Promise<Buffer[]>` | N frames `intervalMs` apart, pulled back in order. |
|
|
196
|
+
| `getDisplaySize` | `(config, opts?) => Promise<DisplaySize \| null>` | Render resolution from `hidumper` (no image work). |
|
|
197
|
+
| `dumpLayout` | `(DumpLayoutOptions) => Promise<DumpLayoutResult>` | `uitest dumpLayout` → pruned, 0–1-normalized `LayoutNode` tree. |
|
|
198
|
+
| `parseBounds` / `pruneLayout` | — | Pure helpers behind `dumpLayout`. |
|
|
199
|
+
|
|
200
|
+
### hdc — input injection
|
|
201
|
+
|
|
202
|
+
| Export | Signature | Description |
|
|
203
|
+
| --- | --- | --- |
|
|
204
|
+
| `sendInput` | `(SendInputOptions) => Promise<void>` | One `uitest uiInput` action in **pixel** space (`InputType`: click/doubleClick/longClick/swipe/drag/fling/keyEvent/inputText). |
|
|
205
|
+
| `sendGesture` | `(SendGestureOptions) => Promise<void>` | Multi-`Waypoint` path; routes through `uinput` when `holdStartMs`/`holdEndMs` need real press timing. |
|
|
206
|
+
| `sendRawTouch` | `(SendRawTouchOptions) => Promise<void>` | Low-level `uinput -T` down/move/up events. |
|
|
207
|
+
| `buildInputCommand` / `buildGestureCommands` / `buildRawTouchCommand` | — | Pure command builders (unit-testable). |
|
|
208
|
+
|
|
209
|
+
### hdc — logging (hilog)
|
|
210
|
+
|
|
211
|
+
| Export | Signature | Description |
|
|
212
|
+
| --- | --- | --- |
|
|
213
|
+
| `waitForLog` | `(WaitForLogOptions) => Promise<HilogEntry>` | First entry matching a regex; auto-respawns the stream so it survives a reboot. |
|
|
214
|
+
| `watchLog` | `(WatchLogOptions) => Promise<HilogEntry[]>` | Collect matches for a duration (deduped by default). |
|
|
215
|
+
| `dumpLog` | `(DumpLogOptions) => Promise<HilogEntry[]>` | One-shot `hilog -x` filtered by domain/bundle/grep, capped to the last N lines. |
|
|
216
|
+
| `streamHilog` | `(StreamHilogOptions) => ChildProcessWithoutNullStreams` | Raw long-lived hilog stream (caller owns the process). |
|
|
217
|
+
| `setHilogLevel` | `(SetHilogLevelOptions) => Promise<void>` | Set the buffer level. |
|
|
218
|
+
| `parseHilogLine` / `dedupEntries` | — | Pure helpers; `HilogEntry` / `HilogLevel` types. |
|
|
219
|
+
|
|
220
|
+
### Build & dependencies
|
|
221
|
+
|
|
222
|
+
| Export | Signature | Description |
|
|
223
|
+
| --- | --- | --- |
|
|
224
|
+
| `buildHap` | `(BuildHapOptions) => Promise<BuildHapResult>` | High-level orchestration: ensure deps → `hvigorw` → discover built HAPs. The call most consumers want. |
|
|
225
|
+
| `runHvigorw` | `(RunHvigorwOptions) => Promise<RunHvigorwResult>` | Raw single `hvigorw` spawn. Parallel by default; `parallel: false` adds `--no-parallel`. |
|
|
226
|
+
| `buildHvigorwArgs` | `(opts) => string[]` | Pure argv builder (unit-testable). |
|
|
227
|
+
| `discoverHaps` | `(DiscoverHapsOptions) => Promise<Record<string, ModuleHaps>>` | Group `*-signed`/`*-unsigned` HAPs by module. |
|
|
228
|
+
| `runOhpm` / `ensureOhModules` | — | Run `ohpm`; install `--all` only when `oh_modules/` is missing. |
|
|
229
|
+
| `runCodelinter` / `parseCodelinterFindings` | — | Run the codelinter → `CodelinterResult { code, findings, raw }`. |
|
|
230
|
+
|
|
231
|
+
### Project scaffolding & inspection
|
|
232
|
+
|
|
233
|
+
| Export | Signature | Description |
|
|
234
|
+
| --- | --- | --- |
|
|
235
|
+
| `createScaffold` | `(CreateScaffoldOptions) => Promise<CreateScaffoldResult>` | Scaffold a project from a template; returns the created path. |
|
|
236
|
+
| `listTemplates` | `(templateRoot) => TemplateOption[]` | Enumerate templates under a caller-owned root. |
|
|
237
|
+
| `validateTemplateLayout` | `(templateDir, defaultModuleName) => string[]` | Missing required files, or `[]`. |
|
|
238
|
+
| `isValidProjectName` / `isValidBundleName` | `(s) => boolean` | Input validators. |
|
|
239
|
+
| `listModules` | `({ projectDir }) => ProjectModule[]` | `modules[]` from `build-profile.json5`. |
|
|
240
|
+
| `listAbilities` | `({ projectDir, moduleName? }) => AbilityInfo[]` | `abilities[]` from a module's `module.json5`. |
|
|
241
|
+
| `prepareSigning` | `(PrepareSigningOptions) => PrepareSigningResult` | No-op when signing material is present; otherwise generate it (`source: 'present' \| 'fresh'`). |
|
|
242
|
+
| `readJson5File` / `writeJson5File` / `readJsonFile` / `writeJsonFile` | — | JSON/JSON5 read/write helpers. |
|
|
243
|
+
|
|
244
|
+
### Device info
|
|
245
|
+
|
|
246
|
+
`getDeviceInfo(GetDeviceInfoOptions) => Promise<DeviceFullInfo>` collates device properties + display resolution. `dumpScreen` / `dumpWindow` / `dumpRenderService` wrap the corresponding `hidumper` services.
|
|
247
|
+
|
|
248
|
+
### Install orchestration
|
|
249
|
+
|
|
250
|
+
| Export | Signature | Description |
|
|
251
|
+
| --- | --- | --- |
|
|
252
|
+
| `applyChanges` | `(ApplyChangesOptions) => Promise<ApplyChangesResult>` | Install a HAP **and verify the process took it** — handles sign-info mismatch, asset-cache invalidation (reboot), and persistent-bundle restart. |
|
|
253
|
+
| `decideInstallMethod` / `decideReboot` | — | The pure (tested) decision functions behind `applyChanges`. |
|
|
254
|
+
| `diffHapAssets` / `diffEntryNames` | — | Diff two HAP archives' file manifests (drives the cache-invalidation reboot). |
|
|
255
|
+
|
|
256
|
+
## Conventions
|
|
257
|
+
|
|
258
|
+
- **Configuration.** Pass a `ConfigProvider`. `staticConfig({...})` is the quick path; a frontend can read settings, env vars, etc. Unset keys fall back to `defaultPaths`.
|
|
259
|
+
- **Logging & progress are opt-in.** Omit `logger`/`progress` for silence, or pass `consoleLogger` / your own. Nothing is written to `console` by default.
|
|
260
|
+
- **Device targeting.** Pass `deviceSerial` to address a specific target; omit it to use the default connected device. `selectDevice` additionally honors `ONIRO_DEVICE_SERIAL` / `DEVICE_SERIAL`.
|
|
261
|
+
- **Timeouts & cancellation.** Device ops take `timeoutMs` (sane per-op defaults) and `abortSignal`; aborting rejects with `CancelledError`.
|
|
262
|
+
- **Error model.** Exec primitives (`runProcess`/`hdcExec`/`shell`) resolve for any exit code — call `ensureOk` to throw `CommandFailedError`. Everything else throws a typed `OniroError` subclass.
|
|
263
|
+
- **No surprises in returns.** Functions return plain JSON-safe data; screenshots/bursts return raw `Buffer`s. No image decoding, no `sharp`-style dependency.
|
|
264
|
+
- **Pure helpers for testing.** Command/argv builders (`build*Command`, `buildHvigorwArgs`), parsers (`parse*`), and decision functions (`decide*`) are exported as side-effect-free functions.
|
|
265
|
+
|
|
266
|
+
## Related
|
|
267
|
+
|
|
268
|
+
- [`@oniroproject/oniro-app`](https://www.npmjs.com/package/@oniroproject/oniro-app) — the CLI built on this library.
|
|
269
|
+
- [Repository README](https://github.com/eclipse-oniro4openharmony/oniro-app-builder#readme) — workflow overview, Docker, and CI.
|
|
22
270
|
|
|
23
271
|
## License
|
|
24
272
|
|
|
25
|
-
Apache-2.0
|
|
273
|
+
Apache-2.0 — see [LICENSE](https://github.com/eclipse-oniro4openharmony/oniro-app-builder/blob/main/LICENSE).
|