Commit graph

653 commits

Author SHA1 Message Date
Kristiyan Kostadinov
c147a0d6de refactor(migrations): simplify integration of tsurge migrations into the CLI (#60386)
Currently when we reuse a Tsurge migration is reused externally, there's some glue code that needs to be executed in a specific order. The code gets copied between the different migrations which is error-prone and means that bugs may have to be fixed several times.

These changes move the common steps out into a separate function so that only the migration-specific logic (mostly instantiation and logging) is left in the schematic.

PR Close #60386
2025-03-14 14:44:26 +01:00
Kristiyan Kostadinov
e170d24240 fix(core): add migration away from InjectFlags (#60318)
Adds an automated migration that will switch users from the deprecated `InjectFlags` API to its non-deprecated equivalent.

PR Close #60318
2025-03-11 11:33:09 -07:00
aparzi
de2bfc0913 fix(core): fix removal of a container reference used in the component file (#60210)
During migration a container reference was deleted even though it was used in the component file.

PR Close #60210
2025-03-11 09:26:13 -07:00
Kristiyan Kostadinov
0e40a1c93f build: remove migrations for v19 (#60304)
Removes the migrations for v19 since they aren't relevant anymore.

PR Close #60304
2025-03-10 09:20:52 -07:00
Alan Agius
9080fdf6f8 test: narrow down signal-input typescript tests (#60266)
Remove TS versions that are no longer supported.

PR Close #60266
2025-03-07 11:00:03 -08:00
Alan Agius
45f899a272 refactor: replace fast-glob usage with tinyglobby (#60264)
Usage of the `fast-glob` package has been replaced with the `tinyglobby` package. The change reduces the number of transitive dependencies related to these packages from 17 to 2 while also maintaining equivalent functionality. This was also changed in the Angular CLI packages.

PR Close #60264
2025-03-07 10:57:23 -08:00
naaajii
b4feeb5a7d docs: update license year (#59883)
updates the year in footer and placeholder for generated files

PR Close #59883
2025-03-04 19:36:47 +00:00
Matthieu Riegler
265387a6c8 refactor(migrations): Don't migrate twice the same file on the self-closing tag migration (#60065)
This commit fixes an issue when ts files are referenced multiple times (and thus analyzed multiple times) for example from a `tsconfig.json` and `tsconfig.spec.json`.

PR Close #60065
2025-02-28 16:27:40 +00:00
Enea Jahollari
1cd3a7db83 feat(migrations): add migration to convert templates to use self-closing tags (#57342)
This schematic helps developers to convert their templates to use self-closing tags mostly as a aesthetic change.

PR Close #57342
2025-02-18 17:33:59 +00:00
Kristiyan Kostadinov
aa285c548c fix(migrations): account for let declarations in control flow migration (#59861)
Fixes that the control flow migration wasn't accounting for `@let` when determining which symbols are used.

PR Close #59861
2025-02-12 09:45:14 -08:00
Kristiyan Kostadinov
1119f85ca9 fix(migrations): count used dependencies inside existing control flow (#59861)
Fixes that the control flow migration wasn't checking the content of pre-existing control flow nodes for dependencies.

Fixes #59846.

PR Close #59861
2025-02-12 09:45:14 -08:00
Kristiyan Kostadinov
d66881d172 fix(migrations): avoid applying the same replacements twice when cleaning up unused imports (#59656)
If a file ends up in multiple programs, the unused imports migration was counting it twice. This was fine since the string replacements were handling it correctly, but it was printing out incorrect data.

These changes rework the migration to de-duplicate the replacements and produce the data from the de-duplicated results.

PR Close #59656
2025-01-22 07:57:38 -08:00
Kristiyan Kostadinov
9931030b0e test(migrations): add test for earlier fix (#59497)
Adds a test for the fix from #59452 now that we know what caused the issue.

PR Close #59497
2025-01-13 11:10:18 -05:00
Paul Gschwendtner
8496fb16bc fix(migrations): incorrect stats when migrating queries with best effort mode (#59463)
We previously did count forcibly ignored queries as incompatible. This
resulted in incorrect migration stats that are printed upon migration
completion.

See: #58657

PR Close #59463
2025-01-10 11:52:13 -05:00
Paul Gschwendtner
86cbaaa2a2 test: add test to verify extending tsconfig works in signal input migration (#59463)
Related to https://github.com/angular/angular/issues/59348

PR Close #59463
2025-01-10 11:52:13 -05:00
Paul Gschwendtner
24f383ab4f test: improve typescript version coverage for signal input migration (#59463)
This ensures the migration works for these TypeScript versions. The
migration is very sensitive to the TS version and its internals; so it
makes sense to test all of these.

PR Close #59463
2025-01-10 11:52:12 -05:00
Kristiyan Kostadinov
966a370390 fix(migrations): resolve text replacement issue (#59452)
Based on https://github.com/angular/angular/pull/59353#issuecomment-2580320424, fixes a text replacement issue that seems to cause code to be duplicated in some setups.

PR Close #59452
2025-01-10 10:47:54 -05:00
RafaelJCamara
5c9e84acd6 docs: update license URL from angular.io to angular.dev and year of license to 2025 (#59407)
PR Close #59407
2025-01-09 10:27:54 -05:00
Kristiyan Kostadinov
d298d25426 feat(migrations): add schematic to clean up unused imports (#59353)
In v19 we added a warning about unused standalone imports, however we didn't do anything about existing code which means that users have to clean it up manually. These changes add the `ng g @angular/core:cleanup-unused-imports` schematic which will remove the unused dependencies automatically.

There isn't any new detection code since all the manipulations are based on the produced diagnostics, but there's a bit of code to remove the import declarations from the file as well.

Fixes #58849.

PR Close #59353
2025-01-06 16:21:26 +00:00
Kristiyan Kostadinov
d6ca669bc9 refactor(migrations): allow compiler options to be customized in tsurge (#59353)
Allows for user-defined options to be passed in when creating a program in tsurge.

PR Close #59353
2025-01-06 16:21:26 +00:00
hawkgs
0513fbc9fc docs: set syntax highlighting of code examples MD code blocks (#59026)
Set the syntax highlighting based on the code examples' language.

PR Close #59026
2024-12-04 17:30:28 +01:00
Kristiyan Kostadinov
35165d152d fix(migrations): inject migration dropping code if everything except super is removed (#58959)
Fixes that in some cases the internal version of the migration was dropping code when all the statements after the `super` call are deleted.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
7191aa6e09 fix(migrations): don't migrate classes with parameters that can't be injected (#58959)
Updates the inject migrations to skip over classes that have uninjectable class parameters.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
68e5ba7a3a fix(migrations): preserve type literals and tuples in inject migrations (#58959)
Updates the inject migration to preserve type literals and tuple types, based on some internal feedback.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
a4924af6d5 fix(migrations): inject migration aggressively removing imports (#58959)
Fixes that the inject migration would remove imports even if they're still used by classes that aren't being migrated.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
508d3a1b3b fix(migrations): correctly strip away parameters surrounded by comments in inject migration (#58959)
Fixes that the inject migration was sometimes producing invalid code if there are comments around the parameters.

PR Close #58959
2024-12-02 08:56:21 +01:00
Kristiyan Kostadinov
e31e52e177 fix(migrations): class content being deleted in some edge cases (#58959)
Fixes that the inject migration was deleting the class' content if a property exists after the constructor that is being rewritten.

PR Close #58959
2024-12-02 08:56:20 +01:00
Kristiyan Kostadinov
bd1f1294ae feat(core): support TypeScript 5.7 (#58609)
Updates the repo to allow for TypeScript 5.7 to be used.

PR Close #58609
2024-11-25 17:12:10 +00:00
Kristiyan Kostadinov
4f1f4a1728 refactor(migrations): skip TS version check in tsurge (#58866)
Skips the TS version check in tsurge since it's blocking some internal changes and generally isn't necessary since the app will be checked when it's built anyways.

PR Close #58866
2024-11-25 15:26:18 +00:00
Younes Jaaidi
1fe001e18b fix(migrations): fix provide-initializer migration when using useFactory (#58518)
Priori to this commit, initializer functions with dependencies were not migrated correctly.
With this commit, the function is executed in a injection context to allow the usage of `inject`.

PR Close #58518
2024-11-21 20:59:35 +00:00
Ryan Russell
3fc14ecc81 fix(migrations): Mark hoisted properties as removed in inject migration (#58804)
Before, in a situation like shown in the test, all of the initializers
would be dropped, as the code would try to insert it at the hoisted
property which is going to be deleted.

PR Close #58804
2024-11-21 20:58:26 +00:00
JoostK
21f757c1c4 fix(core): correctly perform lazy routes migration for components with additional decorators (#58796)
This fixes an issue where the lazy-routes migration would crash for component classes a
decorator without arguments in front of the `@Component` decorator (in particular, it needed
to be the first decorator).

Fixes #58793

PR Close #58796
2024-11-21 16:43:30 +00:00
Kristiyan Kostadinov
18991d3210 fix(migrations): handle parameters with initializers in inject migration (#58769)
Adds some logic to the `inject()` migration that allows is to handle parameter declarations with initializers. This was omitted initially, because we don't officially support such cases, but it came up internally.

PR Close #58769
2024-11-20 08:07:39 -08:00
cexbrayat
2eb4afe2b3 fix(migrations): do not migrate next calls in template if not an EventEmitter (#58631)
Fixes #58630

```html
<button (click)="someSubject.next()">Click</button>
```

was migrated to an `.emit` call, even if `someSubject` was not an `EventEmitter`.

The issue was the same in host listeners.

PR Close #58631
2024-11-15 14:13:52 +01:00
cexbrayat
ecd107b2e3 refactor(migrations): typos in signal migration incompatibility reasons (#58636)
A dot was appearing in the middle of the comment for `DerivedIsIncompatible`.
While at it, a dot was missing in `ClassManuallyInstantiated`.

PR Close #58636
2024-11-14 14:55:04 +00:00
Kristiyan Kostadinov
89256e6868 fix(migrations): replace removed NgModules in tests with their exports (#58627)
In #57684 the standalone migration was changed so that it replaces any leftover modules with their `exports`, in an attempt to preserve more working code. These changes expand that logic to also cover tests since it's somewhat common internally to only import a component's module without having any references to the component.

Note that tests are a bit of a special case, because we don't have access to the template type checker, so instead we copy over all of the `exports` of that module.

PR Close #58627
2024-11-13 18:04:31 +00:00
cexbrayat
579f613a58 fix(migrations): include the output migration in the defaults of the signal migration (#58635)
Running `ng g @angular/core:signals` prompts for the question on which migration to run and offers 3 options (inputs, outputs, queries).
Running with `--defaults` skips the prompts, but only runs 2 of them.
This fixes it by including the `outputs` migration in the default ones.

PR Close #58635
2024-11-13 18:03:58 +00:00
Kristiyan Kostadinov
7e5f705213 refactor(migrations): handle fake async catalyst (#58608)
Fixes that the standalone migration wasn't handling the `fake_async` path for Catalyst.

PR Close #58608
2024-11-12 14:45:40 +00:00
Paul Gschwendtner
5ac0538870 refactor(migrations): improve temporary variable generation in signal migrations (#58581)
This commit improves the temporary variable generation in signal
migrations, whenever references are "shared" inside property
declarations.

PR Close #58581
2024-11-11 15:29:20 +00:00
Paul Gschwendtner
4fe080f04d refactor(migrations): improve control flow analysis for loops in signal migration (#58581)
Currently whenever we would come across a code snippet like this, where
`maxCellsPerRow` is an input, the control flow analysis would fall apart
because the first occurence of the node points to a control flow node
that is offset-wise "after" the first occurence. This commit makes the
logic more robust.

PR Close #58581
2024-11-11 15:29:20 +00:00
Paul Gschwendtner
55fde8dbac refactor(migrations): support running existing migrations with plain TS programs (#58541)
Previously we always ran Tsurge migrations with an Angular program, even
if it's a plain `ts_library` target. This has changed now, so we also
need to properly handle the case where a `ts_library` is analyzed, but
no Angular program is available.

PR Close #58541
2024-11-08 17:22:06 +00:00
Paul Gschwendtner
1a0cee543e refactor(migrations): conditionally create plain TS programs for Tsurge analyzers (#58541)
Tsurge can run against the full Google3 depot, and will often also deal
with plain `ts_library` targets. Those shouldn't be constructed with the
Angular compiler as this could cause out of memory breakages etc. The
targets are simply not "proven" to be compatible with the Angular
compiler; so we shouldn't use them when not necessary.

PR Close #58541
2024-11-08 17:22:06 +00:00
Paul Gschwendtner
8919c80dae refactor(migrations): speed up code refactoring action for queries (#58525)
We were not properly passing around the TCB full program optimization,
so TCB generation was done per individual file. This significantly
slowed down reference resolution.

PR Close #58525
2024-11-06 16:30:18 +01:00
Paul Gschwendtner
121b340916 refactor(migrations): enable debug printing of compiler diagnostics (#58515)
This is useful for some migrations and eases debugging, so we are
building an environment-guarded debug print.

PR Close #58515
2024-11-06 13:04:22 +01:00
Paul Gschwendtner
8d5d5f80b3 fix(migrations): properly bundle shared compiler code into migrations (#58515)
The use of relative imports vs. module imports and the existing mismatch
can cause symbols to be duplicated in migrations. This is problematic as
it breaks migration logic or compiler logic in the worst case.

Long-term we will solve this by having a better Bazel toolchain where
both relative and module imports can point to the same files; but in
practice this is not the case right now.

This commit fixes the fallback template logic in the signal
input/queries migration; in case no type check block information is
available.

PR Close #58515
2024-11-06 13:04:22 +01:00
cexbrayat
01f86287db refactor(migrations): use import manager in provide-initializer (#58456)
The manual replacement logic had a flaw and was inserting the imports several times.

For example:

```ts
import { APP_INITIALIZER, ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    },
    {
      provide: APP_INITIALIZER,
      useFactory: (initService: InitService) => initService.init(),
      deps: [InitService],
      multi: true
    }
  ]
};
```

produced:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer }{ ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
import { InitService } from './init.service';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); }),
    provideAppInitializer(() => { return ((initService: InitService) => initService.init())(inject(InitService)); })
  ]
};
```

It now produces proper imports:

```ts
import { ApplicationConfig, provideZoneChangeDetection, inject, provideAppInitializer } from '@angular/core';
```

PR Close #58456
2024-11-04 18:15:00 +01:00
cexbrayat
a116a64d35 refactor(migrations): useFactory in provide-initializer migration (#58493)
The following provider:

```ts
{
  provide: APP_INITIALIZER,
  useFactory: (initService: InitService) => {
    return () => initService.init()
  },
  deps: [InitService],
  multi: true
}
```

was migrated into:

```ts
provideAppInitializer(() => { return ((initService: InitService) => {
  return () => initService.init()
})(inject(InitService)); })
```

This doesn't compile because there is an extra function:

```
✘ [ERROR] TS2345: Argument of type '() => () => void' is not assignable to parameter of type '() => void | Observable<unknown> | Promise<unknown>'.
  Type '() => void' is not assignable to type 'void | Observable<unknown> | Promise<unknown>'. [plugin angular-compiler]

    src/app/app.config.ts:7:26:
      7 │ ...ovideAppInitializer(() => { return ((initService: InitService) => {
```

It now migrates the provider into:

```ts
provideAppInitializer(((initService: InitService) => {
  return () => initService.init()
})(inject(InitService)))
```

PR Close #58493
2024-11-04 15:45:50 +01:00
Enea Jahollari
6819d6abf3 fix(migrations): flip the default standalone flag in route-lazy-loading migration (#58474)
Before v19, the default value of the standalone flag was false, this code change flips the logic in the migration to make it true by default.

PR Close #58474
2024-11-03 19:07:09 +01:00
Kristiyan Kostadinov
94eae783c1 refactor(migrations): attempt to correct initialization order in internal inject migration (#58427)
Updates the internal part of the `inject` migration to attempt to correct some cases where the declaration order of properties doesn't match the initialization order.

PR Close #58427
2024-10-31 09:17:51 +01:00
Kristiyan Kostadinov
70f8c99885 refactor(migrations): make it easier to delete nodes including comments (#58427)
We were repeating the logic that deletes a node together with all its comments in a few different places. These changes consolidate the logic under `ChangeTracker.removeNode`.

PR Close #58427
2024-10-31 09:17:51 +01:00