@oniroproject/core 0.11.0 → 0.12.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 CHANGED
@@ -99,7 +99,7 @@ The injection points every frontend implements, plus their defaults.
99
99
  | `getInstalledSdks` | `(config) => string[]` | Versions with at least one OS-folder install. |
100
100
  | `removeSdk` | `(config, api) => boolean` | Remove an installed SDK by API level across OS folders. |
101
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`). |
102
+ | `ALL_SDKS` / `SdkRelease` | — | Catalog of known releases (`version`, `api`, `tarballStrip`, optional `archiveSuffix`). |
103
103
  | `OHOS_URL_BASE` | — | Default SDK mirror base URL. |
104
104
  | `getOsFolder()` / `getSdkFilename(version?)` | — | Map the host platform to its OS folder / SDK archive (`SdkArchiveInfo`). |
105
105
 
@@ -182,7 +182,7 @@ The injection-safe primitives every device operation builds on (`spawn` with `sh
182
182
 
183
183
  | Export | Signature | Description |
184
184
  | --- | --- | --- |
185
- | `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). |
185
+ | `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, restarting the hdc server if it keeps the dead session). |
186
186
  | `waitForBundle` | `(WaitForBundleOptions) => Promise<void>` | Poll `pidof <bundle>` until it has a clean numeric pid. |
187
187
  | `waitForBoot` | `(WaitForBootOptions) => Promise<void>` | Poll until reachable (and optionally `untilPidOf` has a pid). Tolerant of the reboot disconnect. |
188
188
  | `waitForCondition` | `(WaitForConditionOptions) => Promise<void>` | Generic deadline + poll + heartbeat loop. A throwing probe counts as "not yet". |
package/dist/index.cjs CHANGED
@@ -375,7 +375,8 @@ var ALL_SDKS = [
375
375
  { version: "5.1.0", api: "18", tarballStrip: { linuxWindows: 1, darwin: 3 } },
376
376
  { version: "5.1.1", api: "19", tarballStrip: { linuxWindows: 1, darwin: 3 } },
377
377
  { version: "6.0", api: "20", tarballStrip: { linuxWindows: 0, darwin: 3 } },
378
- { version: "6.1", api: "23", tarballStrip: { linuxWindows: 0, darwin: 3 } }
378
+ { version: "6.1", api: "23", tarballStrip: { linuxWindows: 0, darwin: 3 } },
379
+ { version: "7.0", api: "26", tarballStrip: { linuxWindows: 1, darwin: 3 }, archiveSuffix: "_20260829" }
379
380
  ];
380
381
  var OHOS_URL_BASE = "https://repo.huaweicloud.com/openharmony/os";
381
382
 
@@ -391,18 +392,20 @@ function getOsFolder() {
391
392
  function getSdkFilename(version) {
392
393
  const platform7 = os2.platform();
393
394
  const v = version ?? ALL_SDKS[ALL_SDKS.length - 1].version;
394
- const strips = ALL_SDKS.find((r) => r.version === v)?.tarballStrip ?? { linuxWindows: 1, darwin: 3 };
395
+ const release = ALL_SDKS.find((r) => r.version === v);
396
+ const strips = release?.tarballStrip ?? { linuxWindows: 1, darwin: 3 };
397
+ const archive = (base) => `${base}${release?.archiveSuffix ?? ""}.tar.gz`;
395
398
  if (platform7 === "linux") {
396
- return { filename: "ohos-sdk-windows_linux-public.tar.gz", osFolder: "linux", strip: strips.linuxWindows };
399
+ return { filename: archive("ohos-sdk-windows_linux-public"), osFolder: "linux", strip: strips.linuxWindows };
397
400
  }
398
401
  if (platform7 === "darwin") {
399
402
  if (os2.arch() === "arm64") {
400
- return { filename: "L2-SDK-MAC-M1-PUBLIC.tar.gz", osFolder: "darwin", strip: strips.darwin };
403
+ return { filename: archive("L2-SDK-MAC-M1-PUBLIC"), osFolder: "darwin", strip: strips.darwin };
401
404
  }
402
- return { filename: "ohos-sdk-mac-public.tar.gz", osFolder: "darwin", strip: strips.darwin };
405
+ return { filename: archive("ohos-sdk-mac-public"), osFolder: "darwin", strip: strips.darwin };
403
406
  }
404
407
  if (platform7 === "win32") {
405
- return { filename: "ohos-sdk-windows_linux-public.tar.gz", osFolder: "windows", strip: strips.linuxWindows };
408
+ return { filename: archive("ohos-sdk-windows_linux-public"), osFolder: "windows", strip: strips.linuxWindows };
406
409
  }
407
410
  throw new UnsupportedPlatformError(platform7);
408
411
  }
@@ -2464,19 +2467,39 @@ async function isReachable(config, deviceSerial) {
2464
2467
  }
2465
2468
  }
