fix(core): support ${configDir} in tsconfig path alias resolution#36037
fix(core): support ${configDir} in tsconfig path alias resolution#36037leosvelperez wants to merge 1 commit into
${configDir} in tsconfig path alias resolution#36037Conversation
TypeScript's `${configDir}` template in a tsconfig `paths` alias resolves to the
directory of the project being compiled, so an alias like
`"@/*": ["${configDir}/src/app/*"]` points each project at its own sources.
The project-graph resolver read these mappings verbatim and never substituted
the template. The literal path matched no project and fell back to whatever
project sits at the workspace root, so `enforce-module-boundaries` reported
false "Imports of apps are forbidden" errors for an app importing its own files
through a configDir alias.
The resolver now expands `${configDir}` the same way `tsc` does: it matches the
template case-insensitively and only as a prefix, then resolves it against the
importing file's project root. A configDir alias now resolves back into the
source project.
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 6b447cb
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud has identified a possible root cause for your failed CI:
We reviewed the two failing tasks and found neither is caused by this PR's changes. The examples-angular-rspack-mf-host:build failure is an environment issue — is-ci is missing from the nx dist bundle, unrelated to the ${configDir} tsconfig path resolution fix. The e2e-release E2E failure is a known flaky timeout (~11% flakiness rate) that affects a different test step than what was seen in other branches.
No code changes were suggested for this issue.
Trigger a rerun:
🎓 Learn more about Self-Healing CI on nx.dev
Current Behavior
TypeScript's
${configDir}template (TS 5.5+) lets a tsconfigpathsalias point at the project currently being compiled, e.g.:Nx's project-graph resolver read these mappings verbatim and never substituted the template. The literal
${configDir}/...path matched no project, so resolution fell back to whatever project sits at the workspace root. With@nx/enforce-module-boundariesthis surfaced as falseImports of apps are forbiddenerrors when an app imported its own files through a configDir alias. Switching the same import to a relative path made the error disappear.Expected Behavior
A
${configDir}path alias resolves to the importing file's own project, matching howtscresolves it, so importing a project's own sources through the alias no longer triggers module-boundary violations.Related Issue(s)
Fixes #35804
Implementation Details
TargetProjectLocator(used by both the project graph andenforce-module-boundaries) now expands${configDir}in matchedpathsvalues before resolving, mirroring TypeScript'scommandLineParserbehavior: the template is matched case-insensitively and only as a prefix, then resolved against the importing file's project root (the directory of the tsconfig used for compilation). Only values that start with${configDir}change; all other aliases are untouched. Added a regression test intarget-project-locator.spec.tscovering nested, deeply nested, and root-project importers.View session information ↗