@weapp-vite/devtools-runtime 0.3.1 → 0.4.0
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.d.ts +4 -3
- package/dist/index.js +25 -11
- package/dist/mcp.d.ts +4 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ interface MiniProgramEventMap {
|
|
|
5
5
|
console: (payload: unknown) => void;
|
|
6
6
|
exception: (payload: unknown) => void;
|
|
7
7
|
}
|
|
8
|
+
declare function resolveSharedMiniProgramSessionKey(options: Pick<DevtoolsRuntimeSessionOptions, 'port' | 'projectPath' | 'sessionId'>): string;
|
|
8
9
|
/**
|
|
9
10
|
* @description 获取指定项目的共享 automator 会话;若不存在则自动创建。
|
|
10
11
|
*/
|
|
@@ -12,11 +13,11 @@ declare function acquireSharedMiniProgram(hooks: DevtoolsRuntimeHooks, options:
|
|
|
12
13
|
/**
|
|
13
14
|
* @description 释放指定项目的共享会话引用;会话对象会继续缓存,直到显式关闭或重置。
|
|
14
15
|
*/
|
|
15
|
-
declare function releaseSharedMiniProgram(projectPath: string): void;
|
|
16
|
+
declare function releaseSharedMiniProgram(projectPath: string, sessionIdOrPort?: string | number): void;
|
|
16
17
|
/**
|
|
17
18
|
* @description 关闭并移除指定项目的共享 automator 会话。
|
|
18
19
|
*/
|
|
19
|
-
declare function closeSharedMiniProgram(projectPath: string): Promise<void>;
|
|
20
|
+
declare function closeSharedMiniProgram(projectPath: string, sessionIdOrPort?: string | number): Promise<void>;
|
|
20
21
|
/**
|
|
21
22
|
* @description 获取当前共享会话数量,供测试断言使用。
|
|
22
23
|
*/
|
|
@@ -26,4 +27,4 @@ declare function getSharedMiniProgramSessionCount(): number;
|
|
|
26
27
|
*/
|
|
27
28
|
declare function withMiniProgram<T>(hooks: DevtoolsRuntimeHooks, options: DevtoolsRuntimeSessionOptions, runner: (miniProgram: AutomatorMiniProgram) => Promise<T>): Promise<T>;
|
|
28
29
|
//#endregion
|
|
29
|
-
export { type AutomatorElement, type AutomatorMiniProgram, type AutomatorPage, type DevtoolsConnectionInput, type DevtoolsContext, type DevtoolsElementSnapshot, type DevtoolsPageSnapshot, type DevtoolsRuntimeHooks, type DevtoolsRuntimeSessionOptions, type DevtoolsToolResult, type MiniProgramElementLike, MiniProgramEventMap, acquireSharedMiniProgram, closeSharedMiniProgram, getSharedMiniProgramSessionCount, readDevtoolsElementSnapshot, releaseSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, toDevtoolsSerializableValue, withMiniProgram };
|
|
30
|
+
export { type AutomatorElement, type AutomatorMiniProgram, type AutomatorPage, type DevtoolsConnectionInput, type DevtoolsContext, type DevtoolsElementSnapshot, type DevtoolsPageSnapshot, type DevtoolsRuntimeHooks, type DevtoolsRuntimeSessionOptions, type DevtoolsToolResult, type MiniProgramElementLike, MiniProgramEventMap, acquireSharedMiniProgram, closeSharedMiniProgram, getSharedMiniProgramSessionCount, readDevtoolsElementSnapshot, releaseSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, resolveSharedMiniProgramSessionKey, toDevtoolsSerializableValue, withMiniProgram };
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,16 @@ function normalizeError(hooks, error) {
|
|
|
5
5
|
const normalized = hooks.normalizeConnectionError?.(error) ?? error;
|
|
6
6
|
return normalized instanceof Error ? normalized : new Error(String(normalized));
|
|
7
7
|
}
|
|
8
|
+
function resolveSharedMiniProgramSessionKey(options) {
|
|
9
|
+
const sessionSuffix = options.sessionId || (options.port ? `port:${options.port}` : "default");
|
|
10
|
+
return `${options.projectPath}#${sessionSuffix}`;
|
|
11
|
+
}
|
|
8
12
|
/**
|
|
9
13
|
* @description 获取指定项目的共享 automator 会话;若不存在则自动创建。
|
|
10
14
|
*/
|
|
11
15
|
async function acquireSharedMiniProgram(hooks, options) {
|
|
12
|
-
const
|
|
16
|
+
const sessionKey = resolveSharedMiniProgramSessionKey(options);
|
|
17
|
+
const existing = sharedMiniProgramSessions.get(sessionKey);
|
|
13
18
|
if (existing) {
|
|
14
19
|
existing.refs += 1;
|
|
15
20
|
return await existing.session;
|
|
@@ -19,29 +24,38 @@ async function acquireSharedMiniProgram(hooks, options) {
|
|
|
19
24
|
refs: 1,
|
|
20
25
|
session
|
|
21
26
|
};
|
|
22
|
-
sharedMiniProgramSessions.set(
|
|
27
|
+
sharedMiniProgramSessions.set(sessionKey, entry);
|
|
23
28
|
try {
|
|
24
29
|
return await session;
|
|
25
30
|
} catch (error) {
|
|
26
|
-
sharedMiniProgramSessions.delete(
|
|
31
|
+
sharedMiniProgramSessions.delete(sessionKey);
|
|
27
32
|
throw normalizeError(hooks, error);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* @description 释放指定项目的共享会话引用;会话对象会继续缓存,直到显式关闭或重置。
|
|
32
37
|
*/
|
|
33
|
-
function releaseSharedMiniProgram(projectPath) {
|
|
34
|
-
const entry = sharedMiniProgramSessions.get(
|
|
38
|
+
function releaseSharedMiniProgram(projectPath, sessionIdOrPort) {
|
|
39
|
+
const entry = sharedMiniProgramSessions.get(resolveSharedMiniProgramSessionKey({
|
|
40
|
+
projectPath,
|
|
41
|
+
...typeof sessionIdOrPort === "number" ? { port: sessionIdOrPort } : {},
|
|
42
|
+
...typeof sessionIdOrPort === "string" ? { sessionId: sessionIdOrPort } : {}
|
|
43
|
+
}));
|
|
35
44
|
if (!entry) return;
|
|
36
45
|
entry.refs = Math.max(0, entry.refs - 1);
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* @description 关闭并移除指定项目的共享 automator 会话。
|
|
40
49
|
*/
|
|
41
|
-
async function closeSharedMiniProgram(projectPath) {
|
|
42
|
-
const
|
|
50
|
+
async function closeSharedMiniProgram(projectPath, sessionIdOrPort) {
|
|
51
|
+
const sessionKey = resolveSharedMiniProgramSessionKey({
|
|
52
|
+
projectPath,
|
|
53
|
+
...typeof sessionIdOrPort === "number" ? { port: sessionIdOrPort } : {},
|
|
54
|
+
...typeof sessionIdOrPort === "string" ? { sessionId: sessionIdOrPort } : {}
|
|
55
|
+
});
|
|
56
|
+
const entry = sharedMiniProgramSessions.get(sessionKey);
|
|
43
57
|
if (!entry) return;
|
|
44
|
-
sharedMiniProgramSessions.delete(
|
|
58
|
+
sharedMiniProgramSessions.delete(sessionKey);
|
|
45
59
|
(await entry.session.catch(() => null))?.disconnect();
|
|
46
60
|
}
|
|
47
61
|
/**
|
|
@@ -60,10 +74,10 @@ async function withMiniProgram(hooks, options, runner) {
|
|
|
60
74
|
try {
|
|
61
75
|
return await runner(miniProgram);
|
|
62
76
|
} catch (error) {
|
|
63
|
-
await closeSharedMiniProgram(options.projectPath);
|
|
77
|
+
await closeSharedMiniProgram(options.projectPath, options.sessionId || options.port);
|
|
64
78
|
throw normalizeError(hooks, error);
|
|
65
79
|
} finally {
|
|
66
|
-
releaseSharedMiniProgram(options.projectPath);
|
|
80
|
+
releaseSharedMiniProgram(options.projectPath, options.sessionId || options.port);
|
|
67
81
|
}
|
|
68
82
|
}
|
|
69
83
|
let miniProgram = null;
|
|
@@ -77,4 +91,4 @@ async function withMiniProgram(hooks, options, runner) {
|
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
//#endregion
|
|
80
|
-
export { acquireSharedMiniProgram, closeSharedMiniProgram, getSharedMiniProgramSessionCount, readDevtoolsElementSnapshot, releaseSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, toDevtoolsSerializableValue, withMiniProgram };
|
|
94
|
+
export { acquireSharedMiniProgram, closeSharedMiniProgram, getSharedMiniProgramSessionCount, readDevtoolsElementSnapshot, releaseSharedMiniProgram, resolveDevtoolsProjectPath, resolveDevtoolsWorkspacePath, resolveSharedMiniProgramSessionKey, toDevtoolsSerializableValue, withMiniProgram };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ type AutomatorElement = InstanceType<typeof Element> & {
|
|
|
9
9
|
interface DevtoolsRuntimeSessionOptions {
|
|
10
10
|
miniProgram?: AutomatorMiniProgram;
|
|
11
11
|
preferOpenedSession?: boolean;
|
|
12
|
+
port?: number;
|
|
12
13
|
projectPath: string;
|
|
13
14
|
sharedSession?: boolean;
|
|
15
|
+
sessionId?: string;
|
|
14
16
|
timeout?: number;
|
|
15
17
|
}
|
|
16
18
|
interface DevtoolsRuntimeHooks {
|
|
@@ -20,7 +22,9 @@ interface DevtoolsRuntimeHooks {
|
|
|
20
22
|
interface DevtoolsConnectionInput {
|
|
21
23
|
projectPath: string;
|
|
22
24
|
timeout?: number;
|
|
25
|
+
port?: number;
|
|
23
26
|
preferOpenedSession?: boolean;
|
|
27
|
+
sessionId?: string;
|
|
24
28
|
}
|
|
25
29
|
interface DevtoolsElementSnapshot {
|
|
26
30
|
selector: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/devtools-runtime",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "Shared WeChat DevTools runtime automation helpers for weapp-vite packages",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"registry": "https://registry.npmjs.org/"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@weapp-vite/miniprogram-automator": "1.
|
|
41
|
+
"@weapp-vite/miniprogram-automator": "1.2.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"dev": "tsdown -w --sourcemap",
|