@open-wxa/wxa-runner-core 0.5.0 → 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 +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +36 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -9
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/frame.js +50 -1
- package/dist/runtime/frame.js.map +1 -1
- package/dist/runtime/host.js +2 -0
- 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,7 +162,8 @@ 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__/* 官方基础库
|
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,7 +162,8 @@ 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__/* 官方基础库
|
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);
|
|
@@ -592,6 +599,22 @@ ${window.disableScroll ? "<style>body{overflow-y:hidden}</style>" : ""}
|
|
|
592
599
|
</body>
|
|
593
600
|
</html>`;
|
|
594
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
|
+
}
|
|
595
618
|
function escapeHtml(text) {
|
|
596
619
|
return text.replace(/[&<>"]/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[ch]);
|
|
597
620
|
}
|
|
@@ -1133,12 +1156,16 @@ ${error.message}`);
|
|
|
1133
1156
|
}));
|
|
1134
1157
|
app.get(/^\/__wxa__\/module\/(.+\.js)$/, this.withBuild((build2, req, res) => {
|
|
1135
1158
|
const id = decodeURIComponent(req.params[0]);
|
|
1136
|
-
if (!build2.modules.includes(id)) {
|
|
1159
|
+
if (!build2.modules.includes(id) && !build2.workerModules.includes(id)) {
|
|
1137
1160
|
res.status(404).type("js").send(`console.error(${JSON.stringify(`[wxa-runner] \u6A21\u5757 ${id} \u4E0D\u5B58\u5728`)})`);
|
|
1138
1161
|
return;
|
|
1139
1162
|
}
|
|
1140
1163
|
res.type("js").send(this.builder.getModuleScript(id));
|
|
1141
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
|
+
}));
|
|
1142
1169
|
app.get("/__wxa__/service-bootstrap.js", this.withBuild((build2, _req, res) => {
|
|
1143
1170
|
res.type("js").send(build2.serviceBootstrap);
|
|
1144
1171
|
}));
|