@xunlei-open/miniapp 0.1.1-beta.4 → 0.1.1-beta.6

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/README.md CHANGED
@@ -21,7 +21,11 @@ pnpm exec xunlei-miniapp
21
21
  | `xunlei-miniapp package` | 构建、校验并生成 ZIP |
22
22
  | `xunlei-miniapp package --no-build` | 校验并打包已有生产产物 |
23
23
 
24
- 默认输出目录为 `dist/`,ZIP 位于 `release/`。构建与打包不自动执行类型检查。
24
+ 开发产物位于 `dist/`,生产构建位于 `output/`,ZIP 位于 `output/`。开发服务运行时可以执行构建和打包,两者不会覆盖开发入口。构建与打包不自动执行类型检查。
25
+
26
+ `build` 将 HTML、清单和资源直接写入 `output/`。`package` 构建后生成 ZIP,仅在 ZIP 成功写入后清理本次构建文件,默认最终只保留安装包;打包失败保留构建文件。`package --no-build` 保留已有产物。默认下一次构建会清空 `output/`,需要长期保留的 ZIP 应另行保存。
27
+
28
+ 自定义开发目录使用 `dev.outDir`,生产目录使用 `vite.build.outDir`,ZIP 目录使用 `package.outDir`。开发目录与生产目录不能相同或互相包含。已有配置若将 `vite.build.outDir` 设为 `dist`,需移除该配置以使用新默认值,或改为独立的生产目录;原来通过它自定义开发路径的项目应迁移到 `dev.outDir`。旧 `release/` 文件不会自动删除。
25
29
 
26
30
  ## 配置
27
31
 
@@ -40,4 +44,14 @@ Vue / React 项目安装并声明对应框架模块;Vanilla 无需模块。额
40
44
 
41
45
  事件源码默认放在 `src/events`,并在 manifest 的 `scripts` 中声明。纯事件应用无需页面入口。事件或图标更新后,宿主若有缓存需重新加载应用。
42
46
 
47
+ ### 事件依赖与开发重建
48
+
49
+ 事件入口输出在 `events/`;公共分块、Worker、WASM 等依赖可以按 Vite 默认规则输出到 `assets/`,无需在应用中强制配置 `events/assets/`。Worker 及其依赖修改也会触发事件重建。
50
+
51
+ 开发模式先完成整个构建和校验,再写入依赖,最后逐个原子替换事件入口。编译或校验失败保留已有产物。输出路径必须位于输出目录内,不允许符号链接绕过边界,不得覆盖页面入口、清单或图标。与已有依赖同名且内容不同会报错;请使用包含内容哈希的依赖文件名。同内容资源可以复用。
52
+
53
+ 开发会话期间保留旧依赖,让已经运行的事件和 Worker 仍能加载旧版本;删除源码只清理本次会话拥有且未被外部修改的事件入口。旧哈希资源会增加磁盘占用;停止 dev 后,默认的生产全量构建会清理输出目录,仅保留本次产物。自定义 `emptyOutDir: false` 时由应用自行管理旧文件。
54
+
55
+ 多个入口不是一个原子事务,事件构建与独立的外部写文件进程也不构成跨进程锁;外部脚本不要清理或覆盖开发目录。入口更新后仍需按宿主缓存行为重载应用。
56
+
43
57
  [示例代码](https://github.com/xunlei-open/miniapp-devkit/tree/main/examples) · [官方文档](https://open.xunlei.com/doc/miniapp/introduction)
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as validateBuiltMiniapp, n as buildMiniapp, r as devMiniapp, t as packageMiniapp } from "./package-DgpqUgd3.mjs";
1
+ import { i as validateBuiltMiniapp, n as buildMiniapp, r as devMiniapp, t as packageMiniapp } from "./package-jNl57UKj.mjs";
2
2
  import { parseArgs } from "node:util";
3
3
  //#region src/cli.ts
