fix(ci): align shared-auth build outputPath with tsconfig.lib.json outDir #209
Reference in New Issue
Block a user
Delete Branch "fix/ci-shared-auth-output-path"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
pnpm ci:checkwas failing onmainafter #208 merged:portal-bff:buildraisedTS6305 Output file 'dist/out-tsc/libs/shared/auth/src/index.d.ts' has not been built from source file 'libs/shared/auth/src/index.ts'against every file inapps/portal-bff/src/auth/that imports fromshared-auth. Fresh CI runners hit it; my local runs masked it because a manualtsc --buildduring development had populated both candidate output dirs.Root cause
When
nx syncwas first run for #206, it added a TypeScript project reference toapps/portal-bff/tsconfig.app.json:portal-bff's build runs webpack withcompiler: 'tsc'against that tsconfig, so tsc validates the referenced project's outputs exist at the location its tsconfig.lib.json declares asoutDir—dist/out-tsc/libs/shared/auth/.But
libs/shared/auth/project.jsonsetoutputPath: dist/libs/shared/authand Nx's@nx/js:tscexecutor honours its ownoutputPathover the tsconfig'soutDir, emitting the declarations todist/libs/shared/auth/instead. tsc looks at the emptydist/out-tsc/libs/shared/auth/location and fails with TS6305.This was harmless until #208: the previous PRs only had a single
importfromshared-auth(inprincipal-builder.ts), and apparently tsc's incremental cache from the local dev box's pre-fix runs was reused in CI. #208 added enough new imports across enough files that the missing declarations became unavoidable.What lands
libs/shared/auth/project.jsonoutputPath: dist/libs/shared/auth→dist/out-tsc/libs/shared/auth. Aligns Nx's emit location with the tsconfig.lib.json's declaredoutDir, so the project-reference validation finds the declaration files.One-line change, no other files touched.
Notes for the reviewer
Why this didn't show in the green CI on #206 / #208. Both PRs ran the same
nx affected -t format:check lint test buildrecipe and both reported green. The likely explanation is that during PR-level runs Nx's distributed cache hit on theportal-bff:buildtask (the inputs included the source files but the cache stored the result of the build, which was green from an earlier successful run before the project reference landed). Post-merge runs onmainevict the cache differently (different commit SHA → cache miss → tsc actually re-runs and hits the missing declarations).Why
shared-util,shared-tokens, etc. don't have the same problem. They share the exact same outputPath / outDir mismatch in their project.json + tsconfig.lib.json, but they're only consumed by the Angular SPAs (portal-shell,portal-admin).@angular/builddoes not validate TypeScript project references the same waywebpack + compiler: 'tsc'does, so the mismatch sits silently.shared-authis the first lib in the workspace that crosses intoportal-bff, which is why the trap surfaced now.Alternative considered: drop the project reference in
portal-bff/tsconfig.app.json. Path aliases intsconfig.base.jsonresolveshared-authto source files directly, so webpack would still find the imports. Rejected becausenx syncadds project references back automatically — the alignment-of-paths fix is more durable than a configuration deletion.Why not align the other shared libs preemptively. They aren't broken — their project references aren't being validated. Touching them in the same PR would expand the diff for zero current benefit. The pattern documented here is what the next lib that's consumed by
portal-bffwill need; the precedent is on the books.Locally reproducible.
pnpm nx reset && rm -rf dist .nx/cache .nx/workspace-data && pnpm ci:checkreproduces the original failure on the previous commit and passes on this commit.Test plan
pnpm nx reset && rm -rf dist .nx/cache .nx/workspace-data && pnpm nx affected -t format:check lint test build --base=main --skip-nx-cache— 3 projects green from a fully cold state.mainruns throughpnpm ci:checkcleanly.