2466
2469
  var TCP_SERIAL_RE = /^.+:\d+$/;
2467
- async function reconnectIfTcp(config, deviceSerial, logger) {
2468
- if (!deviceSerial || !TCP_SERIAL_RE.test(deviceSerial)) return;
2469
- try {
2470
- await hdcExec({ config, args: ["tconn", deviceSerial], timeoutMs: 5e3, logger });
2471
- } catch {
2472
- }
2470
+ var WEDGED_POLLS_BEFORE_RESTART = 3;
2471
+ function tcpReconnector(config, deviceSerial, logger) {
2472
+ let wedgedPolls = 0;
2473
+ return async () => {
2474
+ if (!deviceSerial || !TCP_SERIAL_RE.test(deviceSerial)) return;
2475
+ let claimsConnected = false;
2476
+ try {
2477
+ const res = await hdcExec({ config, args: ["tconn", deviceSerial], timeoutMs: 5e3, logger });
2478
+ claimsConnected = /already connected|repeat operation/i.test(`${res.stdout}
2479
+ ${res.stderr}`);
2480
+ } catch {
2481
+ }
2482
+ if (!claimsConnected || await isReachable(config, deviceSerial)) {
2483
+ wedgedPolls = 0;
2484
+ return;
2485
+ }
2486
+ if (++wedgedPolls < WEDGED_POLLS_BEFORE_RESTART) return;
2487
+ wedgedPolls = 0;
2488
+ logger.warn(`hdc reports ${deviceSerial} as connected but it does not answer; restarting the hdc server.`);
2489
+ try {
2490
+ await hdcExec({ config, args: ["start", "-r"], timeoutMs: 15e3, logger });
2491
+ await hdcExec({ config, args: ["tconn", deviceSerial], timeoutMs: 5e3, logger });
2492
+ } catch {
2493
+ }
2494
+ };
2473
2495
  }
2474
2496
  async function waitForBundle(opts) {
2475
2497
  const logger = scopedLogger(opts.logger ?? noopLogger, "hdc");
2476
2498
  const timeoutMs = opts.timeoutMs ?? 18e4;
2499
+ const reconnectIfTcp = tcpReconnector(opts.config, opts.deviceSerial, logger);
2477
2500
  await waitForCondition({
2478
2501
  probe: async () => {
2479
- await reconnectIfTcp(opts.config, opts.deviceSerial, logger);
2502
+ await reconnectIfTcp();
2480
2503
  return await findRunningProcess({ config: opts.config, bundle: opts.bundle, deviceSerial: opts.deviceSerial, timeoutMs: 8e3 }) !== null;
2481
2504
  },
2482
2505
  timeoutMs,
@@ -2489,9 +2512,10 @@ async function waitForBundle(opts) {
2489
2512
  async function waitForBoot(opts) {
2490
2513
  const logger = scopedLogger(opts.logger ?? noopLogger, "hdc");
2491
2514
  const timeoutMs = opts.timeoutMs ?? 18e4;
2515
+ const reconnectIfTcp = tcpReconnector(opts.config, opts.deviceSerial, logger);
2492
2516
  await waitForCondition({
2493
2517
  probe: async () => {
2494
- await reconnectIfTcp(opts.config, opts.deviceSerial, logger);
2518
+ await reconnectIfTcp();
2495
2519
  if (!await isReachable(opts.config, opts.deviceSerial)) return false;
2496
2520
  if (!opts.untilPidOf) return true;
2497
2521
  return await findRunningProcess({ config: opts.config, bundle: opts.untilPidOf, deviceSerial: opts.deviceSerial, timeoutMs: 8e3 }) !== null;
@@ -4947,7 +4971,7 @@ async function harmonyOsAutoSign(opts) {
4947
4971
  }
4948
4972
 
4949
4973
  // src/index.ts
4950
- var VERSION = "0.11.0";
4974
+ var VERSION = "0.12.0";
4951
4975
  // Annotate the CommonJS export names for ESM import in node:
4952
4976
  0 && (module.exports = {
4953
4977
  ALL_SDKS,