Files
UHD_Media_Tool/apps/server/scripts/build.mjs
T
umtandClaude Fable 5.1 b22c440139 chore: scaffold monorepo and migrate uhd_web design system (W0-A)
- pnpm workspace: apps/{web,server}, packages/{contracts,db,domain,adapters,tasks,agent,testkit}
- server: Hono + zod-openapi, API Key auth with scopes, redacting pino logger, SSE event bus with replay, worker heartbeat
- db: Kysely + pg, file migrator, 0001_init (settings/api_key/audit_event/outbox_event)
- web: React Router 7 SPA console shell with 12 workspace placeholders, uhd_web tokens/ui/guard scripts
- docs: ADR-001 (Node over Deno), dev runbook, design system rules

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-27 17:36:26 +08:00

43 lines
1.5 KiB
JavaScript

// 打包 server:工作区包(@umt/*)以源码内联,npm 依赖保持 external 运行时从 node_modules 加载。
// external 依赖必须在本包 package.json 的 dependencies 里声明(工作区包的运行时依赖也要在此重复声明),
// 否则运行时解析不到,构建直接报错。
import { readFileSync } from "node:fs";
import { builtinModules } from "node:module";
import { build } from "esbuild";
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
const deps = new Set(Object.keys(pkg.dependencies ?? {}));
const builtins = new Set(builtinModules);
const pkgName = (p) => (p.startsWith("@") ? p.split("/").slice(0, 2).join("/") : p.split("/")[0]);
await build({
entryPoints: ["src/main.ts"],
outfile: "dist/main.js",
bundle: true,
platform: "node",
target: "node24",
format: "esm",
sourcemap: true,
logLevel: "info",
plugins: [
{
name: "external-npm",
setup(b) {
b.onResolve({ filter: /^[^./]/ }, (args) => {
if (args.path.startsWith("node:") || builtins.has(args.path)) return { path: args.path, external: true };
const name = pkgName(args.path);
if (name.startsWith("@umt/")) return undefined;
if (!deps.has(name)) {
return {
errors: [
{ text: `运行时依赖 ${name} 未在 apps/server/package.json dependencies 中声明(来自 ${args.importer})` },
],
};
}
return { path: args.path, external: true };
});
},
},
],
});