@oniroproject/core 0.15.0 → 0.15.1

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/dist/index.cjs CHANGED
@@ -163,6 +163,7 @@ __export(index_exports, {
163
163
  isOutOfSpaceError: () => isOutOfSpaceError,
164
164
  isRamBackedPath: () => isRamBackedPath,
165
165
  isUnsignedHap: () => isUnsignedHap,
166
+ isUsableDevice: () => isUsableDevice,
166
167
  isValidBundleName: () => isValidBundleName,
167
168
  isValidProjectName: () => isValidProjectName,
168
169
  killProcessTree: () => killProcessTree,
@@ -2342,12 +2343,13 @@ async function listDevices(config, opts = {}) {
2342
2343
  });
2343
2344
  return parseDeviceList(res.stdout);
2344
2345
  }
2346
+ function isUsableDevice(device) {
2347
+ return device.status === "Connected" || device.status === "Unknown";
2348
+ }
2345
2349
  async function selectDevice(config, serial, opts = {}) {
2346
2350
  const resolved = resolveDeviceSerial(serial);
2347
2351
  if (resolved) return resolved;
2348
- const usable = (await listDevices(config, opts)).filter(
2349
- (d) => d.status === "Connected" || d.status === "Unknown"
2350
- );
2352
+ const usable = (await listDevices(config, opts)).filter(isUsableDevice);
2351
2353
  if (usable.length === 1) return usable[0].serial;
2352
2354
  if (usable.length === 0) {
2353
2355
  throw new OniroError("No connected device found. Connect a device/emulator or set ONIRO_DEVICE_SERIAL.");
@@ -5479,7 +5481,7 @@ var SIGNING_ERRORS = {
5479
5481
  DEVICE_ADD: "AppGallery Connect did not register the device.",
5480
5482
  DEVICE_LIMIT: "This team has reached its device limit. Remove an unused device in AppGallery Connect and retry.",
5481
5483
  DEVICE_NAME_REPEAT: "A device with that name is already registered. Retry.",
5482
- DEVICE_NONE: "No device is connected and none is registered to this team, but a debug profile must name at least one. Connect a device and retry.",
5484
+ DEVICE_NONE: "This team has no registered device and none could be registered from here, but a debug profile must name at least one. Connect a device that reports a UDID (`hdc shell bm get -u`), or register one in AppGallery Connect, and retry.",
5483
5485
  PROFILE_ADD: "AppGallery Connect did not issue the provisioning profile.",
5484
5486
  PROFILE_NAME_REPEAT: "A provisioning profile with that name already exists in AppGallery Connect. Retry.",
5485
5487
  PROVISION_LIMIT: "This team has reached its debug-profile limit. Delete unused profiles in AppGallery Connect and retry.",
@@ -5728,21 +5730,31 @@ function parseDeviceKind(stdout) {
5728
5730
  }
5729
5731
  async function collectLocalDevices(config, logger) {
5730
5732
  const devices = [];
5733
+ const skipped = [];
5731
5734
  for (const target of await listDevices(config, { logger, timeoutMs: 15e3 })) {
5732
- if (target.status !== "Connected") continue;
5735
+ const skip = (why) => {
5736
+ logger.warn(`[harmonyos] ${target.serial} ${why}`);
5737
+ skipped.push(target.serial);
5738
+ };
5739
+ if (!isUsableDevice(target)) {
5740
+ skip(
5741
+ target.status === "Unauthorized" ? "is unauthorized; accept the debugging prompt on the device to register it." : `is ${target.status.toLowerCase()}; skipping it.`
5742
+ );
5743
+ continue;
5744
+ }
5733
5745
  const shell2 = async (...args) => (await hdcExec({ config, deviceSerial: target.serial, args: ["shell", ...args], timeoutMs: 15e3, logger })).stdout;
5734
5746
  try {
5735
5747
  const udid = parseUdid(await shell2("bm", "get", "-u"));
5736
5748
  if (!udid) {
5737
- logger.warn(`[harmonyos] ${target.serial} did not report a UDID; skipping it.`);
5749
+ skip("did not report a UDID (`bm get -u`), so it cannot be registered.");
5738
5750
  continue;
5739
5751
  }
5740
5752
  devices.push({ serial: target.serial, udid, kind: parseDeviceKind(await shell2("getprop", "hw_sc.build.os.deviceType")) });
5741
5753
  } catch (err) {
5742
- logger.warn(`[harmonyos] Could not read ${target.serial}: ${err.message}`);
5754
+ skip(`could not be read: ${err.message}`);
5743
5755
  }
5744
5756
  }
5745
- return devices;
5757
+ return { devices, skipped };
5746
5758
  }
5747
5759
  async function registerDevices(agc, connected, logger) {
5748
5760
  let devices = await agc.listDevices();
@@ -5755,11 +5767,6 @@ async function registerDevices(agc, connected, logger) {
5755
5767
  if (unregistered.length > 0) devices = await agc.listDevices();
5756
5768
  const deviceIds = devices.map((d) => d.id);
5757
5769
  if (deviceIds.length === 0) throw new AgcError(SIGNING_ERRORS.DEVICE_NONE);
5758
- if (connected.length === 0) {
5759
- logger.warn(
5760
- `[harmonyos] No device is connected; the profile will name the ${deviceIds.length} device(s) already registered to this team.`
5761
- );
5762
- }
5763
5770
  return deviceIds;
5764
5771
  }
5765
5772
 
@@ -5996,7 +6003,7 @@ async function harmonyOsAutoSign(opts) {
5996
6003
  const aclPermissions = collectAclPermissions(projectDir, logger);
5997
6004
  const paths = resolveSigningMaterialPaths(opts.config, productName, projectDir);
5998
6005
  logger.info(`[harmonyos] Signing ${bundleName} (product '${productName}', team ${auth.teamId}).`);
5999
- const connected = await collectLocalDevices(opts.config, logger);
6006
+ const local = await collectLocalDevices(opts.config, logger);
6000
6007
  const result = (regenerated) => ({
6001
6008
  bundleName,
6002
6009
  teamId: auth.teamId,
@@ -6010,7 +6017,7 @@ async function harmonyOsAutoSign(opts) {
6010
6017
  productName,
6011
6018
  bundleName,
6012
6019
  teamId: auth.teamId,
6013
- connectedUdids: connected.map((d) => d.udid),
6020
+ connectedUdids: local.devices.map((d) => d.udid),
6014
6021
  aclPermissions,
6015
6022
  force: opts.force
6016
6023
  });
@@ -6020,7 +6027,11 @@ async function harmonyOsAutoSign(opts) {
6020
6027
  }
6021
6028
  logger.info(`[harmonyos] Regenerating signing material: ${reason}.`);
6022
6029
  const agc = createAgcClient(opts.http ?? createHttpClient({ logger }), auth);
6023
- const deviceIds = await registerDevices(agc, connected, logger);
6030
+ const deviceIds = await registerDevices(agc, local.devices, logger);
6031
+ if (local.devices.length === 0) {
6032
+ const cause = local.skipped.length > 0 ? "No connected device could be registered" : "No device is connected";
6033
+ logger.warn(`[harmonyos] ${cause}; the profile will name the ${deviceIds.length} device(s) already registered to this team.`);
6034
+ }
6024
6035
  for (const file of Object.values(paths)) fs40.rmSync(file, { force: true });
6025
6036
  const certName = `oniro_debug_${auth.teamId.replace(/[\\/.:]/g, "")}.cer`;
6026
6037
  const stale = (await agc.listCertificates()).find((c) => c.certName === certName);
@@ -6067,7 +6078,7 @@ async function harmonyOsAutoSign(opts) {
6067
6078
  }
6068
6079
 
6069
6080
  // src/index.ts
6070
- var VERSION = "0.15.0";
6081
+ var VERSION = "0.15.1";
6071
6082
  // Annotate the CommonJS export names for ESM import in node:
6072
6083
  0 && (module.exports = {
6073
6084
  ALL_SDKS,
@@ -6203,6 +6214,7 @@ var VERSION = "0.15.0";
6203
6214
  isOutOfSpaceError,
6204
6215
  isRamBackedPath,
6205
6216
  isUnsignedHap,
6217
+ isUsableDevice,
6206
6218
  isValidBundleName,
6207
6219
  isValidProjectName,
6208
6220
  killProcessTree,