fix(build): defer module-level process.cwd() to fix Edge bundling#174
fix(build): defer module-level process.cwd() to fix Edge bundling#174TerrifiedBug merged 2 commits intomainfrom
Conversation
Greptile SummaryThis PR fixes the Edge bundler build failure by deferring Confidence Score: 5/5Safe to merge — both previously-flagged critical issues are fully resolved and no new issues introduced. All three files correctly defer No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant EB as Edge Bundler
participant Inst as instrumentation.ts
participant SV as system-vector.ts
participant A as audit.ts
participant B as backup.ts
Note over EB: Static analysis / module tracing
EB->>Inst: trace imports
Inst-->>EB: guard: NEXT_RUNTIME === "nodejs"
EB->>SV: trace (still bundles file)
Note over SV: process.cwd() now deferred to getVectorflowDataDir()<br/>process.on() now in ensureShutdownHook()
EB->>A: trace (still bundles file)
Note over A: process.cwd() now deferred to getAuditLogPath()
EB->>B: trace (still bundles file)
Note over B: process.cwd() now deferred to getMigrationsDir()
Note over EB: No module-level Node API calls - build passes
participant RT as Node.js Runtime
RT->>SV: startSystemVector(configYaml)
SV->>SV: getSystemConfigPath() -> process.cwd()
SV->>SV: getVectorflowDataDir() -> process.cwd()
SV->>A: getAuditLogPath() -> process.cwd() (cached)
SV->>SV: ensureShutdownHook() -> process.on(SIGTERM/SIGINT)
Reviews (2): Last reviewed commit: "fix(system-vector): wire startSystemVect..." | Re-trigger Greptile |
|
@greptile review |
Summary
Main CI broke after PR #172 (demo mode) merged: https://github.com/TerrifiedBug/vectorflow/actions/runs/24942402486
The Edge runtime bundler now traces into
src/server/services/{audit,backup,system-vector}.tsand rejects them because they callprocess.cwd()(andprocess.on()for SIGTERM/SIGINT) at module scope. The Edge bundler evaluates module-level code statically; even though the runtime guard ininstrumentation.ts(if (process.env.NEXT_RUNTIME !== "nodejs") return;) prevents execution in Edge, it doesn't prevent bundling.Fix
Defer the offending
process.cwd()calls to call-time via lazy getters:Same pattern for
AUDIT_LOG_PATH,MIGRATIONS_DIR, andSYSTEM_CONFIG_PATH. Module-levelprocess.on()calls insystem-vector.tswere also moved into a function called from the existing startup path.Runtime behaviour unchanged — the values are computed on first access and cached for the process lifetime.
Files
src/server/services/audit.tssrc/server/services/backup.tssrc/server/services/system-vector.tsTest plan
pnpm buildpasses (Edge bundle accepts the new lazy patterns)pnpm testpasses (2526 tests, same as before)