Commit graph

62 commits

Author SHA1 Message Date
Kristiyan Kostadinov
fb540e169a feat(core): add migration for invalid two-way bindings (#54630)
As a part of #54154, an old parser behavior came up where two-way bindings were parsed by appending `= $event` to the event side. This was problematic, because it allowed some non-writable expressions to be passed into two-way bindings.

These changes introduce a migration that will change the two-way bindings into two separate input/output bindings that represent the old behavior so that in a future version we can throw a parser error for the invalid expressions.

```ts
// Before
@Component({
  template: `<input [(ngModel)]="a && b"/>`
})
export class MyComp {}

// After
@Component({
  template: `<input [ngModel]="a && b" (ngModelChange)="a && (b = $event)"/>`
})
export class MyComp {}
```

PR Close #54630
2024-02-28 18:06:23 +01:00
Matthieu Riegler
965ce5a8c5 feat(migrations): Schematics for TransferState, StateKey and makeStateKey migration. (#49594)
These 3 classes have been moved from platform-browser to core by #49563

PR Close #49594
2023-10-10 13:12:36 -07:00
Matthieu Riegler
f0da7c2e44 feat(migrations): schematic to remove deprecated CompilerOptions properties (#49672)
`useJit` and `missingTranslation` have been deprecated since v13 and  are unused in Ivy. They can be safely removed.

PR Close #49672
2023-10-10 09:35:55 -07:00
Alan Agius
ba0effd494 refactor(migrations): rename migration to remove version prefix (#51926)
The version prefix in the migration name is redundant.

PR Close #51926
2023-09-27 09:20:00 -07:00
Alan Agius
e66c18ffa0 refactor(migrations): remove unused version 16 migrations (#51926)
When updating to version 17, version 16 migrations cannot be executed thus making them redundant to have in the package.

PR Close #51926
2023-09-27 09:20:00 -07:00
Kristiyan Kostadinov
c7127b98b5 feat(core): add schematic to escape block syntax characters (#51905)
#51891 introduces a new syntax that assigns a new meaning to the `@` and `}` in Angular templates. This is problematic for existing apps which may have the characters in their templates already, because it can lead to syntax errors.

These changes add an `ng update` schematic that will replace any usages of the special characters with their HTML entities.

PR Close #51905
2023-09-26 15:23:49 -07:00
Alan Agius
465c20cb09 refactor(migrations): remove migrations from previous versions (#49603)
These migration can no longer be executed by the users, thus we remove them.

PR Close #49603
2023-03-28 11:42:00 -07:00
Andrew Scott
5e5dac278d feat(migrations): Migration to remove Router guard and resolver interfaces (#49337)
The class-based guard and resolver interfaces are deprecated. The
`Router` types only support functional guards definitions. Classes can
still be used as the underlying implementation of functional guards and
resolvers but there will not be an interface requiring a specific structure
for those classes.

There are also helper functions like `mapToCanActivate` that allow
converting the existing class-based guards directly to functional guards
at the route definition. This will be done in a separate migration.

PR Close #49337
2023-03-27 12:59:34 -07:00
Paul Gschwendtner
605c536420 feat(core): add migration to remove moduleId references (#49496)
Removes all `moduleId:` property references in `@Directive` and
`@Component`.

PR Close #49496
2023-03-24 10:27:10 -07:00
Paul Gschwendtner
90c2088679 build: make devmode a noop and ensure it never runs (#48521)
This is basically a pre-step for combining devmode and prodmode into a
single compilation. We are already achieving this now, and can claim
with confidence that we reduced possible actions by half. This is
especially important now that prodmode is used more often, but rules
potentially still using the devmode ESM sources. We can avoid double
compilations (which existed before the whole ESM migration too!).

We will measure this more when we have more concrete documentation
of the changes & a better planning document.

Changes:

  * ts_library will no longer generate devmode `d.ts`. Definitions are
    generated as part of prodmode. That way only prodmode can be exposed
    via providers.
  * applied the same to `ng_module`.
  * updates migrations to bundle because *everything* using `ts_library`
    is now ESM. This is actually also useful in the future if
    schematics rely on e.g. the compiler.
  * updates schematics for localize to also bundle. similar reason as
    above.

PR Close #48521
2022-12-19 19:50:45 +00:00
Alan Agius
e376e924d8 refactor(migrations): remove unused migrations (#48414)
These migrations can no longer run due to a single update version policy (IE: from 13 to 14, 14 to 15 etc..). Therefore these are redundant and can be deleted.

We also remove the `-beta` suffix from the version which is not needed as the Angular CLI will add the prerelease suffixes automatically.

PR Close #48414
2022-12-09 10:04:03 -08:00
Andrew Kushnir
7bee28d037 feat(router): add a migration to remove relativeLinkResolution usages (#47604)
As of Angular v15, the deprecated `relativeLinkResolution` config option of the Router is removed.  This migration cleans up (removes) the `relativeLinkResolution` fields from the Router config objects in applications code.

```ts
import { RouterModule } from '@angular/router';

RouterModule.forRoot([], {
  relativeLinkResolution: 'legacy',
  enableTracing: false,
});
```

```ts
import { RouterModule } from '@angular/router';

RouterModule.forRoot([], {
  // the `relativeLinkResolution` is removed
  enableTracing: false,
});
```

PR Close #47604
2022-10-07 10:28:42 -07:00
Andrew Kushnir
16c8f55663 feat(router): migrate RouterLinkWithHref references to RouterLink (#47599)
Since Angular v15, the `RouterLink` contains the logic of the `RouterLinkWithHref` directive and now developers can always import and use the `RouterLink` directive when they need to add a `[routerLink]` in templates. This migration finds all imports and usages of the `RouterLinkWithHref` class and rewrites them to `RouterLink` instead.

```ts
import { RouterLinkWithHref } from '@angular/router';

@Component({
  standalone: true,
  template: `<a [routerLink]="'/abc'">`,
  imports: [RouterLinkWithHref]
})
export class MyComponent {
  @ViewChild(RouterLinkWithHref) aLink!: RouterLinkWithHref;
}
```

```ts
import { RouterLink } from '@angular/router';

@Component({
  standalone: true,
  template: `<a [routerLink]="'/abc'">`,
  imports: [RouterLink]
})
export class MyComponent {
  @ViewChild(RouterLink) aLink!: RouterLink;
}
```

PR Close #47599
2022-10-06 18:57:37 +00:00
Dylan Hunn
89d299105a feat(forms): Implement strict types for the Angular Forms package. (#43834)
This PR strongly types the forms package by adding generics to AbstractControl classes as well as FormBuilder. This makes forms type-safe and null-safe, for both controls and values.

The design uses a "control-types" approach. In other words, the type parameter on FormGroup is an object containing controls, and the type parameter on FormArray is an array of controls.

Special thanks to Alex Rickabaugh and Andrew Kushnir for co-design & implementation, to Sonu Kapoor and Netanel Basal for illustrative prior art, and to Cédric Exbrayat for extensive testing and validation.

BREAKING CHANGE: Forms classes accept a generic.

Forms model classes now accept a generic type parameter. Untyped versions of these classes are available to opt-out of the new, stricter behavior.

PR Close #43834
2022-04-12 17:37:04 +00:00
Andrew Scott
d56a537196 feat(migrations): Add migration to add explicit Route/Routes type (#45084)
Places that use `pathMatch` need an explicit `Route` or `Routes` type on
the variable so TypeScript does not infer the type as just 'string'.

PR Close #45084
2022-04-04 14:53:45 -07:00
Alan Agius
bc61cc2449 refactor(migrations): remove old migrations (#44857)
When using `ng update` users cannot update multiple major versions at the same time. Therefore migrations that are not targeting version 14 cannot be run and therefore we are removing them.

PR Close #44857
2022-02-01 03:52:26 +00:00
Dylan Hunn
e5e81613a7 Revert "refactor(forms): Temporarily disable the typed forms migration. (#44828) (#44834)
This reverts commit 894fa759f1. In that commit, the migration was completely diabled in order to prevent users from selecting it for the 13.2 release. This revert commit restores the migration to its previous (fully optional) state, in order to continue migration-focused work.

PR Close #44834
2022-01-26 17:36:58 -08:00
Dylan Hunn
894fa759f1 refactor(forms): Temporarily disable the typed forms migration. (#44828)
It's best to disable this optional migration in the minor release, although it shouldn't run anyway -- we don't want people accidentally running it.

This PR will be rolled back after the minor is out.

PR Close #44828
2022-01-25 17:03:48 -08:00
Dylan Hunn
f7aa937cac fix(forms): Make some minor fixups for forward-compatibility with typed forms. (#44540)
Make the following fixes:
* When submitting the entire migration in a disabled state, I commented out more code than strictly required
* Responding to some final review comments caused two conditions to become flipped
* Always use explicit checks instead of boolean corecion
* Fix one missed any cast in a test case

PR Close #44540
2022-01-04 12:10:56 -08:00
Kristiyan Kostadinov
e65a245a0b feat(core): add migration to remove entryComponents (#44322)
Adds an automated migration that will drop any usages of `entryComponents` from `@NgModule` and `@Component`.

PR Close #44322
2021-12-01 12:03:14 -08:00
Dylan Hunn
a532040d97 Revert "feat(core): add migration to remove entryComponents (#44308)" (#44318)
This reverts commit 5dff077d50.

PR Close #44318
2021-11-30 16:31:17 -05:00
Kristiyan Kostadinov
5dff077d50 feat(core): add migration to remove entryComponents (#44308)
Adds an automated migration that will drop any usages of `entryComponents` from `@NgModule` and `@Component`.

PR Close #44308
2021-11-30 13:47:03 -05:00
Alan Agius
57cbb4f2e8 refactor(migrations): remove no longer accessible migrations (#43947)
With this change we remove no longer needed migrations. These migrations are no longer accessible following a change angular/angular-cli#21986 in the Angular CLI.  The CLI now shows an error message when users try to update `@angular/` and `@nguniversal/` packages across multiple major versions.

Example to update from version 11 to version 13 the recommand approach is to run the following commands

```
ng update @angular/core@12
ng update @angular/core@13 (which is the same as ng update @angular/core)
```

NB: It is recommand that when update from one major to another, users verify that their applications is working as expected.

PR Close #43947
2021-10-26 23:59:42 +00:00
Jessica Janiuk
0873ae2580 Revert "refactor(migrations): remove no longer accessible migrations" (#43943)
This reverts commit f21ad8780b.

PR Close #43943
2021-10-25 22:02:32 +00:00
Alan Agius
0b4350c6ef refactor(migrations): remove no longer accessible migrations (#43942)
With this change we remove no longer needed migrations. These migrations are no longer accessible following a change https://github.com/angular/angular-cli/pull/21986 in the Angular CLI.  The CLI now shows an error message when users try to update `@angular/` and `@nguniversal/` packages across multiple major versions.

Example to update from version 11 to version 13 the recommand approach is to run the following commands

```
ng update @angular/core@12
ng update @angular/core@13 (which is the same as ng update @angular/core)
```

NB: It is recommand that when update from one major to another, users verify that their applications is working as expected.

PR Close #43942
2021-10-25 19:32:27 +00:00
Kristiyan Kostadinov
81c7eb813c feat(core): add migration to opt out existing apps from new test module teardown behavior (#43353)
Since the `destroyAfterEach` teardown behavior is enabled by default now, existing tests that depended on the old behavior can start to fail. These changes add an automated migration that explicitly adds `destroyAfterEach: false` to existing tests.

The migration works by looking for `initTestEnvironment` calls across the entire app and adding the flag to them. If no calls were found, the migration will add the flag to all `configureTestingModule` and `withModule` calls instead.

PR Close #43353
2021-10-04 16:57:16 -07:00
Andrew Scott
ed24c4a78b docs: fix misspelled word in routerLink migration (#43380)
PR Close #43380
2021-09-08 16:23:23 +00:00
Andrew Scott
e57691c9c5 feat(core): Add migration to update empty routerLinks in templates (#43176)
The previous behavior of `RouterLink` for `null` and `undefined` inputs was to treat
the input the same as `[]` or `''`. This creates several unresolvable issues with
correctly disabling the links because `commands = []` does not behave the same
as disabling a link. Instead, it navigates to the current page, but will also
clear any fragment and/or query params.

The new behavior of the `routerLink` input will be to completely disable navigation
for `null` and `undefined` inputs. For HTML Anchor elements, this will also mean
removing the `href` attribute.

Migration for change in #43087

PR Close #43176
2021-08-19 11:24:12 -07:00
Borislav Ivanov
e7832a6b2f docs(core): fix spelling error (#42783)
Fix spelling error in migration schematics.

PR Close #42783
2021-07-08 14:49:46 -07:00
Alan Agius
7f6213a2f4 fix(migrations): add migration to replace /deep/ with ::ng-deep (#42214)
With this change we add a migration to replace the deprecated shadow-piercing selector from `/deep/` with deprecated but recommended `::ng-deep`.

The main motivation for this change is that the CSS optimizer CSSNano which is used by the Angular CLI no longer supports this non standard selector and causes build time errors due to the selector being minified incorrectly. However, CSSNano does support the recommended deprecated `::ng-deep` selector.

Closes: #42196

PR Close #42214
2021-05-21 22:13:29 +00:00
Alan Agius
95ff5ecb23 feat(core): add migration for XhrFactory import (#41313)
Automatically migrates `XhrFactory` from `@angular/common/http` to `@angular/common`.

PR Close #41313
2021-03-29 15:14:16 -07:00
Kristiyan Kostadinov
190fa07b9a feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092)
Adds a migration that casts the value of `ActivatedRouteSnapshot.fragment` to be non-nullable.

Also moves some code from the `AbstractControl.parent` migration so that it can be reused.

Relates to #37336.

PR Close #41092
2021-03-23 11:18:00 -07:00
Andrew Scott
805b4f936b feat(core): Add schematic to fix invalid Route configs (#40067)
`Route` configs with `redirectTo` as well as `canActivate` are not valid
because the `canActivate` guards will never execute. Redirects are
applied before activation. There is no error currently for these
configs, but another commit will change this so that an error does
appear in dev mode. This migration fixes the configs by removing the
`canActivate` property.

PR Close #40067
2021-01-05 10:09:28 -08:00
Kristiyan Kostadinov
81d72a1e37 fix(router): migration incorrectly replacing deprecated key (#39763)
In #38762 we added a migration to replace the deprecated `preserveQueryParams`
option with `queryParamsHandling`, however due to a typo, we ended up replacing it
with `queryParamsHandler` which is invalid.

Fixes #39755.

PR Close #39763
2020-11-19 09:08:10 -08:00
Adam Plumer
0ec7043490 feat(core): add initialNavigation schematic (#36926)
Add a schematic to update users to the new v11 `initialNavigation`
options for `RouterModule`. This replaces the deprecated/removed
`true`, `false`, `legacy_disabled`, and `legacy_enabled` options
with the newer `enabledBlocking` and `enabledNonBlocking` options.

PR Close #36926
2020-10-14 12:01:07 -07:00
Joey Perrott
93ee05d92a fix(router): create schematic for preserveQueryParams (#38762)
Create a schematic for migrating preserveQueryParams to use queryParamsHandler
instead.

PR Close #38762
2020-10-14 10:40:55 -07:00
Kristiyan Kostadinov
5ce71e0fbc feat(core): add automated migration to replace async with waitForAsync (#39212)
Adds a migration that finds all imports and calls to the deprecated `async` function from
`@angular/core/testing` and replaces them with `waitForAsync`.

These changes also move a bit of code out of the `Renderer2` migration so that it can be reused.

PR Close #39212
2020-10-13 09:55:34 -07:00
Kristiyan Kostadinov
0e733f3689 feat(core): add automated migration to replace ViewEncapsulation.Native (#38882)
Adds an automated migration that replaces any usages of the deprecated
`ViewEncapsulation.Native` with `ViewEncapsulation.ShadowDom`.

PR Close #38882
2020-10-08 11:56:03 -07:00
Kristiyan Kostadinov
aeec223db1 feat(forms): add migration for AbstractControl.parent accesses (#39009)
As of #32671, the type of `AbstractControl.parent` can be null which can cause
compilation errors in existing apps. These changes add a migration that will append
non-null assertions to existing unsafe accesses.

````
// Before
console.log(control.parent.value);

// After
console.log(control.parent!.value);
```

The migration also tries its best to avoid cases where the non-null assertions aren't
necessary (e.g. if the `parent` was null checked already).

PR Close #39009
2020-10-06 13:55:25 -07:00
Andrew Scott
15ea811f05 feat(router): Add relativeLinkResolution migration to update default value (#38698)
The default value for `relativeLinkResolution` is changing from 'legacy' to 'corrected'.
This migration updates `RouterModule` configurations that use the default value to
now specifically use 'legacy' to prevent breakages when updating.

PR Close #38698
2020-09-23 15:45:37 -04:00
Kristiyan Kostadinov
7849fdde09 feat(router): add migration to update calls to navigateByUrl and createUrlTree with invalid parameters (#38825)
In #38227 the signatures of `navigateByUrl` and `createUrlTree` were updated to exclude unsupported
properties from their `extras` parameter. This migration looks for the relevant method calls that
pass in an `extras` parameter and drops the unsupported properties.

**Before:**
```
this._router.navigateByUrl('/', {skipLocationChange: false, fragment: 'foo'});
```

**After:**
```
this._router.navigateByUrl('/', {
  /* Removed unsupported properties by Angular migration: fragment. */
  skipLocationChange: false
});
```

These changes also move the method call detection logic out of the `Renderer2` migration and into
a common place so that it can be reused in other migrations.

PR Close #38825
2020-09-16 15:16:18 -07:00
Paul Gschwendtner
0577bf0e3e refactor: enable ng update migrations for v10 (#36921)
Enables the `ng update` migrations for v10. Status for individual
migrations:

**undecorated-classes-with-di**.

This migration dealt exlusively with inherited constructors and
cases where a derived component was undecorated. In those cases,
the migration added `@Directive()` or copied the inherited decorator
to the derived class.

We don't need to run this migration again because ngtsc throws if
constructor is inherited from an undecorated class. Also ngtsc will
throw if a NgModule references an undecorated class in the declarations.

***undecorated-classes-with-decorated-fields***

This migration exclusively deals with undecorated classes that use
Angular features but are not decorated. Angular features include
the use of lifecycle hooks or class fields with Angular decorators,
such as `@Input()`.

We want to re-run this migration in v10 as we will disable the
compatibility code in ngtsc that detects such undecorated classes
as `@Directive`.

**module-with-providers**:

This migration adds an explicit generic type to `ModuleWithProviders`.
As of v10, the generic type is required, so we need to re-run the
migration again.

**renderer-to-renderer2**:

We don't need to re-run that migration again as the
renderer has been already removed in v9.

**missing-injectable**:

This migration is exclusively concerned with undecorated
providers referenced in an `NgModule`. We should re-run
that migration again as we don't have proper backsliding
prevention for this yet. We can consider adding an error
in ngtsc for v10, or v11. In either way, we should re-run
the migration.

**dynamic-queries**:

We ran this one in v9 to reduce code complexity in projects. Instead
of explicitly passing `static: false`, not passing any object literal
has the same semantics. We don't need to re-run the migration again
since there is no good way to prevent backsliding and we cannot always
run this migration for future versions (as some apps might actually
intentionally use the explicit `static: false` option).

PR Close #36921
2020-05-06 15:06:10 -07:00
Paul Gschwendtner
e7cc1d606a refactor(core): update missing-injectable migration description to match guide (#34125)
Updates the description of the `missing-injectable` migration to mention the second pattern
that will be automatically handled.

PR Close #34125
2019-12-02 11:21:50 -08:00
Filipe Silva
1389d173fb fix(core): remove ngcc postinstall migration (#33727)
Partially address https://github.com/angular/angular-cli/issues/16017

PR Close #33727
2019-11-12 14:03:48 -08:00
Alan Agius
8b5ca670ad refactor(core): update migrations descriptions (#33440)
With the next version of the CLI we don't need to add logging for the description of the schematic as part of the schematic itself.

This is because now, the CLI will print the description defined in the `migrations.json` file.

See: https://github.com/angular/angular-cli/pull/15951

PR Close #33440
2019-10-28 17:07:50 -07:00
Adam Plumer
56731f624a feat(core): add ModuleWithProviders generic type migration (#33217)
Static methods that return a type of ModuleWithProviders currently
do not have to specify a type because the generic falls back to any.
This is problematic because the type of the actual module being
returned is not present in the type information.

Since Ivy uses d.ts files exclusively for downstream packages
(rather than metadata.json files, for example), we no longer have
the type of the actual module being created.

For this reason, a generic type should be added for
ModuleWithProviders that specifies the module type. This will be
required for all users in v10, but will only be necessary for
users of Ivy in v9.

PR Close #33217
2019-10-21 15:53:28 -04:00
Filipe Silva
30d25f67af feat(core): add postinstall ngcc migration (#32999)
PR Close #32999
2019-10-15 17:54:38 +00:00
Charles Lyding
0119f46daf fix(core): set migration schematic versions to valid semver versions (#32991)
PR Close #32991
2019-10-04 13:54:39 -07:00
Charles Lyding
f8eca840ee fix(core): update migration descriptions with links to AIO documentation (#32991)
PR Close #32991
2019-10-04 13:54:39 -07:00
Kristiyan Kostadinov
7f6429d802 refactor: re-enable dynamic queries migration (#32992)
Re-enables the dynamic queries migration, now that we have all of the necessary framework changes in place.

Also moves the logic that identifies static queries out of the compiler and into the static queries migration, because that's the only place left that's using it.

PR Close #32992
2019-10-04 13:54:09 -07:00