Commit graph

704 commits

Author SHA1 Message Date
Matthieu Riegler
d00b3fed58 feat(router): add a currentNavigation signal to the Router service. (#62971)
This new signal property is convenient to derive a `isNavigating` state.

`isNavigating = computed(() => !!this.router.currentNavigation())`

DEPRECATED: The Router.getCurrentNavigation method is deprecated. Use the Router.currentNavigation signal instead.

fixes #62958

PR Close #62971
2025-08-05 10:05:49 +02:00
Kristiyan Kostadinov
b1514d512e fix(migrations): incorrect filtering in inject migration (#62913)
The inject migration wasn't implementing file filtering properly which resulted in it passing an invalid tsconfig path to TypeScript.

Fixes #62866.

PR Close #62913
2025-07-31 09:15:42 +00:00
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +00:00
Joey Perrott
49b7729e88 build: remove usages of rules_nodejs (#62885)
Remove rules_nodejs usages with direct migrations to rule_js alternatives

PR Close #62885
2025-07-30 08:51:27 +00:00
Joey Perrott
32c00ab416 build: standardize usage of js_binary (#62860)
Remove usages of nodejs_binary and use a commonly defined js_binary macro

PR Close #62860
2025-07-29 06:43:44 +02:00
Joey Perrott
caee6ff8e7 build: remove all usages of @bazel/runfiles (#62804)
Remove usages of @bazel/runfiles throughout the repository

PR Close #62804
2025-07-25 10:04:55 +02:00
Joey Perrott
f5d9d084b6 build: move nodejs_test to js_test (#62709)
Move nodejs_test to js_test and remove unnecessary files after move

PR Close #62709
2025-07-22 10:07:13 -04:00
Joey Perrott
8bf97d1370 build: remove all usages of the interop_deps attr for ts_project and ng_project (#62732)
Remove all of the usages of interop_deps as attributes in the repo

PR Close #62732
2025-07-21 13:03:09 -04:00
Kristiyan Kostadinov
745ea44394 feat(core): support TypeScript 5.9 (#62541)
Updates the repo to support TypeScript 5.9 and expands the allowed version range.

PR Close #62541
2025-07-14 14:04:58 -07:00
Joey Perrott
efc2a41d1d build: use rollup directory instead of rollup through @bazel/rollup (#62556)
Use rollup directly instead of using the previous toolchain implementation

PR Close #62556
2025-07-09 16:53:25 -07:00
Paul Gschwendtner
902121ebc0 refactor(migrations): ensure tsurge can properly emit references in g3 (#62447)
Currently when Tsurge runs in g3, it creates a bare bones Angular
compiler plugin. The tsconfigs from compilation units may set options
like "useHostForImportGeneration", but the Ngtsc logic doesn't enable
because the `fileNameToModuleName` method is not defined on the host.

This can break reference emission for Tsurge analyzers/programs and
result in subtle differences to real `ng_module` compilations. This
commit fixes this by making the method available in 1P Tsurge.

Notably, reference emission can occur during analysis— so even if
migrations aren't "emitting TS -> JS" output.

PR Close #62447
2025-07-03 09:36:16 +00:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
Joey Perrott
557ac51c32 build: migrate to using new jasmine_test (#62131)
Migrate additional targets to jasmine_test

PR Close #62131
2025-06-19 10:06:27 +02:00
Kristiyan Kostadinov
34adfdea82 fix(migrations): more robust trailing comma removal in unused imports migration (#62118)
Fixes the following issues with the logic in the unused imports migration that deals with trailing commas:
1. It was generating overlapping text ranges which can break internally.
2. It wasn't handling some cases that produce trailing commas.

PR Close #62118
2025-06-18 15:57:12 +02:00
Joey Perrott
3a0cfd544d build: migrate to using new jasmine_test (#62086)
Use the new jasmine_test based on rules_js instead of jasmine_node_test from rules_nodejs

PR Close #62086
2025-06-18 08:27:26 +02:00
Joey Perrott
1182fe7053 build: migrate to usages of @devinfra// instead of @npm//@angular/build-tooling (#62050)
Use workspace imported devinfra deps instead of npm dep

PR Close #62050
2025-06-16 10:23:30 +02:00
Matthieu Riegler
4040a6ba5d refactor(migrations): support local string tokens for inject migration (#62013)
The `localTypeChecker` allows us to at least support locally defined strings in addition to string literals.

PR Close #62013
2025-06-12 15:53:20 +02:00
Kristiyan Kostadinov
eb43e9242d refactor(compiler): account for new assignment AST (#61682)
Reworks the places that were depending on `PropertyWrite` and `KeyedWrite` to account for the new AST structure.

PR Close #61682
2025-06-03 11:08:50 -04:00
Matthieu Riegler
9630d79d1a refactor(migrations): keep the control flow migration as ng generate. (#61773)
this way `ng generate @angular/core:control-flow` which has been fairly documented, remains valid.

PR Close #61773
2025-06-03 07:12:59 -04:00
Kristiyan Kostadinov
bb88b3f22f fix(migrations): avoid trailing whitespaces in unused imports migration (#61698)
Follow-up to #61674 where we were leaving behind some whitespace, e.g. `[One, Two, Three]` would turn into `[One ]`. These changes only preserve the whitespace if the node is preceded by a newline.

This wasn't caught by tests, because they were stripping away whitespaces before asserting. I've also reworked the tests to be sensitive to formatting changes.

PR Close #61698
2025-05-30 11:07:20 -04:00
Kristiyan Kostadinov
04656d0b6e fix(migrations): preserve comments when removing unused imports (#61674)
Updates the unused imports schematic to preserve comments inside the array. THis is necessary for some internal use cases.

PR Close #61674
2025-05-26 10:26:20 +00:00
Joey Perrott
b37fd9753f build: migrate language service to use rules_js (#61568)
Migrate language service to build using ts_project

PR Close #61568
2025-05-21 17:05:14 +00:00
Paul Gschwendtner
08f7d21d5c refactor(migrations): ensure tsurge configures file system properly (#61553)
Currently in 1P, without this commit, the tsconfig parsing picks up the
default file system (InvalidFS) and results in runtime errors.

PR Close #61553
2025-05-21 10:01:18 +00:00
Paul Gschwendtner
b148e272f6 refactor(migrations): gracefully proceed if reference cannot be resolved (#61426)
A runtime error can surface when TypeScript internally fails to resolve
a reference that is named similar to an input, but no `.d.ts` is
available for it.

See example error:
https://github.com/microsoft/TypeScript/issues/61473#issuecomment-2746537781.

PR Close #61426
2025-05-19 11:04:52 +00:00
Alan Agius
cf8c853523 build: remove @types/diff (#61447)
The latest diff package includes the TS types.

PR Close #61447
2025-05-19 09:17:47 +00:00
Paul Gschwendtner
e4d2347d66 Revert "fix(migrations): avoid applying the same replacements twice when cleaning up unused imports (#59656)" (#61421)
This reverts commit d66881d172.

PR Close #61421
2025-05-16 15:56:44 +00:00
Paul Gschwendtner
ca233446f0 refactor: clean-up deduplication workaround from migrations (#61421)
Since the duplication root-cause was solved by the previous commit, we
can revert/drop the logic that was added back then to overcome this
problem with Tsurge.

PR Close #61421
2025-05-16 15:56:44 +00:00
Paul Gschwendtner
4a3d39cd5a refactor: ensure tsurge migrations have clear ownership of files (#61421)
Currently there can be cases, exlusively in 3P, where multiple tsconfig
projects have overlap of source files. This is the default setup of new
CLI applications as well.

When this is the case, Tsurge will treat each tsconfig as an isolated
compilation unit (given the concepts and mental model to support
scalable batching). This is wrong though, and the same `.ts` source file
can appear in two migration invocations; resulting in duplicate
replacements or analysis (depending on the migration).

We've worked around this problem in the past by deduplicating
replacements, or migrating to an ID-based approach with natural
deduplication. This worked, but it's just working around the root cause.

This commit attempts to fix the root cause by adjusting Tsurge to ensure
that no source file ever appears in two compilation units. This is
naively achieved by not adding a source file to a migration unit, if it
was part of a previous one. This is expected to be fine given the nature
of Tsurge migrations that are built to operate on isolated pieces
anyway— so it shouldn't be problematic if e.g. `app.component.ts` ends
up being part of the test tsconfig compilation unit (we avoid this order
though by visiting build targets first).

PR Close #61421
2025-05-16 15:56:44 +00:00
Paul Gschwendtner
b763059bdd build: migrate packages/core/schematics to ts_project (#61370)
Migrates `packages/core/schematics` to `ts_project`. As part of this,
this commit cleans up some of the mixed module types and tsconfigs in
the folder. A single tsconfig (and it's test variant) are now used.

For the shipped schematics, we explicitly use the `.cjs` extension, so
that the bundles are properly recognized as CommonJS; even if they are
part of the `type: module` `@angular/core` package.

The `package.json` with `type: commonjs` is removed from
`packages/core/schematics` as it's no longer needed given the explicit
extension & caused issues as schematics are compiled with ESM but are
only later bundled for shipping & some tests as ESM.

PR Close #61370
2025-05-16 11:02:07 +00:00
Jonathan Meier
e62fb359d6 feat(compiler-cli): add experimental support for fast type declaration emission (#61334)
In declaration-only emission mode, the compiler extracts the type
declarations (.d.ts) files without full type-checking, which is possible
with sufficient type annotations on exports that can be ensured by the
`isolatedDeclarations` TS compiler option.

This allows us to decouple type declaration emission from the actual
full compilation doing the type-checking, thereby removing the
edge between dependent TS files in the build action graph. In other
words, the compilation of a TS file no longer indirectly depends on the
compilation of all the TS files it imports through its dependency on
their type declarations, because the type declarations themselves no
longer depend on the compilation of their associated TS file.

Without the coupling between type declaration emission and compilation,
compilation time of a TS project is no longer bound dependent on the
depth of the TS dependency tree as we can now build the entire project
with just two entirely parallel phases: 1) emit the type declarations of
all TS files in parallel and 2) compile all TS files in parallel.

Since the Angular compiler adds static metadata fields to components,
directives, modules, pipes and services based on their respective class
annotations, it needs to actively partake in the type declaration
emission in order to provide the types for these static fields in the
declaration.

In this change, we add experimental support for a declaration-only
emission mode based on the local compilation mode, which already
operates without type-checking and access to external type information,
i.e. the same environment as is required for declaration-only emisssion.

Apart from the same restrictions applied in local compilation mode,
there are a few more restrictions imposed on code being compatible with
this initial and experimental implementation:

* No support for `@NgModule`s using external references.
* No support for `hostDirectives` in `@Component`s and `@Directive`s
  using external references
* No support for `@Input` annotations with `transform`.

PR Close #61334
2025-05-14 14:07:37 -07:00
Kristiyan Kostadinov
eae1083a54 refactor(compiler): indicate in AST if node is self-closing (#61307)
Follow-up from https://github.com/angular/angular/pull/61240#discussion_r2084445328. Adds a `isSelfClosing` property on element-like AST nodes so consumers can easily determine if it's self-closing, rather than having to look at the spans. This is useful for migrations and in the language service.

PR Close #61307
2025-05-14 11:06:22 +02:00
Paul Gschwendtner
84d50d205a refactor: support arbitrary stats/metrics in tsurge (#61272)
Supports arbitrary stats/metrics in Tsurge. This will make
complex analysis easier as we aren't bound to just `Record<string,
number>` counters.

PR Close #61272
2025-05-14 11:05:55 +02:00
Paul Gschwendtner
3d0ecb2273 refactor: remove unused beam pipeline code (#61272)
We don't need this logic anymore as we combine in batches and don't deal
with bulk data files that combine all units.

PR Close #61272
2025-05-14 11:05:55 +02:00
Paul Gschwendtner
810b0a7e5c refactor: add explicit types for exports relying on inferred call return type (#61312)
As part of the Bazel toolchain migration we noticed that implicit types
generated by the TypeScript compiler sometimes end up referencing types
from other packages (i.e. cross-package imports).

These imports currently work just because the Bazel `ts_library` and
`ng_module` rules automatically inserted a `<amd-module
name="@angular/x" />` into `.d.ts` of packages. This helped TS figure
out how to import a given file. Notably this is custom logic that is not
occuring in vanilla TS or Angular compilations—so we will drop this
magic as part of the toolchain cleanup!

To improve code quality and keep the existing behavior working, we are
doing the following:

- adding a lint rule that reduces the risk of such imports breaking. The
  failure scenario without the rule is that API goldens show unexpected
  diffs, and types might be duplicated in a different package!

- keeping the `<amd-module` headers, but we manually insert them into
  the package entry-points. This should ensure we don't regress
  anywhere; while we also improved general safety around this above.

Long-term, isolated declarations or a lint rule from eslint-typescript
can make this even more robust.

PR Close #61312
2025-05-13 22:45:18 +00:00
Kristiyan Kostadinov
4dc7136c49 refactor(migrations): remove unused code (#61260)
The `waitForAsync` rule has been disabled internally which allows us to delete its code, as well as some unused adjacent code.

PR Close #61260
2025-05-12 15:34:07 -07:00
Paul Gschwendtner
10bc80a788 build: migrate compiler-cli/src/ngtsc to ts_project (#61181)
Migrates all of `compiler-cli/src/ngtsc` to `ts_project`. This change
was generated using Gemini.

PR Close #61181
2025-05-09 15:59:46 +00:00
Kristiyan Kostadinov
bc9a067ef4 refactor(compiler-cli): add flag to enable selectorless (#60977)
Adds a private flag that we can use to enable selectorless as it's being developed.

PR Close #60977
2025-04-24 13:02:39 -07:00
Ryan Russell
0162ceb427 fix(core): inject migration should treat @Attribute as optional (#60916)
The @Attribute decorator will inject null if a host attribute
is missing, but `inject(new HostAttributeToken(...))` will throw
a no provider error. We should set {optional: true} when migrating
an @Attribute decorator. Also allow nonNullableOptional to add
`!` to those declarations.

PR Close #60916
2025-04-22 10:42:58 +02:00
Ryan Russell
11d441ff8b fix(core): inject migration: replace param with this. (#60713)
The inject tool inserts `const foo = this.foo` if code
in the constructor referenced the constructor parameter `foo`.
If `foo` is a readonly property, we can instead replace `foo` with
`this.foo`. This allows more properties to be moved out of the
constructor with combineMemberInitializers.
For now, it only touches initializers, not all of the code in the
constructor.

PR Close #60713
2025-04-10 13:31:30 -04:00
aparziale
39a4e00464 fix(core): fix ng generate @angular/core:output-migration. Fixes angular#58650 (#60763)
Fixes #58650 - Insert a TODO comment for empty emit (without parameter).

PR Close #60763
2025-04-08 16:10:03 -07:00
JoostK
3d85d9363c fix(core): reduce total memory usage of various migration schematics (#60774)
This commit changes Tsurge's operation within angular-devkit (i.e. the CLI) to
no longer retain all programs across all migrations. This isn't necessary for
so-called "funnel" migrations so not retaining the programs for those migrations
is a pure performance win. The "complex" migrations may see increased execution time
given that the program is now being recreated for the actual migration phase to run,
although reduced memory pressure may help alleviate this overhead. Since this new
approach should help prevent Node from running out of memory and failing entirely
this is preferred over a potentially increased execution time.

Fixes #59813

PR Close #60774
2025-04-07 13:13:33 -07:00
Kristiyan Kostadinov
92c4123a74 refactor(compiler): integrate new AST nodes into visitors (#60724)
Updates the various visitors to add placeholders for the new AST nodes.

PR Close #60724
2025-04-04 11:28:47 -07:00
aparziale
6acce7ca2a fix(core): fixes #592882 ng generate @angular/core:signal-queries-migration (#60688)
fixes #592882 - retain accessibility modifier if it's already present for signal migrations

PR Close #60688
2025-04-02 15:14:43 +00:00
aparziale
cdbc6e8ec1 fix(core): fix ng generate @angular/core:output-migration (#60626)
output-migration command not keep type if @output declaring without initializer

PR Close #60626
2025-04-02 14:26:05 +00:00
Kristiyan Kostadinov
accc65c2c9 refactor(migrations): add a migration to move DOCUMENT imports (#60663)
Adds a migration that moves imports of `DOCUMENT` from `common` to `core`.

PR Close #60663
2025-04-01 12:48:06 +00:00
Matthieu Riegler
e40b5c9ebd refactor(core): run the control flow migration during ng update (#60492)
The migration had to be run manually before this change. It is now part of the update process when migrating to v20.

PR Close #60492
2025-03-28 15:46:41 +00:00
Kristiyan Kostadinov
0c53970aeb fix(migrations): handle shorthand assignments in super call (#60602)
Fixes that the logic which checks whether a parameter is used inside a `super` call wasn't accounting for shorthand assignments.

PR Close #60602
2025-03-28 13:34:36 +00:00
Kristiyan Kostadinov
3ff48b6467 fix(migrations): inject migration not handling super parameter referenced via this (#60602)
The inject migration has some logic that treats parameters referenced directly inside of `super` differently. This logic didn't account for the fact that the parameters could be inside of inline functions which have less strict access requirements.

PR Close #60602
2025-03-28 13:34:36 +00:00
Ryan Russell
0cd7d3bdf0 fix(core): preserve comments in internal inject migration (#60588)
The internal-only combineMemberInitializers option
for the inject migration sometimes dropped the
doc comments from the members.

PR Close #60588
2025-03-27 20:24:22 +00:00
aparzi
cf5c61c849 fix(core): fix used templates are not deleted (#60459)
After running the control flow migration, used templates are not deleted.

PR Close #60459
2025-03-24 09:04:05 -07:00