@mcesystems/apple-kit 1.0.40 → 1.0.44

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.js CHANGED
@@ -947,47 +947,19 @@ function logInfo(message) {
947
947
  function logTask(message) {
948
948
  debugTask(message);
949
949
  }
950
+ function logError(message) {
951
+ debugError(message);
952
+ }
950
953
 
951
- // src/logic/actions/device.ts
954
+ // src/logic/actions/tool.ts
952
955
  var import_node_child_process = require("node:child_process");
953
- var import_node_fs = require("node:fs");
954
- var import_node_path = require("node:path");
956
+ var import_node_path2 = require("node:path");
955
957
  var import_node_util = require("node:util");
956
958
 
957
- // src/logic/dataParser.ts
958
- function parsePlistOutput(output) {
959
- const result = {};
960
- const lines = output.split("\n");
961
- for (const line of lines) {
962
- const colonIndex = line.indexOf(":");
963
- if (colonIndex > 0) {
964
- const key = line.substring(0, colonIndex).trim();
965
- const value = line.substring(colonIndex + 1).trim();
966
- result[key] = value;
967
- }
968
- }
969
- return result;
970
- }
971
- function parseAppList(output) {
972
- const apps = [];
973
- const lines = output.trim().split("\n");
974
- for (const line of lines) {
975
- const match = line.match(/^([^,]+),\s*([^,]+),\s*"?([^"]+)"?/);
976
- if (match) {
977
- apps.push({
978
- bundleId: match[1].trim(),
979
- version: match[2].trim(),
980
- displayName: match[3].trim(),
981
- bundleVersion: ""
982
- });
983
- }
984
- }
985
- return apps;
986
- }
987
-
988
- // src/logic/actions/device.ts
959
+ // src/logic/utils/resolvePath.ts
960
+ var import_node_fs = require("node:fs");
961
+ var import_node_path = require("node:path");
989
962
  var import_meta = {};
