@mcesystems/adb-kit 1.0.70 → 1.0.72
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 +11 -0
- package/dist/index.js +170 -56
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +170 -56
- package/dist/index.mjs.map +3 -3
- package/dist/types/logic/adbDeviceKit.d.ts +1 -1
- package/dist/types/logic/adbDeviceKit.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -31046,55 +31046,172 @@ var require_src2 = __commonJS2({
|
|
|
31046
31046
|
}
|
|
31047
31047
|
});
|
|
31048
31048
|
var import_debug = __toESM2(require_src2());
|
|
31049
|
-
|
|
31050
|
-
|
|
31051
|
-
|
|
31052
|
-
|
|
31053
|
-
|
|
31054
|
-
|
|
31055
|
-
|
|
31056
|
-
|
|
31057
|
-
|
|
31058
|
-
|
|
31059
|
-
|
|
31060
|
-
|
|
31061
|
-
|
|
31062
|
-
|
|
31063
|
-
|
|
31064
|
-
|
|
31065
|
-
|
|
31066
|
-
|
|
31067
|
-
|
|
31068
|
-
|
|
31069
|
-
|
|
31070
|
-
}
|
|
31071
|
-
|
|
31072
|
-
|
|
31073
|
-
|
|
31074
|
-
|
|
31075
|
-
|
|
31076
|
-
|
|
31077
|
-
|
|
31078
|
-
|
|
31079
|
-
|
|
31080
|
-
|
|
31081
|
-
|
|
31082
|
-
|
|
31083
|
-
|
|
31084
|
-
|
|
31085
|
-
|
|
31086
|
-
|
|
31087
|
-
|
|
31088
|
-
|
|
31089
|
-
|
|
31090
|
-
|
|
31091
|
-
|
|
31092
|
-
|
|
31093
|
-
|
|
31094
|
-
|
|
31095
|
-
|
|
31096
|
-
|
|
31049
|
+
function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
|
|
31050
|
+
const logInfo2 = (0, import_debug.default)(`${namespace}:info`);
|
|
31051
|
+
const logTask2 = (0, import_debug.default)(`${namespace}:task`);
|
|
31052
|
+
const logError2 = (0, import_debug.default)(`${namespace}:error`);
|
|
31053
|
+
const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
|
|
31054
|
+
const logDebug = (0, import_debug.default)(`${namespace}:debug`);
|
|
31055
|
+
const logWarning = (0, import_debug.default)(`${namespace}:warning`);
|
|
31056
|
+
const logColor = (0, import_debug.default)(`${namespace}:color`);
|
|
31057
|
+
logInfo2.color = "19";
|
|
31058
|
+
logTask2.color = "25";
|
|
31059
|
+
logError2.color = "1";
|
|
31060
|
+
logDetail2.color = "199";
|
|
31061
|
+
logWarning.color = "186";
|
|
31062
|
+
logDebug.color = "211";
|
|
31063
|
+
logColor.enabled = true;
|
|
31064
|
+
function setNamespace2(namespace2) {
|
|
31065
|
+
logInfo2.namespace = `${namespace2}:info`;
|
|
31066
|
+
logTask2.namespace = `${namespace2}:task`;
|
|
31067
|
+
logError2.namespace = `${namespace2}:error`;
|
|
31068
|
+
logDetail2.namespace = `${namespace2}:detail`;
|
|
31069
|
+
logWarning.namespace = `${namespace2}:warning`;
|
|
31070
|
+
logDebug.namespace = `${namespace2}:debug`;
|
|
31071
|
+
}
|
|
31072
|
+
function setLogLevel(level) {
|
|
31073
|
+
switch (level) {
|
|
31074
|
+
case "info":
|
|
31075
|
+
logInfo2.enabled = true;
|
|
31076
|
+
logTask2.enabled = true;
|
|
31077
|
+
logError2.enabled = true;
|
|
31078
|
+
logWarning.enabled = true;
|
|
31079
|
+
logDetail2.enabled = false;
|
|
31080
|
+
logDebug.enabled = false;
|
|
31081
|
+
break;
|
|
31082
|
+
case "debug":
|
|
31083
|
+
logInfo2.enabled = true;
|
|
31084
|
+
logTask2.enabled = true;
|
|
31085
|
+
logError2.enabled = true;
|
|
31086
|
+
logWarning.enabled = true;
|
|
31087
|
+
logDetail2.enabled = true;
|
|
31088
|
+
logDebug.enabled = true;
|
|
31089
|
+
break;
|
|
31090
|
+
case "none":
|
|
31091
|
+
logInfo2.enabled = false;
|
|
31092
|
+
logTask2.enabled = false;
|
|
31093
|
+
logError2.enabled = false;
|
|
31094
|
+
logWarning.enabled = false;
|
|
31095
|
+
logDetail2.enabled = false;
|
|
31096
|
+
logDebug.enabled = false;
|
|
31097
|
+
break;
|
|
31098
|
+
}
|
|
31099
|
+
}
|
|
31100
|
+
setLogLevel(logLevel);
|
|
31101
|
+
function setColors(type, color) {
|
|
31102
|
+
switch (type) {
|
|
31103
|
+
case "info":
|
|
31104
|
+
logInfo2.color = color;
|
|
31105
|
+
break;
|
|
31106
|
+
case "task":
|
|
31107
|
+
logTask2.color = color;
|
|
31108
|
+
break;
|
|
31109
|
+
case "error":
|
|
31110
|
+
logError2.color = color;
|
|
31111
|
+
break;
|
|
31112
|
+
case "detail":
|
|
31113
|
+
logDetail2.color = color;
|
|
31114
|
+
break;
|
|
31115
|
+
case "warning":
|
|
31116
|
+
logWarning.color = color;
|
|
31117
|
+
break;
|
|
31118
|
+
case "debug":
|
|
31119
|
+
logDebug.color = color;
|
|
31120
|
+
break;
|
|
31121
|
+
default:
|
|
31122
|
+
throw new Error(`Invalid log type: ${type}`);
|
|
31123
|
+
}
|
|
31124
|
+
}
|
|
31125
|
+
function printColors() {
|
|
31126
|
+
for (let i = 0; i < 256; i++) {
|
|
31127
|
+
logColor.color = `${i}`;
|
|
31128
|
+
logColor(`${i}: ${i}`);
|
|
31129
|
+
}
|
|
31130
|
+
}
|
|
31131
|
+
function logDataDetail(data, prefix = "# ") {
|
|
31132
|
+
if (data === null || data === void 0) {
|
|
31133
|
+
return `${prefix}<null or undefined>`;
|
|
31134
|
+
}
|
|
31135
|
+
if (typeof data !== "object") {
|
|
31136
|
+
return `${prefix}${String(data)}`;
|
|
31137
|
+
}
|
|
31138
|
+
const keys = Object.keys(data);
|
|
31139
|
+
let result = "";
|
|
31140
|
+
for (const key of keys) {
|
|
31141
|
+
result += `${prefix}${key}: `;
|
|
31142
|
+
if (key in data) {
|
|
31143
|
+
let dataKey = key;
|
|
31144
|
+
if (key in data) {
|
|
31145
|
+
dataKey = key;
|
|
31146
|
+
const value = data[dataKey];
|
|
31147
|
+
if (value === null || value === void 0) {
|
|
31148
|
+
result += `<${value === null ? "null" : "undefined"}>
|
|
31149
|
+
`;
|
|
31150
|
+
} else if (typeof value === "object") {
|
|
31151
|
+
result += `
|
|
31152
|
+
${logDataDetail(value, `${prefix} `)}
|
|
31153
|
+
`;
|
|
31154
|
+
} else {
|
|
31155
|
+
result += `${value}
|
|
31156
|
+
`;
|
|
31157
|
+
}
|
|
31158
|
+
}
|
|
31159
|
+
}
|
|
31160
|
+
}
|
|
31161
|
+
return result.trim();
|
|
31162
|
+
}
|
|
31163
|
+
function header(title, padding = 0) {
|
|
31164
|
+
return `${" ".repeat(padding)}${"=".repeat(80)}
|
|
31165
|
+
${" ".repeat(40 - title.length / 2)}${title}
|
|
31166
|
+
${" ".repeat(padding)}${"=".repeat(80)}`;
|
|
31167
|
+
}
|
|
31168
|
+
function logHeader(title) {
|
|
31169
|
+
logInfo2(`${header(title, 2)}`);
|
|
31097
31170
|
}
|
|
31171
|
+
function logDataObject(title, ...args) {
|
|
31172
|
+
const stack = new Error().stack?.split("\n")[2] || "";
|
|
31173
|
+
const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
|
|
31174
|
+
let callerDetails = "";
|
|
31175
|
+
if (stackMatch) {
|
|
31176
|
+
const functionMatch = stack.match(/at (.+) \(/);
|
|
31177
|
+
const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
|
|
31178
|
+
callerDetails = `${functionName}`;
|
|
31179
|
+
}
|
|
31180
|
+
logDetail2(`${header(`*${title}* ${callerDetails}`)}
|
|
31181
|
+
${args.reduce((acc, arg) => `${acc}
|
|
31182
|
+
${logDataDetail(arg)}`, "")}
|
|
31183
|
+
|
|
31184
|
+
${"=".repeat(80)}`);
|
|
31185
|
+
}
|
|
31186
|
+
function logErrorObject(error, extraDetails) {
|
|
31187
|
+
if (error instanceof Error) {
|
|
31188
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
|
|
31189
|
+
Error Message:
|
|
31190
|
+
${error.message}
|
|
31191
|
+
Error Stack:
|
|
31192
|
+
${error.stack}
|
|
31193
|
+
${"=".repeat(80)}`);
|
|
31194
|
+
} else {
|
|
31195
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
|
|
31196
|
+
${"=".repeat(80)}`);
|
|
31197
|
+
}
|
|
31198
|
+
}
|
|
31199
|
+
return {
|
|
31200
|
+
logInfo: logInfo2,
|
|
31201
|
+
logTask: logTask2,
|
|
31202
|
+
logError: logError2,
|
|
31203
|
+
logDetail: logDetail2,
|
|
31204
|
+
logDebug,
|
|
31205
|
+
logWarning,
|
|
31206
|
+
logColor,
|
|
31207
|
+
setColors,
|
|
31208
|
+
printColors,
|
|
31209
|
+
logHeader,
|
|
31210
|
+
logDataObject,
|
|
31211
|
+
logErrorObject,
|
|
31212
|
+
setLogLevel,
|
|
31213
|
+
setNamespace: setNamespace2
|
|
31214
|
+
};
|
|
31098
31215
|
}
|
|
31099
31216
|
|
|
31100
31217
|
// ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
|
|
@@ -31274,6 +31391,7 @@ function getAdbBinaryPath() {
|
|
|
31274
31391
|
}
|
|
31275
31392
|
|
|
31276
31393
|
// src/logic/adbDeviceKit.ts
|
|
31394
|
+
var { logInfo, logError, logTask, logDetail, setNamespace } = createLoggers("adb-kit");
|
|
31277
31395
|
function ensureAdbPathFromResources() {
|
|
31278
31396
|
const adbPath = getAdbBinaryPath();
|
|
31279
31397
|
if (adbPath && !process.env.ADB_PATH) {
|
|
@@ -31329,8 +31447,7 @@ var deviceProps = {
|
|
|
31329
31447
|
var AdbDeviceKit = class {
|
|
31330
31448
|
constructor(deviceId, port) {
|
|
31331
31449
|
this.port = port;
|
|
31332
|
-
|
|
31333
|
-
logNamespace(`adb:${deviceId}`);
|
|
31450
|
+
setNamespace(`adb-kit:${deviceId}`);
|
|
31334
31451
|
ensureAdbPathFromResources();
|
|
31335
31452
|
installConnectionErrorHandler();
|
|
31336
31453
|
this.client = this.connect();
|
|
@@ -31362,12 +31479,9 @@ var AdbDeviceKit = class {
|
|
|
31362
31479
|
try {
|
|
31363
31480
|
logTask(`Getting property ${property} for device ${this.deviceId}`);
|
|
31364
31481
|
const stream = await adbDevice.shell(`getprop ${deviceProps[property]}`);
|
|
31365
|
-
logTask(`
|
|
31366
|
-
const
|
|
31367
|
-
|
|
31368
|
-
chunks.push(chunk);
|
|
31369
|
-
}
|
|
31370
|
-
return Buffer.concat(chunks).toString().trim();
|
|
31482
|
+
logTask(`Reading getprop output for ${property}`);
|
|
31483
|
+
const buffer = await adbkit.default.util.readAll(stream);
|
|
31484
|
+
return buffer.toString().trim();
|
|
31371
31485
|
} catch (error) {
|
|
31372
31486
|
logError(`Error getting property ${property} for device ${this.deviceId}: ${error}`);
|
|
31373
31487
|
return "";
|