4
4
  const HELP = `Xunlei Miniapp CLI
@@ -3,11 +3,14 @@
3
3
  var shown = false;
4
4
  var disconnected = false;
5
5
  var reloaded = false;
6
+ var monitoring = false;
6
7
  var timer;
7
8
  var active;
8
9
  var probeUrl = document.currentScript.getAttribute('data-miniapp-dev-probe');
9
10
  function showDisconnected() {
10
11
  disconnected = true;
12
+ // Keep an already-loaded application usable while reconnecting silently.
13
+ if (monitoring) return;
11
14
  if (shown) return;
12
15
  shown = true;
13
16
  function showMessage() {
@@ -45,9 +48,10 @@
45
48
  reloaded = true;
46
49
  clearInterval(timer);
47
50
  window.location.reload();
48
- } else {
51
+ } else if (!monitoring) {
49
52
  // A reachable server means the module failed for another reason.
50
53
  clearInterval(timer);
54
+ timer = undefined;
51
55
  }
52
56
  }).catch(function () {
53
57
  if (active !== controller || reloaded) return;
@@ -55,13 +59,23 @@
55
59
  showDisconnected();
56
60
  });
57
61
  }
62
+ function startRecovery() {
63
+ if (timer !== undefined || reloaded) return;
64
+ timer = setInterval(probeConnection, 1000);
65
+ probeConnection();
66
+ }
58
67
  // Start network requests after the host can observe the local page's load event.
59
68
  window.addEventListener('load', function () {
60
69
  setTimeout(function () {
61
70
  var pending = Array.from(document.querySelectorAll('script[data-miniapp-dev-src]'));
62
71
  function loadNext() {
63
72
  var placeholder = pending.shift();
64
- if (!placeholder || shown) return;
73
+ if (shown) return;
74
+ if (!placeholder) {
75
+ monitoring = true;
76
+ startRecovery();
77
+ return;
78
+ }
65
79
  var script = document.createElement('script');
66
80
  for (var attr of placeholder.attributes) {
67
81
  if (attr.name !== 'type' && attr.name !== 'data-miniapp-dev-src') script.setAttribute(attr.name, attr.value);
@@ -69,11 +83,7 @@
69
83
  script.type = 'module';
70
84
  script.src = placeholder.getAttribute('data-miniapp-dev-src');
71
85
  script.addEventListener('load', loadNext, { once: true });
72
- // Only a failed bootstrap module starts recovery. A loaded page never polls.
73
- script.addEventListener('error', function () {
74
- timer = setInterval(probeConnection, 1000);
75
- probeConnection();
76
- }, { once: true });
86
+ script.addEventListener('error', startRecovery, { once: true });
77
87
  placeholder.replaceWith(script);
78
88
  }
79
89
  loadNext();
package/dist/index.d.mts CHANGED
@@ -10,7 +10,7 @@ interface MiniappEventsConfig {
10
10
  extensions?: string[];
11
11
  }
12
12
  interface MiniappPackageConfig {
13
- /** 未显式指定输出文件时使用的打包目录。默认值:`release`。 */
13
+ /** 未显式指定输出文件时使用的打包目录。默认值:`output`。 */
14
14
  outDir?: string;
15
15
  /** 压缩包文件名,不得包含目录,须以 `.zip` 结尾。默认由清单中的名称和版本经文件名清理后拼接为 `<名称>-<版本>.zip`。 */
16
16
  fileName?: string;
@@ -18,6 +18,11 @@ interface MiniappPackageConfig {
18
18
  /** 构建工具配置,支持配置对象或根据运行环境同步、异步生成配置的函数。 */
19
19
  type MiniappViteConfig = UserConfig | ((env: ConfigEnv) => MaybePromise<UserConfig>);
20
20
  interface MiniappUserConfig {
21
+ /** 开发产物配置;独立于 vite.build.outDir。 */
22
+ dev?: {
23
+ /** 开发输出目录。默认值:`dist`。不能与生产构建目录重叠。 */
24
+ outDir?: string;
25
+ };
21
26
  /** 框架模块列表,按声明顺序从项目依赖中解析并加载,重复模块仅加载一次。 */
22
27
  modules?: string[];
23
28
  /** 微应用清单路径,默认相对于项目根目录。默认值:`manifest.json`。 */
@@ -42,6 +47,7 @@ interface ResolvedMiniappConfig {
42
47
  manifestFile: string;
43
48
  eventsDir: string;
44
49
  eventsExtensions: string[];
50
+ devOutDir: string;
45
51
  packageOutDir: string;
46
52
  packageFileName?: string;
47
53
  vite: UserConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/config.ts","../src/package.ts","../src/validate.ts","../src/vite.ts"],"mappings":";;;;KAIY,aAAa,KAAK,IAAI,QAAQ;UAEzB;;EAEf;;EAEA;;UAGe;;EAEf;;EAEA;;;KAIU,oBACR,eACE,KAAK,cAAc,aAAa;UAErB;;EAEf;;EAEA;;EAEA,SAAS;;EAET,UAAU;;EAEV,OAAO;;UAGQ;;EAEf;;EAEA,MAAM;;;UAIS;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM;;;UAIS;EACf;EACA;EACA,UAAU;EACV;;UAGe;;EAEf;;EAEA;;UAGe,0BAA0B;;EAEzC;;EAEA;;UAGe,8BAA8B;;EAE7C;;EAEA;;;;wBC7Dc,aAAa,QAAQ,oBAAoB;wBAIzC,oBAAoB,QAAQ,gBAAgB;wBA0DtC,kBACpB,uBACA,KAAK,YACJ,QAAQ;;;wBClBW,eACpB,UAAS,wBACR;EAAU;EAAiB;;;;wBCRR,oBAAoB,uBAAuB,QAAQ;wBAoBnD,uBAAuB,uBAAuB,QAAQ;wBAItD,yBACpB,wBACC,QAAQ;;;wBC5CW,aACpB,UAAS,sBACR;EAAU,QAAQ;EAAuB;;wBAYtB,qBACpB,UAAS,sBAAwB,QAAxB;wBAQW,WACpB,UAAS,oBACR,QAAQ"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/config.ts","../src/package.ts","../src/validate.ts","../src/vite.ts"],"mappings":";;;;KAIY,aAAa,KAAK,IAAI,QAAQ;UAEzB;;EAEf;;EAEA;;UAGe;;EAEf;;EAEA;;;KAIU,oBACR,eACE,KAAK,cAAc,aAAa;UAErB;;EAEf;;IAEE;;;EAGF;;EAEA;;EAEA,SAAS;;EAET,UAAU;;EAEV,OAAO;;UAGQ;;EAEf;;EAEA,MAAM;;;UAIS;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM;;;UAIS;EACf;EACA;EACA,UAAU;EACV;;UAGe;;EAEf;;EAEA;;UAGe,0BAA0B;;EAEzC;;EAEA;;UAGe,8BAA8B;;EAE7C;;EAEA;;;;wBCnEc,aAAa,QAAQ,oBAAoB;wBAIzC,oBAAoB,QAAQ,gBAAgB;wBA0DtC,kBACpB,uBACA,KAAK,YACJ,QAAQ;;;wBCSW,eACpB,UAAS,wBACR;EAAU;EAAiB;;;;wBCnCR,oBAAoB,uBAAuB,QAAQ;wBAoBnD,uBAAuB,uBAAuB,QAAQ;wBAItD,yBACpB,wBACC,QAAQ;;;wBC5CW,aACpB,UAAS,sBACR;EAAU,QAAQ;EAAuB;;wBAYtB,qBACpB,UAAS,sBAAwB,QAAxB;wBAQW,WACpB,UAAS,oBACR,QAAQ"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as readMiniappManifest, c as defineConfig, i as validateBuiltMiniapp, l as defineMiniappModule, n as buildMiniapp, o as validateMiniappDirectory, r as devMiniapp, s as validateSourceManifest, t as packageMiniapp, u as loadMiniappConfig } from "./package-DgpqUgd3.mjs";
1
+ import { a as readMiniappManifest, c as defineConfig, i as validateBuiltMiniapp, l as defineMiniappModule, n as buildMiniapp, o as validateMiniappDirectory, r as devMiniapp, s as validateSourceManifest, t as packageMiniapp, u as loadMiniappConfig } from "./package-jNl57UKj.mjs";
2
2
  export { buildMiniapp, defineConfig, defineMiniappModule, devMiniapp, loadMiniappConfig, packageMiniapp, readMiniappManifest, validateBuiltMiniapp, validateMiniappDirectory, validateSourceManifest };
@@ -1,9 +1,9 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { createWriteStream, existsSync } from "node:fs";
3
- import { basename, dirname, isAbsolute, relative, resolve, sep, win32 } from "node:path";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
- import { build, createServer, loadConfigFromFile, mergeConfig, minify, normalizePath } from "vite";
6
- import { copyFile, lstat, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
5
+ import { build, createServer, loadConfigFromFile, mergeConfig, minify } from "vite";
6
+ import { copyFile, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from "node:fs/promises";
7
7
  import { pipeline } from "node:stream/promises";
8
8
  import yazl from "yazl";
9
9
  import miniappPlugin from "@xunlei-open/vite-plugin-miniapp";
@@ -62,15 +62,25 @@ async function loadMiniappConfig(rootDirectory, env) {
62
62
  const config = assertUserConfig(loaded.config, configFile);
63
63
  const eventsExtensions = config.events?.extensions ?? DEFAULT_EVENT_EXTENSIONS;
64
64
  if (eventsExtensions.length === 0) throw new Error("events.extensions must contain at least one file extension");
65
+ const vite = mergeConfig({ build: { outDir: "output" } }, mergeConfig(await loadModules(config.modules ?? [], configFile, env), await resolveViteConfig(config.vite, env)));
66
+ const devOutDir = config.dev?.outDir ?? "dist";
67
+ const devPath = resolve(root, devOutDir);
68
+ const buildPath = resolve(root, vite.build?.outDir ?? "output");
69
+ const contains = (parent, child) => {
70
+ const path = relative(parent, child);
71
+ return path === "" || path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
72
+ };
73
+ if (contains(devPath, buildPath) || contains(buildPath, devPath)) throw new Error("dev.outDir and vite.build.outDir must be separate directories, neither containing the other");
65
74
  return {
66
75
  root,
67
76
  configFile,
68
77
  manifestFile: config.manifest ?? "manifest.json",
69
78
  eventsDir: config.events?.dir ?? "src/events",
70
79
  eventsExtensions,
71
- packageOutDir: config.package?.outDir ?? "release",
80
+ devOutDir,
81
+ packageOutDir: config.package?.outDir ?? "output",
72
82
  packageFileName: config.package?.fileName,
73
- vite: mergeConfig(await loadModules(config.modules ?? [], configFile, env), await resolveViteConfig(config.vite, env))
83
+ vite
74
84
  };
75
85
  }
76
86
  //#endregion
@@ -303,13 +313,104 @@ function localDevEntry(root, outDir, manifestFile, manifest) {
303
313
  };
304
314
  }
305
315
  //#endregion
316
+ //#region src/event-output.ts
317
+ /** Event entries are replaceable; dependencies are immutable for the dev session. */
318
+ function eventOutput(outDir, protectedFiles) {
319
+ const root = resolve(outDir);
320
+ const key = (name) => name.toLowerCase();
321
+ const protectedNames = new Set(protectedFiles.map(key));
322
+ let previousEntries = /* @__PURE__ */ new Map();
323
+ function target(name) {
324
+ if (!name || isAbsolute(name) || name.includes("\\") || name.includes(":") || name.split("/").some((part) => !part || part === "." || part === ".." || /[. ]$/.test(part))) throw new Error(`Event build emitted an invalid output path: ${name}`);
325
+ const path = resolve(root, name);
326
+ const rel = relative(root, path);
327
+ if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw new Error(`Event build emitted a file outside the output directory: ${name}`);
328
+ return path;
329
+ }
330
+ async function checkPath(path) {
331
+ for (let current = path;; current = dirname(current)) {
332
+ if ((await lstat(current).catch((error) => {
333
+ if (error.code === "ENOENT") return void 0;
334
+ throw error;
335
+ }))?.isSymbolicLink()) throw new Error(`Event output contains a symbolic link: ${current}`);
336
+ if (current === root) break;
337
+ }
338
+ }
339
+ async function existing(path) {
340
+ return readFile(path).catch((error) => {
341
+ if (error.code === "ENOENT") return void 0;
342
+ throw error;
343
+ });
344
+ }
345
+ return async (files, entries, requiredEntries) => {
346
+ const names = /* @__PURE__ */ new Set();
347
+ const contents = /* @__PURE__ */ new Map();
348
+ const unchanged = /* @__PURE__ */ new Set();
349
+ for (const [name, content] of files) {
350
+ target(name);
351
+ if (protectedNames.has(key(name))) throw new Error(`Event build would overwrite a protected file: ${name}`);
352
+ if (names.has(key(name))) throw new Error(`Event build emitted conflicting output names: ${name}`);
353
+ names.add(key(name));
354
+ contents.set(name, Buffer.from(content));
355
+ }
356
+ for (const entry of entries) if (!entry.startsWith("events/") || !files.has(entry)) throw new Error(`Invalid event entry: ${entry}`);
357
+ for (const entry of requiredEntries) {
358
+ const name = relative(root, resolve(root, entry)).split(sep).join("/");
359
+ if (!entries.has(name)) throw new Error(`manifest script "${entry}" has no built event entry`);
360
+ }
361
+ for (const [name, bytes] of contents) {
362
+ const path = target(name);
363
+ await checkPath(path);
364
+ const old = await existing(path);
365
+ if (old?.equals(bytes)) unchanged.add(name);
366
+ if (old && !old.equals(bytes)) {
367
+ if (!entries.has(name)) throw new Error(`Event output conflicts with an existing file: ${name}. Use content-hashed dependency filenames.`);
368
+ const owned = previousEntries.get(name);
369
+ if (owned && !owned.equals(old)) throw new Error(`Event entry was modified outside the event build: ${name}`);
370
+ }
371
+ }
372
+ for (const [name, bytes] of previousEntries) {
373
+ if (entries.has(name)) continue;
374
+ await checkPath(target(name));
375
+ const old = await existing(target(name));
376
+ if (old && !old.equals(bytes)) throw new Error(`Event entry was modified outside the event build: ${name}`);
377
+ }
378
+ await mkdir(root, { recursive: true });
379
+ const staging = await mkdtemp(join(root, ".miniapp-events-"));
380
+ const staged = [];
381
+ try {
382
+ const ordered = [...contents].filter(([name]) => !unchanged.has(name)).sort(([a], [b]) => Number(entries.has(a)) - Number(entries.has(b)));
383
+ for (const [index, [, bytes]] of ordered.entries()) {
384
+ const path = join(staging, String(index));
385
+ staged.push(path);
386
+ await writeFile(path, bytes);
387
+ }
388
+ for (const [index, [name]] of ordered.entries()) {
389
+ const path = target(name);
390
+ await mkdir(dirname(path), { recursive: true });
391
+ await rename(staged[index], path);
392
+ }
393
+ for (const name of previousEntries.keys()) if (!entries.has(name)) await rm(target(name), { force: true });
394
+ previousEntries = new Map([...contents].filter(([name]) => entries.has(name)));
395
+ } finally {
396
+ for (const path of staged) await rm(path, { force: true });
397
+ await rmdir(staging);
398
+ }
399
+ };
400
+ }
401
+ //#endregion
306
402
  //#region src/dev-events.ts
307
403
  /** Build sandbox scripts on disk independently from the page's Vite HMR graph. */
308
404
  function devEvents(config, outDir, manifest, mode) {
309
405
  const eventsDir = resolve(config.root, config.eventsDir);
310
406
  let server;
311
407
  let dependencies = /* @__PURE__ */ new Set();
312
- let outputs = /* @__PURE__ */ new Set();
408
+ const publish = eventOutput(outDir, [
409
+ "manifest.json",
410
+ "index.html",
411
+ ...manifest.entry ? [manifest.entry.url] : [],
412
+ ...manifest.icon ? [manifest.icon] : []
413
+ ]);
313
414
  let pending = Promise.resolve();
314
415
  let stopped = false;
315
416
  let failed = false;
@@ -320,6 +421,16 @@ function devEvents(config, outDir, manifest, mode) {
320
421
  })).some((source) => source.isFile() && !source.name.endsWith(".d.ts") && config.eventsExtensions.some((ext) => source.name.endsWith(ext)));
321
422
  const nextDependencies = /* @__PURE__ */ new Set();
322
423
  const files = /* @__PURE__ */ new Map();
424
+ const entries = /* @__PURE__ */ new Set();
425
+ const trackDependencies = () => ({
426
+ name: "miniapp-dev-events-dependencies",
427
+ generateBundle() {
428
+ for (const file of this.getModuleIds()) {
429
+ const path = file.split("?")[0];
430
+ if (isAbsolute(path)) nextDependencies.add(resolve(path));
431
+ }
432
+ }
433
+ });
323
434
  if (hasEntries) {
324
435
  const eventConfig = await loadMiniappConfig(config.root, {
325
436
  command: "build",
@@ -335,6 +446,10 @@ function devEvents(config, outDir, manifest, mode) {
335
446
  mode,
336
447
  publicDir: false,
337
448
  logLevel: "warn",
449
+ worker: {
450
+ ...eventConfig.vite.worker,
451
+ plugins: () => [...eventConfig.vite.worker?.plugins?.() ?? [], trackDependencies()]
452
+ },
338
453
  plugins: [
339
454
  ...eventConfig.vite.plugins ?? [],
340
455
  miniappPlugin({
@@ -342,15 +457,7 @@ function devEvents(config, outDir, manifest, mode) {
342
457
  eventsDir: config.eventsDir,
343
458
  eventsExtensions: config.eventsExtensions
344
459
  }),
345
- {
346
- name: "miniapp-dev-events-output",
347
- generateBundle() {
348
- for (const file of this.getModuleIds()) {
349
- const path = file.split("?")[0];
350
- if (isAbsolute(path)) nextDependencies.add(resolve(path));
351
- }
352
- }
353
- }
460
+ trackDependencies()
354
461
  ],
355
462
  build: {
356
463
  ...options,
@@ -376,26 +483,16 @@ function devEvents(config, outDir, manifest, mode) {
376
483
  });
377
484
  for (const bundle of Array.isArray(result) ? result : [result]) {
378
485
  if (!("output" in bundle)) throw new Error("Unexpected event build watcher");
379
- for (const file of bundle.output) files.set(file.fileName, file.type === "chunk" ? file.code : file.source);
486
+ for (const file of bundle.output) {
487
+ if (files.has(file.fileName)) throw new Error(`Event build emitted duplicate output: ${file.fileName}`);
488
+ files.set(file.fileName, file.type === "chunk" ? file.code : file.source);
489
+ if (file.type === "chunk" && file.isEntry) entries.add(file.fileName);
490
+ }
380
491
  }
381
492
  }
382
493
  dependencies = nextDependencies;
383
494
  server.watcher.add([...dependencies]);
384
- for (const name of files.keys()) {
385
- const path = normalizePath(relative(outDir, resolve(outDir, name)));
386
- if (!path.startsWith("events/") || path.includes("../")) throw new Error(`Event build emitted a file outside events/: ${name}`);
387
- }
388
- for (const [name, content] of files) {
389
- const path = resolve(outDir, name);
390
- await mkdir(dirname(path), { recursive: true });
391
- await writeFile(path, content);
392
- }
393
- for (const name of outputs) if (!files.has(name)) await rm(resolve(outDir, name), { force: true });
394
- outputs = new Set(files.keys());
395
- for (const script of manifest.scripts ?? []) {
396
- const entry = normalizePath(relative(outDir, resolve(outDir, script.entry)));
397
- if (!outputs.has(entry)) throw new Error(`manifest script "${script.entry}" has no built event entry. Add its source to ${config.eventsDir}.`);
398
- }
495
+ await publish(files, entries, (manifest.scripts ?? []).map((script) => script.entry));
399
496
  if (hasEntries) server.config.logger.info("[miniapp] Event scripts built. Reload the application in the host if it caches scripts.");
400
497
  }
401
498
  function onChange(event, file) {
@@ -460,7 +557,7 @@ function createInlineConfig(config) {
460
557
  });
461
558
  }
462
559
  function resolveOutputDirectory(config) {
463
- return resolve(config.root, config.vite.build?.outDir ?? "dist");
560
+ return resolve(config.root, config.vite.build?.outDir ?? "output");
464
561
  }
465
562
  async function buildMiniapp(options = {}) {
466
563
  const config = await loadMiniappConfig(options.root ?? process.cwd(), configEnv("build", options.mode ?? "production"));
@@ -481,7 +578,14 @@ async function devMiniapp(options = {}) {
481
578
  const config = await loadMiniappConfig(root, configEnv("serve", mode));
482
579
  const manifest = await validateSourceManifest(resolve(config.root, config.manifestFile));
483
580
  const inlineConfig = createInlineConfig(config);
484
- const outDir = resolveOutputDirectory(config);
581
+ const outDir = resolve(config.root, config.devOutDir);
582
+ inlineConfig.server = {
583
+ ...inlineConfig.server,
584
+ watch: {
585
+ ...inlineConfig.server?.watch,
586
+ ignored: [...Array.isArray(inlineConfig.server?.watch?.ignored) ? inlineConfig.server.watch.ignored : inlineConfig.server?.watch?.ignored ? [inlineConfig.server.watch.ignored] : [], `${outDir.replaceAll("\\", "/")}/**`]
587
+ }
588
+ };
485
589
  const devEntry = localDevEntry(config.root, outDir, config.manifestFile, manifest);
486
590
  const events = devEvents(config, outDir, manifest, mode);
487
591
  inlineConfig.plugins = [
@@ -534,9 +638,12 @@ function resolveArchivePath(config, manifest, explicitPath) {
534
638
  }
535
639
  async function writeZip(directory, files, outFile) {
536
640
  await mkdir(dirname(outFile), { recursive: true });
641
+ const staging = await mkdtemp(resolve(dirname(outFile), ".miniapp-package-"));
642
+ const temporaryArchive = resolve(staging, "package.zip");
537
643
  const archive = new yazl.ZipFile();
538
- const output = createWriteStream(outFile);
644
+ const output = createWriteStream(temporaryArchive);
539
645
  const completed = pipeline(archive.outputStream, output);
646
+ completed.catch(() => {});
540
647
  try {
541
648
  for (const file of files) archive.addFile(resolve(directory, file), file, {
542
649
  mtime: ZIP_DATE,
@@ -545,11 +652,33 @@ async function writeZip(directory, files, outFile) {
545
652
  });
546
653
  archive.end();
547
654
  await completed;
655
+ await rename(temporaryArchive, outFile);
548
656
  } catch (error) {
549
- await rm(outFile, { force: true });
657
+ output.destroy();
658
+ await completed.catch(() => {});
550
659
  throw error;
660
+ } finally {
661
+ await rm(temporaryArchive, { force: true });
662
+ await rmdir(staging);
551
663
  }
552
664
  }
665
+ async function removeBuildFiles(directory, files) {
666
+ const directories = /* @__PURE__ */ new Set();
667
+ for (const file of files) {
668
+ const path = resolve(directory, file);
669
+ const rel = relative(directory, path);
670
+ if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) throw new Error(`Cannot clean a file outside the build output: ${file}`);
671
+ await rm(path, { force: true });
672
+ for (let parent = dirname(path); parent !== directory; parent = dirname(parent)) directories.add(parent);
673
+ }
674
+ for (const path of [...directories].sort((a, b) => b.length - a.length)) await rmdir(path).catch((error) => {
675
+ if (![
676
+ "ENOENT",
677
+ "ENOTEMPTY",
678
+ "EEXIST"
679
+ ].includes(error.code)) throw error;
680
+ });
681
+ }
553
682
  async function packageMiniapp(options = {}) {
554
683
  let config;
555
684
  let outDir;
@@ -565,9 +694,11 @@ async function packageMiniapp(options = {}) {
565
694
  }
566
695
  const validated = await validateMiniappDirectory(outDir);
567
696
  const outFile = resolveArchivePath(config, validated.manifest, options.outFile);
568
- const archiveRelativeToOutput = relative(outDir, outFile);
569
- if (archiveRelativeToOutput === "" || !archiveRelativeToOutput.startsWith(`..${sep}`) && archiveRelativeToOutput !== "..") throw new Error("Package output must be outside the build output directory");
570
- await writeZip(outDir, validated.files, outFile);
697
+ const archiveRelativeToDev = relative(resolve(config.root, config.devOutDir), outFile);
698
+ if (archiveRelativeToDev === "" || archiveRelativeToDev !== ".." && !archiveRelativeToDev.startsWith(`..${sep}`) && !isAbsolute(archiveRelativeToDev)) throw new Error("Package output must be outside the development output directory");
699
+ const files = validated.files.filter((file) => relative(resolve(outDir, file), outFile) !== "");
700
+ await writeZip(outDir, files, outFile);
701
+ if (options.build ?? true) await removeBuildFiles(outDir, files);
571
702
  return {
572
703
  outFile,
573
704
  outDir
@@ -576,4 +707,4 @@ async function packageMiniapp(options = {}) {
576
707
  //#endregion
577
708
  export { readMiniappManifest as a, defineConfig as c, validateBuiltMiniapp as i, defineMiniappModule as l, buildMiniapp as n, validateMiniappDirectory as o, devMiniapp as r, validateSourceManifest as s, packageMiniapp as t, loadMiniappConfig as u };
578
709
 
579
- //# sourceMappingURL=package-DgpqUgd3.mjs.map
710
+ //# sourceMappingURL=package-jNl57UKj.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-jNl57UKj.mjs","names":["viteBuild"],"sources":["../src/config.ts","../src/validate.ts","../src/dev-entry.ts","../src/event-output.ts","../src/dev-events.ts","../src/vite.ts","../src/package.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { isAbsolute, relative, resolve, sep } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { loadConfigFromFile, mergeConfig, type ConfigEnv, type UserConfig } from 'vite'\nimport type {\n MiniappModule,\n MiniappUserConfig,\n ResolvedMiniappConfig,\n} from './types.js'\n\nconst CONFIG_FILES = [\n 'miniapp.config.ts',\n 'miniapp.config.mts',\n 'miniapp.config.js',\n 'miniapp.config.mjs',\n 'miniapp.config.cts',\n 'miniapp.config.cjs',\n] as const\n\nconst DEFAULT_EVENT_EXTENSIONS = ['.ts', '.js']\n\nexport function defineConfig(config: MiniappUserConfig): MiniappUserConfig {\n return config\n}\n\nexport function defineMiniappModule(module: MiniappModule): MiniappModule {\n return module\n}\n\nasync function loadModules(names: string[], configFile: string, env: ConfigEnv): Promise<UserConfig> {\n if (!Array.isArray(names) || names.some(name => typeof name !== 'string' || !name.trim())) {\n throw new Error('miniapp.config modules must be an array of module names')\n }\n const require = createRequire(configFile)\n let config: UserConfig = {}\n for (const name of new Set(names)) {\n try {\n const { default: module } = await import(pathToFileURL(require.resolve(name)).href)\n if (!module || typeof module !== 'object' || typeof module.name !== 'string' || !module.vite) {\n throw new Error('must export a MiniappModule with name and vite fields')\n }\n config = mergeConfig(config, await resolveViteConfig(module.vite, env))\n } catch (error) {\n throw new Error(`Failed to load miniapp module \"${name}\" from ${configFile}: ${error instanceof Error ? error.message : String(error)}`, { cause: error })\n }\n }\n return config\n}\n\nfunction findConfigFile(root: string): string {\n const matches = CONFIG_FILES.map((file) => resolve(root, file)).filter(existsSync)\n\n if (matches.length === 0) {\n throw new Error(`No miniapp.config file found in ${root}`)\n }\n if (matches.length > 1) {\n throw new Error(\n `Multiple miniapp config files found: ${matches.map((file) => file.split('/').at(-1)).join(', ')}`,\n )\n }\n\n return matches[0]!\n}\n\nfunction assertUserConfig(value: unknown, configFile: string): MiniappUserConfig {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`${configFile} must export a configuration object`)\n }\n return value as MiniappUserConfig\n}\n\nasync function resolveViteConfig(\n vite: MiniappUserConfig['vite'],\n env: ConfigEnv,\n): Promise<UserConfig> {\n if (!vite) return {}\n const config = typeof vite === 'function' ? await vite(env) : vite\n if (typeof config !== 'object' || config === null || Array.isArray(config)) {\n throw new Error('miniapp.config vite must resolve to a Vite configuration object')\n }\n return config\n}\n\nexport async function loadMiniappConfig(\n rootDirectory: string,\n env: ConfigEnv,\n): Promise<ResolvedMiniappConfig> {\n const root = resolve(rootDirectory)\n const configFile = findConfigFile(root)\n const loaded = await loadConfigFromFile(env, configFile, root)\n\n if (!loaded) {\n throw new Error(`Failed to load ${configFile}`)\n }\n\n const config = assertUserConfig(loaded.config, configFile)\n const eventsExtensions = config.events?.extensions ?? DEFAULT_EVENT_EXTENSIONS\n\n if (eventsExtensions.length === 0) {\n throw new Error('events.extensions must contain at least one file extension')\n }\n\n const vite = mergeConfig(\n { build: { outDir: 'output' } },\n mergeConfig(\n await loadModules(config.modules ?? [], configFile, env),\n await resolveViteConfig(config.vite, env),\n ),\n )\n const devOutDir = config.dev?.outDir ?? 'dist'\n const devPath = resolve(root, devOutDir)\n const buildPath = resolve(root, vite.build?.outDir ?? 'output')\n const contains = (parent: string, child: string) => {\n const path = relative(parent, child)\n return path === '' || (path !== '..' && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n }\n if (contains(devPath, buildPath) || contains(buildPath, devPath)) {\n throw new Error('dev.outDir and vite.build.outDir must be separate directories, neither containing the other')\n }\n\n return {\n root,\n configFile,\n manifestFile: config.manifest ?? 'manifest.json',\n eventsDir: config.events?.dir ?? 'src/events',\n eventsExtensions,\n devOutDir,\n packageOutDir: config.package?.outDir ?? 'output',\n packageFileName: config.package?.fileName,\n vite,\n }\n}\n","import { lstat, readFile, readdir } from 'node:fs/promises'\nimport { isAbsolute, relative, resolve, sep, win32 } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport type { MiniappValidationResult } from './types.js'\n\nfunction assertNonEmptyString(value: unknown, field: string): asserts value is string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new Error(`manifest.${field} must be a non-empty string`)\n }\n}\n\nfunction resolvePackagePath(directory: string, value: string, field: string): string {\n if (isAbsolute(value) || win32.isAbsolute(value)) {\n throw new Error(`manifest.${field} must be relative to the package root`)\n }\n\n const target = resolve(directory, value)\n const relativePath = relative(directory, target)\n if (relativePath === '..' || relativePath.startsWith(`..${sep}`)) {\n throw new Error(`manifest.${field} points outside the package root`)\n }\n return target\n}\n\nasync function assertPackageFile(\n directory: string,\n value: unknown,\n field: string,\n): Promise<void> {\n assertNonEmptyString(value, field)\n const target = resolvePackagePath(directory, value, field)\n let stat\n try {\n stat = await lstat(target)\n } catch {\n throw new Error(`manifest.${field} points to a missing file: ${value}`)\n }\n if (!stat.isFile() || stat.isSymbolicLink()) {\n throw new Error(`manifest.${field} must point to a regular package file: ${value}`)\n }\n}\n\nasync function collectFiles(directory: string, current = directory): Promise<string[]> {\n const entries = await readdir(current, { withFileTypes: true })\n const files: string[] = []\n\n for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n const absolutePath = resolve(current, entry.name)\n const packagePath = relative(directory, absolutePath).split(sep).join('/')\n\n if (entry.isSymbolicLink()) {\n throw new Error(`Package must not contain symbolic links: ${packagePath}`)\n }\n if (entry.isDirectory()) {\n files.push(...(await collectFiles(directory, absolutePath)))\n continue\n }\n if (entry.isFile()) files.push(packagePath)\n }\n\n return files\n}\n\nexport async function readMiniappManifest(manifestPath: string): Promise<MiniappManifest> {\n let value: unknown\n try {\n value = JSON.parse(await readFile(manifestPath, 'utf8'))\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`Unable to read manifest: ${reason}`)\n }\n\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error('manifest.json must contain a JSON object')\n }\n\n const manifest = value as MiniappManifest\n assertNonEmptyString(manifest.name, 'name')\n assertNonEmptyString(manifest.title, 'title')\n assertNonEmptyString(manifest.version, 'version')\n return manifest\n}\n\nexport async function validateSourceManifest(manifestPath: string): Promise<MiniappManifest> {\n return readMiniappManifest(manifestPath)\n}\n\nexport async function validateMiniappDirectory(\n directoryPath: string,\n): Promise<MiniappValidationResult> {\n const directory = resolve(directoryPath)\n const directoryStat = await lstat(directory).catch(() => undefined)\n if (!directoryStat?.isDirectory()) {\n throw new Error(`Miniapp output directory does not exist: ${directory}`)\n }\n\n const manifestPath = resolve(directory, 'manifest.json')\n const manifest = await readMiniappManifest(manifestPath)\n\n if (manifest.icon !== undefined) {\n await assertPackageFile(directory, manifest.icon, 'icon')\n }\n if (manifest.entry && (manifest.entry.type ?? 'miniapp') === 'miniapp') {\n await assertPackageFile(directory, manifest.entry.url, 'entry.url')\n const html = await readFile(resolve(directory, manifest.entry.url), 'utf8')\n if (html.startsWith('<!-- miniapp-dev-entry:')) {\n throw new Error('Output contains a development entry. Run build before validating or packaging.')\n }\n }\n for (const [index, script] of (manifest.scripts ?? []).entries()) {\n await assertPackageFile(directory, script.entry, `scripts[${index}].entry`)\n }\n\n const files = await collectFiles(directory)\n const sourcemap = files.find((file) => file.endsWith('.map'))\n if (sourcemap) {\n throw new Error(`Package must not contain sourcemaps: ${sourcemap}`)\n }\n const dependency = files.find((file) => file.split('/').includes('node_modules'))\n if (dependency) {\n throw new Error(`Package must not contain node_modules: ${dependency}`)\n }\n\n return { directory, manifestPath, manifest, files }\n}\n","import { createHash } from 'node:crypto'\nimport { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep, win32 } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport { minify, type Plugin, type ViteDevServer } from 'vite'\nimport { parse, parseFragment, serialize, type DefaultTreeAdapterMap } from 'parse5'\n\nfunction localPath(root: string, file: string): string {\n const target = resolve(root, file)\n const rel = relative(root, target)\n if (isAbsolute(file) || win32.isAbsolute(file) || rel === '..' || rel.startsWith(`..${sep}`)) {\n throw new Error(`Miniapp development entry must stay inside its directory: ${file}`)\n }\n return target\n}\n\nexport function localDevEntry(\n root: string,\n outDir: string,\n manifestFile: string,\n manifest: MiniappManifest,\n) {\n const entry = manifest.entry?.url\n if (manifest.entry && (manifest.entry.type ?? 'miniapp') !== 'miniapp') {\n throw new Error('Local HMR requires a miniapp HTML entry')\n }\n const source = entry ? localPath(root, entry) : undefined\n const output = entry ? localPath(outDir, entry) : undefined\n const iconSource = manifest.icon ? localPath(root, manifest.icon) : undefined\n const iconOutput = manifest.icon ? localPath(outDir, manifest.icon) : undefined\n let iconUpdates = Promise.resolve()\n let stopped = false\n const rootFromOutput = relative(outDir, root)\n if (!rootFromOutput || (!rootFromOutput.startsWith(`..${sep}`) && rootFromOutput !== '..' && !isAbsolute(rootFromOutput))) {\n throw new Error('Development output must not be the project root or its parent')\n }\n let server: ViteDevServer\n let entryUrl: string | undefined\n let pagePath: string\n const inlineModules = new Map<string, string>()\n let clientCode: Promise<string> | undefined\n\n function loadClientCode() {\n return clientCode ??= readFile(new URL('./dev-client.js', import.meta.url), 'utf8')\n .then(code => minify('dev-client.js', code))\n .then(result => result.code.trim().replace(/<\\/script/gi, '<\\\\/script'))\n }\n\n async function copyIcon() {\n if (!iconSource || !iconOutput) return\n await mkdir(dirname(iconOutput), { recursive: true })\n await copyFile(iconSource, iconOutput)\n }\n\n function onIconChange(event: string, file: string) {\n if (stopped || !iconSource || resolve(file) !== iconSource) return\n if (!['add', 'change', 'unlink'].includes(event)) return\n iconUpdates = iconUpdates.then(async () => {\n if (stopped) return\n if (event === 'unlink') await rm(iconOutput!, { force: true })\n else await copyIcon()\n server.config.logger.info('[miniapp] Manifest icon updated. Reload the application in the host to refresh its icon.')\n }).catch(error => {\n server.config.logger.error(`[miniapp] Icon sync failed: ${error instanceof Error ? error.message : String(error)}`)\n })\n }\n\n function rewriteEntry(html: string, bootstrap: string): string {\n const document = parse(html)\n const modules = new Map<string, string>()\n function visit(node: DefaultTreeAdapterMap['node']) {\n if ('tagName' in node) {\n for (const attr of node.attrs) {\n if (attr.name === 'src' || attr.name === 'poster' ||\n (attr.name === 'href' && ['link', 'image', 'use'].includes(node.tagName)) ||\n (attr.name === 'data' && node.tagName === 'object')) {\n if (attr.value && !attr.value.startsWith('#')) attr.value = new URL(attr.value, entryUrl).href\n }\n }\n if (node.tagName === 'script' &&\n node.attrs.some(attr => attr.name === 'type' && attr.value.toLowerCase() === 'module') &&\n !node.attrs.some(attr => attr.name === 'src')) {\n // Framework-injected preambles must resolve imports against HTTP, not file://.\n const code = node.childNodes.map(child => 'value' in child ? child.value : '').join('')\n const hash = createHash('sha256').update(code).digest('hex').slice(0, 16)\n const url = new URL(`./@miniapp-dev/inline-${modules.size}-${hash}.js`, entryUrl)\n const id = url.pathname.slice(server.config.base.length - 1)\n modules.set(id, code)\n node.childNodes = []\n node.attrs.push({ name: 'src', value: url.href })\n }\n if (node.tagName === 'script' &&\n node.attrs.some(attr => attr.name === 'type' && attr.value.toLowerCase() === 'module') &&\n node.attrs.some(attr => attr.name === 'src' && new URL(attr.value, entryUrl).origin === new URL(entryUrl!).origin)) {\n node.attrs.push({ name: 'data-miniapp-dev-module', value: '' })\n // Inert placeholders do not hold DOMContentLoaded or window.load open.\n node.attrs.find(attr => attr.name === 'type')!.value = 'application/x-miniapp-dev-module'\n node.attrs.find(attr => attr.name === 'src')!.name = 'data-miniapp-dev-src'\n }\n }\n if ('childNodes' in node) node.childNodes.forEach(visit)\n if ('content' in node) visit(node.content as DefaultTreeAdapterMap['documentFragment'])\n }\n visit(document)\n const htmlNode = document.childNodes.find(node => 'tagName' in node && node.tagName === 'html') as DefaultTreeAdapterMap['element']\n const head = htmlNode.childNodes.find(node => 'tagName' in node && node.tagName === 'head') as DefaultTreeAdapterMap['element']\n const script = parseFragment(`<script data-miniapp-dev-load-error>${bootstrap}</script>`).childNodes[0] as DefaultTreeAdapterMap['element']\n script.attrs.push({ name: 'data-miniapp-dev-probe', value: new URL(server.config.base, entryUrl).href })\n script.parentNode = head\n head.childNodes.unshift(script)\n inlineModules.clear()\n for (const [path, code] of modules) inlineModules.set(path, code)\n return serialize(document)\n }\n\n async function writeEntry() {\n if (!source || !output) return\n const html = await server.transformIndexHtml(pagePath, await readFile(source, 'utf8'))\n await mkdir(dirname(output), { recursive: true })\n await writeFile(output, `<!-- miniapp-dev-entry: run build before packaging -->\\n${rewriteEntry(html, await loadClientCode())}`)\n // Remove only bootstrap files generated by the previous external-script version.\n const oldClient = resolve(dirname(output), 'miniapp-dev-client.js')\n const oldCode = await readFile(oldClient, 'utf8').catch(() => '')\n if (oldCode.startsWith('// Local development bootstrap: must work without the dev server.')) {\n await rm(oldClient, { force: true })\n }\n }\n\n const plugin: Plugin = {\n name: 'miniapp-local-dev-entry',\n apply: 'serve',\n async closeBundle() {\n stopped = true\n server?.watcher.off('all', onIconChange)\n await iconUpdates\n },\n resolveId(id) {\n if (inlineModules.has(id.split('?')[0]!)) return id\n },\n load(id) {\n return inlineModules.get(id.split('?')[0]!)\n },\n async handleHotUpdate(context) {\n if (resolve(context.file) !== source) return\n await writeEntry()\n // Vite's HTML reload filter otherwise compares against the file:// pathname.\n context.server.ws.send({ type: 'full-reload', path: '*' })\n return []\n },\n }\n\n return {\n plugin,\n async write(devServer: ViteDevServer) {\n server = devServer\n await mkdir(outDir, { recursive: true })\n if (entry) {\n const url = server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0]\n if (!url) throw new Error('Cannot determine the Vite development server URL')\n server.config.server.origin ??= new URL(url).origin\n entryUrl = new URL(entry.replaceAll('\\\\', '/'), url).href\n pagePath = new URL(entryUrl).pathname\n await writeEntry()\n }\n await copyFile(resolve(root, manifestFile), resolve(outDir, 'manifest.json'))\n await copyIcon()\n if (iconSource) {\n server.watcher.add(iconSource)\n server.watcher.on('all', onIconChange)\n }\n },\n }\n}\n","import { lstat, mkdir, mkdtemp, readFile, rename, rm, rmdir, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'\n\nexport type EventFiles = Map<string, string | Uint8Array>\n\n/** Event entries are replaceable; dependencies are immutable for the dev session. */\nexport function eventOutput(outDir: string, protectedFiles: string[]) {\n const root = resolve(outDir)\n const key = (name: string) => name.toLowerCase()\n const protectedNames = new Set(protectedFiles.map(key))\n let previousEntries = new Map<string, Buffer>()\n\n function target(name: string) {\n if (!name || isAbsolute(name) || name.includes('\\\\') || name.includes(':')\n || name.split('/').some(part => !part || part === '.' || part === '..' || /[. ]$/.test(part))) {\n throw new Error(`Event build emitted an invalid output path: ${name}`)\n }\n const path = resolve(root, name)\n const rel = relative(root, path)\n if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {\n throw new Error(`Event build emitted a file outside the output directory: ${name}`)\n }\n return path\n }\n\n async function checkPath(path: string) {\n // Do not allow symlinks/junctions to bypass the output-directory boundary.\n for (let current = path; ; current = dirname(current)) {\n const stat = await lstat(current).catch(error => {\n if (error.code === 'ENOENT') return undefined\n throw error\n })\n if (stat?.isSymbolicLink()) throw new Error(`Event output contains a symbolic link: ${current}`)\n if (current === root) break\n }\n }\n\n async function existing(path: string) {\n return readFile(path).catch(error => {\n if (error.code === 'ENOENT') return undefined\n throw error\n })\n }\n\n return async (files: EventFiles, entries: Set<string>, requiredEntries: string[]) => {\n const names = new Set<string>()\n const contents = new Map<string, Buffer>()\n const unchanged = new Set<string>()\n // Validate the entire result before publishing any part of it.\n for (const [name, content] of files) {\n target(name)\n if (protectedNames.has(key(name))) throw new Error(`Event build would overwrite a protected file: ${name}`)\n if (names.has(key(name))) throw new Error(`Event build emitted conflicting output names: ${name}`)\n names.add(key(name))\n contents.set(name, Buffer.from(content))\n }\n for (const entry of entries) {\n if (!entry.startsWith('events/') || !files.has(entry)) throw new Error(`Invalid event entry: ${entry}`)\n }\n for (const entry of requiredEntries) {\n const name = relative(root, resolve(root, entry)).split(sep).join('/')\n if (!entries.has(name)) throw new Error(`manifest script \"${entry}\" has no built event entry`)\n }\n for (const [name, bytes] of contents) {\n const path = target(name)\n await checkPath(path)\n const old = await existing(path)\n if (old?.equals(bytes)) unchanged.add(name)\n if (old && !old.equals(bytes)) {\n if (!entries.has(name)) throw new Error(`Event output conflicts with an existing file: ${name}. Use content-hashed dependency filenames.`)\n const owned = previousEntries.get(name)\n if (owned && !owned.equals(old)) throw new Error(`Event entry was modified outside the event build: ${name}`)\n }\n }\n // A removed entry is ours only while its bytes still match what we published.\n for (const [name, bytes] of previousEntries) {\n if (entries.has(name)) continue\n await checkPath(target(name))\n const old = await existing(target(name))\n if (old && !old.equals(bytes)) throw new Error(`Event entry was modified outside the event build: ${name}`)\n }\n\n await mkdir(root, { recursive: true })\n const staging = await mkdtemp(join(root, '.miniapp-events-'))\n const staged: string[] = []\n try {\n const ordered = [...contents].filter(([name]) => !unchanged.has(name))\n .sort(([a], [b]) => Number(entries.has(a)) - Number(entries.has(b)))\n for (const [index, [, bytes]] of ordered.entries()) {\n const path = join(staging, String(index))\n staged.push(path)\n await writeFile(path, bytes)\n }\n // Publish dependencies first, then atomically replace each entry file.\n for (const [index, [name]] of ordered.entries()) {\n const path = target(name)\n await mkdir(dirname(path), { recursive: true })\n await rename(staged[index]!, path)\n }\n for (const name of previousEntries.keys()) {\n if (!entries.has(name)) await rm(target(name), { force: true })\n }\n previousEntries = new Map([...contents].filter(([name]) => entries.has(name)))\n // Keep old dependencies: an already-running event/Worker may still import them.\n } finally {\n for (const path of staged) await rm(path, { force: true })\n await rmdir(staging)\n }\n }\n}\n","import { readdir } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport miniappPlugin from '@xunlei-open/vite-plugin-miniapp'\nimport { build, type Plugin, type ViteDevServer } from 'vite'\nimport { eventOutput } from './event-output.js'\nimport { loadMiniappConfig } from './config.js'\nimport type { ResolvedMiniappConfig } from './types.js'\n\n/** Build sandbox scripts on disk independently from the page's Vite HMR graph. */\nexport function devEvents(config: ResolvedMiniappConfig, outDir: string, manifest: MiniappManifest, mode: string) {\n const eventsDir = resolve(config.root, config.eventsDir)\n let server: ViteDevServer\n let dependencies = new Set<string>()\n const publish = eventOutput(outDir, ['manifest.json', 'index.html',\n ...(manifest.entry ? [manifest.entry.url] : []),\n ...(manifest.icon ? [manifest.icon] : []),\n ])\n let pending = Promise.resolve()\n let stopped = false\n let failed = false\n\n async function rebuild() {\n const sources = await readdir(eventsDir, { withFileTypes: true }).catch(error => {\n if (error.code === 'ENOENT') return []\n throw error\n })\n const hasEntries = sources.some(source => source.isFile()\n && !source.name.endsWith('.d.ts')\n && config.eventsExtensions.some(ext => source.name.endsWith(ext)))\n const nextDependencies = new Set<string>()\n const files = new Map<string, string | Uint8Array>()\n const entries = new Set<string>()\n const trackDependencies = (): Plugin => ({\n name: 'miniapp-dev-events-dependencies',\n generateBundle() {\n for (const file of this.getModuleIds()) {\n const path = file.split('?')[0]!\n if (isAbsolute(path)) nextDependencies.add(resolve(path))\n }\n },\n })\n if (hasEntries) {\n // Vite plugins can hold server state. Never reuse the live page's instances.\n const eventConfig = await loadMiniappConfig(config.root, {\n command: 'build', mode, isSsrBuild: false, isPreview: false,\n })\n const options = eventConfig.vite.build\n const result = await build({\n ...eventConfig.vite,\n root: config.root,\n configFile: false,\n mode,\n publicDir: false,\n logLevel: 'warn',\n worker: {\n ...eventConfig.vite.worker,\n plugins: () => [...(eventConfig.vite.worker?.plugins?.() ?? []), trackDependencies()],\n },\n plugins: [\n ...(eventConfig.vite.plugins ?? []),\n miniappPlugin({\n eventsOnly: true,\n eventsDir: config.eventsDir,\n eventsExtensions: config.eventsExtensions,\n }),\n trackDependencies(),\n ],\n build: {\n ...options,\n outDir,\n emptyOutDir: false,\n copyPublicDir: false,\n write: false,\n watch: null,\n lib: false,\n ssr: false,\n sourcemap: false,\n minify: false,\n manifest: false,\n ssrManifest: false,\n // Only sandbox entries; never rebuild/overwrite the local HMR HTML.\n rolldownOptions: undefined,\n rollupOptions: {\n ...options?.rollupOptions,\n ...options?.rolldownOptions,\n input: undefined,\n output: undefined,\n },\n },\n })\n for (const bundle of Array.isArray(result) ? result : [result]) {\n if (!('output' in bundle)) throw new Error('Unexpected event build watcher')\n for (const file of bundle.output) {\n if (files.has(file.fileName)) throw new Error(`Event build emitted duplicate output: ${file.fileName}`)\n files.set(file.fileName, file.type === 'chunk' ? file.code : file.source)\n if (file.type === 'chunk' && file.isEntry) entries.add(file.fileName)\n }\n }\n }\n\n dependencies = nextDependencies\n server.watcher.add([...dependencies])\n await publish(files, entries, (manifest.scripts ?? []).map(script => script.entry))\n if (hasEntries) server.config.logger.info('[miniapp] Event scripts built. Reload the application in the host if it caches scripts.')\n }\n\n function onChange(event: string, file: string) {\n if (stopped || !['add', 'change', 'unlink'].includes(event)) return\n const path = resolve(file)\n const entry = dirname(path) === eventsDir && config.eventsExtensions.some(ext => path.endsWith(ext))\n const relativeToOutput = relative(outDir, path)\n if (relativeToOutput !== '..' && !relativeToOutput.startsWith(`..${sep}`) && !isAbsolute(relativeToOutput)) return\n if (!entry && !dependencies.has(path) && !failed) return\n pending = pending.then(async () => {\n if (stopped) return\n try {\n await rebuild()\n failed = false\n } catch (error) {\n failed = true\n server.config.logger.error(`[miniapp] Event build failed: ${error instanceof Error ? error.message : String(error)}`)\n }\n })\n }\n\n const plugin: Plugin = {\n name: 'miniapp-dev-events',\n apply: 'serve',\n async closeBundle() {\n stopped = true\n server?.watcher.off('all', onChange)\n await pending\n },\n }\n\n return {\n plugin,\n async start(devServer: ViteDevServer) {\n server = devServer\n await rebuild()\n server.watcher.add(eventsDir)\n server.watcher.on('all', onChange)\n },\n }\n}\n","import { resolve } from 'node:path'\nimport miniappPlugin from '@xunlei-open/vite-plugin-miniapp'\nimport {\n build as viteBuild,\n createServer,\n mergeConfig,\n type ConfigEnv,\n type InlineConfig,\n type ViteDevServer,\n} from 'vite'\nimport { loadMiniappConfig } from './config.js'\nimport { localDevEntry } from './dev-entry.js'\nimport { devEvents } from './dev-events.js'\nimport type {\n BuildMiniappOptions,\n DevMiniappOptions,\n ResolvedMiniappConfig,\n} from './types.js'\nimport {\n validateMiniappDirectory,\n validateSourceManifest,\n} from './validate.js'\n\nfunction configEnv(command: ConfigEnv['command'], mode: string): ConfigEnv {\n return { command, mode, isSsrBuild: false, isPreview: false }\n}\n\nfunction createInlineConfig(config: ResolvedMiniappConfig): InlineConfig {\n return mergeConfig(config.vite, {\n root: config.root,\n configFile: false,\n plugins: [\n miniappPlugin({\n eventsDir: config.eventsDir,\n eventsExtensions: config.eventsExtensions,\n manifestFile: config.manifestFile,\n }),\n ],\n })\n}\n\nexport function resolveOutputDirectory(config: ResolvedMiniappConfig): string {\n return resolve(config.root, config.vite.build?.outDir ?? 'output')\n}\n\nexport async function buildMiniapp(\n options: BuildMiniappOptions = {},\n): Promise<{ config: ResolvedMiniappConfig; outDir: string }> {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n const config = await loadMiniappConfig(root, configEnv('build', mode))\n\n await viteBuild(createInlineConfig(config))\n\n const outDir = resolveOutputDirectory(config)\n await validateMiniappDirectory(outDir)\n return { config, outDir }\n}\n\nexport async function validateBuiltMiniapp(\n options: BuildMiniappOptions = {},\n) {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n const config = await loadMiniappConfig(root, configEnv('build', mode))\n return validateMiniappDirectory(resolveOutputDirectory(config))\n}\n\nexport async function devMiniapp(\n options: DevMiniappOptions = {},\n): Promise<ViteDevServer> {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'development'\n const config = await loadMiniappConfig(root, configEnv('serve', mode))\n const manifest = await validateSourceManifest(\n resolve(config.root, config.manifestFile),\n )\n\n const inlineConfig = createInlineConfig(config)\n const outDir = resolve(config.root, config.devOutDir)\n // Vite should ignore the on-disk development output as well as production output.\n inlineConfig.server = {\n ...inlineConfig.server,\n watch: {\n ...inlineConfig.server?.watch,\n ignored: [\n ...(Array.isArray(inlineConfig.server?.watch?.ignored)\n ? inlineConfig.server.watch.ignored\n : inlineConfig.server?.watch?.ignored ? [inlineConfig.server.watch.ignored] : []),\n `${outDir.replaceAll('\\\\', '/')}/**`,\n ],\n },\n }\n const devEntry = localDevEntry(config.root, outDir, config.manifestFile, manifest)\n const events = devEvents(config, outDir, manifest, mode)\n inlineConfig.plugins = [...(inlineConfig.plugins ?? []), devEntry.plugin, events.plugin]\n inlineConfig.server = {\n ...inlineConfig.server,\n // Local file pages have an opaque (\"null\") origin. Explicit user CORS wins.\n cors: inlineConfig.server?.cors ?? {\n origin: [/^https?:\\/\\/(?:(?:[^:]+\\.)?localhost|127\\.0\\.0\\.1|\\[::1\\])(?::\\d+)?$/, 'null'],\n },\n ...(options.host ? { host: options.host } : {}),\n ...(options.port ? { port: options.port } : {}),\n }\n if (!manifest.entry) {\n // Keep Vite's file watcher for sandbox builds without opening an HTTP/HMR server.\n inlineConfig.server.middlewareMode = true\n inlineConfig.server.hmr = false\n inlineConfig.server.open = false\n }\n\n const server = await createServer(inlineConfig)\n try {\n if (manifest.entry) await server.listen()\n await devEntry.write(server)\n await events.start(server)\n } catch (error) {\n await server.close()\n throw error\n }\n if (manifest.entry) {\n server.printUrls()\n server.bindCLIShortcuts({ print: true })\n }\n console.log(`\\nLoad this directory in Xunlei: ${outDir}\\n`)\n return server\n}\n","import { createWriteStream } from 'node:fs'\nimport { mkdir, mkdtemp, rename, rm, rmdir } from 'node:fs/promises'\nimport { basename, dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport yazl from 'yazl'\nimport { loadMiniappConfig } from './config.js'\nimport type {\n PackageMiniappOptions,\n ResolvedMiniappConfig,\n} from './types.js'\nimport { validateMiniappDirectory } from './validate.js'\nimport { buildMiniapp, resolveOutputDirectory } from './vite.js'\n\nconst ZIP_DATE = new Date('1980-01-01T00:00:00.000Z')\n\nfunction safeFilePart(value: string): string {\n return value.trim().replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'miniapp'\n}\n\nfunction resolveArchivePath(\n config: ResolvedMiniappConfig,\n manifest: { name: string; version: string },\n explicitPath?: string,\n): string {\n if (explicitPath) {\n if (!explicitPath.toLowerCase().endsWith('.zip')) {\n throw new Error('--out must end with .zip')\n }\n return isAbsolute(explicitPath) ? explicitPath : resolve(config.root, explicitPath)\n }\n\n const fileName =\n config.packageFileName ??\n `${safeFilePart(manifest.name)}-${safeFilePart(manifest.version)}.zip`\n if (!fileName.toLowerCase().endsWith('.zip')) {\n throw new Error('package.fileName must end with .zip')\n }\n if (basename(fileName) !== fileName) {\n throw new Error('package.fileName must not contain a directory')\n }\n return resolve(config.root, config.packageOutDir, fileName)\n}\n\nasync function writeZip(\n directory: string,\n files: string[],\n outFile: string,\n): Promise<void> {\n await mkdir(dirname(outFile), { recursive: true })\n const staging = await mkdtemp(resolve(dirname(outFile), '.miniapp-package-'))\n const temporaryArchive = resolve(staging, 'package.zip')\n const archive = new yazl.ZipFile()\n const output = createWriteStream(temporaryArchive)\n const completed = pipeline(archive.outputStream, output)\n // Observe stream failures immediately, including while entries are being added.\n void completed.catch(() => {})\n try {\n for (const file of files) {\n archive.addFile(resolve(directory, file), file, {\n mtime: ZIP_DATE,\n mode: 0o644,\n compress: true,\n })\n }\n archive.end()\n await completed\n await rename(temporaryArchive, outFile)\n } catch (error) {\n output.destroy()\n await completed.catch(() => {})\n throw error\n } finally {\n await rm(temporaryArchive, { force: true })\n await rmdir(staging)\n }\n}\n\nasync function removeBuildFiles(directory: string, files: string[]) {\n const directories = new Set<string>()\n for (const file of files) {\n const path = resolve(directory, file)\n const rel = relative(directory, path)\n if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {\n throw new Error(`Cannot clean a file outside the build output: ${file}`)\n }\n await rm(path, { force: true })\n for (let parent = dirname(path); parent !== directory; parent = dirname(parent)) directories.add(parent)\n }\n // Remove only empty directories; preserve the ZIP and any files added after validation.\n for (const path of [...directories].sort((a, b) => b.length - a.length)) {\n await rmdir(path).catch(error => {\n if (!['ENOENT', 'ENOTEMPTY', 'EEXIST'].includes(error.code)) throw error\n })\n }\n}\n\nexport async function packageMiniapp(\n options: PackageMiniappOptions = {},\n): Promise<{ outFile: string; outDir: string }> {\n let config: ResolvedMiniappConfig\n let outDir: string\n\n if (options.build ?? true) {\n ;({ config, outDir } = await buildMiniapp(options))\n } else {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n config = await loadMiniappConfig(root, {\n command: 'build',\n mode,\n isSsrBuild: false,\n isPreview: false,\n })\n outDir = resolveOutputDirectory(config)\n }\n\n const validated = await validateMiniappDirectory(outDir)\n const outFile = resolveArchivePath(config, validated.manifest, options.outFile)\n const archiveRelativeToDev = relative(resolve(config.root, config.devOutDir), outFile)\n if (archiveRelativeToDev === '' ||\n (archiveRelativeToDev !== '..' && !archiveRelativeToDev.startsWith(`..${sep}`) && !isAbsolute(archiveRelativeToDev))) {\n throw new Error('Package output must be outside the development output directory')\n }\n // Repackaging with --no-build must not include the previous destination ZIP itself.\n const files = validated.files.filter(file => relative(resolve(outDir, file), outFile) !== '')\n await writeZip(outDir, files, outFile)\n if (options.build ?? true) await removeBuildFiles(outDir, files)\n return { outFile, outDir }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,2BAA2B,CAAC,OAAO,KAAK;AAE9C,SAAgB,aAAa,QAA8C;CACzE,OAAO;AACT;AAEA,SAAgB,oBAAoB,QAAsC;CACxE,OAAO;AACT;AAEA,eAAe,YAAY,OAAiB,YAAoB,KAAqC;CACnG,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAK,SAAQ,OAAO,SAAS,YAAY,CAAC,KAAK,KAAK,CAAC,GACtF,MAAM,IAAI,MAAM,yDAAyD;CAE3E,MAAM,UAAU,cAAc,UAAU;CACxC,IAAI,SAAqB,CAAC;CAC1B,KAAK,MAAM,QAAQ,IAAI,IAAI,KAAK,GAC9B,IAAI;EACF,MAAM,EAAE,SAAS,WAAW,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;EAC9E,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,OAAO,OAAO,SAAS,YAAY,CAAC,OAAO,MACtF,MAAM,IAAI,MAAM,uDAAuD;EAEzE,SAAS,YAAY,QAAQ,MAAM,kBAAkB,OAAO,MAAM,GAAG,CAAC;CACxE,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,kCAAkC,KAAK,SAAS,WAAW,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAAK,EAAE,OAAO,MAAM,CAAC;CAC3J;CAEF,OAAO;AACT;AAEA,SAAS,eAAe,MAAsB;CAC5C,MAAM,UAAU,aAAa,KAAK,SAAS,QAAQ,MAAM,IAAI,CAAC,CAAC,CAAC,OAAO,UAAU;CAEjF,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI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AAyB,MAC1B,yBAAyB,QAAQ,CAAC,qBAAqB,WAAW,KAAK,KAAK,KAAK,CAAC,WAAW,oBAAoB,GAClH,MAAM,IAAI,MAAM,iEAAiE;CAGnF,MAAM,QAAQ,UAAU,MAAM,QAAO,SAAQ,SAAS,QAAQ,QAAQ,IAAI,GAAG,OAAO,MAAM,EAAE;CAC5F,MAAM,SAAS,QAAQ,OAAO,OAAO;CACrC,IAAI,QAAQ,SAAS,MAAM,MAAM,iBAAiB,QAAQ,KAAK;CAC/D,OAAO;EAAE;EAAS;CAAO;AAC3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xunlei-open/miniapp",
3
- "version": "0.1.1-beta.4",
3
+ "version": "0.1.1-beta.6",
4
4
  "description": "Unified development CLI for Xunlei Miniapps",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -45,8 +45,8 @@
45
45
  "parse5": "^8.0.1",
46
46
  "vite": "^8.2.0",
47
47
  "yazl": "^3.3.1",
48
- "@xunlei-open/miniapp-types": "^0.1.1-beta.4",
49
- "@xunlei-open/vite-plugin-miniapp": "^0.1.1-beta.4"
48
+ "@xunlei-open/miniapp-types": "^0.1.1-beta.6",
49
+ "@xunlei-open/vite-plugin-miniapp": "^0.1.1-beta.6"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/yazl": "^3.3.1"
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-DgpqUgd3.mjs","names":["viteBuild"],"sources":["../src/config.ts","../src/validate.ts","../src/dev-entry.ts","../src/dev-events.ts","../src/vite.ts","../src/package.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { loadConfigFromFile, mergeConfig, type ConfigEnv, type UserConfig } from 'vite'\nimport type {\n MiniappModule,\n MiniappUserConfig,\n ResolvedMiniappConfig,\n} from './types.js'\n\nconst CONFIG_FILES = [\n 'miniapp.config.ts',\n 'miniapp.config.mts',\n 'miniapp.config.js',\n 'miniapp.config.mjs',\n 'miniapp.config.cts',\n 'miniapp.config.cjs',\n] as const\n\nconst DEFAULT_EVENT_EXTENSIONS = ['.ts', '.js']\n\nexport function defineConfig(config: MiniappUserConfig): MiniappUserConfig {\n return config\n}\n\nexport function defineMiniappModule(module: MiniappModule): MiniappModule {\n return module\n}\n\nasync function loadModules(names: string[], configFile: string, env: ConfigEnv): Promise<UserConfig> {\n if (!Array.isArray(names) || names.some(name => typeof name !== 'string' || !name.trim())) {\n throw new Error('miniapp.config modules must be an array of module names')\n }\n const require = createRequire(configFile)\n let config: UserConfig = {}\n for (const name of new Set(names)) {\n try {\n const { default: module } = await import(pathToFileURL(require.resolve(name)).href)\n if (!module || typeof module !== 'object' || typeof module.name !== 'string' || !module.vite) {\n throw new Error('must export a MiniappModule with name and vite fields')\n }\n config = mergeConfig(config, await resolveViteConfig(module.vite, env))\n } catch (error) {\n throw new Error(`Failed to load miniapp module \"${name}\" from ${configFile}: ${error instanceof Error ? error.message : String(error)}`, { cause: error })\n }\n }\n return config\n}\n\nfunction findConfigFile(root: string): string {\n const matches = CONFIG_FILES.map((file) => resolve(root, file)).filter(existsSync)\n\n if (matches.length === 0) {\n throw new Error(`No miniapp.config file found in ${root}`)\n }\n if (matches.length > 1) {\n throw new Error(\n `Multiple miniapp config files found: ${matches.map((file) => file.split('/').at(-1)).join(', ')}`,\n )\n }\n\n return matches[0]!\n}\n\nfunction assertUserConfig(value: unknown, configFile: string): MiniappUserConfig {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`${configFile} must export a configuration object`)\n }\n return value as MiniappUserConfig\n}\n\nasync function resolveViteConfig(\n vite: MiniappUserConfig['vite'],\n env: ConfigEnv,\n): Promise<UserConfig> {\n if (!vite) return {}\n const config = typeof vite === 'function' ? await vite(env) : vite\n if (typeof config !== 'object' || config === null || Array.isArray(config)) {\n throw new Error('miniapp.config vite must resolve to a Vite configuration object')\n }\n return config\n}\n\nexport async function loadMiniappConfig(\n rootDirectory: string,\n env: ConfigEnv,\n): Promise<ResolvedMiniappConfig> {\n const root = resolve(rootDirectory)\n const configFile = findConfigFile(root)\n const loaded = await loadConfigFromFile(env, configFile, root)\n\n if (!loaded) {\n throw new Error(`Failed to load ${configFile}`)\n }\n\n const config = assertUserConfig(loaded.config, configFile)\n const eventsExtensions = config.events?.extensions ?? DEFAULT_EVENT_EXTENSIONS\n\n if (eventsExtensions.length === 0) {\n throw new Error('events.extensions must contain at least one file extension')\n }\n\n return {\n root,\n configFile,\n manifestFile: config.manifest ?? 'manifest.json',\n eventsDir: config.events?.dir ?? 'src/events',\n eventsExtensions,\n packageOutDir: config.package?.outDir ?? 'release',\n packageFileName: config.package?.fileName,\n vite: mergeConfig(\n await loadModules(config.modules ?? [], configFile, env),\n await resolveViteConfig(config.vite, env),\n ),\n }\n}\n","import { lstat, readFile, readdir } from 'node:fs/promises'\nimport { isAbsolute, relative, resolve, sep, win32 } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport type { MiniappValidationResult } from './types.js'\n\nfunction assertNonEmptyString(value: unknown, field: string): asserts value is string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new Error(`manifest.${field} must be a non-empty string`)\n }\n}\n\nfunction resolvePackagePath(directory: string, value: string, field: string): string {\n if (isAbsolute(value) || win32.isAbsolute(value)) {\n throw new Error(`manifest.${field} must be relative to the package root`)\n }\n\n const target = resolve(directory, value)\n const relativePath = relative(directory, target)\n if (relativePath === '..' || relativePath.startsWith(`..${sep}`)) {\n throw new Error(`manifest.${field} points outside the package root`)\n }\n return target\n}\n\nasync function assertPackageFile(\n directory: string,\n value: unknown,\n field: string,\n): Promise<void> {\n assertNonEmptyString(value, field)\n const target = resolvePackagePath(directory, value, field)\n let stat\n try {\n stat = await lstat(target)\n } catch {\n throw new Error(`manifest.${field} points to a missing file: ${value}`)\n }\n if (!stat.isFile() || stat.isSymbolicLink()) {\n throw new Error(`manifest.${field} must point to a regular package file: ${value}`)\n }\n}\n\nasync function collectFiles(directory: string, current = directory): Promise<string[]> {\n const entries = await readdir(current, { withFileTypes: true })\n const files: string[] = []\n\n for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n const absolutePath = resolve(current, entry.name)\n const packagePath = relative(directory, absolutePath).split(sep).join('/')\n\n if (entry.isSymbolicLink()) {\n throw new Error(`Package must not contain symbolic links: ${packagePath}`)\n }\n if (entry.isDirectory()) {\n files.push(...(await collectFiles(directory, absolutePath)))\n continue\n }\n if (entry.isFile()) files.push(packagePath)\n }\n\n return files\n}\n\nexport async function readMiniappManifest(manifestPath: string): Promise<MiniappManifest> {\n let value: unknown\n try {\n value = JSON.parse(await readFile(manifestPath, 'utf8'))\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error)\n throw new Error(`Unable to read manifest: ${reason}`)\n }\n\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error('manifest.json must contain a JSON object')\n }\n\n const manifest = value as MiniappManifest\n assertNonEmptyString(manifest.name, 'name')\n assertNonEmptyString(manifest.title, 'title')\n assertNonEmptyString(manifest.version, 'version')\n return manifest\n}\n\nexport async function validateSourceManifest(manifestPath: string): Promise<MiniappManifest> {\n return readMiniappManifest(manifestPath)\n}\n\nexport async function validateMiniappDirectory(\n directoryPath: string,\n): Promise<MiniappValidationResult> {\n const directory = resolve(directoryPath)\n const directoryStat = await lstat(directory).catch(() => undefined)\n if (!directoryStat?.isDirectory()) {\n throw new Error(`Miniapp output directory does not exist: ${directory}`)\n }\n\n const manifestPath = resolve(directory, 'manifest.json')\n const manifest = await readMiniappManifest(manifestPath)\n\n if (manifest.icon !== undefined) {\n await assertPackageFile(directory, manifest.icon, 'icon')\n }\n if (manifest.entry && (manifest.entry.type ?? 'miniapp') === 'miniapp') {\n await assertPackageFile(directory, manifest.entry.url, 'entry.url')\n const html = await readFile(resolve(directory, manifest.entry.url), 'utf8')\n if (html.startsWith('<!-- miniapp-dev-entry:')) {\n throw new Error('Output contains a development entry. Run build before validating or packaging.')\n }\n }\n for (const [index, script] of (manifest.scripts ?? []).entries()) {\n await assertPackageFile(directory, script.entry, `scripts[${index}].entry`)\n }\n\n const files = await collectFiles(directory)\n const sourcemap = files.find((file) => file.endsWith('.map'))\n if (sourcemap) {\n throw new Error(`Package must not contain sourcemaps: ${sourcemap}`)\n }\n const dependency = files.find((file) => file.split('/').includes('node_modules'))\n if (dependency) {\n throw new Error(`Package must not contain node_modules: ${dependency}`)\n }\n\n return { directory, manifestPath, manifest, files }\n}\n","import { createHash } from 'node:crypto'\nimport { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep, win32 } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport { minify, type Plugin, type ViteDevServer } from 'vite'\nimport { parse, parseFragment, serialize, type DefaultTreeAdapterMap } from 'parse5'\n\nfunction localPath(root: string, file: string): string {\n const target = resolve(root, file)\n const rel = relative(root, target)\n if (isAbsolute(file) || win32.isAbsolute(file) || rel === '..' || rel.startsWith(`..${sep}`)) {\n throw new Error(`Miniapp development entry must stay inside its directory: ${file}`)\n }\n return target\n}\n\nexport function localDevEntry(\n root: string,\n outDir: string,\n manifestFile: string,\n manifest: MiniappManifest,\n) {\n const entry = manifest.entry?.url\n if (manifest.entry && (manifest.entry.type ?? 'miniapp') !== 'miniapp') {\n throw new Error('Local HMR requires a miniapp HTML entry')\n }\n const source = entry ? localPath(root, entry) : undefined\n const output = entry ? localPath(outDir, entry) : undefined\n const iconSource = manifest.icon ? localPath(root, manifest.icon) : undefined\n const iconOutput = manifest.icon ? localPath(outDir, manifest.icon) : undefined\n let iconUpdates = Promise.resolve()\n let stopped = false\n const rootFromOutput = relative(outDir, root)\n if (!rootFromOutput || (!rootFromOutput.startsWith(`..${sep}`) && rootFromOutput !== '..' && !isAbsolute(rootFromOutput))) {\n throw new Error('Development output must not be the project root or its parent')\n }\n let server: ViteDevServer\n let entryUrl: string | undefined\n let pagePath: string\n const inlineModules = new Map<string, string>()\n let clientCode: Promise<string> | undefined\n\n function loadClientCode() {\n return clientCode ??= readFile(new URL('./dev-client.js', import.meta.url), 'utf8')\n .then(code => minify('dev-client.js', code))\n .then(result => result.code.trim().replace(/<\\/script/gi, '<\\\\/script'))\n }\n\n async function copyIcon() {\n if (!iconSource || !iconOutput) return\n await mkdir(dirname(iconOutput), { recursive: true })\n await copyFile(iconSource, iconOutput)\n }\n\n function onIconChange(event: string, file: string) {\n if (stopped || !iconSource || resolve(file) !== iconSource) return\n if (!['add', 'change', 'unlink'].includes(event)) return\n iconUpdates = iconUpdates.then(async () => {\n if (stopped) return\n if (event === 'unlink') await rm(iconOutput!, { force: true })\n else await copyIcon()\n server.config.logger.info('[miniapp] Manifest icon updated. Reload the application in the host to refresh its icon.')\n }).catch(error => {\n server.config.logger.error(`[miniapp] Icon sync failed: ${error instanceof Error ? error.message : String(error)}`)\n })\n }\n\n function rewriteEntry(html: string, bootstrap: string): string {\n const document = parse(html)\n const modules = new Map<string, string>()\n function visit(node: DefaultTreeAdapterMap['node']) {\n if ('tagName' in node) {\n for (const attr of node.attrs) {\n if (attr.name === 'src' || attr.name === 'poster' ||\n (attr.name === 'href' && ['link', 'image', 'use'].includes(node.tagName)) ||\n (attr.name === 'data' && node.tagName === 'object')) {\n if (attr.value && !attr.value.startsWith('#')) attr.value = new URL(attr.value, entryUrl).href\n }\n }\n if (node.tagName === 'script' &&\n node.attrs.some(attr => attr.name === 'type' && attr.value.toLowerCase() === 'module') &&\n !node.attrs.some(attr => attr.name === 'src')) {\n // Framework-injected preambles must resolve imports against HTTP, not file://.\n const code = node.childNodes.map(child => 'value' in child ? child.value : '').join('')\n const hash = createHash('sha256').update(code).digest('hex').slice(0, 16)\n const url = new URL(`./@miniapp-dev/inline-${modules.size}-${hash}.js`, entryUrl)\n const id = url.pathname.slice(server.config.base.length - 1)\n modules.set(id, code)\n node.childNodes = []\n node.attrs.push({ name: 'src', value: url.href })\n }\n if (node.tagName === 'script' &&\n node.attrs.some(attr => attr.name === 'type' && attr.value.toLowerCase() === 'module') &&\n node.attrs.some(attr => attr.name === 'src' && new URL(attr.value, entryUrl).origin === new URL(entryUrl!).origin)) {\n node.attrs.push({ name: 'data-miniapp-dev-module', value: '' })\n // Inert placeholders do not hold DOMContentLoaded or window.load open.\n node.attrs.find(attr => attr.name === 'type')!.value = 'application/x-miniapp-dev-module'\n node.attrs.find(attr => attr.name === 'src')!.name = 'data-miniapp-dev-src'\n }\n }\n if ('childNodes' in node) node.childNodes.forEach(visit)\n if ('content' in node) visit(node.content as DefaultTreeAdapterMap['documentFragment'])\n }\n visit(document)\n const htmlNode = document.childNodes.find(node => 'tagName' in node && node.tagName === 'html') as DefaultTreeAdapterMap['element']\n const head = htmlNode.childNodes.find(node => 'tagName' in node && node.tagName === 'head') as DefaultTreeAdapterMap['element']\n const script = parseFragment(`<script data-miniapp-dev-load-error>${bootstrap}</script>`).childNodes[0] as DefaultTreeAdapterMap['element']\n script.attrs.push({ name: 'data-miniapp-dev-probe', value: new URL(server.config.base, entryUrl).href })\n script.parentNode = head\n head.childNodes.unshift(script)\n inlineModules.clear()\n for (const [path, code] of modules) inlineModules.set(path, code)\n return serialize(document)\n }\n\n async function writeEntry() {\n if (!source || !output) return\n const html = await server.transformIndexHtml(pagePath, await readFile(source, 'utf8'))\n await mkdir(dirname(output), { recursive: true })\n await writeFile(output, `<!-- miniapp-dev-entry: run build before packaging -->\\n${rewriteEntry(html, await loadClientCode())}`)\n // Remove only bootstrap files generated by the previous external-script version.\n const oldClient = resolve(dirname(output), 'miniapp-dev-client.js')\n const oldCode = await readFile(oldClient, 'utf8').catch(() => '')\n if (oldCode.startsWith('// Local development bootstrap: must work without the dev server.')) {\n await rm(oldClient, { force: true })\n }\n }\n\n const plugin: Plugin = {\n name: 'miniapp-local-dev-entry',\n apply: 'serve',\n async closeBundle() {\n stopped = true\n server?.watcher.off('all', onIconChange)\n await iconUpdates\n },\n resolveId(id) {\n if (inlineModules.has(id.split('?')[0]!)) return id\n },\n load(id) {\n return inlineModules.get(id.split('?')[0]!)\n },\n async handleHotUpdate(context) {\n if (resolve(context.file) !== source) return\n await writeEntry()\n // Vite's HTML reload filter otherwise compares against the file:// pathname.\n context.server.ws.send({ type: 'full-reload', path: '*' })\n return []\n },\n }\n\n return {\n plugin,\n async write(devServer: ViteDevServer) {\n server = devServer\n await mkdir(outDir, { recursive: true })\n if (entry) {\n const url = server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0]\n if (!url) throw new Error('Cannot determine the Vite development server URL')\n server.config.server.origin ??= new URL(url).origin\n entryUrl = new URL(entry.replaceAll('\\\\', '/'), url).href\n pagePath = new URL(entryUrl).pathname\n await writeEntry()\n }\n await copyFile(resolve(root, manifestFile), resolve(outDir, 'manifest.json'))\n await copyIcon()\n if (iconSource) {\n server.watcher.add(iconSource)\n server.watcher.on('all', onIconChange)\n }\n },\n }\n}\n","import { mkdir, readdir, rm, writeFile } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport type { MiniappManifest } from '@xunlei-open/miniapp-types'\nimport miniappPlugin from '@xunlei-open/vite-plugin-miniapp'\nimport { build, normalizePath, type Plugin, type ViteDevServer } from 'vite'\nimport { loadMiniappConfig } from './config.js'\nimport type { ResolvedMiniappConfig } from './types.js'\n\n/** Build sandbox scripts on disk independently from the page's Vite HMR graph. */\nexport function devEvents(config: ResolvedMiniappConfig, outDir: string, manifest: MiniappManifest, mode: string) {\n const eventsDir = resolve(config.root, config.eventsDir)\n let server: ViteDevServer\n let dependencies = new Set<string>()\n let outputs = new Set<string>()\n let pending = Promise.resolve()\n let stopped = false\n let failed = false\n\n async function rebuild() {\n const sources = await readdir(eventsDir, { withFileTypes: true }).catch(error => {\n if (error.code === 'ENOENT') return []\n throw error\n })\n const hasEntries = sources.some(source => source.isFile()\n && !source.name.endsWith('.d.ts')\n && config.eventsExtensions.some(ext => source.name.endsWith(ext)))\n const nextDependencies = new Set<string>()\n const files = new Map<string, string | Uint8Array>()\n if (hasEntries) {\n // Vite plugins can hold server state. Never reuse the live page's instances.\n const eventConfig = await loadMiniappConfig(config.root, {\n command: 'build', mode, isSsrBuild: false, isPreview: false,\n })\n const options = eventConfig.vite.build\n const result = await build({\n ...eventConfig.vite,\n root: config.root,\n configFile: false,\n mode,\n publicDir: false,\n logLevel: 'warn',\n plugins: [\n ...(eventConfig.vite.plugins ?? []),\n miniappPlugin({\n eventsOnly: true,\n eventsDir: config.eventsDir,\n eventsExtensions: config.eventsExtensions,\n }),\n {\n name: 'miniapp-dev-events-output',\n generateBundle() {\n for (const file of this.getModuleIds()) {\n const path = file.split('?')[0]!\n if (isAbsolute(path)) nextDependencies.add(resolve(path))\n }\n },\n },\n ],\n build: {\n ...options,\n outDir,\n emptyOutDir: false,\n copyPublicDir: false,\n write: false,\n watch: null,\n lib: false,\n ssr: false,\n sourcemap: false,\n minify: false,\n manifest: false,\n ssrManifest: false,\n // Only sandbox entries; never rebuild/overwrite the local HMR HTML.\n rolldownOptions: undefined,\n rollupOptions: {\n ...options?.rollupOptions,\n ...options?.rolldownOptions,\n input: undefined,\n output: undefined,\n },\n },\n })\n for (const bundle of Array.isArray(result) ? result : [result]) {\n if (!('output' in bundle)) throw new Error('Unexpected event build watcher')\n for (const file of bundle.output) {\n files.set(file.fileName, file.type === 'chunk' ? file.code : file.source)\n }\n }\n }\n\n dependencies = nextDependencies\n server.watcher.add([...dependencies])\n // Publish only event outputs, and only after a successful compilation.\n for (const name of files.keys()) {\n const path = normalizePath(relative(outDir, resolve(outDir, name)))\n if (!path.startsWith('events/') || path.includes('../')) {\n throw new Error(`Event build emitted a file outside events/: ${name}`)\n }\n }\n for (const [name, content] of files) {\n const path = resolve(outDir, name)\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, content)\n }\n for (const name of outputs) {\n if (!files.has(name)) await rm(resolve(outDir, name), { force: true })\n }\n outputs = new Set(files.keys())\n for (const script of manifest.scripts ?? []) {\n const entry = normalizePath(relative(outDir, resolve(outDir, script.entry)))\n if (!outputs.has(entry)) {\n throw new Error(`manifest script \"${script.entry}\" has no built event entry. Add its source to ${config.eventsDir}.`)\n }\n }\n if (hasEntries) server.config.logger.info('[miniapp] Event scripts built. Reload the application in the host if it caches scripts.')\n }\n\n function onChange(event: string, file: string) {\n if (stopped || !['add', 'change', 'unlink'].includes(event)) return\n const path = resolve(file)\n const entry = dirname(path) === eventsDir && config.eventsExtensions.some(ext => path.endsWith(ext))\n const relativeToOutput = relative(outDir, path)\n if (relativeToOutput !== '..' && !relativeToOutput.startsWith(`..${sep}`) && !isAbsolute(relativeToOutput)) return\n if (!entry && !dependencies.has(path) && !failed) return\n pending = pending.then(async () => {\n if (stopped) return\n try {\n await rebuild()\n failed = false\n } catch (error) {\n failed = true\n server.config.logger.error(`[miniapp] Event build failed: ${error instanceof Error ? error.message : String(error)}`)\n }\n })\n }\n\n const plugin: Plugin = {\n name: 'miniapp-dev-events',\n apply: 'serve',\n async closeBundle() {\n stopped = true\n server?.watcher.off('all', onChange)\n await pending\n },\n }\n\n return {\n plugin,\n async start(devServer: ViteDevServer) {\n server = devServer\n await rebuild()\n server.watcher.add(eventsDir)\n server.watcher.on('all', onChange)\n },\n }\n}\n","import { resolve } from 'node:path'\nimport miniappPlugin from '@xunlei-open/vite-plugin-miniapp'\nimport {\n build as viteBuild,\n createServer,\n mergeConfig,\n type ConfigEnv,\n type InlineConfig,\n type ViteDevServer,\n} from 'vite'\nimport { loadMiniappConfig } from './config.js'\nimport { localDevEntry } from './dev-entry.js'\nimport { devEvents } from './dev-events.js'\nimport type {\n BuildMiniappOptions,\n DevMiniappOptions,\n ResolvedMiniappConfig,\n} from './types.js'\nimport {\n validateMiniappDirectory,\n validateSourceManifest,\n} from './validate.js'\n\nfunction configEnv(command: ConfigEnv['command'], mode: string): ConfigEnv {\n return { command, mode, isSsrBuild: false, isPreview: false }\n}\n\nfunction createInlineConfig(config: ResolvedMiniappConfig): InlineConfig {\n return mergeConfig(config.vite, {\n root: config.root,\n configFile: false,\n plugins: [\n miniappPlugin({\n eventsDir: config.eventsDir,\n eventsExtensions: config.eventsExtensions,\n manifestFile: config.manifestFile,\n }),\n ],\n })\n}\n\nexport function resolveOutputDirectory(config: ResolvedMiniappConfig): string {\n return resolve(config.root, config.vite.build?.outDir ?? 'dist')\n}\n\nexport async function buildMiniapp(\n options: BuildMiniappOptions = {},\n): Promise<{ config: ResolvedMiniappConfig; outDir: string }> {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n const config = await loadMiniappConfig(root, configEnv('build', mode))\n\n await viteBuild(createInlineConfig(config))\n\n const outDir = resolveOutputDirectory(config)\n await validateMiniappDirectory(outDir)\n return { config, outDir }\n}\n\nexport async function validateBuiltMiniapp(\n options: BuildMiniappOptions = {},\n) {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n const config = await loadMiniappConfig(root, configEnv('build', mode))\n return validateMiniappDirectory(resolveOutputDirectory(config))\n}\n\nexport async function devMiniapp(\n options: DevMiniappOptions = {},\n): Promise<ViteDevServer> {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'development'\n const config = await loadMiniappConfig(root, configEnv('serve', mode))\n const manifest = await validateSourceManifest(\n resolve(config.root, config.manifestFile),\n )\n\n const inlineConfig = createInlineConfig(config)\n const outDir = resolveOutputDirectory(config)\n const devEntry = localDevEntry(config.root, outDir, config.manifestFile, manifest)\n const events = devEvents(config, outDir, manifest, mode)\n inlineConfig.plugins = [...(inlineConfig.plugins ?? []), devEntry.plugin, events.plugin]\n inlineConfig.server = {\n ...inlineConfig.server,\n // Local file pages have an opaque (\"null\") origin. Explicit user CORS wins.\n cors: inlineConfig.server?.cors ?? {\n origin: [/^https?:\\/\\/(?:(?:[^:]+\\.)?localhost|127\\.0\\.0\\.1|\\[::1\\])(?::\\d+)?$/, 'null'],\n },\n ...(options.host ? { host: options.host } : {}),\n ...(options.port ? { port: options.port } : {}),\n }\n if (!manifest.entry) {\n // Keep Vite's file watcher for sandbox builds without opening an HTTP/HMR server.\n inlineConfig.server.middlewareMode = true\n inlineConfig.server.hmr = false\n inlineConfig.server.open = false\n }\n\n const server = await createServer(inlineConfig)\n try {\n if (manifest.entry) await server.listen()\n await devEntry.write(server)\n await events.start(server)\n } catch (error) {\n await server.close()\n throw error\n }\n if (manifest.entry) {\n server.printUrls()\n server.bindCLIShortcuts({ print: true })\n }\n console.log(`\\nLoad this directory in Xunlei: ${outDir}\\n`)\n return server\n}\n","import { createWriteStream } from 'node:fs'\nimport { mkdir, rm } from 'node:fs/promises'\nimport { basename, dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport yazl from 'yazl'\nimport { loadMiniappConfig } from './config.js'\nimport type {\n PackageMiniappOptions,\n ResolvedMiniappConfig,\n} from './types.js'\nimport { validateMiniappDirectory } from './validate.js'\nimport { buildMiniapp, resolveOutputDirectory } from './vite.js'\n\nconst ZIP_DATE = new Date('1980-01-01T00:00:00.000Z')\n\nfunction safeFilePart(value: string): string {\n return value.trim().replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'miniapp'\n}\n\nfunction resolveArchivePath(\n config: ResolvedMiniappConfig,\n manifest: { name: string; version: string },\n explicitPath?: string,\n): string {\n if (explicitPath) {\n if (!explicitPath.toLowerCase().endsWith('.zip')) {\n throw new Error('--out must end with .zip')\n }\n return isAbsolute(explicitPath) ? explicitPath : resolve(config.root, explicitPath)\n }\n\n const fileName =\n config.packageFileName ??\n `${safeFilePart(manifest.name)}-${safeFilePart(manifest.version)}.zip`\n if (!fileName.toLowerCase().endsWith('.zip')) {\n throw new Error('package.fileName must end with .zip')\n }\n if (basename(fileName) !== fileName) {\n throw new Error('package.fileName must not contain a directory')\n }\n return resolve(config.root, config.packageOutDir, fileName)\n}\n\nasync function writeZip(\n directory: string,\n files: string[],\n outFile: string,\n): Promise<void> {\n await mkdir(dirname(outFile), { recursive: true })\n\n const archive = new yazl.ZipFile()\n const output = createWriteStream(outFile)\n const completed = pipeline(archive.outputStream, output)\n try {\n for (const file of files) {\n archive.addFile(resolve(directory, file), file, {\n mtime: ZIP_DATE,\n mode: 0o644,\n compress: true,\n })\n }\n archive.end()\n await completed\n } catch (error) {\n await rm(outFile, { force: true })\n throw error\n }\n}\n\nexport async function packageMiniapp(\n options: PackageMiniappOptions = {},\n): Promise<{ outFile: string; outDir: string }> {\n let config: ResolvedMiniappConfig\n let outDir: string\n\n if (options.build ?? true) {\n ;({ config, outDir } = await buildMiniapp(options))\n } else {\n const root = options.root ?? process.cwd()\n const mode = options.mode ?? 'production'\n config = await loadMiniappConfig(root, {\n command: 'build',\n mode,\n isSsrBuild: false,\n isPreview: false,\n })\n outDir = resolveOutputDirectory(config)\n }\n\n const validated = await validateMiniappDirectory(outDir)\n const outFile = resolveArchivePath(config, validated.manifest, options.outFile)\n const archiveRelativeToOutput = relative(outDir, outFile)\n if (\n archiveRelativeToOutput === '' ||\n (!archiveRelativeToOutput.startsWith(`..${sep}`) && archiveRelativeToOutput !== '..')\n ) {\n throw new Error('Package output must be outside the build output directory')\n }\n\n await writeZip(outDir, validated.files, outFile)\n return { outFile, outDir }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,2BAA2B,CAAC,OAAO,KAAK;AAE9C,SAAgB,aAAa,QAA8C;CACzE,OAAO;AACT;AAEA,SAAgB,oBAAoB,QAAsC;CACxE,OAAO;AACT;AAEA,eAAe,YAAY,OAAiB,YAAoB,KAAqC;CACnG,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAK,SAAQ,OAAO,SAAS,YAAY,CAAC,KAAK,KAAK,CAAC,GACtF,MAAM,IAAI,MAAM,yDAAyD;CAE3E,MAAM,UAAU,cAAc,UAAU;CACxC,IAAI,SAAqB,CAAC;CAC1B,KAAK,MAAM,QAAQ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