Skip to content

Support Angular 21 - #2

Merged
aminesbdev merged 1 commit into
mainfrom
angular-21
Oct 13, 2026
Merged

aminesbdev merged 1 commit into
mainfrom
angular-21

Conversation

@aminesbdev

Copy link
Copy Markdown
Owner

The package only accepted Angular 22.2, because the enableTemplateSourceLocations compiler option only exists since 22.1.4. Angular 21 has the same feature in the compiler and the same attribute at runtime, but the only switch is setEnableTemplateSourceLocations(), a function that @angular/compiler exports for Angular's own tests.

What changes

  • New entry point ngx-source-inspector/enable-source-locations, a preload for ng serve that calls that function in the process and in the worker thread that compile the templates:

    NODE_OPTIONS="--import ngx-source-inspector/enable-source-locations" ng serve

    It only does something for the dev server (ng serve, ng s, ng dev, a serve target), so a production build stays clean even when NODE_OPTIONS is set for it too. On Angular versions that have the compiler option it does nothing and says so.

  • ng add looks at the installed Angular version. With the compiler option it does what it did before. Without it, it only adds the provider and prints the command above. It doesn't touch the start script, since the VAR=value command syntax isn't portable to Windows.

  • Peer dependencies accept >=21.0.0 <23.0.0, and the version goes to 0.2.0.

How it was checked

  • Unit tests for the preload (dev server commands, other commands, a compiler without the setter, outside of a workspace) and for the new ng add path.
  • npm run check:angular-21, also run in CI: sets up a new Angular 21 app with ng add, checks that ng serve with the preload produces source locations and that a production build with the same NODE_OPTIONS contains none.
  • By hand on Angular 21.2.25 in headless Chrome: Alt+hover shows <app-root> · src/app/app.html:235:7 on the <h1> of the new app, and Alt+click calls the editor with that file, line and column.

Not checked: Windows, and Angular 21.0, 21.1 and 22.0 to 22.1.3.

🤖 Generated with Claude Code

The `enableTemplateSourceLocations` compiler option only exists since Angular
22.1.4. Before that, the compiler has the same feature behind
`setEnableTemplateSourceLocations()`, a function that `@angular/compiler`
exports for Angular's own tests, and the runtime writes the same attribute.

- New `ngx-source-inspector/enable-source-locations` entry point, a preload for
  `ng serve` that calls that function in the process and the worker thread
  that compile the templates:

    NODE_OPTIONS="--import ngx-source-inspector/enable-source-locations" ng serve

  It only does something for the dev server, so a production build stays clean
  even when NODE_OPTIONS is set for it too.
- `ng add` looks at the installed Angular version: with the compiler option it
  does what it did before, without it it only adds the provider and prints the
  command above.
- The peer dependencies accept Angular 21 and 22.

CI sets up a new Angular 21 app with `ng add` and checks that `ng serve` with
the preload produces source locations and that a production build doesn't.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aminesbdev
aminesbdev merged commit bdc06a1 into main Oct 13, 2026
1 check passed
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