Skip to content

fix(plugin): support TypeScript project references in ReadonlyVisitor#3804

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-3641-plugin-tsconfig-references
Apr 9, 2026
Merged

fix(plugin): support TypeScript project references in ReadonlyVisitor#3804
kamilmysliwiec merged 1 commit intonestjs:masterfrom
maruthang:fix/issue-3641-plugin-tsconfig-references

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Summary

Fixes #3641

Bug: The Swagger plugin fails with TS6305 errors when used in a TypeScript project that uses references (composite project references) in tsconfig.json.

Root Cause: ts.createProgram({ ..., projectReferences }) requires pre-built output files (.d.ts) from each referenced composite project, triggering TS6305 when those outputs do not exist yet.

Fix: A new static method ReadonlyVisitor.createTsProgram(tsconfigPath) recursively collects source files from all transitively referenced projects (with cycle detection) and creates the program with merged rootNames but without passing projectReferences, bypassing TS6305 while still resolving all types across the project graph.

Changes

  • lib/plugin/visitors/readonly.visitor.ts: Added collectProjectReferenceSourceFiles helper and ReadonlyVisitor.createTsProgram() static method that handles composite project references without requiring pre-built outputs.
  • test/plugin/readonly-visitor-project-refs.spec.ts: 5 new tests covering the createTsProgram method with project reference fixtures.
  • test/plugin/fixtures/project-references/: New fixture with an app project referencing a libs/shared composite project, used by the new tests.

Testing

  • Added regression tests in test/plugin/readonly-visitor-project-refs.spec.ts that verify createTsProgram works correctly with a project using composite project references, handles missing tsconfig gracefully, detects cycles, and collects source files from transitive references.
  • All existing tests pass (163 passing).

@kamilmysliwiec kamilmysliwiec merged commit 62ae029 into nestjs:master Apr 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swagger plugin generator doesn't respect project references

2 participants