@xunlei-open/miniapp 0.1.1-beta.0 → 0.1.1-beta.2

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
@@ -1,59 +1,43 @@
1
1
  # @xunlei-open/miniapp
2
2
 
3
- 迅雷微应用统一开发工具,内部复用 Vite,提供开发、构建、校验和打包命令。
3
+ 迅雷微应用开发工具,支持页面应用、事件应用及两者组合,提供开发、构建、校验和 ZIP 打包命令。
4
+
5
+ ## 使用
4
6
 
5
7
  ```bash
6
8
  pnpm add -D @xunlei-open/miniapp
9
+ pnpm exec xunlei-miniapp
7
10
  ```
8
11
 
9
- ```json
10
- {
11
- "scripts": {
12
- "dev": "xunlei-miniapp",
13
- "build": "xunlei-miniapp build",
14
- "package": "xunlei-miniapp package"
15
- }
16
- }
17
- ```
18
-
19
- 项目使用 `miniapp.config.ts` 作为唯一工具配置:
20
-
21
- ```ts
22
- import { defineConfig } from '@xunlei-open/miniapp'
23
-
24
- export default defineConfig({
25
- vite: {
26
- build: {
27
- target: 'es2015',
28
- },
29
- },
30
- })
31
- ```
32
-
33
- 框架插件、alias、CSS、开发服务器等 Vite 配置均写在 `vite` 字段中。`manifest.json` 继续作为迅雷运行时读取的应用清单。
12
+ 在迅雷客户端中加载本地应用的目录(默认 `dist`)。页面开发需要保持 dev server 运行;修改 `manifest.json` 后重启开发服务并重新加载应用。
34
13
 
35
14
  ## 命令
36
15
 
37
- Vue/React 项目可安装 `@xunlei-open/miniapp-module-vue` / `@xunlei-open/miniapp-module-react`,并在配置中声明 `modules: ['@xunlei-open/miniapp-module-vue']`。模块从项目依赖中解析,按声明顺序合并 Vite 配置,最后合并项目的 `vite` 配置,无需再次注册框架插件。Vanilla 项目无需模块。
16
+ | 命令 | 用途 |
17
+ | --- | --- |
18
+ | `xunlei-miniapp` | 开发与热更新 |
19
+ | `xunlei-miniapp build` | 构建并校验生产产物 |
20
+ | `xunlei-miniapp validate` | 校验已有构建产物 |
21
+ | `xunlei-miniapp package` | 构建、校验并生成 ZIP |
22
+ | `xunlei-miniapp package --no-build` | 校验并打包已有生产产物 |
38
23
 
39
- 自定义模块默认导出 `defineMiniappModule({ name, vite })`,其中 `vite` 支持配置对象或接收 Vite `ConfigEnv` 的异步函数。`defineMiniappModule` 从 `@xunlei-open/miniapp` 导入。
24
+ 默认输出目录为 `dist/`,ZIP 位于 `release/`。构建与打包不自动执行类型检查。
40
25
 
41
- dev、build 和 package 均不默认执行类型检查。TS 模板提供可选的 `typecheck` 脚本,供手动执行或 CI 使用。
26
+ ## 配置
42
27
 
43
- 支持纯页面、纯事件、页面与事件并存三种形态。纯事件微应用只需声明 manifest 的 `scripts`,不声明 `entry`,也不需要 `index.html` 或框架模块。dev 会编译并监听事件脚本、同步 manifest 和图标,不启动页面 HTTP 服务;build 和 package 同样无需页面文件。
28
+ 应用清单使用 `manifest.json`,工具配置使用 `miniapp.config.ts` 或 `.js`:
44
29
 
