@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.mjs
CHANGED
|
@@ -190,8 +190,10 @@ var AppBuilder = class {
|
|
|
190
190
|
]);
|
|
191
191
|
this.wxmlCache = wxml;
|
|
192
192
|
this.wxssCache = wxss;
|
|
193
|
-
const workersDir =
|
|
194
|
-
const
|
|
193
|
+
const workersDir = this.project.workersDir(app);
|
|
194
|
+
const inWorkers = (file) => workersDir !== null && file.startsWith(workersDir + "/");
|
|
195
|
+
const scripts = this.project.listFiles([".js"]);
|
|
196
|
+
const modules = scripts.filter((file) => !inWorkers(file));
|
|
195
197
|
const serviceTemplates = this.createTemplates(app, units, unitJson, wxml.cut);
|
|
196
198
|
const pageTemplates = this.createTemplates(app, units, unitJson, wxml.full);
|
|
197
199
|
const pageStyles = createStyles(units, wxss);
|
|
@@ -205,6 +207,7 @@ var AppBuilder = class {
|
|
|
205
207
|
subPackages: this.project.subPackages(app)
|
|
206
208
|
}),
|
|
207
209
|
modules,
|
|
210
|
+
workerModules: scripts.filter(inWorkers),
|
|
208
211
|
serviceTemplates,
|
|
209
212
|
serviceBootstrap: this.createServiceBootstrap(serviceTemplates, units, modules),
|
|
210
213
|
pageFrame: `${pageTemplates}
|
|
@@ -226,7 +229,7 @@ ${pageStyles}`,
|
|
|
226
229
|
const files = this.project.listFiles([".wxml", ".wxs"]).map((f) => "./" + f);
|
|
227
230
|
const components = units.filter((id) => this.project.exists(id + ".wxml")).map((id) => {
|
|
228
231
|
const json = unitJson.get(id);
|
|
229
|
-
return { path: id, tags: Object.keys({ ...json.usingComponents, ...json.componentGenerics
|
|
232
|
+
return { path: id, tags: Object.keys({ ...json.usingComponents, ...json.componentGenerics }) };
|
|
230
233
|
});
|
|
231
234
|
const cwd = this.project.root;
|
|
232
235
|
const [full, cut] = await Promise.all([
|
|
@@ -319,6 +322,11 @@ var MiniProgram = class {
|
|
|
319
322
|
subPackages(app) {
|
|
320
323
|
return app.subPackages || app.subpackages || [];
|
|
321
324
|
}
|
|
325
|
+
/** Worker 代码所在目录,不带首尾的 /;没有配置 workers 时为 null */
|
|
326
|
+
workersDir(app) {
|
|
327
|
+
const dir = typeof app.workers === "string" ? app.workers : app.workers?.path;
|
|
328
|
+
return dir ? path.posix.normalize(dir).replace(/^\/+|\/+$/g, "") : null;
|
|
329
|
+
}
|
|
322
330
|
/** 主包页面 + 分包页面(带 root 前缀) */
|
|
323
331
|
allPages(app) {
|
|
324
332
|
const pages = [...app.pages];
|
|
@@ -332,8 +340,8 @@ var MiniProgram = class {
|
|
|
332
340
|
}
|
|
333
341
|
/** 读取并预处理页面/组件 json,id 不带扩展名 */
|
|
334
342
|
readUnitJson(id, app) {
|
|
335
|
-
const json = { ...readJsonFile(path.join(this.root, id + ".json"))
|
|
336
|
-
json.usingComponents = { ...json.usingComponents
|
|
343
|
+
const json = { ...readJsonFile(path.join(this.root, id + ".json")) };
|
|
344
|
+
json.usingComponents = { ...json.usingComponents };
|
|
337
345
|
if (!id.startsWith("miniprogram_npm/") && !this.isInIndependentSubPackage(id, app)) {
|
|
338
346
|
for (const [tag, ref] of Object.entries(app.usingComponents || {})) {
|
|
339
347
|
if (json.usingComponents[tag]) continue;
|
|
@@ -400,15 +408,14 @@ var MiniProgram = class {
|
|
|
400
408
|
return { pages, components };
|
|
401
409
|
}
|
|
402
410
|
/** 列出代码根目录下指定扩展名的文件,返回 posix 风格的相对路径 */
|
|
403
|
-
listFiles(extensions
|
|
411
|
+
listFiles(extensions) {
|
|
404
412
|
const result = [];
|
|
405
|
-
const excluded = new Set(excludeDirs.map((dir) => dir.replace(/^\/|\/$/g, "")));
|
|
406
413
|
const walk = (dir, rel) => {
|
|
407
414
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
408
415
|
if (entry.name.startsWith(".") || IGNORED_DIRS.has(entry.name)) continue;
|
|
409
416
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
410
417
|
if (entry.isDirectory()) {
|
|
411
|
-
|
|
418
|
+
walk(path.join(dir, entry.name), childRel);
|
|
412
419
|
} else if (extensions.some((ext) => entry.name.endsWith(ext))) {
|
|
413
420
|
if (!rel && PROJECT_FILES.has(entry.name)) continue;
|
|
414
421
|
result.push(childRel);
|
|
@@ -556,6 +563,22 @@ ${window.disableScroll ? "<style>body{overflow-y:hidden}</style>" : ""}
|
|
|
556
563
|
</body>
|
|
557
564
|
</html>`;
|
|
558
565
|
}
|
|
566
|
+
function workerScript(build2, baseLib) {
|
|
567
|
+
const modules = build2.workerModules.map((id) => `/__wxa__/module/${encodeURI(id)}?v=${build2.version}`);
|
|
568
|
+
const prelude = `var __wxConfig = ${toJs(build2.wxConfig)};
|
|
569
|
+
importScripts('/__wxa__/runtime/worker.js');
|
|
570
|
+
`;
|
|
571
|
+
if (!baseLib.hasWorker) {
|
|
572
|
+
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`;
|
|
573
|
+
return `${prelude}throw new Error(${toJs(message)});
|
|
574
|
+
`;
|
|
575
|
+
}
|
|
576
|
+
return `${prelude}var __wxaConsole = self.console;
|
|
577
|
+
importScripts('/__baselib__/WAWorker.js');
|
|
578
|
+
self.console = __wxaConsole;
|
|
579
|
+
importScripts(${modules.map((url) => toJs(url)).join(", ")});
|
|
580
|
+
`;
|
|
581
|
+
}
|
|
559
582
|
function escapeHtml(text) {
|
|
560
583
|
return text.replace(/[&<>"]/g, (ch) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[ch]);
|
|
561
584
|
}
|
|
@@ -1097,12 +1120,16 @@ ${error.message}`);
|
|
|
1097
1120
|
}));
|
|
1098
1121
|
app.get(/^\/__wxa__\/module\/(.+\.js)$/, this.withBuild((build2, req, res) => {
|
|
1099
1122
|
const id = decodeURIComponent(req.params[0]);
|
|
1100
|
-
if (!build2.modules.includes(id)) {
|
|
1123
|
+
if (!build2.modules.includes(id) && !build2.workerModules.includes(id)) {
|
|
1101
1124
|
res.status(404).type("js").send(`console.error(${JSON.stringify(`[wxa-runner] \u6A21\u5757 ${id} \u4E0D\u5B58\u5728`)})`);
|
|
1102
1125
|
return;
|
|
1103
1126
|
}
|
|
1104
1127
|
res.type("js").send(this.builder.getModuleScript(id));
|
|
1105
1128
|
}));
|
|
1129
|
+
app.get("/__wxa__/worker.js", this.withBuild((build2, _req, res) => {
|
|
1130
|
+
const hasWorker = fs4.existsSync(path4.join(this.baseLib.dir, "WAWorker.js"));
|
|
1131
|
+
res.type("js").send(workerScript(build2, { version: this.baseLib.version, hasWorker }));
|
|
1132
|
+
}));
|
|
1106
1133
|
app.get("/__wxa__/service-bootstrap.js", this.withBuild((build2, _req, res) => {
|
|
1107
1134
|
res.type("js").send(build2.serviceBootstrap);
|
|
1108
1135
|
}));
|