@open-wxa/wxa-runner-core 0.0.0-stage → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 open-wxa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @open-wxa/wxa-runner-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [wxa-runner](https://github.com/open-wxa/wxa-runner) 的开发服务器和浏览器端运行时。
4
+
5
+ 一般不用直接安装:命令行用 [`wxa-runner`](https://www.npmjs.com/package/wxa-runner),在 Playwright 中测试用
6
+ [`@open-wxa/wxa-runner-playwright`](https://www.npmjs.com/package/@open-wxa/wxa-runner-playwright)。以下情况把它加为开发依赖:
7
+
8
+ - setup 文件要类型提示:`import { defineSetup } from '@open-wxa/wxa-runner-core/setup'`,见
9
+ [docs/setup.md](https://github.com/open-wxa/wxa-runner/blob/main/docs/setup.md)
10
+ - 不用 fixture、直接使用测试 API:`/// <reference types="@open-wxa/wxa-runner-core/test-api" />` 为
11
+ `window.__wxa_test_api__` 提供类型,见 [docs/testing.md](https://github.com/open-wxa/wxa-runner/blob/main/docs/testing.md#直接使用测试-api)
12
+ - 在 Node 里启动开发服务器:
13
+
14
+ ```ts
15
+ import { DevServer } from '@open-wxa/wxa-runner-core';
16
+
17
+ const server = new DevServer({ projectPath: './dist/dev/mp-weixin', port: 3000, watch: false });
18
+ const url = await server.start();
19
+ // …
20
+ await server.close();
21
+ ```
@@ -0,0 +1,11 @@
1
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ var getFilename = () => fileURLToPath(import.meta.url);
5
+ var getDirname = () => path.dirname(getFilename());
6
+ var __dirname = /* @__PURE__ */ getDirname();
7
+
8
+ export {
9
+ __dirname
10
+ };
11
+ //# sourceMappingURL=chunk-22T3D5KS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.30_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n"],"mappings":";AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,YAA4B,2BAAW;","names":[]}
@@ -0,0 +1,236 @@
1
+ import { ResolvedBaseLib } from '@open-wxa/wxa-runner-extractor';
2
+ import { D as DeviceProfile } from './setup-COzZ6vzS.mjs';
3
+ export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-COzZ6vzS.mjs';
4
+ export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-D5o7hK-Z.mjs';
5
+
6
+ /**
7
+ * 小程序项目结构解析
8
+ *
9
+ * 负责读取 app.json / 页面与组件 json,并按开发者工具的规则做预处理:
10
+ * - app.json 的全局 usingComponents 展开到每个页面和组件(miniprogram_npm 内除外)
11
+ * - 每个页面/组件 json 都保证有 usingComponents 字段
12
+ */
13
+ interface AppJson {
14
+ pages: string[];
15
+ entryPagePath?: string;
16
+ window?: Record<string, any>;
17
+ tabBar?: {
18
+ list: Array<{
19
+ pagePath: string;
20
+ text?: string;
21
+ iconPath?: string;
22
+ selectedIconPath?: string;
23
+ }>;
24
+ [key: string]: any;
25
+ };
26
+ subPackages?: Array<{
27
+ root: string;
28
+ pages: string[];
29
+ independent?: boolean;
30
+ [key: string]: any;
31
+ }>;
32
+ subpackages?: AppJson['subPackages'];
33
+ usingComponents?: Record<string, string>;
34
+ workers?: string | {
35
+ path: string;
36
+ };
37
+ [key: string]: any;
38
+ }
39
+ interface UnitJson {
40
+ usingComponents: Record<string, string>;
41
+ componentGenerics?: Record<string, boolean | {
42
+ default?: string;
43
+ }>;
44
+ component?: boolean;
45
+ [key: string]: any;
46
+ }
47
+ declare class MiniProgram {
48
+ readonly projectPath: string;
49
+ /** 小程序代码根目录(已考虑 project.config.json 的 miniprogramRoot) */
50
+ readonly root: string;
51
+ readonly appid: string;
52
+ constructor(projectPath: string);
53
+ readAppJson(): AppJson;
54
+ subPackages(app: AppJson): {
55
+ [key: string]: any;
56
+ root: string;
57
+ pages: string[];
58
+ independent?: boolean;
59
+ }[];
60
+ /** 主包页面 + 分包页面(带 root 前缀) */
61
+ allPages(app: AppJson): string[];
62
+ /** 读取并预处理页面/组件 json,id 不带扩展名 */
63
+ readUnitJson(id: string, app: AppJson): UnitJson;
64
+ /**
65
+ * 解析组件引用到组件路径(不带扩展名);插件组件或找不到时返回 null。
66
+ * 规则:/ 开头为根目录绝对路径;否则先按相对路径找,再沿目录向上查找 miniprogram_npm。
67
+ */
68
+ resolveComponent(fromId: string, ref: string): string | null;
69
+ /** 收集所有页面以及它们(递归)引用到的自定义组件 */
70
+ collectUnits(app: AppJson): {
71
+ pages: string[];
72
+ components: string[];
73
+ };
74
+ /** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
75
+ listFiles(extensions: string[], excludeDirs?: string[]): string[];
76
+ exists(relPath: string): boolean;
77
+ readText(relPath: string): string;
78
+ private isInIndependentSubPackage;
79
+ }
80
+
81
+ /**
82
+ * 把小程序项目构建成官方基础库能直接加载的形式
83
+ *
84
+ * 逻辑层(appservice):
85
+ * 1. 裁剪版 $gwx(wcc -xc),基础库用它了解组件的节点结构
86
+ * 2. 每个 JS 文件单独一个 define("x.js", fn) 脚本(便于在 DevTools 里按原文件调试)
87
+ * 3. bootstrap:注册 __wxAppCode__ 的 json/wxml(serviceTemplates,热更新时单独下发),
88
+ * require("app.js"),再依次 require 组件和页面
89
+ *
90
+ * 渲染层(page-frame):
91
+ * 1. 完整版 $gwx(wcc -cc)与每个页面/组件的 __wxAppCode__ json / wxml(pageTemplates)
92
+ * 2. wcsc 的公共样式运行时 + app.wxss,与每个页面/组件的 __wxAppCode__ wxss(pageStyles)
93
+ * 两部分在热更新时分别下发
94
+ * 样式和模板里的 env(safe-area-inset-*) 改写成 CSS 变量,见 rewriteSafeAreaInsets
95
+ */
96
+
97
+ interface BuildResult {
98
+ version: number;
99
+ wxConfig: Record<string, any>;
100
+ /** 所有 JS 模块 id(如 "pages/index/index.js"),逻辑层按此顺序加载 define 脚本 */
101
+ modules: string[];
102
+ /** 逻辑层的 $gwx 与 __wxAppCode__ json/wxml,不含 require */
103
+ serviceTemplates: string;
104
+ serviceBootstrap: string;
105
+ pageFrame: string;
106
+ /** 渲染层的 $gwx 与 __wxAppCode__ json/wxml,不含样式(热更新时单独下发) */
107
+ pageTemplates: string;
108
+ /** 渲染层的样式:公共样式立即注入,页面和组件的样式注册到 __wxAppCode__(热更新时单独下发) */
109
+ pageStyles: string;
110
+ pages: string[];
111
+ components: string[];
112
+ durationMs: number;
113
+ }
114
+ declare class AppBuilder {
115
+ readonly project: MiniProgram;
116
+ private version;
117
+ /** invalidate 标记过的变化次数;每次构建记下开始时覆盖到第几次 */
118
+ private changes;
119
+ private pending;
120
+ private last;
121
+ private dirty;
122
+ private wxmlCache;
123
+ private wxssCache;
124
+ constructor(project: MiniProgram);
125
+ /** 根据变化的文件标记需要重新构建的部分;返回 true 表示需要刷新 */
126
+ invalidate(changedFiles?: string[]): boolean;
127
+ /**
128
+ * 返回包含调用前所有变化的构建结果。并发调用共享同一次构建;
129
+ * 进行中的构建开始得比最近一次变化早时(可能已读到旧文件),等它结束后再构建一次
130
+ */
131
+ build(): Promise<BuildResult>;
132
+ /**
133
+ * 单个 JS 模块的 define 包装
134
+ *
135
+ * 包装头和代码第一行写在同一行,行号与源文件一致。使用 import/export 的文件
136
+ * 先转换为 CommonJS(对应开发者工具的「ES6 转 ES5」),并内联 source map。
137
+ */
138
+ getModuleScript(id: string): string;
139
+ private doBuild;
140
+ private compileTemplates;
141
+ /** 与开发者工具一致,项目里的 wxss 全部交给 wcsc:被 @import 的文件(如 uni-app 的 common/main.wxss)也要在列表里 */
142
+ private compileStyles;
143
+ /** $gwx 加上各页面、组件的 json / wxml 注册;逻辑层用裁剪版 $gwx,渲染层用完整版 */
144
+ private createTemplates;
145
+ private createServiceBootstrap;
146
+ }
147
+
148
+ /**
149
+ * 开发服务器
150
+ *
151
+ * / 宿主页面
152
+ * /__wxa__/app-info.json 构建信息(__wxConfig、页面列表、设备参数、setup)
153
+ * /__wxa__/setup.js 编译后的 setup 文件
154
+ * /__wxa__/appservice.html 逻辑层
155
+ * /__wxa__/webview/<page>.html 渲染层(路径与页面一致,wxml 里的相对资源路径因此能正确解析)
156
+ * /__wxa__/module/<file>.js 单个业务 JS 模块
157
+ * /__wxa__/service-templates.js、page-templates.js 两层的模板(热更新时重新下发)
158
+ * /__wxa__/page-styles.js 渲染层的样式(热更新时重新下发)
159
+ * /__baselib__/* 官方基础库
160
+ * /__wxa__/proxy?url= 网络代理
161
+ * /__wxa__/tmp 临时文件:POST ?type=png 保存,返回可直接访问的地址
162
+ * /__wxa__/region/<kind> 地区选择器用的行政区划数据(districts / streets),取自本机开发者工具
163
+ * /__wxa__/api/* 真实登录(--real-login):wx.login 的 code、手机号,只允许本机访问
164
+ * /__wxa__/ws 文件变化通知:热更新(hot)或整页刷新(reload)
165
+ * 其余路径 小程序目录下的静态资源
166
+ */
167
+
168
+ interface DevServerOptions {
169
+ projectPath: string;
170
+ /** 默认 3000,传 0 使用随机端口 */
171
+ port?: number;
172
+ host?: string;
173
+ /** 指定基础库版本,默认使用本机已安装的最新兼容版本 */
174
+ baseLibVersion?: string;
175
+ baseLibCacheDir?: string;
176
+ watch?: boolean;
177
+ device?: Partial<DeviceProfile>;
178
+ /**
179
+ * 小程序启动前执行的 setup 文件;默认使用项目目录下的 wxa.setup.ts / .js / .mjs,传 false 不使用
180
+ * 环境变量在构造时读取,只暴露 WXA_ 前缀的变量
181
+ */
182
+ setup?: string | false;
183
+ /** 浏览器端运行时(host.js / frame.js)所在目录,默认取构建产物 */
184
+ runtimeDir?: string;
185
+ /** 使用本机微信开发者工具登录态获取真实 code 和手机号 */
186
+ realLogin?: boolean;
187
+ logger?: Pick<Console, 'log' | 'warn' | 'error'>;
188
+ }
189
+ declare const DEFAULT_DEVICE: DeviceProfile;
190
+ declare class DevServer {
191
+ private readonly options;
192
+ readonly project: MiniProgram;
193
+ readonly builder: AppBuilder;
194
+ readonly baseLib: ResolvedBaseLib;
195
+ /** 生效的 setup 文件绝对路径,没有时为 null */
196
+ readonly setupFile: string | null;
197
+ private readonly setupEnv;
198
+ private readonly device;
199
+ private readonly logger;
200
+ private readonly app;
201
+ private server;
202
+ private sockets;
203
+ private watcher;
204
+ private address;
205
+ /** 运行时生成的临时文件(canvas 导出、拍照等),随服务器进程存在 */
206
+ private readonly tempFiles;
207
+ constructor(options: DevServerOptions);
208
+ get url(): string;
209
+ start(): Promise<string>;
210
+ close(): Promise<void>;
211
+ private createApp;
212
+ /** 先编译一遍 setup:编译错误随 app-info 交给宿主显示,而不是让浏览器 import 失败 */
213
+ private setupInfo;
214
+ /** 需要构建结果的路由;构建失败时返回错误文本 */
215
+ private withBuild;
216
+ private runtimeDir;
217
+ /** 只在监听文件变化时打开基础库的热更新开关,跑测试(watch: false)时运行环境与真机一致 */
218
+ private get hotEnabled();
219
+ private startWatching;
220
+ private broadcast;
221
+ }
222
+
223
+ /**
224
+ * 生成基础库读取的 __wxConfig,字段与开发者工具保持一致
225
+ */
226
+
227
+ interface WxConfigInput {
228
+ app: AppJson;
229
+ pages: string[];
230
+ unitJson: Map<string, UnitJson>;
231
+ appid: string;
232
+ subPackages: NonNullable<AppJson['subPackages']>;
233
+ }
234
+ declare function createWxConfig(input: WxConfigInput): Record<string, any>;
235
+
236
+ export { AppBuilder, type AppJson, type BuildResult, DEFAULT_DEVICE, DevServer, type DevServerOptions, DeviceProfile, MiniProgram, type UnitJson, createWxConfig };
@@ -0,0 +1,236 @@
1
+ import { ResolvedBaseLib } from '@open-wxa/wxa-runner-extractor';
2
+ import { D as DeviceProfile } from './setup-COzZ6vzS.js';
3
+ export { A as ApiContext, a as ApiHandler, b as ApiResult, c as AppInfo, M as MockConfig, d as MockRequest, e as MockResponse, f as MockValue, N as NetworkConfig, R as RouteHandler, S as SetupApi, g as SetupConfig, h as SetupContext, i as SetupDefinition } from './setup-COzZ6vzS.js';
4
+ export { F as FrameError, P as PageSnapshot, R as RecordedRequest, W as WxaTestApi } from './testApi-BTPLQvFs.js';
5
+
6
+ /**
7
+ * 小程序项目结构解析
8
+ *
9
+ * 负责读取 app.json / 页面与组件 json,并按开发者工具的规则做预处理:
10
+ * - app.json 的全局 usingComponents 展开到每个页面和组件(miniprogram_npm 内除外)
11
+ * - 每个页面/组件 json 都保证有 usingComponents 字段
12
+ */
13
+ interface AppJson {
14
+ pages: string[];
15
+ entryPagePath?: string;
16
+ window?: Record<string, any>;
17
+ tabBar?: {
18
+ list: Array<{
19
+ pagePath: string;
20
+ text?: string;
21
+ iconPath?: string;
22
+ selectedIconPath?: string;
23
+ }>;
24
+ [key: string]: any;
25
+ };
26
+ subPackages?: Array<{
27
+ root: string;
28
+ pages: string[];
29
+ independent?: boolean;
30
+ [key: string]: any;
31
+ }>;
32
+ subpackages?: AppJson['subPackages'];
33
+ usingComponents?: Record<string, string>;
34
+ workers?: string | {
35
+ path: string;
36
+ };
37
+ [key: string]: any;
38
+ }
39
+ interface UnitJson {
40
+ usingComponents: Record<string, string>;
41
+ componentGenerics?: Record<string, boolean | {
42
+ default?: string;
43
+ }>;
44
+ component?: boolean;
45
+ [key: string]: any;
46
+ }
47
+ declare class MiniProgram {
48
+ readonly projectPath: string;
49
+ /** 小程序代码根目录(已考虑 project.config.json 的 miniprogramRoot) */
50
+ readonly root: string;
51
+ readonly appid: string;
52
+ constructor(projectPath: string);
53
+ readAppJson(): AppJson;
54
+ subPackages(app: AppJson): {
55
+ [key: string]: any;
56
+ root: string;
57
+ pages: string[];
58
+ independent?: boolean;
59
+ }[];
60
+ /** 主包页面 + 分包页面(带 root 前缀) */
61
+ allPages(app: AppJson): string[];
62
+ /** 读取并预处理页面/组件 json,id 不带扩展名 */
63
+ readUnitJson(id: string, app: AppJson): UnitJson;
64
+ /**
65
+ * 解析组件引用到组件路径(不带扩展名);插件组件或找不到时返回 null。
66
+ * 规则:/ 开头为根目录绝对路径;否则先按相对路径找,再沿目录向上查找 miniprogram_npm。
67
+ */
68
+ resolveComponent(fromId: string, ref: string): string | null;
69
+ /** 收集所有页面以及它们(递归)引用到的自定义组件 */
70
+ collectUnits(app: AppJson): {
71
+ pages: string[];
72
+ components: string[];
73
+ };
74
+ /** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
75
+ listFiles(extensions: string[], excludeDirs?: string[]): string[];
76
+ exists(relPath: string): boolean;
77
+ readText(relPath: string): string;
78
+ private isInIndependentSubPackage;
79
+ }
80
+
81
+ /**
82
+ * 把小程序项目构建成官方基础库能直接加载的形式
83
+ *
84
+ * 逻辑层(appservice):
85
+ * 1. 裁剪版 $gwx(wcc -xc),基础库用它了解组件的节点结构
86
+ * 2. 每个 JS 文件单独一个 define("x.js", fn) 脚本(便于在 DevTools 里按原文件调试)
87
+ * 3. bootstrap:注册 __wxAppCode__ 的 json/wxml(serviceTemplates,热更新时单独下发),
88
+ * require("app.js"),再依次 require 组件和页面
89
+ *
90
+ * 渲染层(page-frame):
91
+ * 1. 完整版 $gwx(wcc -cc)与每个页面/组件的 __wxAppCode__ json / wxml(pageTemplates)
92
+ * 2. wcsc 的公共样式运行时 + app.wxss,与每个页面/组件的 __wxAppCode__ wxss(pageStyles)
93
+ * 两部分在热更新时分别下发
94
+ * 样式和模板里的 env(safe-area-inset-*) 改写成 CSS 变量,见 rewriteSafeAreaInsets
95
+ */
96
+
97
+ interface BuildResult {
98
+ version: number;
99
+ wxConfig: Record<string, any>;
100
+ /** 所有 JS 模块 id(如 "pages/index/index.js"),逻辑层按此顺序加载 define 脚本 */
101
+ modules: string[];
102
+ /** 逻辑层的 $gwx 与 __wxAppCode__ json/wxml,不含 require */
103
+ serviceTemplates: string;
104
+ serviceBootstrap: string;
105
+ pageFrame: string;
106
+ /** 渲染层的 $gwx 与 __wxAppCode__ json/wxml,不含样式(热更新时单独下发) */
107
+ pageTemplates: string;
108
+ /** 渲染层的样式:公共样式立即注入,页面和组件的样式注册到 __wxAppCode__(热更新时单独下发) */
109
+ pageStyles: string;
110
+ pages: string[];
111
+ components: string[];
112
+ durationMs: number;
113
+ }
114
+ declare class AppBuilder {
115
+ readonly project: MiniProgram;
116
+ private version;
117
+ /** invalidate 标记过的变化次数;每次构建记下开始时覆盖到第几次 */
118
+ private changes;
119
+ private pending;
120
+ private last;
121
+ private dirty;
122
+ private wxmlCache;
123
+ private wxssCache;
124
+ constructor(project: MiniProgram);
125
+ /** 根据变化的文件标记需要重新构建的部分;返回 true 表示需要刷新 */
126
+ invalidate(changedFiles?: string[]): boolean;
127
+ /**
128
+ * 返回包含调用前所有变化的构建结果。并发调用共享同一次构建;
129
+ * 进行中的构建开始得比最近一次变化早时(可能已读到旧文件),等它结束后再构建一次
130
+ */
131
+ build(): Promise<BuildResult>;
132
+ /**
133
+ * 单个 JS 模块的 define 包装
134
+ *
135
+ * 包装头和代码第一行写在同一行,行号与源文件一致。使用 import/export 的文件
136
+ * 先转换为 CommonJS(对应开发者工具的「ES6 转 ES5」),并内联 source map。
137
+ */
138
+ getModuleScript(id: string): string;
139
+ private doBuild;
140
+ private compileTemplates;
141
+ /** 与开发者工具一致,项目里的 wxss 全部交给 wcsc:被 @import 的文件(如 uni-app 的 common/main.wxss)也要在列表里 */
142
+ private compileStyles;
143
+ /** $gwx 加上各页面、组件的 json / wxml 注册;逻辑层用裁剪版 $gwx,渲染层用完整版 */
144
+ private createTemplates;
145
+ private createServiceBootstrap;
146
+ }
147
+
148
+ /**
149
+ * 开发服务器
150
+ *
151
+ * / 宿主页面
152
+ * /__wxa__/app-info.json 构建信息(__wxConfig、页面列表、设备参数、setup)
153
+ * /__wxa__/setup.js 编译后的 setup 文件
154
+ * /__wxa__/appservice.html 逻辑层
155
+ * /__wxa__/webview/<page>.html 渲染层(路径与页面一致,wxml 里的相对资源路径因此能正确解析)
156
+ * /__wxa__/module/<file>.js 单个业务 JS 模块
157
+ * /__wxa__/service-templates.js、page-templates.js 两层的模板(热更新时重新下发)
158
+ * /__wxa__/page-styles.js 渲染层的样式(热更新时重新下发)
159
+ * /__baselib__/* 官方基础库
160
+ * /__wxa__/proxy?url= 网络代理
161
+ * /__wxa__/tmp 临时文件:POST ?type=png 保存,返回可直接访问的地址
162
+ * /__wxa__/region/<kind> 地区选择器用的行政区划数据(districts / streets),取自本机开发者工具
163
+ * /__wxa__/api/* 真实登录(--real-login):wx.login 的 code、手机号,只允许本机访问
164
+ * /__wxa__/ws 文件变化通知:热更新(hot)或整页刷新(reload)
165
+ * 其余路径 小程序目录下的静态资源
166
+ */
167
+
168
+ interface DevServerOptions {
169
+ projectPath: string;
170
+ /** 默认 3000,传 0 使用随机端口 */
171
+ port?: number;
172
+ host?: string;
173
+ /** 指定基础库版本,默认使用本机已安装的最新兼容版本 */
174
+ baseLibVersion?: string;
175
+ baseLibCacheDir?: string;
176
+ watch?: boolean;
177
+ device?: Partial<DeviceProfile>;
178
+ /**
179
+ * 小程序启动前执行的 setup 文件;默认使用项目目录下的 wxa.setup.ts / .js / .mjs,传 false 不使用
180
+ * 环境变量在构造时读取,只暴露 WXA_ 前缀的变量
181
+ */
182
+ setup?: string | false;
183
+ /** 浏览器端运行时(host.js / frame.js)所在目录,默认取构建产物 */
184
+ runtimeDir?: string;
185
+ /** 使用本机微信开发者工具登录态获取真实 code 和手机号 */
186
+ realLogin?: boolean;
187
+ logger?: Pick<Console, 'log' | 'warn' | 'error'>;
188
+ }
189
+ declare const DEFAULT_DEVICE: DeviceProfile;
190
+ declare class DevServer {
191
+ private readonly options;
192
+ readonly project: MiniProgram;
193
+ readonly builder: AppBuilder;
194
+ readonly baseLib: ResolvedBaseLib;
195
+ /** 生效的 setup 文件绝对路径,没有时为 null */
196
+ readonly setupFile: string | null;
197
+ private readonly setupEnv;
198
+ private readonly device;
199
+ private readonly logger;
200
+ private readonly app;
201
+ private server;
202
+ private sockets;
203
+ private watcher;
204
+ private address;
205
+ /** 运行时生成的临时文件(canvas 导出、拍照等),随服务器进程存在 */
206
+ private readonly tempFiles;
207
+ constructor(options: DevServerOptions);
208
+ get url(): string;
209
+ start(): Promise<string>;
210
+ close(): Promise<void>;
211
+ private createApp;
212
+ /** 先编译一遍 setup:编译错误随 app-info 交给宿主显示,而不是让浏览器 import 失败 */
213
+ private setupInfo;
214
+ /** 需要构建结果的路由;构建失败时返回错误文本 */
215
+ private withBuild;
216
+ private runtimeDir;
217
+ /** 只在监听文件变化时打开基础库的热更新开关,跑测试(watch: false)时运行环境与真机一致 */
218
+ private get hotEnabled();
219
+ private startWatching;
220
+ private broadcast;
221
+ }
222
+
223
+ /**
224
+ * 生成基础库读取的 __wxConfig,字段与开发者工具保持一致
225
+ */
226
+
227
+ interface WxConfigInput {
228
+ app: AppJson;
229
+ pages: string[];
230
+ unitJson: Map<string, UnitJson>;
231
+ appid: string;
232
+ subPackages: NonNullable<AppJson['subPackages']>;
233
+ }
234
+ declare function createWxConfig(input: WxConfigInput): Record<string, any>;
235
+
236
+ export { AppBuilder, type AppJson, type BuildResult, DEFAULT_DEVICE, DevServer, type DevServerOptions, DeviceProfile, MiniProgram, type UnitJson, createWxConfig };