@mcesystems/adb-kit 1.0.23 → 1.0.24
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 +155 -8
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +155 -8
- package/dist/index.mjs.map +4 -4
- package/dist/types/logic/adbDeviceKit.d.ts +2 -0
- package/dist/types/logic/adbDeviceKit.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6154,7 +6154,7 @@ var require_has_flag = __commonJS({
|
|
|
6154
6154
|
var require_supports_color = __commonJS({
|
|
6155
6155
|
"../../node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js"(exports2, module2) {
|
|
6156
6156
|
"use strict";
|
|
6157
|
-
var
|
|
6157
|
+
var os2 = __require("os");
|
|
6158
6158
|
var tty = __require("tty");
|
|
6159
6159
|
var hasFlag = require_has_flag();
|
|
6160
6160
|
var { env: env2 } = process;
|
|
@@ -6202,7 +6202,7 @@ var require_supports_color = __commonJS({
|
|
|
6202
6202
|
return min;
|
|
6203
6203
|
}
|
|
6204
6204
|
if (process.platform === "win32") {
|
|
6205
|
-
const osRelease =
|
|
6205
|
+
const osRelease = os2.release().split(".");
|
|
6206
6206
|
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
6207
6207
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
6208
6208
|
}
|
|
@@ -29716,13 +29716,13 @@ var require_client2 = __commonJS({
|
|
|
29716
29716
|
var server_1 = __importDefault(require_server());
|
|
29717
29717
|
var DeviceClient_1 = __importDefault(require_DeviceClient());
|
|
29718
29718
|
var Client = class extends events_1.EventEmitter {
|
|
29719
|
-
constructor({ host = "127.0.0.1", port = 5037, bin = "adb", timeout = 0 } = { port: 5037 }) {
|
|
29719
|
+
constructor({ host = "127.0.0.1", port = 5037, bin = "adb", timeout: timeout2 = 0 } = { port: 5037 }) {
|
|
29720
29720
|
super();
|
|
29721
29721
|
this.host = host;
|
|
29722
29722
|
this.port = port;
|
|
29723
29723
|
this.bin = bin;
|
|
29724
|
-
this.timeout =
|
|
29725
|
-
this.options = { host, port, bin, timeout };
|
|
29724
|
+
this.timeout = timeout2;
|
|
29725
|
+
this.options = { host, port, bin, timeout: timeout2 };
|
|
29726
29726
|
}
|
|
29727
29727
|
createTcpUsbBridge(serial, options) {
|
|
29728
29728
|
return new server_1.default(this, serial, options);
|
|
@@ -30707,6 +30707,141 @@ var require_src2 = __commonJS({
|
|
|
30707
30707
|
// src/logic/adbDeviceKit.ts
|
|
30708
30708
|
var adbkit = __toESM(require_dist());
|
|
30709
30709
|
|
|
30710
|
+
// ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
|
|
30711
|
+
import net from "node:net";
|
|
30712
|
+
import os from "node:os";
|
|
30713
|
+
var Locked = class extends Error {
|
|
30714
|
+
constructor(port) {
|
|
30715
|
+
super(`${port} is locked`);
|
|
30716
|
+
}
|
|
30717
|
+
};
|
|
30718
|
+
var lockedPorts = {
|
|
30719
|
+
old: /* @__PURE__ */ new Set(),
|
|
30720
|
+
young: /* @__PURE__ */ new Set()
|
|
30721
|
+
};
|
|
30722
|
+
var releaseOldLockedPortsIntervalMs = 1e3 * 15;
|
|
30723
|
+
var minPort = 1024;
|
|
30724
|
+
var maxPort = 65535;
|
|
30725
|
+
var timeout;
|
|
30726
|
+
var getLocalHosts = () => {
|
|
30727
|
+
const interfaces = os.networkInterfaces();
|
|
30728
|
+
const results = /* @__PURE__ */ new Set([void 0, "0.0.0.0"]);
|
|
30729
|
+
for (const _interface of Object.values(interfaces)) {
|
|
30730
|
+
for (const config of _interface) {
|
|
30731
|
+
results.add(config.address);
|
|
30732
|
+
}
|
|
30733
|
+
}
|
|
30734
|
+
return results;
|
|
30735
|
+
};
|
|
30736
|
+
var checkAvailablePort = (options) => new Promise((resolve, reject) => {
|
|
30737
|
+
const server = net.createServer();
|
|
30738
|
+
server.unref();
|
|
30739
|
+
server.on("error", reject);
|
|
30740
|
+
server.listen(options, () => {
|
|
30741
|
+
const { port } = server.address();
|
|
30742
|
+
server.close(() => {
|
|
30743
|
+
resolve(port);
|
|
30744
|
+
});
|
|
30745
|
+
});
|
|
30746
|
+
});
|
|
30747
|
+
var getAvailablePort = async (options, hosts) => {
|
|
30748
|
+
if (options.host || options.port === 0) {
|
|
30749
|
+
return checkAvailablePort(options);
|
|
30750
|
+
}
|
|
30751
|
+
for (const host of hosts) {
|
|
30752
|
+
try {
|
|
30753
|
+
await checkAvailablePort({ port: options.port, host });
|
|
30754
|
+
} catch (error) {
|
|
30755
|
+
if (!["EADDRNOTAVAIL", "EINVAL"].includes(error.code)) {
|
|
30756
|
+
throw error;
|
|
30757
|
+
}
|
|
30758
|
+
}
|
|
30759
|
+
}
|
|
30760
|
+
return options.port;
|
|
30761
|
+
};
|
|
30762
|
+
var portCheckSequence = function* (ports) {
|
|
30763
|
+
if (ports) {
|
|
30764
|
+
yield* ports;
|
|
30765
|
+
}
|
|
30766
|
+
yield 0;
|
|
30767
|
+
};
|
|
30768
|
+
async function getPorts(options) {
|
|
30769
|
+
let ports;
|
|
30770
|
+
let exclude = /* @__PURE__ */ new Set();
|
|
30771
|
+
if (options) {
|
|
30772
|
+
if (options.port) {
|
|
30773
|
+
ports = typeof options.port === "number" ? [options.port] : options.port;
|
|
30774
|
+
}
|
|
30775
|
+
if (options.exclude) {
|
|
30776
|
+
const excludeIterable = options.exclude;
|
|
30777
|
+
if (typeof excludeIterable[Symbol.iterator] !== "function") {
|
|
30778
|
+
throw new TypeError("The `exclude` option must be an iterable.");
|
|
30779
|
+
}
|
|
30780
|
+
for (const element of excludeIterable) {
|
|
30781
|
+
if (typeof element !== "number") {
|
|
30782
|
+
throw new TypeError("Each item in the `exclude` option must be a number corresponding to the port you want excluded.");
|
|
30783
|
+
}
|
|
30784
|
+
if (!Number.isSafeInteger(element)) {
|
|
30785
|
+
throw new TypeError(`Number ${element} in the exclude option is not a safe integer and can't be used`);
|
|
30786
|
+
}
|
|
30787
|
+
}
|
|
30788
|
+
exclude = new Set(excludeIterable);
|
|
30789
|
+
}
|
|
30790
|
+
}
|
|
30791
|
+
if (timeout === void 0) {
|
|
30792
|
+
timeout = setTimeout(() => {
|
|
30793
|
+
timeout = void 0;
|
|
30794
|
+
lockedPorts.old = lockedPorts.young;
|
|
30795
|
+
lockedPorts.young = /* @__PURE__ */ new Set();
|
|
30796
|
+
}, releaseOldLockedPortsIntervalMs);
|
|
30797
|
+
if (timeout.unref) {
|
|
30798
|
+
timeout.unref();
|
|
30799
|
+
}
|
|
30800
|
+
}
|
|
30801
|
+
const hosts = getLocalHosts();
|
|
30802
|
+
for (const port of portCheckSequence(ports)) {
|
|
30803
|
+
try {
|
|
30804
|
+
if (exclude.has(port)) {
|
|
30805
|
+
continue;
|
|
30806
|
+
}
|
|
30807
|
+
let availablePort = await getAvailablePort({ ...options, port }, hosts);
|
|
30808
|
+
while (lockedPorts.old.has(availablePort) || lockedPorts.young.has(availablePort)) {
|
|
30809
|
+
if (port !== 0) {
|
|
30810
|
+
throw new Locked(port);
|
|
30811
|
+
}
|
|
30812
|
+
availablePort = await getAvailablePort({ ...options, port }, hosts);
|
|
30813
|
+
}
|
|
30814
|
+
lockedPorts.young.add(availablePort);
|
|
30815
|
+
return availablePort;
|
|
30816
|
+
} catch (error) {
|
|
30817
|
+
if (!["EADDRINUSE", "EACCES"].includes(error.code) && !(error instanceof Locked)) {
|
|
30818
|
+
throw error;
|
|
30819
|
+
}
|
|
30820
|
+
}
|
|
30821
|
+
}
|
|
30822
|
+
throw new Error("No available ports found");
|
|
30823
|
+
}
|
|
30824
|
+
function portNumbers(from, to) {
|
|
30825
|
+
if (!Number.isInteger(from) || !Number.isInteger(to)) {
|
|
30826
|
+
throw new TypeError("`from` and `to` must be integer numbers");
|
|
30827
|
+
}
|
|
30828
|
+
if (from < minPort || from > maxPort) {
|
|
30829
|
+
throw new RangeError(`'from' must be between ${minPort} and ${maxPort}`);
|
|
30830
|
+
}
|
|
30831
|
+
if (to < minPort || to > maxPort) {
|
|
30832
|
+
throw new RangeError(`'to' must be between ${minPort} and ${maxPort}`);
|
|
30833
|
+
}
|
|
30834
|
+
if (from > to) {
|
|
30835
|
+
throw new RangeError("`to` must be greater than or equal to `from`");
|
|
30836
|
+
}
|
|
30837
|
+
const generator = function* (from2, to2) {
|
|
30838
|
+
for (let port = from2; port <= to2; port++) {
|
|
30839
|
+
yield port;
|
|
30840
|
+
}
|
|
30841
|
+
};
|
|
30842
|
+
return generator(from, to);
|
|
30843
|
+
}
|
|
30844
|
+
|
|
30710
30845
|
// src/utils/adbPath.ts
|
|
30711
30846
|
import { existsSync } from "node:fs";
|
|
30712
30847
|
import path from "node:path";
|
|
@@ -30811,6 +30946,7 @@ var AdbDeviceKit = class {
|
|
|
30811
30946
|
client;
|
|
30812
30947
|
device;
|
|
30813
30948
|
deviceId;
|
|
30949
|
+
devicePort = null;
|
|
30814
30950
|
async listDevices() {
|
|
30815
30951
|
const devices = await this.client.listDevices();
|
|
30816
30952
|
return devices;
|
|
@@ -30825,7 +30961,8 @@ var AdbDeviceKit = class {
|
|
|
30825
30961
|
chunks.push(chunk);
|
|
30826
30962
|
}
|
|
30827
30963
|
return Buffer.concat(chunks).toString().trim();
|
|
30828
|
-
} catch {
|
|
30964
|
+
} catch (error) {
|
|
30965
|
+
logError(`Error getting property ${property} for device ${this.deviceId}: ${error}`);
|
|
30829
30966
|
return "";
|
|
30830
30967
|
}
|
|
30831
30968
|
}
|
|
@@ -30878,7 +31015,7 @@ var AdbDeviceKit = class {
|
|
|
30878
31015
|
const devices = await this.listDevices();
|
|
30879
31016
|
return !!devices.find((device) => device.id === this.deviceId);
|
|
30880
31017
|
}
|
|
30881
|
-
async waitForUsbDebugging(
|
|
31018
|
+
async waitForUsbDebugging(timeout2 = 12e4) {
|
|
30882
31019
|
if (await this.hasUsbDebugging()) {
|
|
30883
31020
|
return true;
|
|
30884
31021
|
}
|
|
@@ -30886,7 +31023,7 @@ var AdbDeviceKit = class {
|
|
|
30886
31023
|
return new Promise((resolve, reject) => {
|
|
30887
31024
|
const timeoutId = setTimeout(() => {
|
|
30888
31025
|
reject(new Error("Timeout waiting for USB debugging"));
|
|
30889
|
-
},
|
|
31026
|
+
}, timeout2);
|
|
30890
31027
|
tracker.on("remove", (_) => {
|
|
30891
31028
|
clearTimeout(timeoutId);
|
|
30892
31029
|
});
|
|
@@ -30906,6 +31043,16 @@ var AdbDeviceKit = class {
|
|
|
30906
31043
|
});
|
|
30907
31044
|
});
|
|
30908
31045
|
}
|
|
31046
|
+
async startPortForward(serviceName) {
|
|
31047
|
+
if (this.devicePort) {
|
|
31048
|
+
return this.devicePort;
|
|
31049
|
+
}
|
|
31050
|
+
const port = await getPorts({ port: portNumbers(3e4, 31e3) });
|
|
31051
|
+
if (await this.device.forward(`tcp:${port}`, serviceName)) {
|
|
31052
|
+
this.devicePort = port;
|
|
31053
|
+
}
|
|
31054
|
+
return this.devicePort;
|
|
31055
|
+
}
|
|
30909
31056
|
getDeviceId() {
|
|
30910
31057
|
return this.deviceId;
|
|
30911
31058
|
}
|