990
- var execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
991
963
  function getModuleDir() {
992
964
  if (typeof import_meta !== "undefined" && import_meta.url) {
993
965
  const { fileURLToPath } = require("node:url");
@@ -995,56 +967,6 @@ function getModuleDir() {
995
967
  }
996
968
  return __dirname;
997
969
  }
998
- async function getDeviceInfo(udid) {
999
- logTask(`Getting device info for ${udid}`);
1000
- const result = await runIDeviceTool("ideviceinfo", ["-u", udid]);
1001
- if (!result) {
1002
- throw new Error("Failed to get device info");
1003
- }
1004
- const props = parsePlistOutput(result.stdout);
1005
- return {
1006
- deviceName: props.DeviceName || "",
1007
- productType: props.ProductType || "",
1008
- productVersion: props.ProductVersion || "",
1009
- buildVersion: props.BuildVersion || "",
1010
- serialNumber: props.SerialNumber || "",
1011
- udid: props.UniqueDeviceID || udid,
1012
- wifiAddress: props.WiFiAddress || "",
1013
- bluetoothAddress: props.BluetoothAddress || "",
1014
- phoneNumber: props.PhoneNumber || "",
1015
- cpuArchitecture: props.CPUArchitecture || "",
1016
- hardwareModel: props.HardwareModel || "",
1017
- modelNumber: props.ModelNumber || "",
1018
- regionInfo: props.RegionInfo || "",
1019
- timeZone: props.TimeZone || "",
1020
- uniqueChipID: props.UniqueChipID || "",
1021
- isPaired: true
1022
- // If we can get info, device is paired
1023
- };
1024
- }
1025
- async function runIDeviceTool(toolName, args = [], options = {}) {
1026
- const binPath = getIDeviceBinPath();
1027
- const ext = process.platform === "win32" ? ".exe" : "";
1028
- const toolPath = binPath ? (0, import_node_path.join)(binPath, `${toolName}${ext}`) : `${toolName}${ext}`;
1029
- const command = `"${toolPath}" ${args.map((a) => `"${a}"`).join(" ")}`;
1030
- return execIDevice(command, options);
1031
- }
1032
- async function execIDevice(command, options = {}) {
1033
- const binPath = getIDeviceBinPath();
1034
- if (binPath) {
1035
- options.cwd = binPath;
1036
- }
1037
- const result = await execAsync(command, {
1038
- ...options,
1039
- env: process.env,
1040
- windowsHide: true,
1041
- encoding: "utf8"
1042
- });
1043
- return {
1044
- stdout: result.stdout.toString(),
1045
- stderr: result.stderr.toString()
1046
- };
1047
- }
1048
970
  function getPlatformDir() {
1049
971
  const platform = process.platform;
1050
972
  if (platform === "win32") {
@@ -1058,29 +980,19 @@ function getPlatformDir() {
1058
980
  }
1059
981
  return platform;
1060
982
  }
1061
- function getBundledResourcesPath() {
1062
- const moduleDir = getModuleDir();
1063
- let packageRoot;
1064
- if (moduleDir.includes("dist")) {
1065
- packageRoot = (0, import_node_path.join)(moduleDir, "..", "..");
1066
- } else {
1067
- packageRoot = (0, import_node_path.join)(moduleDir, "..", "..", "..", "..");
1068
- }
1069
- const platformDir = getPlatformDir();
1070
- const distPath = (0, import_node_path.join)(packageRoot, "dist", "resources", "bin", platformDir);
1071
- if ((0, import_node_fs.existsSync)((0, import_node_path.join)(distPath, "idevice_id")) || (0, import_node_fs.existsSync)((0, import_node_path.join)(distPath, "idevice_id.exe"))) {
1072
- return distPath;
1073
- }
1074
- const devPath = (0, import_node_path.join)(packageRoot, "resources", "bin", platformDir);
1075
- if ((0, import_node_fs.existsSync)((0, import_node_path.join)(devPath, "idevice_id")) || (0, import_node_fs.existsSync)((0, import_node_path.join)(devPath, "idevice_id.exe"))) {
1076
- return devPath;
1077
- }
1078
- return null;
1079
- }
1080
983
  function getResourcesBinPath() {
1081
984
  const envBinPath = process.env.IDeviceBinPath;
1082
985
  if (envBinPath) {
1083
- return envBinPath;
986
+ if ((0, import_node_path.isAbsolute)(envBinPath)) {
987
+ return envBinPath;
988
+ }
989
+ const absolutePath = (0, import_node_path.join)(process.cwd(), envBinPath);
990
+ logInfo(`Using absolute path: ${absolutePath}`);
991
+ if ((0, import_node_fs.existsSync)(absolutePath)) {
992
+ return absolutePath;
993
+ }
994
+ logError(`Absolute path does not exist: ${absolutePath}`);
995
+ return "";
1084
996
  }
1085
997
  const bundledPath = getBundledResourcesPath();
1086
998
  if (bundledPath) {
@@ -1106,8 +1018,50 @@ function getResourcesBinPath() {
1106
1018
  }
1107
1019
  return "";
1108
1020
  }
1109
- function getIDeviceBinPath() {
1110
- return getResourcesBinPath();
1021
+ function getBundledResourcesPath() {
1022
+ const moduleDir = getModuleDir();
1023
+ let packageRoot;
1024
+ if (moduleDir.includes("dist")) {
1025
+ packageRoot = (0, import_node_path.join)(moduleDir, "..", "..");
1026
+ } else {
1027
+ packageRoot = (0, import_node_path.join)(moduleDir, "..", "..", "..", "..");
1028
+ }
1029
+ const platformDir = getPlatformDir();
1030
+ const distPath = (0, import_node_path.join)(packageRoot, "dist", "resources", "bin", platformDir);
1031
+ if ((0, import_node_fs.existsSync)((0, import_node_path.join)(distPath, "idevice_id")) || (0, import_node_fs.existsSync)((0, import_node_path.join)(distPath, "idevice_id.exe"))) {
1032
+ return distPath;
1033
+ }
1034
+ const devPath = (0, import_node_path.join)(packageRoot, "resources", "bin", platformDir);
1035
+ if ((0, import_node_fs.existsSync)((0, import_node_path.join)(devPath, "idevice_id")) || (0, import_node_fs.existsSync)((0, import_node_path.join)(devPath, "idevice_id.exe"))) {
1036
+ return devPath;
1037
+ }
1038
+ return null;
1039
+ }
1040
+
1041
+ // src/logic/actions/tool.ts
1042
+ var execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
1043
+ async function runIDeviceTool(toolName, args = [], options = {}) {
1044
+ const binPath = getResourcesBinPath();
1045
+ const ext = process.platform === "win32" ? ".exe" : "";
1046
+ const toolPath = binPath ? (0, import_node_path2.join)(binPath, `${toolName}${ext}`) : `${toolName}${ext}`;
1047
+ const command = `"${toolPath}" ${args.map((a) => `"${a}"`).join(" ")}`;
1048
+ return execIDevice(command, options);
1049
+ }
1050
+ async function execIDevice(command, options = {}) {
1051
+ const binPath = getResourcesBinPath();
1052
+ if (binPath) {
1053
+ options.cwd = binPath;
1054
+ }
1055
+ const result = await execAsync(command, {
1056
+ ...options,
1057
+ env: process.env,
1058
+ windowsHide: true,
1059
+ encoding: "utf8"
1060
+ });
1061
+ return {
1062
+ stdout: result.stdout.toString(),
1063
+ stderr: result.stderr.toString()
1064
+ };
1111
1065
  }
1112
1066
 
1113
1067
  // src/logic/actions/activation.ts
@@ -1148,6 +1102,70 @@ async function activate(udid) {
1148
1102
  }
1149
1103
  }
1150
1104
 
1105
+ // src/logic/actions/device.ts
1106
+ var import_node_fs2 = require("node:fs");
1107
+ var import_node_path3 = require("node:path");
1108
+
1109
+ // src/logic/dataParser.ts
1110
+ function parsePlistOutput(output) {
1111
+ const result = {};
1112
+ const lines = output.split("\n");
1113
+ for (const line of lines) {
1114
+ const colonIndex = line.indexOf(":");
1115
+ if (colonIndex > 0) {
1116
+ const key = line.substring(0, colonIndex).trim();
1117
+ const value = line.substring(colonIndex + 1).trim();
1118
+ result[key] = value;
1119
+ }
1120
+ }
1121
+ return result;
1122
+ }
1123
+ function parseAppList(output) {
1124
+ const apps = [];
1125
+ const lines = output.trim().split("\n");
1126
+ for (const line of lines) {
1127
+ const match = line.match(/^([^,]+),\s*([^,]+),\s*"?([^"]+)"?/);
1128
+ if (match) {
1129
+ apps.push({
1130
+ bundleId: match[1].trim(),
1131
+ version: match[2].trim(),
1132
+ displayName: match[3].trim(),
1133
+ bundleVersion: ""
1134
+ });
1135
+ }
1136
+ }
1137
+ return apps;
1138
+ }
1139
+
1140
+ // src/logic/actions/device.ts
1141
+ async function getDeviceInfo(udid) {
1142
+ logTask(`Getting device info for ${udid}`);
1143
+ const result = await runIDeviceTool("ideviceinfo", ["-u", udid]);
1144
+ if (!result) {
1145
+ throw new Error("Failed to get device info");
1146
+ }
1147
+ const props = parsePlistOutput(result.stdout);
1148
+ return {
1149
+ deviceName: props.DeviceName || "",
1150
+ productType: props.ProductType || "",
1151
+ productVersion: props.ProductVersion || "",
1152
+ buildVersion: props.BuildVersion || "",
1153
+ serialNumber: props.SerialNumber || "",
1154
+ udid: props.UniqueDeviceID || udid,
1155
+ wifiAddress: props.WiFiAddress || "",
1156
+ bluetoothAddress: props.BluetoothAddress || "",
1157
+ phoneNumber: props.PhoneNumber || "",
1158
+ cpuArchitecture: props.CPUArchitecture || "",
1159
+ hardwareModel: props.HardwareModel || "",
1160
+ modelNumber: props.ModelNumber || "",
1161
+ regionInfo: props.RegionInfo || "",
1162
+ timeZone: props.TimeZone || "",
1163
+ uniqueChipID: props.UniqueChipID || "",
1164
+ isPaired: true
1165
+ // If we can get info, device is paired
1166
+ };
1167
+ }
1168
+
1151
1169
  // src/logic/actions/pair.ts
1152
1170
  async function isPaired(udid) {
1153
1171
  logTask(`Checking pairing status for ${udid}`);
@@ -1168,10 +1186,14 @@ async function trustDevice(udid, timeout2 = 6e4, onWaitingForTrust) {
1168
1186
  return true;
1169
1187
  }
1170
1188
  logInfo(`Initiating pairing for device ${udid}`);
1171
- const pairResult = await pair(udid);
1172
- if (pairResult) {
1173
- logInfo(`Device ${udid} paired successfully`);
1174
- return true;
1189
+ try {
1190
+ const pairResult = await pair(udid);
1191
+ if (pairResult) {
1192
+ logInfo(`Device ${udid} paired successfully`);
1193
+ return true;
1194
+ }
1195
+ } catch (error) {
1196
+ logError(`Pairing failed with ${udid}: ${error}`);
1175
1197
  }
1176
1198
  logInfo("Please accept the trust dialog on the device...");
1177
1199
  onWaitingForTrust?.();
@@ -1286,6 +1308,12 @@ async function launchApp(bundleId, args, udid) {
1286
1308
  if (!await isPaired(udid)) {
1287
1309
  await waitForPairing(udid, 1e4);
1288
1310
  }
1311
+ const installed = await isAppInstalled(bundleId, udid);
1312
+ if (!installed) {
1313
+ throw new Error(
1314
+ `App "${bundleId}" is not installed on the device. Install the app first or verify the bundle identifier is correct.`
1315
+ );
1316
+ }
1289
1317
  await wakeDevice(udid);
1290
1318
  try {
1291
1319
  logInfo(`Attempting to launch ${bundleId} using idevicedebug...`);
@@ -1413,83 +1441,13 @@ async function launchAppWithPymobiledevice3(bundleId, args, udid) {
1413
1441
 
1414
1442
  // src/logic/actions/proxy.ts
1415
1443
  var import_node_child_process2 = require("node:child_process");
1416
- var import_node_fs2 = require("node:fs");
1417
- var import_node_path2 = require("node:path");
1418
- var import_meta2 = {};
1419
- function getModuleDir2() {
1420
- if (typeof import_meta2 !== "undefined" && import_meta2.url) {
1421
- const { fileURLToPath } = require("node:url");
1422
- return (0, import_node_path2.dirname)(fileURLToPath(import_meta2.url));
1423
- }
1424
- return __dirname;
1425
- }
1426
- function getPlatformDir2() {
1427
- const platform = process.platform;
1428
- if (platform === "win32") {
1429
- return "windows";
1430
- }
1431
- if (platform === "darwin") {
1432
- return "darwin";
1433
- }
1434
- if (platform === "linux") {
1435
- return "linux";
1436
- }
1437
- return platform;
1438
- }
1439
- function getBundledResourcesPath2() {
1440
- const moduleDir = getModuleDir2();
1441
- let packageRoot;
1442
- if (moduleDir.includes("dist")) {
1443
- packageRoot = (0, import_node_path2.join)(moduleDir, "..", "..");
1444
- } else {
1445
- packageRoot = (0, import_node_path2.join)(moduleDir, "..", "..", "..", "..");
1446
- }
1447
- const platformDir = getPlatformDir2();
1448
- const distPath = (0, import_node_path2.join)(packageRoot, "dist", "resources", "bin", platformDir);
1449
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(distPath, "iproxy")) || (0, import_node_fs2.existsSync)((0, import_node_path2.join)(distPath, "iproxy.exe"))) {
1450
- return distPath;
1451
- }
1452
- const devPath = (0, import_node_path2.join)(packageRoot, "resources", "bin", platformDir);
1453
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(devPath, "iproxy")) || (0, import_node_fs2.existsSync)((0, import_node_path2.join)(devPath, "iproxy.exe"))) {
1454
- return devPath;
1455
- }
1456
- return null;
1457
- }
1458
- function getResourcesBinPath2() {
1459
- const envBinPath = process.env.IDeviceBinPath;
1460
- if (envBinPath) {
1461
- return envBinPath;
1462
- }
1463
- const bundledPath = getBundledResourcesPath2();
1464
- if (bundledPath) {
1465
- return bundledPath;
1466
- }
1467
- if (process.platform === "darwin") {
1468
- const homebrewArmPath = "/opt/homebrew/bin";
1469
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(homebrewArmPath, "iproxy"))) {
1470
- return homebrewArmPath;
1471
- }
1472
- const homebrewIntelPath = "/usr/local/bin";
1473
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(homebrewIntelPath, "iproxy"))) {
1474
- return homebrewIntelPath;
1475
- }
1476
- }
1477
- if (process.platform === "linux") {
1478
- const linuxPaths = ["/usr/bin", "/usr/local/bin"];
1479
- for (const linuxPath of linuxPaths) {
1480
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(linuxPath, "iproxy"))) {
1481
- return linuxPath;
1482
- }
1483
- }
1484
- }
1485
- return "";
1486
- }
1444
+ var import_node_path4 = require("node:path");
1487
1445
  function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
