@weapp-vite/miniprogram-automator 1.1.0 → 1.1.2
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.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import process from "node:process";
|
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
|
-
import
|
|
7
|
+
import { createDebug } from "obug";
|
|
8
8
|
import WebSocket from "ws";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
10
10
|
import { decodeQrCodeFromBase64, renderTerminalQrCode } from "@weapp-vite/qr";
|
|
@@ -224,6 +224,8 @@ function toStr(value) {
|
|
|
224
224
|
//#region src/Element.ts
|
|
225
225
|
/** Element 的实现。 */
|
|
226
226
|
var Element = class Element {
|
|
227
|
+
connection;
|
|
228
|
+
elementMap;
|
|
227
229
|
tagName = "";
|
|
228
230
|
nodeId;
|
|
229
231
|
videoId;
|
|
@@ -474,6 +476,7 @@ var ContextElement = class extends Element {
|
|
|
474
476
|
//#region src/Transport.ts
|
|
475
477
|
/** Transport 的实现。 */
|
|
476
478
|
var Transport = class extends EventEmitter {
|
|
479
|
+
ws;
|
|
477
480
|
constructor(ws) {
|
|
478
481
|
super();
|
|
479
482
|
this.ws = ws;
|
|
@@ -496,11 +499,12 @@ var Transport = class extends EventEmitter {
|
|
|
496
499
|
/**
|
|
497
500
|
* @file 自动化协议连接实现。
|
|
498
501
|
*/
|
|
499
|
-
const debugProtocol =
|
|
502
|
+
const debugProtocol = createDebug("automator:protocol");
|
|
500
503
|
const closeErrTip = "Connection closed, check if wechat web devTools is still running";
|
|
501
504
|
const REQUEST_TIMEOUT = 3e4;
|
|
502
505
|
/** Connection 的实现。 */
|
|
503
506
|
var Connection = class Connection extends EventEmitter {
|
|
507
|
+
transport;
|
|
504
508
|
callbacks = /* @__PURE__ */ new Map();
|
|
505
509
|
constructor(transport) {
|
|
506
510
|
super();
|
|
@@ -578,15 +582,16 @@ var Connection = class Connection extends EventEmitter {
|
|
|
578
582
|
//#endregion
|
|
579
583
|
//#region src/headless.ts
|
|
580
584
|
async function launchHeadlessAutomator(options) {
|
|
581
|
-
return await (await import("./launch-
|
|
585
|
+
return await (await import("./launch-F4arniwI.mjs")).launch({ projectPath: options.projectPath });
|
|
582
586
|
}
|
|
583
587
|
//#endregion
|
|
584
588
|
//#region package.json
|
|
585
|
-
var version = "1.1.
|
|
589
|
+
var version = "1.1.2";
|
|
586
590
|
//#endregion
|
|
587
591
|
//#region src/Native.ts
|
|
588
592
|
/** Native 的实现。 */
|
|
589
593
|
var Native = class extends EventEmitter {
|
|
594
|
+
connection;
|
|
590
595
|
constructor(connection) {
|
|
591
596
|
super();
|
|
592
597
|
this.connection = connection;
|
|
@@ -635,6 +640,7 @@ var Native = class extends EventEmitter {
|
|
|
635
640
|
//#region src/Page.ts
|
|
636
641
|
/** Page 的实现。 */
|
|
637
642
|
var Page = class Page {
|
|
643
|
+
connection;
|
|
638
644
|
path = "";
|
|
639
645
|
query = {};
|
|
640
646
|
id;
|
|
@@ -801,6 +807,9 @@ function isFnStr(value) {
|
|
|
801
807
|
function isCurrentPageProtocolTimeout(error) {
|
|
802
808
|
return error instanceof Error && "code" in error && error.code === "DEVTOOLS_PROTOCOL_TIMEOUT" && "method" in error && error.method === "App.getCurrentPage";
|
|
803
809
|
}
|
|
810
|
+
function isPageStackProtocolTimeout(error) {
|
|
811
|
+
return error instanceof Error && "code" in error && error.code === "DEVTOOLS_PROTOCOL_TIMEOUT" && "method" in error && error.method === "App.getPageStack";
|
|
812
|
+
}
|
|
804
813
|
function normalizeRoutePath(value) {
|
|
805
814
|
return String(value ?? "").split("?", 1)[0].replace(/^\/+/, "").replace(/\/+$/, "");
|
|
806
815
|
}
|
|
@@ -810,6 +819,7 @@ function logChangeRouteDebug(message) {
|
|
|
810
819
|
}
|
|
811
820
|
/** MiniProgram 的实现。 */
|
|
812
821
|
var MiniProgram = class extends EventEmitter {
|
|
822
|
+
connection;
|
|
813
823
|
appBindings = /* @__PURE__ */ new Map();
|
|
814
824
|
pageMap = /* @__PURE__ */ new Map();
|
|
815
825
|
nativeIns;
|
|
@@ -856,8 +866,22 @@ var MiniProgram = class extends EventEmitter {
|
|
|
856
866
|
}, this.pageMap);
|
|
857
867
|
} catch (error) {
|
|
858
868
|
lastError = error;
|
|
859
|
-
if (!isCurrentPageProtocolTimeout(error)
|
|
860
|
-
|
|
869
|
+
if (!isCurrentPageProtocolTimeout(error)) throw error;
|
|
870
|
+
if (attempt < CURRENT_PAGE_RETRIES) {
|
|
871
|
+
await sleep(CURRENT_PAGE_RETRY_DELAY);
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (isCurrentPageProtocolTimeout(lastError)) try {
|
|
876
|
+
const { pageStack } = await this.send("App.getPageStack");
|
|
877
|
+
const page = pageStack[pageStack.length - 1];
|
|
878
|
+
if (page) return Page.create(this.connection, {
|
|
879
|
+
id: page.pageId,
|
|
880
|
+
path: page.path,
|
|
881
|
+
query: page.query
|
|
882
|
+
}, this.pageMap);
|
|
883
|
+
} catch (error) {
|
|
884
|
+
if (!isPageStackProtocolTimeout(error)) throw error;
|
|
861
885
|
}
|
|
862
886
|
throw lastError;
|
|
863
887
|
}
|
|
@@ -1018,7 +1042,21 @@ var MiniProgram = class extends EventEmitter {
|
|
|
1018
1042
|
return this.nativeIns;
|
|
1019
1043
|
}
|
|
1020
1044
|
async changeRoute(method, url) {
|
|
1021
|
-
const currentPage = await this.currentPage()
|
|
1045
|
+
const currentPage = await this.currentPage().catch(async (error) => {
|
|
1046
|
+
if (!isCurrentPageProtocolTimeout(error)) throw error;
|
|
1047
|
+
try {
|
|
1048
|
+
const { pageStack } = await this.send("App.getPageStack");
|
|
1049
|
+
const page = pageStack[pageStack.length - 1];
|
|
1050
|
+
return page ? Page.create(this.connection, {
|
|
1051
|
+
id: page.pageId,
|
|
1052
|
+
path: page.path,
|
|
1053
|
+
query: page.query
|
|
1054
|
+
}, this.pageMap) : void 0;
|
|
1055
|
+
} catch (pageStackError) {
|
|
1056
|
+
if (!isPageStackProtocolTimeout(pageStackError)) throw pageStackError;
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1022
1060
|
logChangeRouteDebug(`start method=${method} url=${url ?? "<none>"} current=${currentPage?.path ?? "<none>"}`);
|
|
1023
1061
|
if (currentPage && isPluginPath(currentPage.path)) {
|
|
1024
1062
|
const pluginId = extractPluginId(currentPage.path);
|
|
@@ -1127,6 +1165,9 @@ function isInputCapableElement(element) {
|
|
|
1127
1165
|
return typeof Reflect.get(element, "input") === "function";
|
|
1128
1166
|
}
|
|
1129
1167
|
var SmartappElement = class {
|
|
1168
|
+
element;
|
|
1169
|
+
selectors;
|
|
1170
|
+
index;
|
|
1130
1171
|
id;
|
|
1131
1172
|
tagName;
|
|
1132
1173
|
constructor(element, selectors = "", index = 0) {
|
|
@@ -1184,6 +1225,7 @@ var SmartappElement = class {
|
|
|
1184
1225
|
//#endregion
|
|
1185
1226
|
//#region src/smartapp/Page.ts
|
|
1186
1227
|
var SmartappPage = class {
|
|
1228
|
+
page;
|
|
1187
1229
|
path;
|
|
1188
1230
|
query;
|
|
1189
1231
|
uri;
|
|
@@ -1207,6 +1249,8 @@ var SmartappPage = class {
|
|
|
1207
1249
|
//#endregion
|
|
1208
1250
|
//#region src/smartapp/App.ts
|
|
1209
1251
|
var SmartappApp = class {
|
|
1252
|
+
miniProgram;
|
|
1253
|
+
appKey;
|
|
1210
1254
|
constructor(miniProgram, appKey) {
|
|
1211
1255
|
this.miniProgram = miniProgram;
|
|
1212
1256
|
this.appKey = appKey;
|
|
@@ -1268,6 +1312,10 @@ var SmartappApp = class {
|
|
|
1268
1312
|
//#endregion
|
|
1269
1313
|
//#region src/smartapp/Device.ts
|
|
1270
1314
|
var SmartappDevice = class {
|
|
1315
|
+
type;
|
|
1316
|
+
connectType;
|
|
1317
|
+
id;
|
|
1318
|
+
driver;
|
|
1271
1319
|
constructor(type, connectType, id, driver = {}) {
|
|
1272
1320
|
this.type = type;
|
|
1273
1321
|
this.connectType = connectType;
|
|
@@ -1479,6 +1527,7 @@ function toSmartappLaunchOptions(options) {
|
|
|
1479
1527
|
};
|
|
1480
1528
|
}
|
|
1481
1529
|
var SwanLauncher = class {
|
|
1530
|
+
automator;
|
|
1482
1531
|
constructor(automator = SmartappAutomator$1) {
|
|
1483
1532
|
this.automator = automator;
|
|
1484
1533
|
}
|
|
@@ -4047,6 +4047,8 @@ function resolveComponentScopeId(scopeId) {
|
|
|
4047
4047
|
return scopeId;
|
|
4048
4048
|
}
|
|
4049
4049
|
var HeadlessTestingNodeHandle = class HeadlessTestingNodeHandle {
|
|
4050
|
+
node;
|
|
4051
|
+
interactions;
|
|
4050
4052
|
constructor(node, interactions) {
|
|
4051
4053
|
this.node = node;
|
|
4052
4054
|
this.interactions = interactions;
|
|
@@ -5239,11 +5241,10 @@ function deriveMenuButtonBoundingClientRect(systemInfo) {
|
|
|
5239
5241
|
const height = 32;
|
|
5240
5242
|
const top = 32;
|
|
5241
5243
|
const right = Math.max(systemInfo.windowWidth - 12, width);
|
|
5242
|
-
const left = Math.max(0, right - width);
|
|
5243
5244
|
return {
|
|
5244
|
-
bottom:
|
|
5245
|
+
bottom: 64,
|
|
5245
5246
|
height,
|
|
5246
|
-
left,
|
|
5247
|
+
left: Math.max(0, right - width),
|
|
5247
5248
|
right,
|
|
5248
5249
|
top,
|
|
5249
5250
|
width
|
|
@@ -7720,6 +7721,9 @@ function createHeadlessSession(options) {
|
|
|
7720
7721
|
const DEFAULT_WAIT_TIMEOUT$1 = 1e3;
|
|
7721
7722
|
const DEFAULT_WAIT_INTERVAL$1 = 10;
|
|
7722
7723
|
var HeadlessTestingPageHandle = class {
|
|
7724
|
+
project;
|
|
7725
|
+
page;
|
|
7726
|
+
session;
|
|
7723
7727
|
constructor(project, page, session) {
|
|
7724
7728
|
this.project = project;
|
|
7725
7729
|
this.page = page;
|
|
@@ -7886,6 +7890,9 @@ async function pollUntil(check, errorMessage, options = {}) {
|
|
|
7886
7890
|
//#endregion
|
|
7887
7891
|
//#region ../../mpcore/packages/simulator/src/testing/sessionHandle/scope.ts
|
|
7888
7892
|
var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
|
|
7893
|
+
scopeId;
|
|
7894
|
+
project;
|
|
7895
|
+
session;
|
|
7889
7896
|
constructor(scopeId, project, session) {
|
|
7890
7897
|
this.scopeId = scopeId;
|
|
7891
7898
|
this.project = project;
|
|
@@ -7940,6 +7947,8 @@ var HeadlessTestingScopeHandle = class HeadlessTestingScopeHandle {
|
|
|
7940
7947
|
//#endregion
|
|
7941
7948
|
//#region ../../mpcore/packages/simulator/src/testing/sessionHandle/index.ts
|
|
7942
7949
|
var HeadlessTestingSessionHandle = class {
|
|
7950
|
+
project;
|
|
7951
|
+
session;
|
|
7943
7952
|
constructor(project, session) {
|
|
7944
7953
|
this.project = project;
|
|
7945
7954
|
this.session = session;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/miniprogram-automator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "完全兼容微信 miniprogram-automator 的现代化替代实现",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"node": "^20.19.0 || >=22.12.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"ws": "^8.
|
|
44
|
+
"obug": "^2.1.1",
|
|
45
|
+
"ws": "^8.20.1",
|
|
46
46
|
"@weapp-vite/qr": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|