Skip to content

feat(vite): default angularVersion to the installed @angular/core version - #672

Merged
Brooooooklyn merged 2 commits into
mainfrom
fix/angular-version-default
Nov 3, 2026
Merged

Brooooooklyn merged 2 commits into
mainfrom
fix/angular-version-default

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Follow-up to #654 / #669.

Problem

When the Vite plugin's angularVersion option is unset, the compiler targets the latest Angular. Since #669, the latest (≥ 22.2) rejects the array form of @Component.deferredImports with error 1010. A project on Angular 22.1 or older that never set angularVersion hits that error, even though its runtime still expects the array form.

Change

angular({ angularVersion?: ... })
  set   → used as is (unchanged)
  unset → node_modules/@angular/core/package.json, searched up from Vite's `root`
          not found, or a 0.0.0-... build → latest (as before)
  • The lookup starts at Vite's root, not workspaceRoot/cwd, so an app that has its own @angular/core under a workspace with another hoisted version gets the version it actually imports.
  • The linker plugin reads the version for the same root, so app code, linked libraries and the dependency-optimizer cache key all agree.
  • A relative path is resolved before the upward search.
  • Under Yarn PnP it uses createRequire. Otherwise it walks node_modules like the existing zone.js check, which avoids pnpm's NODE_PATH.

Only the Vite plugin changes. The programmatic transformAngularFile API still defaults to latest.

Visible effect for projects that leave angularVersion unset

The compiler now targets the installed version, so everything gated on that version follows the runtime:

Installed Before (latest) Now
≤ 22.1, array deferredImports error 1010 compiles
22.x template ?. lowered to the legacy == null ? null : form native ?., like ngtsc's v22 default
< 22 modern style encapsulation legacy encapsulation, matching that runtime

Tests

test/angular-version.test.ts (10 tests):

  • parsing: stable, prerelease, +build, 0.0.0-PLACEHOLDER, invalid
  • lookup: from a nested directory, from a relative . inside a hoisted workspace, an unreadable package
  • plugin: Angular 22.1 compiles the array form, 22.2 reports it, the explicit option wins, Vite's root is used over the workspace root, and the linker's optimizer name follows the same version

The key tests fail without the change. Full pnpm test (429) and pnpm check pass.

🤖 Generated with Claude Code

Brooooooklyn and others added 2 commits November 3, 2026 11:00
…sion

Without the option the compiler targeted the latest Angular, so an
Angular 22.1 project got error 1010 for the array form of
`deferredImports`, which its runtime still expects. The plugin now
reads @angular/core's version from node_modules, up from
`workspaceRoot`; a `0.0.0-...` build or no package keeps the latest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The app's own @angular/core can sit under Vite's root in a workspace
that hoists another version, and a relative path stopped the upward
search at `.`. The linker now reads the version for the same root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T03:29:20.337356Z 8e0004c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 8e0004c5ee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit 631ea32 into main Nov 3, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/angular-version-default branch November 3, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant