diff --git a/index.ts b/index.ts deleted file mode 100644 index 2b3fe0c..0000000 --- a/index.ts +++ /dev/null @@ -1 +0,0 @@ -import "./src/server/dev.ts"; diff --git a/openspec/specs/single-executable-packaging/spec.md b/openspec/specs/single-executable-packaging/spec.md index 8d7f53e..e6fe318 100644 --- a/openspec/specs/single-executable-packaging/spec.md +++ b/openspec/specs/single-executable-packaging/spec.md @@ -27,7 +27,7 @@ - **THEN** 生成的嵌入资源模块 SHALL 保持语义一致且不依赖文件系统遍历顺序 ### Requirement: 单 executable 输出 -生产构建 SHALL 输出一个 standalone executable,其中包含 Bun 后端、必要 server 依赖和构建后的前端资源。 +生产构建 SHALL 输出一个 standalone executable,其中包含 Bun 后端、必要 server 依赖和构建后的前端资源。构建成功后 SHALL 自动清理中间产物目录(`.build/`),构建失败时 SHALL 保留中间产物以便排查。 #### Scenario: 在目标机器运行 executable - **WHEN** 生成的 executable 在兼容目标平台上运行 @@ -41,6 +41,14 @@ - **WHEN** 生成的 executable 启动,且浏览器打开前端根路径 - **THEN** 页面 SHALL 展示同一个 executable 进程中 `/api/demo` 返回的数据 +#### Scenario: 构建成功后清理中间产物 +- **WHEN** 生产构建成功完成并输出 executable +- **THEN** 系统 SHALL 自动删除 `.build/` 目录及其所有内容 + +#### Scenario: 构建失败时保留中间产物 +- **WHEN** 生产构建在任意步骤失败(前端构建、中间产物生成、Bun 编译) +- **THEN** `.build/` 目录 SHALL 保留在磁盘上以供排查 + ### Requirement: 外部运行时配置 executable MUST 将环境相关运行时配置保留在嵌入的前端和 server bundle 之外。 diff --git a/package.json b/package.json index a0b1f39..e28aa2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "gateway-checker", - "module": "src/server/dev.ts", "type": "module", "private": true, "scripts": { diff --git a/scripts/build.ts b/scripts/build.ts index e228ef6..409a7ed 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -52,6 +52,8 @@ if (!result.success) { console.log(`Built executable: ${executablePath}`); +await rm(buildDir, { recursive: true, force: true }); + async function listFiles(directory: string): Promise { const entries = await readdir(directory, { withFileTypes: true }); const files = await Promise.all(