@mbws/plugin-sdk 0.3.16 → 0.3.18
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/caps.d.ts +27 -1
- package/dist/caps.js +4 -0
- package/dist/client.d.ts +17 -1
- package/dist/client.js +6 -0
- package/dist/dev-mock.js +49 -0
- package/dist/expand-zip.d.ts +15 -0
- package/dist/expand-zip.js +279 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vite.d.ts +18 -4
- package/dist/vite.js +430 -49
- package/package.json +40 -16
package/dist/caps.d.ts
CHANGED
|
@@ -148,6 +148,19 @@ export interface LocalizedInput {
|
|
|
148
148
|
*/
|
|
149
149
|
filename: string;
|
|
150
150
|
}
|
|
151
|
+
/** caps.exec.expandZip 返回的一条视频(工作区相对路径 + 可直接播放的预览地址)。 */
|
|
152
|
+
export interface ExpandedZipVideo {
|
|
153
|
+
/** 插件工作区相对路径(spawn cwd 下 ffprobe/ffmpeg 直接引用) */
|
|
154
|
+
path: string;
|
|
155
|
+
filename: string;
|
|
156
|
+
/** 包内路径,同名文件靠它区分 */
|
|
157
|
+
entryName: string;
|
|
158
|
+
/** media-local:// 或 dev 可播地址 */
|
|
159
|
+
previewUrl: string;
|
|
160
|
+
}
|
|
161
|
+
export interface ExpandedZipResult {
|
|
162
|
+
videos: ExpandedZipVideo[];
|
|
163
|
+
}
|
|
151
164
|
/** caps.exec.pickFile 请求:插件可限制可选文件类型(宿主系统选择器的过滤形状)。 */
|
|
152
165
|
export interface CapsPickFileRequest {
|
|
153
166
|
/** 扩展名过滤(如 [{ name: "视频", extensions: ["mp4", "mov"] }];缺省不限类型) */
|
|
@@ -176,6 +189,19 @@ export interface ReservedOutput {
|
|
|
176
189
|
export interface RegisteredOutput {
|
|
177
190
|
placeholder: MbwsRef;
|
|
178
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* caps.exec.renameOutput 返回:同目录物理改名结果。
|
|
194
|
+
* placeholder 与入参相同(已 commit 字段 / 上传主键冻结);filename 为最终落盘名。
|
|
195
|
+
*/
|
|
196
|
+
export interface RenamedOutput {
|
|
197
|
+
placeholder: MbwsRef;
|
|
198
|
+
/** 最终文件名(可能被 auto-rename 调整) */
|
|
199
|
+
filename: string;
|
|
200
|
+
/** 所在目录(未变) */
|
|
201
|
+
dirname: string;
|
|
202
|
+
/** onConflict:"reject" 且撞名时 */
|
|
203
|
+
conflict?: boolean;
|
|
204
|
+
}
|
|
179
205
|
/** caps.exec.spawn 返回的裸句柄(SDK 包装成 ExecJob;jobResult 断线兜底同形)。 */
|
|
180
206
|
export interface SpawnedJob {
|
|
181
207
|
jobId: string;
|
|
@@ -211,7 +237,7 @@ export interface ExecJob {
|
|
|
211
237
|
read(path: string, maxBytes?: number): Promise<string | null>;
|
|
212
238
|
}
|
|
213
239
|
/** caps.exec 方法白名单(宿主 broker 路由 + 参数校验依据,防调到桥内部方法)。 */
|
|
214
|
-
export declare const CAPS_EXEC_METHODS: readonly ["ensureAttachment", "attachmentStatus", "localize", "spawn", "attachJob", "jobResult", "cancelJob", "readFile", "reserveOutput", "registerOutput", "mediaUrl", "pickDirectory", "pickFile"];
|
|
240
|
+
export declare const CAPS_EXEC_METHODS: readonly ["ensureAttachment", "attachmentStatus", "localize", "expandZip", "spawn", "attachJob", "jobResult", "cancelJob", "readFile", "reserveOutput", "registerOutput", "renameOutput", "mediaUrl", "pickDirectory", "pickFile"];
|
|
215
241
|
export declare const CAPS_UPLOADS_METHODS: readonly ["status", "list"];
|
|
216
242
|
export type CapsExecMethod = (typeof CAPS_EXEC_METHODS)[number];
|
|
217
243
|
export type CapsUploadsMethod = (typeof CAPS_UPLOADS_METHODS)[number];
|
package/dist/caps.js
CHANGED
|
@@ -99,6 +99,7 @@ export const CAPS_EXEC_METHODS = [
|
|
|
99
99
|
"ensureAttachment",
|
|
100
100
|
"attachmentStatus",
|
|
101
101
|
"localize",
|
|
102
|
+
"expandZip",
|
|
102
103
|
"spawn",
|
|
103
104
|
"attachJob",
|
|
104
105
|
"jobResult",
|
|
@@ -106,6 +107,7 @@ export const CAPS_EXEC_METHODS = [
|
|
|
106
107
|
"readFile",
|
|
107
108
|
"reserveOutput",
|
|
108
109
|
"registerOutput",
|
|
110
|
+
"renameOutput",
|
|
109
111
|
"mediaUrl",
|
|
110
112
|
"pickDirectory",
|
|
111
113
|
"pickFile",
|
|
@@ -133,11 +135,13 @@ export const METHOD_INTRODUCED_AT = {
|
|
|
133
135
|
"caps.exec.ensureAttachment": "0.3.0",
|
|
134
136
|
"caps.exec.attachmentStatus": "0.3.0",
|
|
135
137
|
"caps.exec.localize": "0.3.0",
|
|
138
|
+
"caps.exec.expandZip": "0.3.17",
|
|
136
139
|
"caps.exec.spawn": "0.3.0",
|
|
137
140
|
"caps.exec.jobResult": "0.3.0",
|
|
138
141
|
"caps.exec.cancelJob": "0.3.0",
|
|
139
142
|
"caps.exec.readFile": "0.3.0",
|
|
140
143
|
"caps.exec.registerOutput": "0.3.0",
|
|
144
|
+
"caps.exec.renameOutput": "0.3.18",
|
|
141
145
|
"caps.exec.mediaUrl": "0.3.0",
|
|
142
146
|
"caps.exec.pickDirectory": "0.3.7",
|
|
143
147
|
"caps.exec.pickFile": "0.3.7",
|
package/dist/client.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* 安全定位:客户端只是包装不是防线——插件绕过客户端手发消息伪造调用,
|
|
14
14
|
* broker 对每条进入的消息仍按 manifest 独立校验(防线在宿主侧)。
|
|
15
15
|
*/
|
|
16
|
-
import type { AttachmentState, CapsAttachmentEvent, CapsPickFileRequest, CapsUploadEvent, ExecJob, HostCapabilities, LocalizedInput, MbwsRef, RegisteredOutput, ReservedOutput, UploadStatusPayload } from "./caps.js";
|
|
16
|
+
import type { AttachmentState, CapsAttachmentEvent, CapsPickFileRequest, CapsUploadEvent, ExecJob, ExpandedZipResult, HostCapabilities, LocalizedInput, MbwsRef, RegisteredOutput, RenamedOutput, ReservedOutput, UploadStatusPayload } from "./caps.js";
|
|
17
17
|
import { type FetchContractOptions, type PluginContract } from "./contract.js";
|
|
18
18
|
import { type MbwsErrorCode } from "./errors.js";
|
|
19
19
|
import type { MbwsErrorPayload } from "./protocol.js";
|
|
@@ -151,6 +151,13 @@ export interface MbwsClient<C extends MbwsContractTypes = MbwsContractTypes> {
|
|
|
151
151
|
* 对它 split("/").pop() 会得到乱码——local: 占位值是 URL 编码串)
|
|
152
152
|
*/
|
|
153
153
|
localize(ref: MbwsRef | string): Promise<LocalizedInput>;
|
|
154
|
+
/**
|
|
155
|
+
* 把已 localize 的 ZIP 解到插件工作区,返回包内视频的相对路径与预览地址。
|
|
156
|
+
* 单视频不要调用:非 zip 输入仍走 localize + mediaUrl。
|
|
157
|
+
*/
|
|
158
|
+
expandZip(req: {
|
|
159
|
+
path: string;
|
|
160
|
+
}): Promise<ExpandedZipResult>;
|
|
154
161
|
/**
|
|
155
162
|
* 启动附件执行(args 插件全权组装,cwd = job 沙箱),返回 job 句柄。
|
|
156
163
|
* spawn 是「派发任务」语义:队列执行方式(并发池/优先级/暂停恢复)归宿主决定,
|
|
@@ -204,6 +211,15 @@ export interface MbwsClient<C extends MbwsContractTypes = MbwsContractTypes> {
|
|
|
204
211
|
filename: string;
|
|
205
212
|
contentType?: string;
|
|
206
213
|
}): Promise<RegisteredOutput>;
|
|
214
|
+
/**
|
|
215
|
+
* 同目录物理改名已登记产物。placeholder 不变(已 commit 字段 / 上传主键冻结);
|
|
216
|
+
* 返回最终 filename。冲突缺省 auto-rename。可选——旧宿主不进 capabilities。
|
|
217
|
+
*/
|
|
218
|
+
renameOutput(req: {
|
|
219
|
+
placeholder: MbwsRef | string;
|
|
220
|
+
filename: string;
|
|
221
|
+
onConflict?: "auto-rename" | "reject";
|
|
222
|
+
}): Promise<RenamedOutput>;
|
|
207
223
|
/**
|
|
208
224
|
* 媒体预览 URL:local: 占位 / OSS key → media-local://(桌面)或签名 URL。
|
|
209
225
|
* 产物还在编码(文件未落盘)时抛 E_NOT_READY(error.data 带 { status })——
|
package/dist/client.js
CHANGED
|
@@ -284,6 +284,7 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
284
284
|
});
|
|
285
285
|
},
|
|
286
286
|
localize: (ref) => invoke("caps.exec", "localize", { ref }),
|
|
287
|
+
expandZip: (req) => invoke("caps.exec", "expandZip", req),
|
|
287
288
|
spawn: async (req) => {
|
|
288
289
|
const spawned = (await invoke("caps.exec", "spawn", req));
|
|
289
290
|
return makeExecJob(spawned.jobId);
|
|
@@ -310,6 +311,11 @@ export function connectMbwsPort(port, init, opts = {}) {
|
|
|
310
311
|
registered.placeholder = asMbwsRef(registered.placeholder);
|
|
311
312
|
return registered;
|
|
312
313
|
},
|
|
314
|
+
renameOutput: async (req) => {
|
|
315
|
+
const renamed = (await invoke("caps.exec", "renameOutput", req));
|
|
316
|
+
renamed.placeholder = asMbwsRef(renamed.placeholder);
|
|
317
|
+
return renamed;
|
|
318
|
+
},
|
|
313
319
|
mediaUrl: (ref) => invoke("caps.exec", "mediaUrl", { ref }),
|
|
314
320
|
pickDirectory: () => invoke("caps.exec", "pickDirectory", {}),
|
|
315
321
|
pickFile: (req) => invoke("caps.exec", "pickFile", req ?? {}),
|
package/dist/dev-mock.js
CHANGED
|
@@ -590,6 +590,22 @@ export function createDevMockMbws() {
|
|
|
590
590
|
const filename = devRefBasename(ref);
|
|
591
591
|
return { path: `samples/${filename}`, size: 0, filename };
|
|
592
592
|
},
|
|
593
|
+
expandZip: async (req) => {
|
|
594
|
+
const response = await fetch(`/__mbws__/dev/expand-zip?path=${encodeURIComponent(req.path)}`);
|
|
595
|
+
if (!response.ok) {
|
|
596
|
+
let message = "解压失败";
|
|
597
|
+
try {
|
|
598
|
+
const body = (await response.json());
|
|
599
|
+
if (body.message)
|
|
600
|
+
message = body.message;
|
|
601
|
+
}
|
|
602
|
+
catch {
|
|
603
|
+
// 非 JSON 错误体,用默认文案
|
|
604
|
+
}
|
|
605
|
+
throw new Error(message);
|
|
606
|
+
}
|
|
607
|
+
return (await response.json());
|
|
608
|
+
},
|
|
593
609
|
spawn: (req) => spawnDevJob(req),
|
|
594
610
|
attachJob: (jobId) => Promise.resolve(attachDevJob(jobId)),
|
|
595
611
|
// dev 无宿主队列可查:reserve 恒无冲突返回原名 + 假占位(占位符先行协议同构:
|
|
@@ -648,6 +664,39 @@ export function createDevMockMbws() {
|
|
|
648
664
|
simulateDevUpload(placeholder);
|
|
649
665
|
return { placeholder: asMbwsRef(placeholder) };
|
|
650
666
|
},
|
|
667
|
+
// dev 无真磁盘:只更新上传镜像展示名;placeholder 不变(与宿主同形)
|
|
668
|
+
renameOutput: async (req) => {
|
|
669
|
+
if (!req.filename || /[\\/]/.test(req.filename)) {
|
|
670
|
+
throw new Error("filename 必须是非空纯文件名(不含路径分隔符)");
|
|
671
|
+
}
|
|
672
|
+
const seeded = devUploadStates.get(req.placeholder);
|
|
673
|
+
if (!seeded)
|
|
674
|
+
throw new Error("local: 引用未登记");
|
|
675
|
+
if (seeded.status === "uploading")
|
|
676
|
+
throw new Error("上传中不可改名");
|
|
677
|
+
let finalName = req.filename;
|
|
678
|
+
if (devReservedNames.has(req.filename) && seeded.filename !== req.filename) {
|
|
679
|
+
if (req.onConflict === "reject") {
|
|
680
|
+
return {
|
|
681
|
+
placeholder: asMbwsRef(req.placeholder),
|
|
682
|
+
filename: req.filename,
|
|
683
|
+
dirname: "",
|
|
684
|
+
conflict: true,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
finalName = devAvailableFilename(req.filename, (n) => n === seeded.filename ? false : devReservedNames.has(n));
|
|
688
|
+
}
|
|
689
|
+
if (seeded.filename)
|
|
690
|
+
devReservedNames.delete(seeded.filename);
|
|
691
|
+
devReservedNames.add(finalName);
|
|
692
|
+
seeded.filename = finalName;
|
|
693
|
+
console.info(`[mbws:dev] renameOutput(${req.placeholder})→${finalName}——dev 仅更新展示名`);
|
|
694
|
+
return {
|
|
695
|
+
placeholder: asMbwsRef(req.placeholder),
|
|
696
|
+
filename: finalName,
|
|
697
|
+
dirname: "",
|
|
698
|
+
};
|
|
699
|
+
},
|
|
651
700
|
mediaUrl: async (ref) => {
|
|
652
701
|
// 占位符先行:编码中(reserved,文件未落盘)→ E_NOT_READY 带 status,
|
|
653
702
|
// 插件/viewer 据此渲染「编码中」占位卡(与宿主同形)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const VIDEO_EXTENSIONS: Set<string>;
|
|
2
|
+
export declare class ExpandZipError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export interface ZipVideoFile {
|
|
6
|
+
/** dest 内相对路径(posix) */
|
|
7
|
+
relPath: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
/** 包内路径,同名文件靠它区分 */
|
|
10
|
+
entryName: string;
|
|
11
|
+
size: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function isVideoFilename(name: string): boolean;
|
|
14
|
+
/** 解压 archivePath 中的视频到 destDir。非视频条目不落盘。 */
|
|
15
|
+
export declare function expandZipVideos(archivePath: string, destDir: string): Promise<ZipVideoFile[]>;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 ZIP 里的视频解到目标目录。
|
|
3
|
+
*
|
|
4
|
+
* 桌面主进程与 dev-mock 共用。只读中央目录定位条目,按存储/deflate 流式落盘,
|
|
5
|
+
* 不把整包读进内存。跳过 __MACOSX 等系统垃圾;拒绝绝对路径与 `..`。
|
|
6
|
+
*/
|
|
7
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
8
|
+
import fs from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { pipeline } from "node:stream/promises";
|
|
11
|
+
import { createInflateRaw } from "node:zlib";
|
|
12
|
+
export const VIDEO_EXTENSIONS = new Set([".mp4", ".mov", ".avi", ".mkv", ".webm", ".m4v"]);
|
|
13
|
+
const SIG_EOCD = 0x06054b50;
|
|
14
|
+
const SIG_ZIP64_LOCATOR = 0x07064b50;
|
|
15
|
+
const SIG_ZIP64_EOCD = 0x06064b50;
|
|
16
|
+
const SIG_CD = 0x02014b50;
|
|
17
|
+
const SIG_LOCAL = 0x04034b50;
|
|
18
|
+
const ZIP64_EXTRA = 0x0001;
|
|
19
|
+
const MAX_MEMBERS = 2000;
|
|
20
|
+
const MAX_VIDEOS = 200;
|
|
21
|
+
const MAX_BYTES = 64 * 1024 * 1024 * 1024;
|
|
22
|
+
const SKIP = [/^__MACOSX(?:\/|$)/, /(^|\/)\.DS_Store$/, /^\.git\//, /(^|\/)Thumbs\.db$/i];
|
|
23
|
+
export class ExpandZipError extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ExpandZipError";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function isVideoFilename(name) {
|
|
30
|
+
return VIDEO_EXTENSIONS.has(path.posix.extname(name).toLowerCase());
|
|
31
|
+
}
|
|
32
|
+
function u16(buf, off) {
|
|
33
|
+
return buf.readUInt16LE(off);
|
|
34
|
+
}
|
|
35
|
+
function u32(buf, off) {
|
|
36
|
+
return buf.readUInt32LE(off);
|
|
37
|
+
}
|
|
38
|
+
function u64(buf, off) {
|
|
39
|
+
return buf.readBigUInt64LE(off);
|
|
40
|
+
}
|
|
41
|
+
function findSignatureFromEnd(buf, signature) {
|
|
42
|
+
for (let i = buf.length - 4; i >= 0; i--) {
|
|
43
|
+
if (buf.readUInt32LE(i) === signature)
|
|
44
|
+
return i;
|
|
45
|
+
}
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
function shouldSkip(name) {
|
|
49
|
+
return SKIP.some((pattern) => pattern.test(name));
|
|
50
|
+
}
|
|
51
|
+
function decodeName(bytes, flags) {
|
|
52
|
+
if ((flags & 0x800) !== 0)
|
|
53
|
+
return bytes.toString("utf8");
|
|
54
|
+
try {
|
|
55
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return new TextDecoder("gbk").decode(bytes);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function assertSafeName(name) {
|
|
62
|
+
const normalized = name.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
63
|
+
if (!normalized || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized)) {
|
|
64
|
+
throw new ExpandZipError(`包内路径不合法:${name}`);
|
|
65
|
+
}
|
|
66
|
+
if (normalized.split("/").some((seg) => seg === "..")) {
|
|
67
|
+
throw new ExpandZipError(`包内路径越界:${name}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function toSafeNumber(value, label) {
|
|
71
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
72
|
+
throw new ExpandZipError(`${label}过大,无法在本机解压`);
|
|
73
|
+
}
|
|
74
|
+
return Number(value);
|
|
75
|
+
}
|
|
76
|
+
/** ZIP64 扩展:仅补齐中央目录里被写成 0xFFFFFFFF 的字段,顺序固定。 */
|
|
77
|
+
function readZip64(extra, need) {
|
|
78
|
+
let off = 0;
|
|
79
|
+
while (off + 4 <= extra.length) {
|
|
80
|
+
const id = u16(extra, off);
|
|
81
|
+
const size = u16(extra, off + 2);
|
|
82
|
+
const start = off + 4;
|
|
83
|
+
const end = start + size;
|
|
84
|
+
if (end > extra.length)
|
|
85
|
+
break;
|
|
86
|
+
if (id === ZIP64_EXTRA) {
|
|
87
|
+
let cursor = start;
|
|
88
|
+
const read = () => {
|
|
89
|
+
const value = u64(extra, cursor);
|
|
90
|
+
cursor += 8;
|
|
91
|
+
return value;
|
|
92
|
+
};
|
|
93
|
+
const out = {};
|
|
94
|
+
if (need.uncomp)
|
|
95
|
+
out.uncomp = read();
|
|
96
|
+
if (need.comp)
|
|
97
|
+
out.comp = read();
|
|
98
|
+
if (need.offset)
|
|
99
|
+
out.offset = read();
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
off = end;
|
|
103
|
+
}
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
async function readMembers(archivePath) {
|
|
107
|
+
const fh = await fs.open(archivePath, "r");
|
|
108
|
+
try {
|
|
109
|
+
const stat = await fh.stat();
|
|
110
|
+
const size = BigInt(stat.size);
|
|
111
|
+
if (size < 22n)
|
|
112
|
+
throw new ExpandZipError("文件太小,不是有效 ZIP");
|
|
113
|
+
const tailLen = Number(size < 128n * 1024n ? size : 128n * 1024n);
|
|
114
|
+
const tail = Buffer.alloc(tailLen);
|
|
115
|
+
await fh.read(tail, 0, tailLen, Number(size - BigInt(tailLen)));
|
|
116
|
+
const eocdRel = findSignatureFromEnd(tail, SIG_EOCD);
|
|
117
|
+
if (eocdRel < 0)
|
|
118
|
+
throw new ExpandZipError("未找到 ZIP 结束记录");
|
|
119
|
+
const eocd = tail.subarray(eocdRel);
|
|
120
|
+
let entryCount = BigInt(u16(eocd, 10));
|
|
121
|
+
let cdSize = BigInt(u32(eocd, 12));
|
|
122
|
+
let cdOffset = BigInt(u32(eocd, 16));
|
|
123
|
+
if (entryCount === 0xffffn || cdSize === 0xffffffffn || cdOffset === 0xffffffffn) {
|
|
124
|
+
const locRel = findSignatureFromEnd(tail.subarray(0, eocdRel), SIG_ZIP64_LOCATOR);
|
|
125
|
+
if (locRel < 0)
|
|
126
|
+
throw new ExpandZipError("ZIP64 结束定位器缺失");
|
|
127
|
+
const zip64EocdOffset = u64(tail, locRel + 8);
|
|
128
|
+
const z64Buf = Buffer.alloc(128);
|
|
129
|
+
const z64Read = await fh.read(z64Buf, 0, 128, Number(zip64EocdOffset));
|
|
130
|
+
if (z64Read.bytesRead < 56 || u32(z64Buf, 0) !== SIG_ZIP64_EOCD) {
|
|
131
|
+
throw new ExpandZipError("ZIP64 结束记录无效");
|
|
132
|
+
}
|
|
133
|
+
entryCount = u64(z64Buf, 32);
|
|
134
|
+
cdSize = u64(z64Buf, 40);
|
|
135
|
+
cdOffset = u64(z64Buf, 48);
|
|
136
|
+
}
|
|
137
|
+
if (cdSize > BigInt(Number.MAX_SAFE_INTEGER) || cdOffset > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
138
|
+
throw new ExpandZipError("中央目录过大,无法在本机解析");
|
|
139
|
+
}
|
|
140
|
+
const cdSizeNum = Number(cdSize);
|
|
141
|
+
const cdOffsetNum = Number(cdOffset);
|
|
142
|
+
if (cdSizeNum <= 0)
|
|
143
|
+
return [];
|
|
144
|
+
const cd = Buffer.alloc(cdSizeNum);
|
|
145
|
+
const { bytesRead } = await fh.read(cd, 0, cdSizeNum, cdOffsetNum);
|
|
146
|
+
if (bytesRead < cdSizeNum)
|
|
147
|
+
throw new ExpandZipError("中央目录读取不完整");
|
|
148
|
+
const out = [];
|
|
149
|
+
let off = 0;
|
|
150
|
+
const maxEntries = Number(entryCount > 0n ? entryCount : BigInt(MAX_MEMBERS));
|
|
151
|
+
for (let n = 0; n < maxEntries && off + 46 <= cd.length; n++) {
|
|
152
|
+
if (u32(cd, off) !== SIG_CD)
|
|
153
|
+
break;
|
|
154
|
+
const flags = u16(cd, off + 8);
|
|
155
|
+
const method = u16(cd, off + 10);
|
|
156
|
+
let compressedSize = BigInt(u32(cd, off + 20));
|
|
157
|
+
let uncompressedSize = BigInt(u32(cd, off + 24));
|
|
158
|
+
const nameLen = u16(cd, off + 28);
|
|
159
|
+
const extraLen = u16(cd, off + 30);
|
|
160
|
+
const commentLen = u16(cd, off + 32);
|
|
161
|
+
let localOffset = BigInt(u32(cd, off + 42));
|
|
162
|
+
const nameStart = off + 46;
|
|
163
|
+
const nameEnd = nameStart + nameLen;
|
|
164
|
+
const extraEnd = nameEnd + extraLen;
|
|
165
|
+
if (extraEnd > cd.length)
|
|
166
|
+
break;
|
|
167
|
+
const name = decodeName(cd.subarray(nameStart, nameEnd), flags);
|
|
168
|
+
const extra = cd.subarray(nameEnd, extraEnd);
|
|
169
|
+
off = extraEnd + commentLen;
|
|
170
|
+
if (!name || shouldSkip(name))
|
|
171
|
+
continue;
|
|
172
|
+
if (out.length >= MAX_MEMBERS)
|
|
173
|
+
throw new ExpandZipError(`包内条目过多(${MAX_MEMBERS})`);
|
|
174
|
+
assertSafeName(name);
|
|
175
|
+
const zip64 = readZip64(extra, {
|
|
176
|
+
uncomp: uncompressedSize === 0xffffffffn,
|
|
177
|
+
comp: compressedSize === 0xffffffffn,
|
|
178
|
+
offset: localOffset === 0xffffffffn,
|
|
179
|
+
});
|
|
180
|
+
if (zip64.uncomp !== undefined)
|
|
181
|
+
uncompressedSize = zip64.uncomp;
|
|
182
|
+
if (zip64.comp !== undefined)
|
|
183
|
+
compressedSize = zip64.comp;
|
|
184
|
+
if (zip64.offset !== undefined)
|
|
185
|
+
localOffset = zip64.offset;
|
|
186
|
+
out.push({
|
|
187
|
+
name: name.replace(/\\/g, "/"),
|
|
188
|
+
method,
|
|
189
|
+
compressedSize: toSafeNumber(compressedSize, "压缩数据"),
|
|
190
|
+
uncompressedSize: toSafeNumber(uncompressedSize, "视频"),
|
|
191
|
+
localOffset: toSafeNumber(localOffset, "条目偏移"),
|
|
192
|
+
directory: name.endsWith("/"),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
await fh.close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function localDataOffset(archivePath, localOffset) {
|
|
202
|
+
const fh = await fs.open(archivePath, "r");
|
|
203
|
+
try {
|
|
204
|
+
const buf = Buffer.alloc(30);
|
|
205
|
+
const { bytesRead } = await fh.read(buf, 0, 30, localOffset);
|
|
206
|
+
if (bytesRead < 30 || u32(buf, 0) !== SIG_LOCAL) {
|
|
207
|
+
throw new ExpandZipError("本地文件头无效");
|
|
208
|
+
}
|
|
209
|
+
return localOffset + 30 + u16(buf, 26) + u16(buf, 28);
|
|
210
|
+
}
|
|
211
|
+
finally {
|
|
212
|
+
await fh.close();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function extractMember(archivePath, member, destFile) {
|
|
216
|
+
if ((member.method !== 0 && member.method !== 8) || member.compressedSize < 0) {
|
|
217
|
+
throw new ExpandZipError(`不支持的压缩方式:${member.name}`);
|
|
218
|
+
}
|
|
219
|
+
await fs.mkdir(path.dirname(destFile), { recursive: true });
|
|
220
|
+
if (member.compressedSize === 0) {
|
|
221
|
+
await fs.writeFile(destFile, Buffer.alloc(0));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const start = await localDataOffset(archivePath, member.localOffset);
|
|
225
|
+
const input = createReadStream(archivePath, {
|
|
226
|
+
start,
|
|
227
|
+
end: start + member.compressedSize - 1,
|
|
228
|
+
});
|
|
229
|
+
const output = createWriteStream(destFile);
|
|
230
|
+
if (member.method === 0) {
|
|
231
|
+
await pipeline(input, output);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
await pipeline(input, createInflateRaw(), output);
|
|
235
|
+
}
|
|
236
|
+
function outputPath(destDir, entryName) {
|
|
237
|
+
const root = path.resolve(destDir);
|
|
238
|
+
const abs = path.resolve(root, ...entryName.split("/").filter(Boolean));
|
|
239
|
+
if (abs !== root && !abs.startsWith(`${root}${path.sep}`)) {
|
|
240
|
+
throw new ExpandZipError(`包内路径越界:${entryName}`);
|
|
241
|
+
}
|
|
242
|
+
return abs;
|
|
243
|
+
}
|
|
244
|
+
/** 解压 archivePath 中的视频到 destDir。非视频条目不落盘。 */
|
|
245
|
+
export async function expandZipVideos(archivePath, destDir) {
|
|
246
|
+
const members = await readMembers(archivePath);
|
|
247
|
+
const videos = members.filter((member) => !member.directory && isVideoFilename(member.name));
|
|
248
|
+
if (videos.length > MAX_VIDEOS) {
|
|
249
|
+
throw new ExpandZipError(`视频数量超出上限(${MAX_VIDEOS})`);
|
|
250
|
+
}
|
|
251
|
+
let total = 0;
|
|
252
|
+
for (const member of videos) {
|
|
253
|
+
if (member.uncompressedSize <= 0)
|
|
254
|
+
continue;
|
|
255
|
+
total += member.uncompressedSize;
|
|
256
|
+
if (total > MAX_BYTES)
|
|
257
|
+
throw new ExpandZipError("解压体积超出上限");
|
|
258
|
+
}
|
|
259
|
+
await fs.mkdir(destDir, { recursive: true });
|
|
260
|
+
const written = [];
|
|
261
|
+
for (const member of videos) {
|
|
262
|
+
if (member.uncompressedSize <= 0)
|
|
263
|
+
continue;
|
|
264
|
+
const rel = member.name.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
265
|
+
const destFile = outputPath(destDir, rel);
|
|
266
|
+
await extractMember(archivePath, member, destFile);
|
|
267
|
+
const size = (await fs.stat(destFile)).size;
|
|
268
|
+
if (size <= 0)
|
|
269
|
+
continue;
|
|
270
|
+
written.push({
|
|
271
|
+
relPath: rel,
|
|
272
|
+
filename: path.posix.basename(rel),
|
|
273
|
+
entryName: rel,
|
|
274
|
+
size,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
written.sort((a, b) => a.entryName.localeCompare(b.entryName, "en"));
|
|
278
|
+
return written;
|
|
279
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/dist/vite.d.ts
CHANGED
|
@@ -33,9 +33,23 @@ export declare function mbwsVitePlugin(opts: MbwsVitePluginOptions): Plugin;
|
|
|
33
33
|
* 当前进程 → 附件平台键(与 manifest 的 ATTACHMENT_PLATFORMS 同词表)。
|
|
34
34
|
*/
|
|
35
35
|
export declare function currentAttachmentPlatform(): string;
|
|
36
|
+
/** dev 附件覆盖的可辨别联合:本机命令(PATH 解析)/ 本地路径 / https 临时直链 */
|
|
37
|
+
export type DevAttachmentOverride = {
|
|
38
|
+
kind: "cmd";
|
|
39
|
+
cmd: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "path";
|
|
42
|
+
path: string;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "url";
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
36
47
|
/**
|
|
37
|
-
* dev 用附件本地覆盖:env MBWS_DEV_ATTACHMENT_<NAME>(名字大写、- → _
|
|
38
|
-
*
|
|
39
|
-
*
|
|
48
|
+
* dev 用附件本地覆盖:env MBWS_DEV_ATTACHMENT_<NAME>(名字大写、- → _)优先,取值三形态——
|
|
49
|
+
* 本机命令名(如 ffmpeg,dev exec 直接 spawn,PATH 解析零下载)/ 本地路径(existsSync 命中)/
|
|
50
|
+
* https 临时直链(走直链下载分支,无 hash 校验);其次工程内 `.mbws/attachment-overrides.json`
|
|
51
|
+
* 本地文件(同三形态;dev 起来后在欢迎页可视化编辑,不进 git);再其次 attachments 声明里
|
|
52
|
+
* 的 devPath(线上还没有的新版本指本机路径)。
|
|
53
|
+
* 未配置 / 全不可用返回 null(走官方附件库自动下载)。
|
|
40
54
|
*/
|
|
41
|
-
export declare function resolveDevAttachmentOverride(config: MbwsUserConfig, name: string):
|
|
55
|
+
export declare function resolveDevAttachmentOverride(config: MbwsUserConfig, name: string, root?: string): DevAttachmentOverride | null;
|
package/dist/vite.js
CHANGED
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
import { spawn, spawnSync } from "node:child_process";
|
|
18
18
|
import crypto from "node:crypto";
|
|
19
19
|
import fs from "node:fs";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
20
21
|
import path from "node:path";
|
|
21
22
|
import { pipeline } from "node:stream/promises";
|
|
22
23
|
import zlib from "node:zlib";
|
|
23
24
|
import { attachmentsOssBase, buildManifest, resolveAttachmentRefs, } from "./config.js";
|
|
25
|
+
import { ExpandZipError, expandZipVideos } from "./expand-zip.js";
|
|
24
26
|
import { generateContractTypes } from "./schema-types.js";
|
|
25
27
|
// 契约类型生成经本子路径暴露(Node 端工具链用;依赖 prettier,不进根入口)
|
|
26
28
|
export { generateContractTypes } from "./schema-types.js";
|
|
@@ -281,6 +283,28 @@ export function mbwsVitePlugin(opts) {
|
|
|
281
283
|
// 附件状态快照:面板首屏提示(missing/ready + 尽力而为的 totalBytes)
|
|
282
284
|
return handleDevAttachmentsSnapshot(config, projectRoot, res).catch(next);
|
|
283
285
|
}
|
|
286
|
+
if (pathname === "/__mbws__/dev/attachment-overrides") {
|
|
287
|
+
if (req.method === "GET") {
|
|
288
|
+
// 本地覆盖读面:每个声明附件的覆盖值与生效来源(env > .mbws 文件 > devPath > 官方库)
|
|
289
|
+
return handleDevAttachmentOverridesGet(config, projectRoot, res).catch(next);
|
|
290
|
+
}
|
|
291
|
+
if (req.method === "POST") {
|
|
292
|
+
// 本地覆盖写面:写 .mbws/attachment-overrides.json(欢迎页配置卡消费)
|
|
293
|
+
return handleDevAttachmentOverridesSet(projectRoot, req, res).catch(next);
|
|
294
|
+
}
|
|
295
|
+
res.statusCode = 405;
|
|
296
|
+
res.end();
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
if (pathname === "/__mbws__/dev/test-attachment-url") {
|
|
300
|
+
if (req.method !== "POST") {
|
|
301
|
+
res.statusCode = 405;
|
|
302
|
+
res.end();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// 发布前自检:直链下载 → sha256/size → 解包 → 冒烟跑 entry,防给加工者配死链
|
|
306
|
+
return handleDevTestAttachmentUrl(req, res).catch(next);
|
|
307
|
+
}
|
|
284
308
|
if (pathname === "/__mbws__/dev/pick-directory") {
|
|
285
309
|
if (req.method !== "POST") {
|
|
286
310
|
res.statusCode = 405;
|
|
@@ -330,6 +354,15 @@ export function mbwsVitePlugin(opts) {
|
|
|
330
354
|
}
|
|
331
355
|
return handleDevLocalize(projectRoot, res, ref).catch(next);
|
|
332
356
|
}
|
|
357
|
+
if (pathname === "/__mbws__/dev/expand-zip") {
|
|
358
|
+
const rel = new URL(req.url ?? "/", "http://dev").searchParams.get("path") ?? "";
|
|
359
|
+
if (!rel) {
|
|
360
|
+
res.statusCode = 400;
|
|
361
|
+
res.end(JSON.stringify({ message: "缺少 path" }));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
return handleDevExpandZip(projectRoot, res, rel).catch(next);
|
|
365
|
+
}
|
|
333
366
|
if (pathname === "/__mbws__/dev/file") {
|
|
334
367
|
const relPath = new URL(req.url ?? "/", "http://dev").searchParams.get("path") ?? "";
|
|
335
368
|
if (!relPath) {
|
|
@@ -397,20 +430,70 @@ export function currentAttachmentPlatform() {
|
|
|
397
430
|
}
|
|
398
431
|
/** dev 附件缓存目录(工程内,应进插件工程 .gitignore) */
|
|
399
432
|
const DEV_ATTACHMENT_CACHE = ".mbws/attachments";
|
|
433
|
+
/** 本机命令是否 PATH 可达(which / where 探测;探测失败一律按不可达回落官方库) */
|
|
434
|
+
function isCommandAvailable(cmd) {
|
|
435
|
+
const probe = process.platform === "win32" ? spawnSync("where", [cmd]) : spawnSync("which", [cmd]);
|
|
436
|
+
return probe.status === 0;
|
|
437
|
+
}
|
|
400
438
|
/**
|
|
401
|
-
* dev 用附件本地覆盖:env MBWS_DEV_ATTACHMENT_<NAME>(名字大写、- → _
|
|
402
|
-
*
|
|
403
|
-
*
|
|
439
|
+
* dev 用附件本地覆盖:env MBWS_DEV_ATTACHMENT_<NAME>(名字大写、- → _)优先,取值三形态——
|
|
440
|
+
* 本机命令名(如 ffmpeg,dev exec 直接 spawn,PATH 解析零下载)/ 本地路径(existsSync 命中)/
|
|
441
|
+
* https 临时直链(走直链下载分支,无 hash 校验);其次工程内 `.mbws/attachment-overrides.json`
|
|
442
|
+
* 本地文件(同三形态;dev 起来后在欢迎页可视化编辑,不进 git);再其次 attachments 声明里
|
|
443
|
+
* 的 devPath(线上还没有的新版本指本机路径)。
|
|
444
|
+
* 未配置 / 全不可用返回 null(走官方附件库自动下载)。
|
|
404
445
|
*/
|
|
405
|
-
export function resolveDevAttachmentOverride(config, name) {
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
446
|
+
export function resolveDevAttachmentOverride(config, name, root) {
|
|
447
|
+
const classify = (value) => {
|
|
448
|
+
if (/^https?:\/\//i.test(value))
|
|
449
|
+
return { kind: "url", url: value };
|
|
450
|
+
if (fs.existsSync(value))
|
|
451
|
+
return { kind: "path", path: value };
|
|
452
|
+
if (isCommandAvailable(value))
|
|
453
|
+
return { kind: "cmd", cmd: value };
|
|
454
|
+
// 配了但三形态都不成立(路径不存在且命令不在 PATH):忽略该值,让下一层/官方库说话
|
|
455
|
+
return null;
|
|
456
|
+
};
|
|
457
|
+
const envValue = process.env[`MBWS_DEV_ATTACHMENT_${name.replace(/-/g, "_").toUpperCase()}`]?.trim();
|
|
458
|
+
if (envValue) {
|
|
459
|
+
const hit = classify(envValue);
|
|
460
|
+
if (hit)
|
|
461
|
+
return hit;
|
|
462
|
+
}
|
|
463
|
+
if (root) {
|
|
464
|
+
const fileValue = readAttachmentOverridesFile(root)[name]?.trim();
|
|
465
|
+
if (fileValue) {
|
|
466
|
+
const hit = classify(fileValue);
|
|
467
|
+
if (hit)
|
|
468
|
+
return hit;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
409
471
|
const ref = (config.attachments ?? []).find((a) => a.name === name);
|
|
410
|
-
if (typeof ref?.devPath === "string" && fs.existsSync(ref.devPath))
|
|
411
|
-
return ref.devPath;
|
|
472
|
+
if (typeof ref?.devPath === "string" && fs.existsSync(ref.devPath)) {
|
|
473
|
+
return { kind: "path", path: ref.devPath };
|
|
474
|
+
}
|
|
412
475
|
return null;
|
|
413
476
|
}
|
|
477
|
+
/** 工程内本地覆盖文件(dev 配置页写入;.mbws 本就是 dev 缓存目录,不进 git) */
|
|
478
|
+
const ATTACHMENT_OVERRIDES_FILE = path.join(".mbws", "attachment-overrides.json");
|
|
479
|
+
function readAttachmentOverridesFile(root) {
|
|
480
|
+
try {
|
|
481
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(root, ATTACHMENT_OVERRIDES_FILE), "utf8"));
|
|
482
|
+
if (parsed && typeof parsed.overrides === "object" && parsed.overrides !== null) {
|
|
483
|
+
return parsed.overrides;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
// 不存在/损坏都当空(首次写会建文件)
|
|
488
|
+
}
|
|
489
|
+
return {};
|
|
490
|
+
}
|
|
491
|
+
function writeAttachmentOverridesFile(root, overrides) {
|
|
492
|
+
const file = path.join(root, ATTACHMENT_OVERRIDES_FILE);
|
|
493
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
494
|
+
const body = { version: 1, overrides };
|
|
495
|
+
fs.writeFileSync(file, `${JSON.stringify(body, null, 2)}\n`);
|
|
496
|
+
}
|
|
414
497
|
/** 同一附件并发解析去重(下载进行中第二个 spawn 等同一 Promise) */
|
|
415
498
|
const inflightDevAttachments = new Map();
|
|
416
499
|
/**
|
|
@@ -488,6 +571,45 @@ async function downloadToFile(url, dest, log, sizeHint) {
|
|
|
488
571
|
* 附件未声明 / 无 url 且库未登记返回 null(调用方回 501);下载/校验/解包失败抛错。
|
|
489
572
|
* log 收下载进度行(调用方转 NDJSON 事件流)。
|
|
490
573
|
*/
|
|
574
|
+
/**
|
|
575
|
+
* 直链下载就绪(声明 url 与 env 覆盖直链共用):无 sha256,缓存目录不带 hash 层
|
|
576
|
+
* (`.mbws/attachments/<name>@<version>/`,同 version 重传视为修正);按后缀分派
|
|
577
|
+
* tar.gz/zip 解包、.gz 单文件解压、其余当裸二进制。返回入口绝对路径。
|
|
578
|
+
*/
|
|
579
|
+
async function ensureDirectUrlAttachment(root, name, version, entry, directUrl, log) {
|
|
580
|
+
const platform = currentAttachmentPlatform();
|
|
581
|
+
const dir = path.join(root, DEV_ATTACHMENT_CACHE, `${name}@${version}`);
|
|
582
|
+
const entryPath = path.join(dir, entry);
|
|
583
|
+
if (fs.existsSync(entryPath))
|
|
584
|
+
return entryPath;
|
|
585
|
+
log(`[mbws:dev] 下载附件 ${name}@${version}(${platform} 直链,无 hash 校验)`);
|
|
586
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
587
|
+
const tmpPath = path.join(dir, "download.tmp");
|
|
588
|
+
try {
|
|
589
|
+
await downloadToFile(directUrl, tmpPath, log);
|
|
590
|
+
const lower = directUrl.toLowerCase();
|
|
591
|
+
if (/\.(tar\.gz|tgz|zip)$/.test(lower)) {
|
|
592
|
+
const extracted = spawnSync("tar", ["-xf", tmpPath, "-C", dir]);
|
|
593
|
+
if (extracted.status !== 0) {
|
|
594
|
+
throw new Error(`解包失败:${extracted.stderr?.toString().trim() || `tar exit ${extracted.status}`}`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
else if (/\.gz$/.test(lower)) {
|
|
598
|
+
await pipeline(fs.createReadStream(tmpPath), zlib.createGunzip(), fs.createWriteStream(entryPath));
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
fs.copyFileSync(tmpPath, entryPath);
|
|
602
|
+
}
|
|
603
|
+
if (!fs.existsSync(entryPath))
|
|
604
|
+
throw new Error(`解包后未见入口 ${entry}`);
|
|
605
|
+
fs.chmodSync(entryPath, 0o755);
|
|
606
|
+
log(`[mbws:dev] 附件 ${name}@${version} 就绪(已缓存,后续零下载)`);
|
|
607
|
+
return entryPath;
|
|
608
|
+
}
|
|
609
|
+
finally {
|
|
610
|
+
fs.rmSync(tmpPath, { force: true });
|
|
611
|
+
}
|
|
612
|
+
}
|
|
491
613
|
async function ensureLibraryAttachment(config, root, name, log) {
|
|
492
614
|
const key = `${root}::${name}`;
|
|
493
615
|
const inflight = inflightDevAttachments.get(key);
|
|
@@ -503,37 +625,7 @@ async function ensureLibraryAttachment(config, root, name, log) {
|
|
|
503
625
|
// —— url 直链分支(开发者提供的官方地址)——
|
|
504
626
|
const directUrl = typeof ref.url === "string" ? ref.url : ref.url?.[platform];
|
|
505
627
|
if (directUrl) {
|
|
506
|
-
|
|
507
|
-
const entryPath = path.join(dir, entry);
|
|
508
|
-
if (fs.existsSync(entryPath))
|
|
509
|
-
return entryPath;
|
|
510
|
-
log(`[mbws:dev] 下载附件 ${name}@${ref.version}(${platform} 直链,无 hash 校验)`);
|
|
511
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
512
|
-
const tmpPath = path.join(dir, "download.tmp");
|
|
513
|
-
try {
|
|
514
|
-
await downloadToFile(directUrl, tmpPath, log);
|
|
515
|
-
const lower = directUrl.toLowerCase();
|
|
516
|
-
if (/\.(tar\.gz|tgz|zip)$/.test(lower)) {
|
|
517
|
-
const extracted = spawnSync("tar", ["-xf", tmpPath, "-C", dir]);
|
|
518
|
-
if (extracted.status !== 0) {
|
|
519
|
-
throw new Error(`解包失败:${extracted.stderr?.toString().trim() || `tar exit ${extracted.status}`}`);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
else if (/\.gz$/.test(lower)) {
|
|
523
|
-
await pipeline(fs.createReadStream(tmpPath), zlib.createGunzip(), fs.createWriteStream(entryPath));
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
fs.copyFileSync(tmpPath, entryPath);
|
|
527
|
-
}
|
|
528
|
-
if (!fs.existsSync(entryPath))
|
|
529
|
-
throw new Error(`解包后未见入口 ${entry}`);
|
|
530
|
-
fs.chmodSync(entryPath, 0o755);
|
|
531
|
-
log(`[mbws:dev] 附件 ${name}@${ref.version} 就绪(已缓存,后续零下载)`);
|
|
532
|
-
return entryPath;
|
|
533
|
-
}
|
|
534
|
-
finally {
|
|
535
|
-
fs.rmSync(tmpPath, { force: true });
|
|
536
|
-
}
|
|
628
|
+
return await ensureDirectUrlAttachment(root, name, ref.version, entry, directUrl, log);
|
|
537
629
|
}
|
|
538
630
|
// —— 官方附件库分支(OSS 公共读直连:index.json 拿 hash,下载地址内容寻址自拼) ——
|
|
539
631
|
const resolved = await resolveLibraryIndex(name, ref.version, platform);
|
|
@@ -574,16 +666,41 @@ async function ensureLibraryAttachment(config, root, name, log) {
|
|
|
574
666
|
}
|
|
575
667
|
}
|
|
576
668
|
/**
|
|
577
|
-
* dev 附件准备(exec / ensure-attachment 共用):本地覆盖(env / devPath
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
669
|
+
* dev 附件准备(exec / ensure-attachment 共用):本地覆盖(env / devPath)零网络——
|
|
670
|
+
* env 覆盖三形态:本机命令名(直接返回命令名,spawn 走 PATH)/ 本地路径 / https 临时
|
|
671
|
+
* 直链(与声明 url 同一条直链下载分支);否则按 attachments 声明自动下载官方附件库
|
|
672
|
+
* /直链缓存(下载进度行经 write 流回)。返回入口路径(或命令名)。
|
|
673
|
+
* 不可用(未声明 / 库未登记)时已写好 501 响应;下载/校验/解包失败时已按「附件 X
|
|
674
|
+
* 下载失败」exit 事件收尾——两种失败都返回 null 且响应已结束,调用方直接返回。
|
|
581
675
|
*/
|
|
582
676
|
async function prepareDevAttachment(config, root, attachment, write, res) {
|
|
583
|
-
|
|
677
|
+
const log = (text) => write({ kind: "lines", lines: [{ stream: "stderr", text }] });
|
|
678
|
+
const override = resolveDevAttachmentOverride(config, attachment, root);
|
|
679
|
+
let binPath = null;
|
|
680
|
+
if (override?.kind === "path") {
|
|
681
|
+
binPath = override.path;
|
|
682
|
+
}
|
|
683
|
+
else if (override?.kind === "cmd") {
|
|
684
|
+
binPath = override.cmd;
|
|
685
|
+
}
|
|
686
|
+
else if (override?.kind === "url") {
|
|
687
|
+
const ref = (config.attachments ?? []).find((a) => a.name === attachment);
|
|
688
|
+
const platform = currentAttachmentPlatform();
|
|
689
|
+
const entry = ref?.entry ?? `${attachment}${platform.startsWith("win") ? ".exe" : ""}`;
|
|
690
|
+
try {
|
|
691
|
+
// 覆盖直链与声明 url 同一条分支(无 hash 校验,缓存同目录同 version 语义)
|
|
692
|
+
binPath = await ensureDirectUrlAttachment(root, attachment, ref?.version ?? "override", entry, override.url, log);
|
|
693
|
+
}
|
|
694
|
+
catch (error) {
|
|
695
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
696
|
+
write({ kind: "exit", exitCode: -1, stderrTail: `附件 ${attachment} 下载失败:${message}` });
|
|
697
|
+
res.end();
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
584
701
|
if (!binPath) {
|
|
585
702
|
try {
|
|
586
|
-
binPath = await ensureLibraryAttachment(config, root, attachment,
|
|
703
|
+
binPath = await ensureLibraryAttachment(config, root, attachment, log);
|
|
587
704
|
}
|
|
588
705
|
catch (error) {
|
|
589
706
|
// 下载/校验/解包失败:已经开始流式响应(可能已写过进度行),按 job 失败收尾
|
|
@@ -595,11 +712,12 @@ async function prepareDevAttachment(config, root, attachment, write, res) {
|
|
|
595
712
|
if (!binPath) {
|
|
596
713
|
// 501 = 能力明确不可用:SDK dev-mock 收到非 2xx 退模拟执行
|
|
597
714
|
const declared = (config.attachments ?? []).some((a) => a.name === attachment);
|
|
715
|
+
const envName = `MBWS_DEV_ATTACHMENT_${attachment.replace(/-/g, "_").toUpperCase()}`;
|
|
598
716
|
res.statusCode = 501;
|
|
599
717
|
res.end(JSON.stringify({
|
|
600
718
|
message: declared
|
|
601
|
-
? `附件 ${attachment} 无 url 直链且未在官方附件库(OSS
|
|
602
|
-
: `mbws.config.ts 的 attachments 未声明附件 ${attachment}(dev
|
|
719
|
+
? `附件 ${attachment} 无 url 直链且未在官方附件库(OSS)登记当前平台产物(或不可达);本机覆盖可配 env ${envName}(取值:本机命令名 / 本地路径 / https 直链),或 attachments 的 url 直链 / devPath`
|
|
720
|
+
: `mbws.config.ts 的 attachments 未声明附件 ${attachment}(dev 自动下载依赖声明);本机覆盖可配 env ${envName}(取值:本机命令名 / 本地路径 / https 直链),或在该项声明 devPath`,
|
|
603
721
|
}));
|
|
604
722
|
return null;
|
|
605
723
|
}
|
|
@@ -748,7 +866,7 @@ async function handleDevAttachmentsSnapshot(config, root, res) {
|
|
|
748
866
|
const entry = ref.entry ?? `${ref.name}${platform.startsWith("win") ? ".exe" : ""}`;
|
|
749
867
|
let status = "missing";
|
|
750
868
|
let totalBytes;
|
|
751
|
-
if (resolveDevAttachmentOverride(config, ref.name)) {
|
|
869
|
+
if (resolveDevAttachmentOverride(config, ref.name, root)) {
|
|
752
870
|
status = "ready";
|
|
753
871
|
}
|
|
754
872
|
else {
|
|
@@ -783,6 +901,229 @@ async function handleDevAttachmentsSnapshot(config, root, res) {
|
|
|
783
901
|
res.setHeader("cache-control", "no-store");
|
|
784
902
|
res.end(JSON.stringify(items));
|
|
785
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* GET /__mbws__/dev/attachment-overrides:本地覆盖读面(欢迎页配置卡消费)。
|
|
906
|
+
* 每个声明附件一条:当前各层配置值(env / .mbws 文件)+ 生效来源与形态
|
|
907
|
+
* (env > file > devPath > library)。
|
|
908
|
+
*/
|
|
909
|
+
async function handleDevAttachmentOverridesGet(config, root, res) {
|
|
910
|
+
const fileOverrides = readAttachmentOverridesFile(root);
|
|
911
|
+
const items = (config.attachments ?? []).map((ref) => {
|
|
912
|
+
const envName = `MBWS_DEV_ATTACHMENT_${ref.name.replace(/-/g, "_").toUpperCase()}`;
|
|
913
|
+
const envValue = process.env[envName]?.trim() ?? "";
|
|
914
|
+
const fileValue = fileOverrides[ref.name]?.trim() ?? "";
|
|
915
|
+
const classify = (value) => {
|
|
916
|
+
if (/^https?:\/\//i.test(value))
|
|
917
|
+
return { kind: "url", url: value };
|
|
918
|
+
if (fs.existsSync(value))
|
|
919
|
+
return { kind: "path", path: value };
|
|
920
|
+
if (isCommandAvailable(value))
|
|
921
|
+
return { kind: "cmd", cmd: value };
|
|
922
|
+
return null;
|
|
923
|
+
};
|
|
924
|
+
let source = "library";
|
|
925
|
+
let effective = null;
|
|
926
|
+
const envHit = classify(envValue);
|
|
927
|
+
const fileHit = classify(fileValue);
|
|
928
|
+
if (envHit) {
|
|
929
|
+
source = "env";
|
|
930
|
+
effective = envHit;
|
|
931
|
+
}
|
|
932
|
+
else if (fileHit) {
|
|
933
|
+
source = "file";
|
|
934
|
+
effective = fileHit;
|
|
935
|
+
}
|
|
936
|
+
else if (typeof ref.devPath === "string" && fs.existsSync(ref.devPath)) {
|
|
937
|
+
source = "devPath";
|
|
938
|
+
effective = { kind: "path", path: ref.devPath };
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
name: ref.name,
|
|
942
|
+
version: ref.version,
|
|
943
|
+
// 生效覆盖(null = 走官方附件库自动下载)
|
|
944
|
+
override: effective,
|
|
945
|
+
source,
|
|
946
|
+
envName,
|
|
947
|
+
envValue,
|
|
948
|
+
fileValue,
|
|
949
|
+
// env 配了但不合法的提示(路径不存在且不在 PATH)
|
|
950
|
+
...(envValue && !classify(envValue) ? { envInvalid: true } : {}),
|
|
951
|
+
};
|
|
952
|
+
});
|
|
953
|
+
res.setHeader("content-type", "application/json");
|
|
954
|
+
res.setHeader("cache-control", "no-store");
|
|
955
|
+
res.end(JSON.stringify(items));
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* POST /__mbws__/dev/attachment-overrides:本地覆盖写面(欢迎页配置卡消费)。
|
|
959
|
+
* body { name, value }——value 非空须能归类(https 直链 / 真实路径 / PATH 命令名),
|
|
960
|
+
* 空串 = 删除该项。写 `.mbws/attachment-overrides.json`(纯本机配置,不进 git、不进产物)。
|
|
961
|
+
*/
|
|
962
|
+
async function handleDevAttachmentOverridesSet(root, req, res) {
|
|
963
|
+
let body;
|
|
964
|
+
try {
|
|
965
|
+
body = JSON.parse((await readRequestBody(req)).toString("utf8"));
|
|
966
|
+
}
|
|
967
|
+
catch {
|
|
968
|
+
res.statusCode = 400;
|
|
969
|
+
res.end(JSON.stringify({ message: "body 不是合法 JSON" }));
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const { name, value } = body;
|
|
973
|
+
if (typeof name !== "string" ||
|
|
974
|
+
!/^[a-z][a-z0-9-]{1,63}$/.test(name) ||
|
|
975
|
+
typeof value !== "string") {
|
|
976
|
+
res.statusCode = 400;
|
|
977
|
+
res.end(JSON.stringify({ message: "name(附件名) 与 value(string,空=删除) 必填" }));
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const trimmed = value.trim();
|
|
981
|
+
if (trimmed) {
|
|
982
|
+
const looksValid = /^https?:\/\//i.test(trimmed) || fs.existsSync(trimmed) || isCommandAvailable(trimmed);
|
|
983
|
+
if (!looksValid) {
|
|
984
|
+
res.statusCode = 400;
|
|
985
|
+
res.end(JSON.stringify({
|
|
986
|
+
message: `覆盖值无法识别:既不是 https 直链,路径也不存在,也不在 PATH——检查拼写(可填本机命令名 / 本地路径 / https 临时直链)`,
|
|
987
|
+
}));
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const overrides = readAttachmentOverridesFile(root);
|
|
992
|
+
if (trimmed) {
|
|
993
|
+
overrides[name] = trimmed;
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
delete overrides[name];
|
|
997
|
+
}
|
|
998
|
+
writeAttachmentOverridesFile(root, overrides);
|
|
999
|
+
res.setHeader("content-type", "application/json");
|
|
1000
|
+
res.setHeader("cache-control", "no-store");
|
|
1001
|
+
res.end(JSON.stringify({ name, value: trimmed, saved: true }));
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* POST /__mbws__/dev/test-attachment-url:发布前直链自检——下载 → sha256/size →
|
|
1005
|
+
* 按后缀解包 → 冒烟跑 entry(--version,短超时)→ 清理临时目录。
|
|
1006
|
+
* body { url, entry?, smoke? };返回 { ok, sha256, size, archive, smoke: { exitCode, output } | "skipped" }。
|
|
1007
|
+
* 冒烟非零退出不算失败(不少工具不认 --version),只回显 exitCode 与输出供人判断。
|
|
1008
|
+
*/
|
|
1009
|
+
async function handleDevTestAttachmentUrl(req, res) {
|
|
1010
|
+
let body;
|
|
1011
|
+
try {
|
|
1012
|
+
body = JSON.parse((await readRequestBody(req)).toString("utf8"));
|
|
1013
|
+
}
|
|
1014
|
+
catch {
|
|
1015
|
+
res.statusCode = 400;
|
|
1016
|
+
res.end(JSON.stringify({ message: "body 不是合法 JSON" }));
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const { url, entry } = body;
|
|
1020
|
+
if (typeof url !== "string" ||
|
|
1021
|
+
!/^https?:\/\//i.test(url) ||
|
|
1022
|
+
(entry !== undefined && typeof entry !== "string")) {
|
|
1023
|
+
res.statusCode = 400;
|
|
1024
|
+
res.end(JSON.stringify({ message: "url(https 直链) 必填,entry(string) 选填" }));
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const smoke = body.smoke !== false;
|
|
1028
|
+
const entryName = (typeof entry === "string" && entry.trim()) || "attachment-entry";
|
|
1029
|
+
const log = (_text) => { }; // 静默(一次性自检,不打进度)
|
|
1030
|
+
// 系统临时目录(不落工程 .mbws——自检完即清理,避免污染附件缓存目录)
|
|
1031
|
+
const dir = fs.mkdtempSync(path.join(tmpdir(), "mbws-url-test-"));
|
|
1032
|
+
try {
|
|
1033
|
+
const tmpPath = path.join(dir, "download.bin");
|
|
1034
|
+
let sha256;
|
|
1035
|
+
try {
|
|
1036
|
+
sha256 = await downloadToFile(url, tmpPath, log);
|
|
1037
|
+
}
|
|
1038
|
+
catch (error) {
|
|
1039
|
+
res.setHeader("content-type", "application/json");
|
|
1040
|
+
res.end(JSON.stringify({
|
|
1041
|
+
ok: false,
|
|
1042
|
+
stage: "download",
|
|
1043
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1044
|
+
}));
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
const size = fs.statSync(tmpPath).size;
|
|
1048
|
+
const lower = url.toLowerCase().split("?")[0];
|
|
1049
|
+
const archive = /\.(tar\.gz|tgz)$/.test(lower)
|
|
1050
|
+
? "tar.gz"
|
|
1051
|
+
: /\.zip$/.test(lower)
|
|
1052
|
+
? "zip"
|
|
1053
|
+
: /\.gz$/.test(lower)
|
|
1054
|
+
? "gz"
|
|
1055
|
+
: "bare";
|
|
1056
|
+
let entryPath;
|
|
1057
|
+
if (archive === "tar.gz" || archive === "zip") {
|
|
1058
|
+
const extracted = spawnSync("tar", ["-xf", tmpPath, "-C", dir]);
|
|
1059
|
+
if (extracted.status !== 0) {
|
|
1060
|
+
res.setHeader("content-type", "application/json");
|
|
1061
|
+
res.end(JSON.stringify({
|
|
1062
|
+
ok: false,
|
|
1063
|
+
stage: "extract",
|
|
1064
|
+
archive,
|
|
1065
|
+
sha256,
|
|
1066
|
+
size,
|
|
1067
|
+
message: extracted.stderr?.toString().trim() || `tar exit ${extracted.status}`,
|
|
1068
|
+
}));
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
// 优先匹配 entry 名(含 .exe 变体),缺省取第一个文件
|
|
1072
|
+
const files = fs
|
|
1073
|
+
.readdirSync(dir, { recursive: true })
|
|
1074
|
+
.map((f) => String(f))
|
|
1075
|
+
.filter((f) => f !== "download.bin" && fs.statSync(path.join(dir, f)).isFile());
|
|
1076
|
+
const picked = files.find((f) => {
|
|
1077
|
+
const base = path.basename(f);
|
|
1078
|
+
return base === entryName || base === `${entryName}.exe`;
|
|
1079
|
+
}) ?? files[0];
|
|
1080
|
+
if (!picked) {
|
|
1081
|
+
res.setHeader("content-type", "application/json");
|
|
1082
|
+
res.end(JSON.stringify({
|
|
1083
|
+
ok: false,
|
|
1084
|
+
stage: "extract",
|
|
1085
|
+
archive,
|
|
1086
|
+
sha256,
|
|
1087
|
+
size,
|
|
1088
|
+
message: "包内没有文件条目",
|
|
1089
|
+
}));
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
entryPath = path.join(dir, picked);
|
|
1093
|
+
}
|
|
1094
|
+
else if (archive === "gz") {
|
|
1095
|
+
entryPath = path.join(dir, entryName);
|
|
1096
|
+
await pipeline(fs.createReadStream(tmpPath), zlib.createGunzip(), fs.createWriteStream(entryPath));
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
entryPath = tmpPath;
|
|
1100
|
+
}
|
|
1101
|
+
if (archive !== "tar.gz" && archive !== "zip")
|
|
1102
|
+
fs.chmodSync(entryPath, 0o755);
|
|
1103
|
+
let smokeResult = "skipped";
|
|
1104
|
+
if (smoke) {
|
|
1105
|
+
const run = spawnSync(entryPath, ["--version"], { timeout: 15_000, encoding: "utf8" });
|
|
1106
|
+
const output = `${run.stdout ?? ""}${run.stderr ?? ""}`
|
|
1107
|
+
.trim()
|
|
1108
|
+
.split("\n")
|
|
1109
|
+
.slice(0, 3)
|
|
1110
|
+
.join("\n");
|
|
1111
|
+
smokeResult = { exitCode: run.status ?? -1, output };
|
|
1112
|
+
}
|
|
1113
|
+
res.setHeader("content-type", "application/json");
|
|
1114
|
+
res.end(JSON.stringify({
|
|
1115
|
+
ok: true,
|
|
1116
|
+
sha256,
|
|
1117
|
+
size,
|
|
1118
|
+
archive,
|
|
1119
|
+
entry: path.basename(entryPath),
|
|
1120
|
+
smoke: smokeResult,
|
|
1121
|
+
}));
|
|
1122
|
+
}
|
|
1123
|
+
finally {
|
|
1124
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
786
1127
|
/**
|
|
787
1128
|
* POST /__mbws__/dev/pick-directory:dev 无系统选择器——固定指 `.mbws/dev-outputs/`
|
|
788
1129
|
* (绝对路径,目录即建)。插件拿路径拼产物输出位置,spawn(cwd=工程根)直接写绝对路径。
|
|
@@ -935,6 +1276,46 @@ async function handleDevLocalize(root, res, ref) {
|
|
|
935
1276
|
res.statusCode = 404;
|
|
936
1277
|
res.end(JSON.stringify({ message: `samples/${basename} 不存在` }));
|
|
937
1278
|
}
|
|
1279
|
+
/** GET /__mbws__/dev/expand-zip?path=:把工程内 zip 解到 .mbws/expanded,返回可预览视频。 */
|
|
1280
|
+
async function handleDevExpandZip(root, res, relPath) {
|
|
1281
|
+
const rootResolved = path.resolve(root);
|
|
1282
|
+
const archive = path.resolve(root, relPath);
|
|
1283
|
+
if (archive !== rootResolved && !archive.startsWith(`${rootResolved}${path.sep}`)) {
|
|
1284
|
+
res.statusCode = 403;
|
|
1285
|
+
res.end(JSON.stringify({ message: "path 超出工程目录" }));
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
const id = crypto.createHash("sha256").update(relPath).digest("hex").slice(0, 16);
|
|
1289
|
+
const dest = path.join(root, ".mbws", "expanded", id);
|
|
1290
|
+
await fs.promises.rm(dest, { recursive: true, force: true });
|
|
1291
|
+
try {
|
|
1292
|
+
const videos = await expandZipVideos(archive, dest);
|
|
1293
|
+
if (videos.length === 0) {
|
|
1294
|
+
res.statusCode = 422;
|
|
1295
|
+
res.end(JSON.stringify({ message: "压缩包内没有可识别的视频" }));
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
const payload = {
|
|
1299
|
+
videos: videos.map((video) => {
|
|
1300
|
+
const rel = path.posix.join(".mbws", "expanded", id, video.relPath);
|
|
1301
|
+
return {
|
|
1302
|
+
path: rel,
|
|
1303
|
+
filename: video.filename,
|
|
1304
|
+
entryName: video.entryName,
|
|
1305
|
+
previewUrl: `/__mbws__/dev/file?path=${encodeURIComponent(rel)}`,
|
|
1306
|
+
};
|
|
1307
|
+
}),
|
|
1308
|
+
};
|
|
1309
|
+
res.setHeader("content-type", "application/json");
|
|
1310
|
+
res.setHeader("cache-control", "no-store");
|
|
1311
|
+
res.end(JSON.stringify(payload));
|
|
1312
|
+
}
|
|
1313
|
+
catch (error) {
|
|
1314
|
+
res.statusCode = 400;
|
|
1315
|
+
const message = error instanceof ExpandZipError ? error.message : "解压失败";
|
|
1316
|
+
res.end(JSON.stringify({ message }));
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
938
1319
|
const DEV_FILE_MIME = {
|
|
939
1320
|
".mp4": "video/mp4",
|
|
940
1321
|
".webm": "video/webm",
|
package/package.json
CHANGED
|
@@ -1,38 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbws/plugin-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"description": "Moye 插件开发 SDK——panel/viewer 与宿主的类型定义与运行时端口适配",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./
|
|
8
|
-
"types": "./
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"@mbws/source": "./src/index.ts",
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"default": "./src/index.ts"
|
|
13
14
|
},
|
|
14
15
|
"./package.json": "./package.json",
|
|
15
16
|
"./vite": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
17
|
+
"@mbws/source": "./src/vite.ts",
|
|
18
|
+
"types": "./src/vite.ts",
|
|
19
|
+
"default": "./src/vite.ts"
|
|
20
|
+
},
|
|
21
|
+
"./expand-zip": {
|
|
22
|
+
"@mbws/source": "./src/expand-zip.ts",
|
|
23
|
+
"types": "./src/expand-zip.ts",
|
|
24
|
+
"default": "./src/expand-zip.ts"
|
|
18
25
|
}
|
|
19
26
|
},
|
|
20
27
|
"publishConfig": {
|
|
21
|
-
"access": "public"
|
|
28
|
+
"access": "public",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json",
|
|
37
|
+
"./vite": {
|
|
38
|
+
"types": "./dist/vite.d.ts",
|
|
39
|
+
"default": "./dist/vite.js"
|
|
40
|
+
},
|
|
41
|
+
"./expand-zip": {
|
|
42
|
+
"types": "./dist/expand-zip.d.ts",
|
|
43
|
+
"default": "./dist/expand-zip.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
22
46
|
},
|
|
23
47
|
"files": [
|
|
24
48
|
"dist"
|
|
25
49
|
],
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"json-schema-to-typescript": "^16.0.0",
|
|
28
|
-
"zod": "^4.4.3"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"vite": "^8.0.14"
|
|
32
|
-
},
|
|
33
50
|
"scripts": {
|
|
34
51
|
"build": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
35
52
|
"test": "vitest run",
|
|
36
53
|
"pack:sdk": "pnpm build && pnpm pack"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"json-schema-to-typescript": "catalog:",
|
|
57
|
+
"zod": "catalog:"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"vite": "catalog:"
|
|
37
61
|
}
|
|
38
|
-
}
|
|
62
|
+
}
|