@open-wxa/wxa-runner-core 0.4.1 → 0.6.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.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +55 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -10
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/frame.js +99 -2
- package/dist/runtime/frame.js.map +1 -1
- package/dist/runtime/host.js +155 -36
- package/dist/runtime/host.js.map +1 -1
- package/dist/runtime/worker.js +42 -0
- package/dist/runtime/worker.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -32,8 +32,10 @@ interface AppJson {
|
|
|
32
32
|
}>;
|
|
33
33
|
subpackages?: AppJson['subPackages'];
|
|
34
34
|
usingComponents?: Record<string, string>;
|
|
35
|
+
/** isSubpackage:Worker 代码作为分包,业务先调 wx.preDownloadSubpackage({ packageType: 'workers' }) 再创建 Worker */
|
|
35
36
|
workers?: string | {
|
|
36
37
|
path: string;
|
|
38
|
+
isSubpackage?: boolean;
|
|
37
39
|
};
|
|
38
40
|
[key: string]: any;
|
|
39
41
|
}
|
|
@@ -58,6 +60,8 @@ declare class MiniProgram {
|
|
|
58
60
|
pages: string[];
|
|
59
61
|
independent?: boolean;
|
|
60
62
|
}[];
|
|
63
|
+
/** Worker 代码所在目录,不带首尾的 /;没有配置 workers 时为 null */
|
|
64
|
+
workersDir(app: AppJson): string | null;
|
|
61
65
|
/** 主包页面 + 分包页面(带 root 前缀) */
|
|
62
66
|
allPages(app: AppJson): string[];
|
|
63
67
|
/** 读取并预处理页面/组件 json,id 不带扩展名 */
|
|
@@ -73,7 +77,7 @@ declare class MiniProgram {
|
|
|
73
77
|
components: string[];
|
|
74
78
|
};
|
|
75
79
|
/** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
|
|
76
|
-
listFiles(extensions: string[]
|
|
80
|
+
listFiles(extensions: string[]): string[];
|
|
77
81
|
exists(relPath: string): boolean;
|
|
78
82
|
readText(relPath: string): string;
|
|
79
83
|
private isInIndependentSubPackage;
|
|
@@ -93,6 +97,8 @@ declare class MiniProgram {
|
|
|
93
97
|
* 2. wcsc 的公共样式运行时 + app.wxss,与每个页面/组件的 __wxAppCode__ wxss(pageStyles)
|
|
94
98
|
* 两部分在热更新时分别下发
|
|
95
99
|
* 样式和模板里的 env(safe-area-inset-*) 改写成 CSS 变量,见 rewriteSafeAreaInsets
|
|
100
|
+
*
|
|
101
|
+
* Worker:workers 目录下的 JS 不进逻辑层,同样包装成 define 脚本,由 Worker 入口(server/html.ts 的 workerScript)加载
|
|
96
102
|
*/
|
|
97
103
|
|
|
98
104
|
interface BuildResult {
|
|
@@ -100,6 +106,8 @@ interface BuildResult {
|
|
|
100
106
|
wxConfig: Record<string, any>;
|
|
101
107
|
/** 所有 JS 模块 id(如 "pages/index/index.js"),逻辑层按此顺序加载 define 脚本 */
|
|
102
108
|
modules: string[];
|
|
109
|
+
/** workers 目录下的 JS 模块 id,Worker 按此顺序加载 define 脚本 */
|
|
110
|
+
workerModules: string[];
|
|
103
111
|
/** 逻辑层的 $gwx 与 __wxAppCode__ json/wxml,不含 require */
|
|
104
112
|
serviceTemplates: string;
|
|
105
113
|
serviceBootstrap: string;
|
|
@@ -154,12 +162,13 @@ declare class AppBuilder {
|
|
|
154
162
|
* /__wxa__/setup.js 编译后的 setup 文件
|
|
155
163
|
* /__wxa__/appservice.html 逻辑层
|
|
156
164
|
* /__wxa__/webview/<page>.html 渲染层(路径与页面一致,wxml 里的相对资源路径因此能正确解析)
|
|
157
|
-
* /__wxa__/module/<file>.js 单个业务 JS
|
|
165
|
+
* /__wxa__/module/<file>.js 单个业务 JS 模块(含 workers 目录下的)
|
|
166
|
+
* /__wxa__/worker.js?id= Worker 的入口
|
|
158
167
|
* /__wxa__/service-templates.js、page-templates.js 两层的模板(热更新时重新下发)
|
|
159
168
|
* /__wxa__/page-styles.js 渲染层的样式(热更新时重新下发)
|
|
160
169
|
* /__baselib__/* 官方基础库
|
|
161
170
|
* /__wxa__/proxy?url= 网络代理
|
|
162
|
-
* /__wxa__/tmp 临时文件:POST ?type=png
|
|
171
|
+
* /__wxa__/tmp 临时文件:POST ?type=png 保存,返回可直接访问的地址(GET 支持分段请求);对该地址 HEAD 查大小、DELETE 删除
|
|
163
172
|
* /__wxa__/region/<kind> 地区选择器用的行政区划数据(districts / streets),取自本机开发者工具
|
|
164
173
|
* /__wxa__/api/* 真实登录(--real-login):wx.login 的 code、手机号,只允许本机访问
|
|
165
174
|
* /__wxa__/ws 文件变化通知:热更新(hot)或整页刷新(reload)
|
package/dist/index.d.ts
CHANGED
|
@@ -32,8 +32,10 @@ interface AppJson {
|
|
|
32
32
|
}>;
|
|
33
33
|
subpackages?: AppJson['subPackages'];
|
|
34
34
|
usingComponents?: Record<string, string>;
|
|
35
|
+
/** isSubpackage:Worker 代码作为分包,业务先调 wx.preDownloadSubpackage({ packageType: 'workers' }) 再创建 Worker */
|
|
35
36
|
workers?: string | {
|
|
36
37
|
path: string;
|
|
38
|
+
isSubpackage?: boolean;
|
|
37
39
|
};
|
|
38
40
|
[key: string]: any;
|
|
39
41
|
}
|
|
@@ -58,6 +60,8 @@ declare class MiniProgram {
|
|
|
58
60
|
pages: string[];
|
|
59
61
|
independent?: boolean;
|
|
60
62
|
}[];
|
|
63
|
+
/** Worker 代码所在目录,不带首尾的 /;没有配置 workers 时为 null */
|
|
64
|
+
workersDir(app: AppJson): string | null;
|
|
61
65
|
/** 主包页面 + 分包页面(带 root 前缀) */
|
|
62
66
|
allPages(app: AppJson): string[];
|
|
63
67
|
/** 读取并预处理页面/组件 json,id 不带扩展名 */
|
|
@@ -73,7 +77,7 @@ declare class MiniProgram {
|
|
|
73
77
|
components: string[];
|
|
74
78
|
};
|
|
75
79
|
/** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
|
|
76
|
-
listFiles(extensions: string[]
|
|
80
|
+
listFiles(extensions: string[]): string[];
|
|
77
81
|
exists(relPath: string): boolean;
|
|
78
82
|
readText(relPath: string): string;
|
|
79
83
|
private isInIndependentSubPackage;
|
|
@@ -93,6 +97,8 @@ declare class MiniProgram {
|
|
|
93
97
|
* 2. wcsc 的公共样式运行时 + app.wxss,与每个页面/组件的 __wxAppCode__ wxss(pageStyles)
|
|
94
98
|
* 两部分在热更新时分别下发
|
|
95
99
|
* 样式和模板里的 env(safe-area-inset-*) 改写成 CSS 变量,见 rewriteSafeAreaInsets
|
|
100
|
+
*
|
|
101
|
+
* Worker:workers 目录下的 JS 不进逻辑层,同样包装成 define 脚本,由 Worker 入口(server/html.ts 的 workerScript)加载
|
|
96
102
|
*/
|
|
97
103
|
|
|
98
104
|
interface BuildResult {
|
|
@@ -100,6 +106,8 @@ interface BuildResult {
|
|
|
100
106
|
wxConfig: Record<string, any>;
|
|
101
107
|
/** 所有 JS 模块 id(如 "pages/index/index.js"),逻辑层按此顺序加载 define 脚本 */
|
|
102
108
|
modules: string[];
|
|
109
|
+
/** workers 目录下的 JS 模块 id,Worker 按此顺序加载 define 脚本 */
|
|
110
|
+
workerModules: string[];
|
|
103
111
|
/** 逻辑层的 $gwx 与 __wxAppCode__ json/wxml,不含 require */
|
|
104
112
|
serviceTemplates: string;
|
|
105
113
|
serviceBootstrap: string;
|
|
@@ -154,12 +162,13 @@ declare class AppBuilder {
|
|
|
154
162
|
* /__wxa__/setup.js 编译后的 setup 文件
|
|
155
163
|
* /__wxa__/appservice.html 逻辑层
|
|
156
164
|
* /__wxa__/webview/<page>.html 渲染层(路径与页面一致,wxml 里的相对资源路径因此能正确解析)
|
|
157
|
-
* /__wxa__/module/<file>.js 单个业务 JS
|
|
165
|
+
* /__wxa__/module/<file>.js 单个业务 JS 模块(含 workers 目录下的)
|
|
166
|
+
* /__wxa__/worker.js?id= Worker 的入口
|
|
158
167
|
* /__wxa__/service-templates.js、page-templates.js 两层的模板(热更新时重新下发)
|
|
159
168
|
* /__wxa__/page-styles.js 渲染层的样式(热更新时重新下发)
|
|
160
169
|
* /__baselib__/* 官方基础库
|
|
161
170
|
* /__wxa__/proxy?url= 网络代理
|
|
162
|
-
* /__wxa__/tmp 临时文件:POST ?type=png
|
|
171
|
+
* /__wxa__/tmp 临时文件:POST ?type=png 保存,返回可直接访问的地址(GET 支持分段请求);对该地址 HEAD 查大小、DELETE 删除
|
|
163
172
|
* /__wxa__/region/<kind> 地区选择器用的行政区划数据(districts / streets),取自本机开发者工具
|
|
164
173
|
* /__wxa__/api/* 真实登录(--real-login):wx.login 的 code、手机号,只允许本机访问
|
|
165
174
|
* /__wxa__/ws 文件变化通知:热更新(hot)或整页刷新(reload)
|
package/dist/index.js
CHANGED
|
@@ -226,8 +226,10 @@ var AppBuilder = class {
|
|
|
226
226
|
]);
|
|
227
227
|
this.wxmlCache = wxml;
|
|
228
228
|
this.wxssCache = wxss;
|
|
229
|
-
const workersDir =
|
|
230
|
-
const
|
|
229
|
+
const workersDir = this.project.workersDir(app);
|
|
230
|
+
const inWorkers = (file) => workersDir !== null && file.startsWith(workersDir + "/");
|
|
231
|
+
const scripts = this.project.listFiles([".js"]);
|
|
232
|
+
const modules = scripts.filter((file) => !inWorkers(file));
|
|
231
233
|
const serviceTemplates = this.createTemplates(app, units, unitJson, wxml.cut);
|
|
232
234
|
const pageTemplates = this.createTemplates(app, units, unitJson, wxml.full);
|
|
233
235
|
const pageStyles = createStyles(units, wxss);
|
|
@@ -241,6 +243,7 @@ var AppBuilder = class {
|
|
|
241
243
|
subPackages: this.project.subPackages(app)
|
|
242
244
|
}),
|
|
243
245
|
modules,
|
|
246
|
+
workerModules: scripts.filter(inWorkers),
|
|
244
247
|
serviceTemplates,
|
|
245
248
|
serviceBootstrap: this.createServiceBootstrap(serviceTemplates, units, modules),
|
|
246
249
|
pageFrame: `${pageTemplates}
|
|
@@ -262,7 +265,7 @@ ${pageStyles}`,
|
|
|
262
265
|
const files = this.project.listFiles([".wxml", ".wxs"]).map((f) => "./" + f);
|
|
263
266
|
const components = units.filter((id) => this.project.exists(id + ".wxml")).map((id) => {
|
|
264
267
|
const json = unitJson.get(id);
|
|
265
|
-
return { path: id, tags: Object.keys({ ...json.usingComponents, ...json.componentGenerics
|
|
268
|
+
return { path: id, tags: Object.keys({ ...json.usingComponents, ...json.componentGenerics }) };
|
|
266
269
|
});
|
|
267
270
|
const cwd = this.project.root;
|
|
268
271
|
const [full, cut] = await Promise.all([
|
|
@@ -355,6 +358,11 @@ var MiniProgram = class {
|
|
|
355
358
|
subPackages(app) {
|
|
356
359
|
return app.subPackages || app.subpackages || [];
|
|
357
360
|
}
|
|
361
|
+
/** Worker 代码所在目录,不带首尾的 /;没有配置 workers 时为 null */
|
|
362
|
+
workersDir(app) {
|
|
363
|
+
const dir = typeof app.workers === "string" ? app.workers : app.workers?.path;
|
|
364
|
+
return dir ? import_path.default.posix.normalize(dir).replace(/^\/+|\/+$/g, "") : null;
|
|
365
|
+
}
|
|
358
366
|
/** 主包页面 + 分包页面(带 root 前缀) */
|
|
359
367
|
allPages(app) {
|
|
360
368
|
const pages = [...app.pages];
|
|
@@ -368,8 +376,8 @@ var MiniProgram = class {
|
|
|
368
376
|
}
|
|
369
377
|
/** 读取并预处理页面/组件 json,id 不带扩展名 */
|
|
370
378
|
readUnitJson(id, app) {
|
|
371
|
-
const json = { ...readJsonFile(import_path.default.join(this.root, id + ".json"))
|
|
372
|
-
json.usingComponents = { ...json.usingComponents
|
|
379
|
+
const json = { ...readJsonFile(import_path.default.join(this.root, id + ".json")) };
|
|
380
|
+
json.usingComponents = { ...json.usingComponents };
|
|
373
381
|
if (!id.startsWith("miniprogram_npm/") && !this.isInIndependentSubPackage(id, app)) {
|
|
374
382
|
for (const [tag, ref] of Object.entries(app.usingComponents || {})) {
|
|
375
383
|
if (json.usingComponents[tag]) continue;
|
|
@@ -436,15 +444,14 @@ var MiniProgram = class {
|
|
|
436
444
|
return { pages, components };
|
|
437
445
|
}
|
|
438
446
|
/** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
|
|
439
|
-
listFiles(extensions
|
|
447
|
+
listFiles(extensions) {
|
|
440
448
|
const result = [];
|
|
441
|
-
const excluded = new Set(excludeDirs.map((dir) => dir.replace(/^\/|\/$/g, "")));
|
|
442
449
|
const walk = (dir, rel) => {
|
|
443
450
|
for (const entry of import_fs.default.readdirSync(dir, { withFileTypes: true })) {
|
|
444
451
|
if (entry.name.startsWith(".") || IGNORED_DIRS.has(entry.name)) continue;
|
|
445
452
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
446
453
|
if (entry.isDirectory()) {
|
|
447
|
-
|
|
454
|
+
walk(import_path.default.join(dir, entry.name), childRel);
|
|
448
455
|
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
449
456
|
if (!rel && PROJECT_FILES.has(entry.name)) continue;
|
|
450
457
|
result.push(childRel);
|
|
@@ -565,6 +572,9 @@ function webviewHtml(build2, pagePath, webviewId, options) {
|
|
|
565
572
|
<!-- \u771F\u673A\u7684\u6EDA\u52A8\u6761\u662F\u4E0D\u5360\u5E03\u5C40\u7684\u6D6E\u5C42\uFF1B\u684C\u9762\u6D4F\u89C8\u5668\u7684\u5E38\u89C4\u6EDA\u52A8\u6761\u548C\u81EA\u5B9A\u4E49 ::-webkit-scrollbar \u4F1A\u6324\u7A84\u9875\u9762\uFF0C\u4E00\u5F8B\u9690\u85CF\u3002
|
|
566
573
|
scrollbar-width \u4F18\u5148\u4E8E ::-webkit-scrollbar\uFF0C\u9875\u9762\u6837\u5F0F\u4E0D\u4F1A\u518D\u628A\u6EDA\u52A8\u6761\u52A0\u56DE\u6765 -->
|
|
567
574
|
<style>*{scrollbar-width:none}::-webkit-scrollbar{display:none}</style>
|
|
575
|
+
<!-- \u903B\u8F91\u5C42\u5EFA\u7684 2d\u3001webgl \u753B\u5E03\u642C\u8FDB wx-canvas \u540E\u94FA\u6EE1\u5B83\uFF08\u89C1 frame.ts \u7684 moveCanvasesIntoPages\uFF09\u3002
|
|
576
|
+
\u57FA\u7840\u5E93\u8FD8\u4F1A\u6309\u903B\u8F91\u5C42\u91CC\u7684\u5E03\u5C40\u6539\u5B83\u7684\u4F4D\u7F6E\u548C\u663E\u9690\uFF0C\u8FD9\u91CC\u4E00\u5F8B\u538B\u4F4F\uFF1B\u89E6\u6478\u7167\u5E38\u4EA4\u7ED9 wx-canvas \u81EA\u5DF1\u7684 canvas -->
|
|
577
|
+
<style>.wxa-service-canvas{position:absolute!important;left:0!important;top:0!important;width:100%!important;height:100%!important;visibility:inherit!important;pointer-events:none}</style>
|
|
568
578
|
<script>var __wxConfig = ${toJs(wxConfig)};</script>
|
|
569
579
|
<script src="/__wxa__/runtime/frame.js" data-kind="webview" data-webview-id="${id}"></script>
|
|
570
580
|
<script src="/__baselib__/WAWebview.js"></script>
|
|
@@ -589,6 +599,22 @@ ${window.disableScroll ? "<style>body{overflow-y:hidden}</style>" : ""}
|
|
|
589
599
|
</body>
|
|
590
600
|
</html>`;
|
|
591
601
|
}
|
|
602
|
+
function workerScript(build2, baseLib) {
|
|
603
|
+
const modules = build2.workerModules.map((id) => `/__wxa__/module/${encodeURI(id)}?v=${build2.version}`);
|
|
604
|
+
const prelude = `var __wxConfig = ${toJs(build2.wxConfig)};
|
|
605
|
+
importScripts('/__wxa__/runtime/worker.js');
|
|
606
|
+
`;
|
|
607
|
+
if (!baseLib.hasWorker) {
|
|
608
|
+
const message = `[wxa-runner] \u57FA\u7840\u5E93 ${baseLib.version} \u91CC\u6CA1\u6709 WAWorker.js\uFF0CWorker \u4E0D\u80FD\u8FD0\u884C\u3002\u6362\u7528\u5F00\u53D1\u8005\u5DE5\u5177\u4E0B\u8F7D\u7684\u57FA\u7840\u5E93\uFF0C\u6216\u5347\u7EA7 wxa-runner \u5E26\u4E0A\u65B0\u7684\u5185\u7F6E\u57FA\u7840\u5E93`;
|
|
609
|
+
return `${prelude}throw new Error(${toJs(message)});
|
|
610
|
+
`;
|
|
611
|
+
}
|
|
612
|
+
return `${prelude}var __wxaConsole = self.console;
|
|
613
|
+
importScripts('/__baselib__/WAWorker.js');
|
|
614
|
+
self.console = __wxaConsole;
|
|
615
|
+
importScripts(${modules.map((url) => toJs(url)).join(", ")});
|
|
616
|
+
`;
|
|
617
|
+
}
|
|
592
618
|
function escapeHtml(text) {
|
|
593
619
|
return text.replace(/[&<>"]/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[ch]);
|
|
594
620
|
}
|
|
@@ -1130,12 +1156,16 @@ ${error.message}`);
|
|
|
1130
1156
|
}));
|
|
1131
1157
|
app.get(/^\/__wxa__\/module\/(.+\.js)$/, this.withBuild((build2, req, res) => {
|
|
1132
1158
|
const id = decodeURIComponent(req.params[0]);
|
|
1133
|
-
if (!build2.modules.includes(id)) {
|
|
1159
|
+
if (!build2.modules.includes(id) && !build2.workerModules.includes(id)) {
|
|
1134
1160
|
res.status(404).type("js").send(`console.error(${JSON.stringify(`[wxa-runner] \u6A21\u5757 ${id} \u4E0D\u5B58\u5728`)})`);
|
|
1135
1161
|
return;
|
|
1136
1162
|
}
|
|
1137
1163
|
res.type("js").send(this.builder.getModuleScript(id));
|
|
1138
1164
|
}));
|
|
1165
|
+
app.get("/__wxa__/worker.js", this.withBuild((build2, _req, res) => {
|
|
1166
|
+
const hasWorker = import_fs4.default.existsSync(import_path4.default.join(this.baseLib.dir, "WAWorker.js"));
|
|
1167
|
+
res.type("js").send(workerScript(build2, { version: this.baseLib.version, hasWorker }));
|
|
1168
|
+
}));
|
|
1139
1169
|
app.get("/__wxa__/service-bootstrap.js", this.withBuild((build2, _req, res) => {
|
|
1140
1170
|
res.type("js").send(build2.serviceBootstrap);
|
|
1141
1171
|
}));
|
|
@@ -1191,7 +1221,22 @@ ${error.message}`);
|
|
|
1191
1221
|
res.status(404).end();
|
|
1192
1222
|
return;
|
|
1193
1223
|
}
|
|
1194
|
-
res.type(import_path4.default.extname(req.params.name))
|
|
1224
|
+
res.type(import_path4.default.extname(req.params.name));
|
|
1225
|
+
res.setHeader("ETag", `"${req.params.name}"`);
|
|
1226
|
+
res.setHeader("Accept-Ranges", "bytes");
|
|
1227
|
+
const ranges = req.range(data.length);
|
|
1228
|
+
if (ranges === -1) {
|
|
1229
|
+
res.status(416).setHeader("Content-Range", `bytes */${data.length}`);
|
|
1230
|
+
res.end();
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
if (Array.isArray(ranges) && ranges.type === "bytes" && ranges.length === 1) {
|
|
1234
|
+
const { start, end } = ranges[0];
|
|
1235
|
+
res.status(206).setHeader("Content-Range", `bytes ${start}-${end}/${data.length}`);
|
|
1236
|
+
res.send(data.subarray(start, end + 1));
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
res.send(data);
|
|
1195
1240
|
});
|
|
1196
1241
|
app.delete("/__wxa__/tmp/:name", (req, res) => {
|
|
1197
1242
|
res.status(this.tempFiles.delete(req.params.name) ? 204 : 404).end();
|