modelstage 0.0.0-stage → 0.5.28
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 +21 -0
- package/README.md +274 -2
- package/THIRD_PARTY_NOTICES.md +90 -0
- package/bin/modelstage.mjs +137 -0
- package/config/diag-upload.example.json +7 -0
- package/config/models/live2d.assetbundls.json +1 -0
- package/config/models/live2d.azurlane.json +1 -0
- package/config/models/live2d.azurlane_bundle.json +1 -0
- package/config/models/live2d.azurlane_spine.json +1 -0
- package/config/models/live2d.bd2.json +1 -0
- package/config/models/live2d.bluearchive.json +1 -0
- package/config/models/live2d.live2d.json +1 -0
- package/config/models/live2d.nikke.json +1 -0
- package/config/models/live2d.nikke_2.json +1 -0
- package/config/models/live2d.npc.json +1 -0
- package/config/models/spine.assetbundls.json +1 -0
- package/config/models/spine.azurlane.json +1 -0
- package/config/models/spine.azurlane_bundle.json +1 -0
- package/config/models/spine.azurlane_spine.json +1 -0
- package/config/models/spine.bd2.json +1 -0
- package/config/models/spine.bluearchive.json +1 -0
- package/config/models/spine.live2d.json +1 -0
- package/config/models/spine.nikke.json +1 -0
- package/config/models/spine.nikke_2.json +1 -0
- package/config/models/spine.npc.json +1 -0
- package/config/names/NIKKE.json +1058 -0
- package/config/names/README.md +47 -0
- package/config/names//345/244/251/345/221/275/344/271/213/345/255/220.json +42897 -0
- package/config/names//346/243/225/350/211/262/345/260/230/345/237/2032.json +4016 -0
- package/config/names//347/242/247/350/223/235/350/210/252/347/272/277.json +38342 -0
- package/config/plugins.json +13 -0
- package/config/resources.example.json +40 -0
- package/package.json +63 -4
- package/plugins/unity-live2d-bundle/README.md +98 -0
- package/plugins/unity-live2d-bundle/index.js +891 -0
- package/plugins/unity-live2d-bundle/lib/anim-to-motion.js +402 -0
- package/plugins/unity-live2d-bundle/lib/bundle-probe.js +244 -0
- package/plugins/unity-live2d-bundle/lib/bytes.js +189 -0
- package/plugins/unity-live2d-bundle/lib/common-strings.js +46 -0
- package/plugins/unity-live2d-bundle/lib/dxt.js +197 -0
- package/plugins/unity-live2d-bundle/lib/errors.js +71 -0
- package/plugins/unity-live2d-bundle/lib/etc2.js +371 -0
- package/plugins/unity-live2d-bundle/lib/extract.js +242 -0
- package/plugins/unity-live2d-bundle/lib/lzma-d-min.LICENSE.txt +21 -0
- package/plugins/unity-live2d-bundle/lib/lzma-d-min.js +34 -0
- package/plugins/unity-live2d-bundle/lib/model3.js +137 -0
- package/plugins/unity-live2d-bundle/lib/png.js +424 -0
- package/plugins/unity-live2d-bundle/lib/serialized.js +233 -0
- package/plugins/unity-live2d-bundle/lib/texdecode.js +190 -0
- package/plugins/unity-live2d-bundle/lib/typetree.js +215 -0
- package/plugins/unity-live2d-bundle/lib/unityfs.js +396 -0
- package/plugins/unity-live2d-bundle/plugin.json +81 -0
- package/plugins/unity-live2d-bundle/profiles/unityfs-live2d.json +26 -0
- package/plugins/unity-spine-bundle/index.js +535 -0
- package/plugins/unity-spine-bundle/lib/bytes.js +189 -0
- package/plugins/unity-spine-bundle/lib/common-strings.js +46 -0
- package/plugins/unity-spine-bundle/lib/dxt.js +197 -0
- package/plugins/unity-spine-bundle/lib/errors.js +79 -0
- package/plugins/unity-spine-bundle/lib/etc2.js +371 -0
- package/plugins/unity-spine-bundle/lib/extract.js +242 -0
- package/plugins/unity-spine-bundle/lib/lzma-d-min.LICENSE.txt +21 -0
- package/plugins/unity-spine-bundle/lib/lzma-d-min.js +34 -0
- package/plugins/unity-spine-bundle/lib/png.js +424 -0
- package/plugins/unity-spine-bundle/lib/serialized.js +233 -0
- package/plugins/unity-spine-bundle/lib/texdecode.js +190 -0
- package/plugins/unity-spine-bundle/lib/typetree.js +215 -0
- package/plugins/unity-spine-bundle/lib/unityfs.js +396 -0
- package/plugins/unity-spine-bundle/plugin.json +75 -0
- package/src/server/README.md +69 -0
- package/src/server/assets/browse.mjs +56 -0
- package/src/server/assets/bundle-probe.mjs +94 -0
- package/src/server/assets/probe.mjs +184 -0
- package/src/server/core/config.mjs +173 -0
- package/src/server/core/env-num.mjs +60 -0
- package/src/server/core/env.mjs +49 -0
- package/src/server/core/fs-portable.mjs +37 -0
- package/src/server/core/log.mjs +107 -0
- package/src/server/core/paths.mjs +44 -0
- package/src/server/data/catalog.mjs +1091 -0
- package/src/server/data/entry-states.mjs +499 -0
- package/src/server/data/live2d.mjs +272 -0
- package/src/server/data/manifest-cache.mjs +58 -0
- package/src/server/data/manifest-stamp.mjs +135 -0
- package/src/server/data/model-meta.mjs +114 -0
- package/src/server/data/names.mjs +106 -0
- package/src/server/data/shape-probe-worker.mjs +33 -0
- package/src/server/data/shape-probe.mjs +626 -0
- package/src/server/data/spine.mjs +336 -0
- package/src/server/data/tree.mjs +126 -0
- package/src/server/http/atomic-json.mjs +145 -0
- package/src/server/http/background-solids.mjs +270 -0
- package/src/server/http/backgrounds.mjs +388 -0
- package/src/server/http/diag-upload.mjs +264 -0
- package/src/server/http/diag.mjs +173 -0
- package/src/server/http/ready.mjs +167 -0
- package/src/server/http/static.mjs +312 -0
- package/src/server/http/write.mjs +654 -0
- package/src/server/index.mjs +114 -0
- package/src/server/plugins/builtin-providers.json +30 -0
- package/src/server/plugins/registry.mjs +650 -0
- package/src/server/plugins/slot-catalog.mjs +286 -0
- package/src/server/routes/background-solids.mjs +56 -0
- package/src/server/routes/backgrounds.mjs +77 -0
- package/src/server/routes/config.mjs +38 -0
- package/src/server/routes/data.mjs +313 -0
- package/src/server/routes/diag.mjs +37 -0
- package/src/server/routes/entries.mjs +170 -0
- package/src/server/routes/ready.mjs +122 -0
- package/src/server/serve.mjs +396 -0
- package/src/server/unpack/capacity.mjs +217 -0
- package/src/server/unpack/mem-probe.mjs +27 -0
- package/src/server/unpack/plugin-runner.mjs +529 -0
- package/src/server/unpack/plugin-store.mjs +736 -0
- package/src/server/unpack/probe-store.mjs +73 -0
- package/src/server/unpack/routes.mjs +359 -0
- package/src/server/unpack/runtime/exec.mjs +558 -0
- package/src/server/unpack/runtime/index.mjs +141 -0
- package/src/server/unpack/runtime/node-vm.mjs +111 -0
- package/src/server/unpack/unpack-worker.mjs +105 -0
- package/src/server/unpack/worker-client.mjs +184 -0
- package/src/server/unpack/write-result.mjs +84 -0
- package/src/shared/bundle-shape.mjs +83 -0
- package/src/shared/entry-reasons.mjs +119 -0
- package/src/shared/names.mjs +45 -0
- package/src/shared/type-labels.mjs +31 -0
- package/src/web/README.md +193 -0
- package/src/web/app/anim-list.js +222 -0
- package/src/web/app/background-solids.js +150 -0
- package/src/web/app/backgrounds.js +152 -0
- package/src/web/app/camera-log.js +28 -0
- package/src/web/app/context.js +72 -0
- package/src/web/app/dir-picker.js +242 -0
- package/src/web/app/entry-report.js +71 -0
- package/src/web/app/memory-bars.js +91 -0
- package/src/web/app/memory-budget.js +228 -0
- package/src/web/app/memory-guard.js +204 -0
- package/src/web/app/model-actions.js +682 -0
- package/src/web/app/renderer-setting.js +70 -0
- package/src/web/app/root-manager.js +254 -0
- package/src/web/app/status.js +138 -0
- package/src/web/app/topbar-actions.js +357 -0
- package/src/web/app/transport-actions.js +297 -0
- package/src/web/app/ui-state.js +559 -0
- package/src/web/app/url-params.js +171 -0
- package/src/web/app/view-settings.js +186 -0
- package/src/web/components.css +524 -0
- package/src/web/debug/diag-hud.js +95 -0
- package/src/web/debug/drag.js +369 -0
- package/src/web/debug/log.js +320 -0
- package/src/web/debug/model-cmp.js +292 -0
- package/src/web/debug/panel.css +474 -0
- package/src/web/debug/panel.js +712 -0
- package/src/web/debug/race-probe.js +82 -0
- package/src/web/debug/upload.js +130 -0
- package/src/web/engine/adapters/atlas.js +47 -0
- package/src/web/engine/adapters/index.js +22 -0
- package/src/web/engine/adapters/renderer.js +223 -0
- package/src/web/engine/adapters/skeleton.js +105 -0
- package/src/web/engine/adapters/texture.js +64 -0
- package/src/web/engine/animation.js +181 -0
- package/src/web/engine/appearance.js +136 -0
- package/src/web/engine/camera-adapter.js +212 -0
- package/src/web/engine/effect-chain.js +138 -0
- package/src/web/engine/engine-state.js +120 -0
- package/src/web/engine/filters.js +224 -0
- package/src/web/engine/fit.js +197 -0
- package/src/web/engine/frame-gate.js +33 -0
- package/src/web/engine/gl-driver.js +56 -0
- package/src/web/engine/gl.js +77 -0
- package/src/web/engine/index.js +20 -0
- package/src/web/engine/loader.js +55 -0
- package/src/web/engine/model-info.js +26 -0
- package/src/web/engine/pipeline.js +200 -0
- package/src/web/engine/player.js +427 -0
- package/src/web/engine/pma/blend.js +76 -0
- package/src/web/engine/pma/detect.js +118 -0
- package/src/web/engine/pma/index.js +8 -0
- package/src/web/engine/pma/resolve.js +112 -0
- package/src/web/engine/pma/upload.js +127 -0
- package/src/web/engine/pma.js +5 -0
- package/src/web/engine/render-frame.js +93 -0
- package/src/web/engine/runtime-capabilities.js +209 -0
- package/src/web/engine/runtime.js +37 -0
- package/src/web/engine/skins.js +165 -0
- package/src/web/engine/textures.js +174 -0
- package/src/web/index.html +117 -0
- package/src/web/infra/api.js +531 -0
- package/src/web/infra/diag.js +509 -0
- package/src/web/infra/document.js +269 -0
- package/src/web/infra/dom.js +31 -0
- package/src/web/infra/events.mjs +27 -0
- package/src/web/infra/log.js +153 -0
- package/src/web/infra/mem-stats.js +112 -0
- package/src/web/infra/plugin-host-registration.mjs +285 -0
- package/src/web/infra/plugin-host-report.mjs +32 -0
- package/src/web/infra/plugin-host-unload.mjs +79 -0
- package/src/web/infra/plugin-host-unpack.mjs +899 -0
- package/src/web/infra/plugin-host-warmup.mjs +180 -0
- package/src/web/infra/plugin-host.js +628 -0
- package/src/web/infra/ready.js +461 -0
- package/src/web/infra/schedule.js +51 -0
- package/src/web/infra/shortcuts.js +129 -0
- package/src/web/infra/slot-registry.js +402 -0
- package/src/web/infra/vfs.js +247 -0
- package/src/web/live2d/bridge.js +400 -0
- package/src/web/live2d/model.js +321 -0
- package/src/web/live2d/overlay.js +142 -0
- package/src/web/live2d/pixi-app.js +111 -0
- package/src/web/live2d/playback-probe.js +92 -0
- package/src/web/live2d/probe-geometry.js +329 -0
- package/src/web/live2d/probe.js +119 -0
- package/src/web/live2d/release.js +66 -0
- package/src/web/live2d/runtime-adapter.js +289 -0
- package/src/web/live2d/stage-ctx.js +152 -0
- package/src/web/live2d/stage.js +204 -0
- package/src/web/live2d/vfs-settings.js +174 -0
- package/src/web/live2d/view.js +89 -0
- package/src/web/main.js +629 -0
- package/src/web/panel/background-list.js +373 -0
- package/src/web/panel/bg-source.js +291 -0
- package/src/web/panel/color-picker.css +199 -0
- package/src/web/panel/color-picker.js +278 -0
- package/src/web/panel/dialog.css +116 -0
- package/src/web/panel/dialog.js +173 -0
- package/src/web/panel/dom.js +35 -0
- package/src/web/panel/icons.js +58 -0
- package/src/web/panel/memory-bar.js +195 -0
- package/src/web/panel/panel-settings.js +1263 -0
- package/src/web/panel/panel.css +1304 -0
- package/src/web/panel/render-choice.js +104 -0
- package/src/web/panel/schema.js +784 -0
- package/src/web/panel/settings-io.js +291 -0
- package/src/web/panel/shell-controls.js +274 -0
- package/src/web/panel/slider.js +210 -0
- package/src/web/panel/toolbar-schema.js +111 -0
- package/src/web/panel/toolbar.js +195 -0
- package/src/web/panel/transport-picker.js +375 -0
- package/src/web/panel/transport.js +321 -0
- package/src/web/panel/view.js +553 -0
- package/src/web/plugin/unpack-worker.js +185 -0
- package/src/web/render/camera/constants.js +60 -0
- package/src/web/render/camera/index.js +123 -0
- package/src/web/render/camera/spine.js +124 -0
- package/src/web/render/capture.js +30 -0
- package/src/web/render/interaction.js +527 -0
- package/src/web/render/live2d.js +627 -0
- package/src/web/render/playback.js +47 -0
- package/src/web/render/reset-view.js +29 -0
- package/src/web/render/spine.js +386 -0
- package/src/web/render/surface-switch.js +176 -0
- package/src/web/render/surface.js +571 -0
- package/src/web/render/surfaces.js +70 -0
- package/src/web/roster/filter.js +31 -0
- package/src/web/roster/list.js +276 -0
- package/src/web/roster/persist.js +92 -0
- package/src/web/roster/reveal.js +77 -0
- package/src/web/roster/rows.js +248 -0
- package/src/web/roster/snapshot.js +39 -0
- package/src/web/roster/type-filter.js +97 -0
- package/src/web/roster/view.js +761 -0
- package/src/web/spine/canvas-api-groups.js +267 -0
- package/src/web/spine/canvas-api.js +97 -0
- package/src/web/spine/canvas-document.js +80 -0
- package/src/web/spine/canvas-engine.js +193 -0
- package/src/web/spine/canvas-entry.js +28 -0
- package/src/web/spine/canvas-pixels.js +36 -0
- package/src/web/spine/canvas-runtime.js +127 -0
- package/src/web/spine/canvas-view.js +108 -0
- package/src/web/spine/canvas.js +7 -0
- package/src/web/spine/runtime-hint.js +73 -0
- package/src/web/spine/runtimes.js +212 -0
- package/src/web/style.css +493 -0
- package/tool/lib/bundle-probe-node.mjs +121 -0
- package/tool/lib/paths.mjs +20 -0
- package/tool/lib/runtime-guides.mjs +65 -0
- package/tool/lib/runtime-package.mjs +403 -0
- package/tool/lib/spine-meta.mjs +227 -0
- package/tool/lib/spine-motions.mjs +104 -0
- package/tool/parse-jsonc.mjs +86 -0
- package/tool/resolve-live2d-runtimes.mjs +276 -0
- package/tool/spine-motion-rules.json +101 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// names.mjs —— 名表读取(只读文件、原样返回)
|
|
2
|
+
//
|
|
3
|
+
// 名表是数据(JSON),不写死在代码里。**服务端不认识它的结构**:
|
|
4
|
+
// 不做解析、不归一化、不校验业务字段 —— 只把 config/names/<id>.json 读出来交给调用方。
|
|
5
|
+
//
|
|
6
|
+
// 为什么这样切:名表是纯数据,形状会随游戏演进(多语言数组、归并字段…)。
|
|
7
|
+
// 服务端当文件搬运工 ⇒ 以后改名表结构不需要动服务端一行代码,
|
|
8
|
+
// 也不会出现"服务端理解一份形状、前端理解另一份"的两套知识。
|
|
9
|
+
// 结构合法性由 tool/check-index.mjs 在提交前拦,不在运行期兜底。
|
|
10
|
+
//
|
|
11
|
+
// 「文件不存在」必须**明确报错**而不是静默返回空表:
|
|
12
|
+
// 静默空表的后果是整片名字消失且界面上没有任何提示,比一条明确的错误难查一百倍。
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import { createLogger } from '../core/log.mjs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
|
|
17
|
+
const log = createLogger('names');
|
|
18
|
+
|
|
19
|
+
/** 名表读取失败的原因码(调用方据此决定 HTTP 状态码与文案) */
|
|
20
|
+
export const NAME_TABLE_ERRORS = {
|
|
21
|
+
NOT_CONFIGURED: 'NOT_CONFIGURED', // 该资源根没配 names
|
|
22
|
+
NO_TABLE: 'NO_TABLE', // 配了 names,但 config/names/<id>.json 不存在
|
|
23
|
+
BROKEN: 'BROKEN', // 文件存在但解析失败
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @param {{root: string, namesDir: string, indexDir: string}} p */
|
|
27
|
+
export function createNames(p) {
|
|
28
|
+
const NAMES_DIR = p.namesDir || path.join(p.root, 'config', 'names');
|
|
29
|
+
/** 名表缓存:按 names id 记忆归一化结果(含失败结果),避免重复解析大 JSON */
|
|
30
|
+
const nameTableCache = new Map();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 读一个 names id 对应的表:**只读 config/names/<id>.json,原样返回**。
|
|
34
|
+
*
|
|
35
|
+
* 为什么不做任何解析/归一化:名表是纯数据,形状会随游戏演进(这轮就在改 name 为多语言数组、
|
|
36
|
+
* 加归并字段)。服务端只当文件搬运工 ⇒ 以后改名表结构不需要动服务端一行代码,
|
|
37
|
+
* 也不会出现"服务端理解一份形状、前端理解另一份"的两套知识。
|
|
38
|
+
* 结构不合法由 tool/check-index.mjs 在提交前拦,不在运行期兜底。
|
|
39
|
+
*
|
|
40
|
+
* @param {string} namesId 名表 id(= resources.json 里该根的 names 字段,即 config/names/<id>.json 的文件名)
|
|
41
|
+
* @returns {{table: object|null, error: string|null, detail: string}}
|
|
42
|
+
*/
|
|
43
|
+
function loadNamesTable(namesId) {
|
|
44
|
+
if (!namesId) return { table: null, error: NAME_TABLE_ERRORS.NOT_CONFIGURED, detail: '该资源根未配置 names 名表' };
|
|
45
|
+
|
|
46
|
+
const file = path.join(NAMES_DIR, `${namesId}.json`);
|
|
47
|
+
// 缓存按文件 mtime 失效:名表是**手工维护的纯数据文件**,改完不该要求重启服务才生效
|
|
48
|
+
// (踩过:改了表里的中文名,接口仍返回旧内容,排查半天以为链路错)。
|
|
49
|
+
// 一次 stat 的开销可忽略,换来"存盘即生效"。
|
|
50
|
+
let mtimeMs = 0;
|
|
51
|
+
try { mtimeMs = fs.statSync(file).mtimeMs; } catch { mtimeMs = 0; }
|
|
52
|
+
const cached = nameTableCache.get(namesId);
|
|
53
|
+
if (cached && cached.mtimeMs === mtimeMs) return cached.result;
|
|
54
|
+
|
|
55
|
+
let result;
|
|
56
|
+
try {
|
|
57
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
58
|
+
result = {
|
|
59
|
+
table: {
|
|
60
|
+
source: 'names',
|
|
61
|
+
specVersion: Number((raw._meta && raw._meta.v) || 2),
|
|
62
|
+
game: (raw._meta && raw._meta.game) || namesId,
|
|
63
|
+
mergeBy: (raw._meta && raw._meta.mergeBy) || 'id',
|
|
64
|
+
characters: raw.characters || {},
|
|
65
|
+
byAsset: raw.byAsset || {},
|
|
66
|
+
},
|
|
67
|
+
error: null,
|
|
68
|
+
detail: '',
|
|
69
|
+
};
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const missing = e && e.code === 'ENOENT';
|
|
72
|
+
result = missing
|
|
73
|
+
? { table: null, error: NAME_TABLE_ERRORS.NO_TABLE, detail: `名表不存在:config/names/${namesId}.json` }
|
|
74
|
+
: { table: null, error: NAME_TABLE_ERRORS.BROKEN, detail: `config/names/${namesId}.json 解析失败:${e.message}` };
|
|
75
|
+
}
|
|
76
|
+
nameTableCache.set(namesId, { mtimeMs, result });
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 读资源根的名表(旧签名:只返回表,供头像解析这类"拿到就用、拿不到就退化"的场景)。
|
|
82
|
+
* 拿不到时**记一条 warn**(不静默),返回 null 让调用方走回退路径。
|
|
83
|
+
*/
|
|
84
|
+
function getNameTable(root) {
|
|
85
|
+
if (!root || !root.names) return null;
|
|
86
|
+
const { table, error, detail } = loadNamesTable(root.names);
|
|
87
|
+
if (!table) {
|
|
88
|
+
log.warn('名表不可用', { names: root.names, error, detail });
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return table;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 清空名表缓存。
|
|
96
|
+
*
|
|
97
|
+
* 为什么需要:名表是"文件内容"的缓存,导入配置会整体替换名表文件;
|
|
98
|
+
* 不清缓存的话,进程内还留着旧名表,界面会继续显示导入前的角色名,
|
|
99
|
+
* 直到重启服务才更新(表现为"导入没生效")。
|
|
100
|
+
*/
|
|
101
|
+
function clearNameCache() {
|
|
102
|
+
nameTableCache.clear();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { getNameTable, loadNamesTable, clearNameCache };
|
|
106
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// data/shape-probe-worker.mjs —— 后台形态探测的**解析线程**(契约 §八 的执行者之一)
|
|
2
|
+
//
|
|
3
|
+
// 为什么要有它:解析一个 40MB 的 UnityFS 包要 ~543ms,纯 CPU。放在主线程里
|
|
4
|
+
// 会把事件循环钉住,用户那边就表现成"某个请求莫名慢半秒"(实测 catalog P95 +45ms、max +865ms)。
|
|
5
|
+
// 挪进 worker 之后主线程不再被解析占用,探测可以放开节奏跑。
|
|
6
|
+
//
|
|
7
|
+
// 刻意做得极简(只有"读包 → 出形态",不搬解包 worker 的那套状态机):
|
|
8
|
+
// · 入:{ id, abs }(绝对路径)
|
|
9
|
+
// · 出:{ id, ok, assetDependency?, dependencyReason? } 或 { id, ok:false, error }
|
|
10
|
+
// 判定仍然复用 tool/lib/bundle-probe-node.mjs(与 /api/unpack、前端同一份实现)。
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import { parentPort } from 'node:worker_threads';
|
|
13
|
+
|
|
14
|
+
import { probeBundleBytes } from '../../../tool/lib/bundle-probe-node.mjs';
|
|
15
|
+
|
|
16
|
+
parentPort.on('message', async (msg) => {
|
|
17
|
+
const id = msg && msg.id;
|
|
18
|
+
const abs = msg && msg.abs;
|
|
19
|
+
if (typeof id !== 'number' || typeof abs !== 'string' || !abs) return;
|
|
20
|
+
try {
|
|
21
|
+
// 读盘也放在 worker 里:40MB 的 readFile 虽然异步,但落在主线程上仍要排队回调
|
|
22
|
+
const bytes = new Uint8Array(await fs.promises.readFile(abs));
|
|
23
|
+
const shape = probeBundleBytes(bytes);
|
|
24
|
+
parentPort.postMessage({
|
|
25
|
+
id,
|
|
26
|
+
ok: true,
|
|
27
|
+
assetDependency: !!(shape && shape.assetDependency),
|
|
28
|
+
dependencyReason: (shape && shape.dependencyReason) || null,
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
parentPort.postMessage({ id, ok: false, error: (e && e.message) || String(e) });
|
|
32
|
+
}
|
|
33
|
+
});
|