1488
1446
  return new Promise((resolve, reject) => {
1489
1447
  logTask(`Starting port forward ${localPort} -> ${devicePort} for device ${udid}`);
1490
- const binPath = getResourcesBinPath2();
1448
+ const binPath = getResourcesBinPath();
1491
1449
  const ext = process.platform === "win32" ? ".exe" : "";
1492
- const toolPath = binPath ? (0, import_node_path2.join)(binPath, `iproxy${ext}`) : `iproxy${ext}`;
1450
+ const toolPath = binPath ? (0, import_node_path4.join)(binPath, `iproxy${ext}`) : `iproxy${ext}`;
1493
1451
  const spawnOptions = {
1494
1452
  windowsHide: true,
1495
1453
  stdio: ["ignore", "pipe", "pipe"]
@@ -1497,6 +1455,9 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
1497
1455
  if (binPath) {
1498
1456
  spawnOptions.cwd = binPath;
1499
1457
  }
1458
+ logInfo(`Spawning iproxy with path: ${toolPath}`);
1459
+ logInfo(`Arguments: ${[localPort.toString(), devicePort.toString(), "-u", udid].join(" ")}`);
1460
+ logInfo(`Options: ${JSON.stringify(spawnOptions)}`);
1500
1461
  const child = (0, import_node_child_process2.spawn)(
1501
1462
  toolPath,
1502
1463
  [localPort.toString(), devicePort.toString(), "-u", udid],
@@ -1504,7 +1465,11 @@ function startPortForward(localPort, devicePort, udid, startupTimeout = 500) {
1504
1465
  );
1505
1466
  let hasResolved = false;
1506
1467
  let stderrOutput = "";
1468
+ child.stdout?.on("data", (data) => {
1469
+ logTask(`${data.toString()}`);
1470
+ });
1507
1471
  child.stderr?.on("data", (data) => {
1472
+ logError(`${data.toString()}`);
1508
1473
  const msg = data.toString();
1509
1474
  stderrOutput += msg;
1510
1475
  if (msg.toLowerCase().includes("error") && !hasResolved) {