45
- 开发时加载终端提示的 `dist` 目录(或 `vite.build.outDir`)。CLI 将经过 Vite 和框架插件转换的 HTML 写入该目录,并复制 manifest 和图标。本地 HTML 通过绝对 URL 从开发服务器加载模块、资源和 HMR 客户端,因此需要保持 dev 服务运行。Vue/React 的模块热更新无需整页刷新;HTML 入口修改会重新生成本地入口并刷新页面。
30
+ ```ts
31
+ import { defineConfig } from '@xunlei-open/miniapp'
46
32
 
47
- dev 也会将 `src/events`(或配置的 `events.dir`)中的事件脚本编译到 `dist/events`,监听脚本及其导入依赖的修改,并处理入口新增、删除。事件构建不会覆盖页面的 HMR 入口;manifest 声明的脚本缺少对应源码时,启动会报错。事件编译失败会保留上一次成功编译的产物并输出错误,修复后自动重试。
33
+ export default defineConfig({
34
+ modules: ['@xunlei-open/miniapp-module-vue'],
35
+ vite: {},
36
+ })
37
+ ```
48
38
 
49
- 只有 manifest 的 `icon` 字段声明的应用图标会复制到开发目录,修改、删除或重新创建图标文件也会同步。事件沙箱和宿主应用图标不使用页面 HMR:如果宿主缓存脚本或图标,需在宿主中重新加载应用。修改 manifest 的入口、脚本声明或图标路径仍需重启 dev。
39
+ Vue / React 项目安装并声明对应框架模块;Vanilla 无需模块。额外 Vite 配置写在 `vite` 中。
50
40
 
51
- 默认允许本地文件的 `null` origin 访问开发资源。如果宿主使用自己的协议并发送其他 Origin,可通过 `vite.server.cors.origin` 配置该来源;宿主也需要允许访问本机开发服务器及其 WebSocket。开发入口使用绝对资源地址,不注入 `<base>`,兼容 `base-uri 'none'`。修改 manifest 后重启 dev 并重新加载应用。发布前运行 build 生成生产产物。
41
+ 事件源码默认放在 `src/events`,并在 manifest 的 `scripts` 中声明。纯事件应用无需页面入口。事件或图标更新后,宿主若有缓存需重新加载应用。
52
42
 
