diff --git a/.github/workflows/ootb.yml b/.github/workflows/ootb.yml index c6ac97d..ca96f44 100644 --- a/.github/workflows/ootb.yml +++ b/.github/workflows/ootb.yml @@ -27,6 +27,15 @@ jobs: shell: pwsh run: npm run build --workspaces --if-present + - name: Populate configs from defaults + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path configs | Out-Null + Get-ChildItem -Path configs-default -Filter *.json | ForEach-Object { + $dest = Join-Path configs $_.Name + if (-not (Test-Path $dest)) { Copy-Item $_.FullName $dest } + } + - name: Run check-ootb shell: pwsh run: node tools/check-ootb.js diff --git a/configs-default/db_config.json b/configs-default/db_config.json index 0dff98e..c1380db 100644 --- a/configs-default/db_config.json +++ b/configs-default/db_config.json @@ -3,5 +3,5 @@ "db_port": 3001, "http_auth": "", "dbDir": "./data/sfmc_data.db", - "modulesDir": "../modules" + "modulesDir": "modules" } diff --git a/package.json b/package.json index f3d3e81..8f57faf 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "module-core:typecheck": "npm run sdk:typecheck", "module-core:test": "echo \"no sdk tests yet\"", "module-core:verify": "npm run sdk:verify", - "check-catalog": "node /tools/check-catalog.js", + "check-catalog": "node tools/check-catalog.js", "lint": "eslint . --ext .ts,.tsx", "bundle": "node build-sea.mjs", "sea": "node --build-sea sea-config.json" diff --git a/tools/check-catalog.js b/tools/check-catalog.js index 26a3f4a..4cd259b 100644 --- a/tools/check-catalog.js +++ b/tools/check-catalog.js @@ -11,12 +11,13 @@ * - entry.init 仅在 sapi 类型可选 * - 不允许循环依赖(拓扑排序检测) */ -import { accessSync, constants, readFileSync } from "node:fs"; -import { resolve, join, dirname } from "node:path"; -import { fileURLToPath } from 'node:url'; -import path from "node:path"; +const { accessSync, constants, readFileSync } = require("node:fs"); +const { resolve, join } = require("node:path"); -const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +// 本文件以 CommonJS 方式运行(仓库根 package.json 未设置 "type": "module"), +// 直接使用 __dirname,避免 import.meta.url 触发 "Cannot use import statement +// outside a module" 语法错误。 +const ROOT = resolve(__dirname, ".."); const CATALOG = join(ROOT, "modules", "catalog.json"); const SERVICES_CATALOG = join(ROOT, "services", "catalog.json"); /* SAPI modules no longer register through a single static entry.ts — diff --git a/tools/check-ootb.js b/tools/check-ootb.js index 970b038..19d6694 100644 --- a/tools/check-ootb.js +++ b/tools/check-ootb.js @@ -106,7 +106,9 @@ function fileContains(p, needle) { { let dbProc = null; try { - dbProc = spawn(process.execPath, [path.join(ROOT, "db-server", "index.js")], { + const dbEntry = path.join(ROOT, "db-server", "dist", "index.js"); + if (!exists(dbEntry)) throw new Error(`db-server 未构建: ${dbEntry} 不存在,请先运行 npm run build`); + dbProc = spawn(process.execPath, [dbEntry], { cwd: ROOT, env: { ...process.env }, stdio: ["ignore", "pipe", "pipe"], diff --git a/tools/sim-new-user.js b/tools/sim-new-user.js index 18990b9..cb7b752 100644 --- a/tools/sim-new-user.js +++ b/tools/sim-new-user.js @@ -29,8 +29,12 @@ function expect(cond, msg) { let dbProc = null; function startDb(simDir) { + const dbEntry = path.join(ROOT, "db-server", "dist", "index.js"); + if (!fs.existsSync(dbEntry)) { + fail(`db-server 未构建: ${dbEntry} 不存在,请先运行 npm run build (或 npm run build --workspace db-server)`); + } const env = { ...process.env, SFMC_ROOT: simDir, DB_PORT: String(DB_PORT) }; - dbProc = spawn(process.execPath, [path.join(ROOT, "db-server", "index.js")], { + dbProc = spawn(process.execPath, [dbEntry], { cwd: ROOT, env, stdio: ["ignore", "pipe", "pipe"],