Title: fix(@angular/build): respect tsconfig customConditions in unit-test builder by RobbyRabbitman · Pull Request #33246 · angular/angular-cli · GitHub
Open Graph Title: fix(@angular/build): respect tsconfig customConditions in unit-test builder by RobbyRabbitman · Pull Request #33246 · angular/angular-cli
X Title: fix(@angular/build): respect tsconfig customConditions in unit-test builder by RobbyRabbitman · Pull Request #33246 · angular/angular-cli
Description: PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-commit-message-guidelines Tests for the changes have been added (for bug fixes / features) Docs have been added / updated (for bug fixes / features) PR Type What kind of change does this PR introduce? Bugfix Feature Code style update (formatting, local variables) Refactoring (no functional changes, no api changes) Build related changes CI related changes Documentation content changes Other... Please describe: What is the current behavior? When @angular/build:unit-test is configured with an @angular/build:ng-packagr build target, the synthesized application-builder build never receives the test tsconfig's compilerOptions.customConditions. Module resolution therefore diverges from ng build, which honors customConditions natively through ng-packagr: transformNgPackagrOptions() only forwards stylePreprocessorOptions, assets and inlineStyleLanguage from ng-package.json; ng-packagr's schema has no conditions field, so nothing is carried over. The synthesized ApplicationBuilderInternalOptions is then handed to buildApplicationInternal() without conditions, so esbuild resolves library imports with only the default conditions (module, development/production, plus browser/node). The Vitest runner's resolve.conditions was hardcoded to ['es2015', 'es2020', 'module', (browser)], also ignoring custom conditions. Concrete impact: monorepo setups that use customConditions (e.g. a source condition) to redirect workspace library imports to local TypeScript sources during development work as expected for ng build, but ng test silently falls back to the published entry points — defeating the purpose of source‑mapped local development and making library tests harder to debug. Issue Number: N/A What is the new behavior? The unit-test builder now reads compilerOptions.customConditions from the test tsconfig (following the extends chain via the TypeScript config parser) and: forwards them as conditions into the synthesized application-builder options, but only when the build target did not already set conditions. This preserves the existing application-builder behavior, including explicit opt‑outs (conditions: []) and user-supplied lists. appends them to Vite's resolve.conditions in the Vitest plugin, so the runner's own resolver matches the build-time resolution. No schema changes and no public API surface changes; the new behavior is opt‑in via the existing compilerOptions.customConditions tsconfig field (TS 5.0+). A new integration spec at packages/angular/build/src/builders/unit-test/tests/options/conditions_spec.ts locks the behavior in with two cases: Positive – with customConditions: ['staging'] in tsconfig.spec.json and a #target imports map that exposes the good source only under the staging condition, the spec resolves to the good source and passes. Negative regression guard – same target mapping but no customConditions declared; the spec must fall back to the default (bad) target, proving the new behavior is opt‑in and does not inject unrelated conditions. Does this PR introduce a breaking change? Yes No The new behavior only activates when compilerOptions.customConditions is present in the test tsconfig — a field most projects do not set today. For @angular/build:application build targets that explicitly set conditions, that value is preserved (the backfill is guarded by conditions === undefined). For ng-packagr targets, this brings ng test into parity with ng build, which is a convergence rather than a divergence. Other information Files changed: packages/angular/build/src/builders/unit-test/options.ts — read customConditions from the test tsconfig via ts.parseJsonConfigFileContent (extends‑aware) and expose it on the normalized options. packages/angular/build/src/builders/unit-test/builder.ts — backfill conditions into the application-builder options only when the build target did not set it. packages/angular/build/src/builders/unit-test/runners/vitest/executor.ts — thread customConditions through to the Vitest config plugin. packages/angular/build/src/builders/unit-test/runners/vitest/plugins.ts — append customConditions to Vite's resolve.conditions. packages/angular/build/src/builders/unit-test/tests/options/conditions_spec.ts — new integration spec. The Karma runner intentionally was not touched: it does not share the Vite resolver code path, and forwarding conditions through the application build it consumes is already covered by the same builder.ts change.](#33246)
Open Graph Description: PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-comm...
X Description: PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-comm...
Opengraph URL: https://github.com/angular/angular-cli/pull/33246
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:ff1c865a-2118-83af-65ed-5ac22a09989e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A730:2D3AF3:257E06:3468A2:6A630161 |
| html-safe-nonce | b55aa51cfb5d902cae321361e6ac2b0a1c59e9a03e0c020c4c50a405659d78a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzMwOjJEM0FGMzoyNTdFMDY6MzQ2OEEyOjZBNjMwMTYxIiwidmlzaXRvcl9pZCI6Ijg5NzU0MjIyMTk0MzE5MDM1ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 93a6212c66e63616269cbf132107c351021508e9c290ee64507baf39d71e1816 |
| hovercard-subject-tag | pull_request:3734787432 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular-cli/pull/33246/files |
| twitter:image | https://avatars.githubusercontent.com/u/54601487?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/54601487?s=400&v=4 |
| og:image:alt | PR Checklist Please check to confirm your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular-cli/blob/main/CONTRIBUTING.md#-comm... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 14517cd57568049be7ed25bfe9708f10d1e36b7254adfd920dfb9d44bcc71c41 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b2ed33e3827bc186c45c037f9274b5493aaca4c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width