53
- ```bash
54
- xunlei-miniapp # 启动开发服务
55
- xunlei-miniapp build # 构建并校验 dist
56
- xunlei-miniapp package # 构建、校验并生成 ZIP
57
- xunlei-miniapp package --no-build
58
- xunlei-miniapp validate # 校验当前配置对应的构建目录
59
- ```
43
+ [示例代码](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-BQM2LBwr.mjs";
1
+ import { i as validateBuiltMiniapp, n as buildMiniapp, r as devMiniapp, t as packageMiniapp } from "./package-BySxiiHU.mjs";
2
2
  import { parseArgs } from "node:util";
3
3
  //#region src/cli.ts
4
4
  const HELP = `Xunlei Miniapp CLI
@@ -0,0 +1,40 @@
1
+ // Local development bootstrap: must work without the dev server.
2
+ (function () {
3
+ var shown = false;
4
+ window.addEventListener('error', function (event) {
5
+ var target = event.target;
6
+ if (!target || target.tagName !== 'SCRIPT' || !target.hasAttribute('data-miniapp-dev-module') || shown) return;
7
+ shown = true;
8
+ function showMessage() {
9
+ var notice = document.createElement('div');
10
+ notice.setAttribute('role', 'alert');
11
+ notice.style.cssText = 'position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;background:radial-gradient(ellipse at top,#eef2ff,#f8fafc 65%);color:#475569;font:14px/1.7 system-ui,sans-serif;text-align:center';
12
+ var card = document.createElement('div');
13
+ card.style.cssText = 'max-width:360px;padding:24px 28px;border:1px solid #e2e8f0;border-radius:16px;background:#fff;box-shadow:0 8px 32px #0f172a08';
14
+ card.textContent = '请启动 dev server 后重新打开微应用';
15
+ notice.appendChild(card);
16
+ document.body.appendChild(notice);
17
+ }
18
+ if (document.body) showMessage();
19
+ else document.addEventListener('DOMContentLoaded', showMessage, { once: true });
20
+ }, true);
21
+ // Start network requests after the host can observe the local page's load event.
22
+ window.addEventListener('load', function () {
23
+ setTimeout(function () {
24
+ var pending = Array.from(document.querySelectorAll('script[data-miniapp-dev-src]'));
25
+ function loadNext() {
26
+ var placeholder = pending.shift();
27
+ if (!placeholder || shown) return;
28
+ var script = document.createElement('script');
29
+ for (var attr of placeholder.attributes) {
30
+ if (attr.name !== 'type' && attr.name !== 'data-miniapp-dev-src') script.setAttribute(attr.name, attr.value);
31
+ }
32
+ script.type = 'module';
33
+ script.src = placeholder.getAttribute('data-miniapp-dev-src');
34
+ script.addEventListener('load', loadNext, { once: true });
35
+ placeholder.replaceWith(script);
36
+ }
37
+ loadNext();
38
+ }, 0);
39
+ }, { once: true });
40
+ })();
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-BQM2LBwr.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-BySxiiHU.mjs";
2
2
  export { buildMiniapp, defineConfig, defineMiniappModule, devMiniapp, loadMiniappConfig, packageMiniapp, readMiniappManifest, validateBuiltMiniapp, validateMiniappDirectory, validateSourceManifest };
@@ -2,13 +2,13 @@ import { createRequire } from "node:module";
2
2
  import { createWriteStream, existsSync } from "node:fs";
3
3
  import { basename, dirname, isAbsolute, relative, resolve, sep, win32 } from "node:path";
4
4
  import { pathToFileURL } from "node:url";
5
- import { build, createServer, loadConfigFromFile, mergeConfig, normalizePath } from "vite";
5
+ import { build, createServer, loadConfigFromFile, mergeConfig, minify, normalizePath } from "vite";
6
6
  import { copyFile, lstat, mkdir, readFile, readdir, rm, 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";
10
10
  import { createHash } from "node:crypto";
11
- import { parse, serialize } from "parse5";
11
+ import { parse, parseFragment, serialize } from "parse5";
12
12
  //#region src/config.ts
13
13
  const CONFIG_FILES = [
14
14
  "miniapp.config.ts",
@@ -175,6 +175,10 @@ function localDevEntry(root, outDir, manifestFile, manifest) {
175
175
  let entryUrl;
176
176
  let pagePath;
177
177
  const inlineModules = /* @__PURE__ */ new Map();
178
+ let clientCode;
179
+ function loadClientCode() {
180
+ return clientCode ??= readFile(new URL("./dev-client.js", import.meta.url), "utf8").then((code) => minify("dev-client.js", code)).then((result) => result.code.trim().replace(/<\/script/gi, "<\\/script"));
181
+ }
178
182
  async function copyIcon() {
179
183
  if (!iconSource || !iconOutput) return;
180
184
  await mkdir(dirname(iconOutput), { recursive: true });
@@ -196,7 +200,7 @@ function localDevEntry(root, outDir, manifestFile, manifest) {
196
200
  server.config.logger.error(`[miniapp] Icon sync failed: ${error instanceof Error ? error.message : String(error)}`);
197
201
  });
198
202
  }
199
- function rewriteEntry(html) {
203
+ function rewriteEntry(html, bootstrap) {
200
204
  const document = parse(html);
201
205
  const modules = /* @__PURE__ */ new Map();
202
206
  function visit(node) {
@@ -220,11 +224,23 @@ function localDevEntry(root, outDir, manifestFile, manifest) {
220
224
  value: url.href
221
225
  });
222
226
  }
227
+ if (node.tagName === "script" && node.attrs.some((attr) => attr.name === "type" && attr.value.toLowerCase() === "module") && node.attrs.some((attr) => attr.name === "src" && new URL(attr.value, entryUrl).origin === new URL(entryUrl).origin)) {
228
+ node.attrs.push({
229
+ name: "data-miniapp-dev-module",
230
+ value: ""
231
+ });
232
+ node.attrs.find((attr) => attr.name === "type").value = "application/x-miniapp-dev-module";
233
+ node.attrs.find((attr) => attr.name === "src").name = "data-miniapp-dev-src";
234
+ }
223
235
  }
224
236
  if ("childNodes" in node) node.childNodes.forEach(visit);
225
237
  if ("content" in node) visit(node.content);
226
238
  }
227
239
  visit(document);
240
+ const head = document.childNodes.find((node) => "tagName" in node && node.tagName === "html").childNodes.find((node) => "tagName" in node && node.tagName === "head");
241
+ const script = parseFragment(`<script data-miniapp-dev-load-error>${bootstrap}<\/script>`).childNodes[0];
242
+ script.parentNode = head;
243
+ head.childNodes.unshift(script);
228
244
  inlineModules.clear();
229
245
  for (const [path, code] of modules) inlineModules.set(path, code);
230
246
  return serialize(document);
@@ -233,7 +249,9 @@ function localDevEntry(root, outDir, manifestFile, manifest) {
233
249
  if (!source || !output) return;
234
250
  const html = await server.transformIndexHtml(pagePath, await readFile(source, "utf8"));
235
251
  await mkdir(dirname(output), { recursive: true });
236
- await writeFile(output, `<!-- miniapp-dev-entry: run build before packaging -->\n${rewriteEntry(html)}`);
252
+ await writeFile(output, `<!-- miniapp-dev-entry: run build before packaging -->\n${rewriteEntry(html, await loadClientCode())}`);
253
+ const oldClient = resolve(dirname(output), "miniapp-dev-client.js");
254
+ if ((await readFile(oldClient, "utf8").catch(() => "")).startsWith("// Local development bootstrap: must work without the dev server.")) await rm(oldClient, { force: true });
237
255
  }
238
256
  return {
239
257
  plugin: {
@@ -554,4 +572,4 @@ async function packageMiniapp(options = {}) {
554
572
  //#endregion
555
573
  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 };
556
574
 
557
- //# sourceMappingURL=package-BQM2LBwr.mjs.map
575
+ //# sourceMappingURL=package-BySxiiHU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-BySxiiHU.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.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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,KAAK,MAAM,QAAQ,OACjB,QAAQ,QAAQ,QAAQ,WAAW,IAAI,GAAG,MAAM;GAC9C,OAAO;GACP,MAAM;GACN,UAAU;EACZ,CAAC;EAEH,QAAQ,IAAI;EACZ,MAAM;CACR,SAAS,OAAO;EACd,MAAM,GAAG,SAAS,EAAE,OAAO,KAAK,CAAC;EACjC,MAAM;CACR;AACF;AAEA,eAAsB,eACpB,UAAiC,CAAC,GACY;CAC9C,IAAI;CACJ,IAAI;CAEJ,IAAI,QAAQ,SAAS,MAClB,CAAC,CAAE,QAAQ,UAAW,MAAM,aAAa,OAAO;MAC5C;EAGL,SAAS,MAAM,kBAFF,QAAQ,QAAQ,QAAQ,IAAI,GAEF;GACrC,SAAS;GACT,MAHW,QAAQ,QAAQ;GAI3B,YAAY;GACZ,WAAW;EACb,CAAC;EACD,SAAS,uBAAuB,MAAM;CACxC;CAEA,MAAM,YAAY,MAAM,yBAAyB,MAAM;CACvD,MAAM,UAAU,mBAAmB,QAAQ,UAAU,UAAU,QAAQ,OAAO;CAC9E,MAAM,0BAA0B,SAAS,QAAQ,OAAO;CACxD,IACE,4BAA4B,MAC3B,CAAC,wBAAwB,WAAW,KAAK,KAAK,KAAK,4BAA4B,MAEhF,MAAM,IAAI,MAAM,2DAA2D;CAG7E,MAAM,SAAS,QAAQ,UAAU,OAAO,OAAO;CAC/C,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.0",
3
+ "version": "0.1.1-beta.2",
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.0",
49
- "@xunlei-open/vite-plugin-miniapp": "^0.1.1-beta.0"
48
+ "@xunlei-open/miniapp-types": "^0.1.1-beta.2",
49
+ "@xunlei-open/vite-plugin-miniapp": "^0.1.1-beta.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/yazl": "^3.3.1"
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-BQM2LBwr.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 type { Plugin, ViteDevServer } from 'vite'\nimport { parse, 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\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): 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 }\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 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)}`)\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,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;CA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