Commit Graph

175 Commits

Author SHA1 Message Date
Matthieu Riegler 8468df19c9 fix(migrations): Prevent a component from importing itself. (#50554)
This commit fixes the migrations for recursive components.

fixes #50525

PR Close #50554
2023-06-14 15:44:35 +02: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
Kristiyan Kostadinov 546b285ec1 fix(migrations): preserve trailing commas in code generated by standalone migration (#49533)
This is based on some internal feedback. Adds logic to the standalone migration that attempts to preserve trailing commas when updating existing AST nodes. When creating new ones, it tries to infer whether to generate the trailing comma based on the surrounding code.

PR Close #49533
2023-03-22 16:41:53 +01:00
Kristiyan Kostadinov 2fbaee3cbe fix(migrations): add protractor support if protractor imports are detected (#49274)
The new `bootstrapApplication` API doesn't include Protractor support anymore which may cause existing e2e tests to break after the migration. These changes add some logic that will provide Protractor support if any imports to `protractor` or `protractor/*` are detected.

PR Close #49274
2023-03-01 11:13:56 -08:00
Kristiyan Kostadinov 7dd19570e8 fix(migrations): delete barrel exports in standalone migration (#49176)
Adds some logic to automatically delete `export * from './foo'` style imports. Previously they weren't being picked up, because finding all the references using the language service doesn't include barrel exports.

PR Close #49176
2023-02-24 08:23:01 -08:00
cexbrayat 660fbf5d27 fix(migrations): migrate HttpClientModule to provideHttpClient() (#48949)
The `standalone-bootstrap` migration now migrates `HttpClientModule` imports to `provideHttpClient(withInterceptorsFromDi())` instead of `importProvidersFrom(HttpClientModule)`.

The `withInterceptorsFromDi()` feature is added to make sure class-based interceptors still works if there are any in the application.

Fixes #48948

PR Close #48949
2023-02-22 11:30:00 -08:00
Kristiyan Kostadinov 2268278ce9 fix(migrations): don't copy animations modules into the imports of test components (#49147)
Since we have less information about how to copy test components, we copy all the `imports` from the `configureTestingModule` call into the component's `imports`. It fixes some tests, but it can cause issues with animations modules, because they throw errors if they're imported multiple times.

These changes add an exception for animations modules imported in testing modules.

PR Close #49147
2023-02-21 13:35:43 -08:00
Kristiyan Kostadinov 36b9ff7ff9 fix(migrations): return correct alias when conflicting import exists (#49139)
Fixes that the `ImportManager` was returning the `propertyName` instead of the `name` when there's an import with a conflicting identifier.

PR Close #49139
2023-02-21 13:17:21 -08:00
Kristiyan Kostadinov 816e76a578 fix(migrations): automatically prune root module after bootstrap step (#49030)
Currently as a part of the bootstrapping API migration we comment out the metadata of the root module and instruct users to re-run the module pruning step which can be cumbersome. These changes run the module pruning automatically.

Note that initially I tried to reuse the module pruning logic and to run it against the existing program, but it was problematic, because it was common to have conflicting changes for the same AST nodes.

PR Close #49030
2023-02-13 09:52:07 +01:00
Kristiyan Kostadinov 40c976c909 fix(migrations): use NgForOf instead of NgFor (#49022)
Adds a function that allows for the import resolution for files to be customized in the standalone migration. Externally it's only use is to change `NgForOf` to `NgFor`, but we'll need it internally to deduplicate some Material modules.

Fixes #49006.

PR Close #49022
2023-02-10 17:19:49 +01:00
cexbrayat c19486702a test: typos in standalone test names (#49014)
Fixes a recurring typo in test names containing `bootstrap`

PR Close #49014
2023-02-10 10:22:21 +01:00
Kristiyan Kostadinov 4ac25b2aff perf(migrations): avoid re-traversing nodes when resolving bootstrap call dependencies (#49010)
Fixes that the migration was unnecessarily traversing top-level nodes. This was a large performance bottle-neck, because it involves a lot of language service lookups.

PR Close #49010
2023-02-09 15:37:18 +01:00
Kristiyan Kostadinov c7926b5773 fix(migrations): move standalone migrations into imports (#48987)
Normally having a standalone declaration in the `imports` array is an error and something we handle in the conversion to standalone, but tests can end up in this situation, because apps may have separate tsconfigs for the main app and for tests.

These changes make it so that we move any incorrectly-defined standalone declarations, even if they aren't part of the current migration.

PR Close #48987
2023-02-08 15:18:06 +01:00
Kristiyan Kostadinov 1afa6ed322 fix(migrations): don't add ModuleWithProviders to standalone test components (#48987)
Fixes that we were copying all expressions in the `imports` array of the test to the `imports` of the component, including any potential `ModuleWithProviders`.

Fixes #48971.

PR Close #48987
2023-02-08 15:18:05 +01:00
Kristiyan Kostadinov 770191cf1f fix(migrations): migrate tests when switching to standalone bootstrap API (#48987)
The first step of the migration updates the tests of the component being migrated, however it also skips any bootstraped declarations. We get back to the these declarations when converting to the standalone bootstrapping APIs, but we weren't updating their tests.

These changes rework some of the logic so that we migrate any remaining tests as a part of the final step.

Relates to #48944.

PR Close #48987
2023-02-08 15:18:05 +01:00
Kristiyan Kostadinov 6377487b1a fix(migrations): only exclude bootstrapped declarations from initial standalone migration (#48987)
Currently the standalone migration is set up to skip any modules that have a `bootstrap` array with at least one element. This ends up being misleading for small apps who have everything in the root module.

These changes add some logic to only skip the root component.

Fixes #48944.

PR Close #48987
2023-02-08 15:18:05 +01:00
Kristiyan Kostadinov 0cf11167f1 fix(compiler-cli): incorrectly detecting forward refs when symbol already exists in file (#48988)
In #48898 the `isForwardRef` flag was added to indicate whether a reference should be wrapped in a `forwardRef`. This logic assumed that the node can't be referring to another node within the same file, however from testing it looks like that's not actually the case, because we hit the same code path when an external import to the same symbol exists already.

PR Close #48988
2023-02-07 09:00:46 -08:00
Kristiyan Kostadinov 32cf4e5cb9 fix(migrations): avoid internal modules when generating imports (#48958)
Adds some logic to prefer non-Angular-internal modules when generating imports. This allows us to generate better code for some cases like the `ɵInternalFormsSharedModule` in Forms.

Also adds some logic to prefer symbols that are already in the same file.

Fixes #48942.

PR Close #48958
2023-02-06 12:27:52 -08:00
Kristiyan Kostadinov 759db12e0b fix(migrations): duplicated comments on migrated classes (#48966)
Fixes that the migration was duplicating the comments on class nodes that were being converted to standalone.

Fixes #48943.

PR Close #48966
2023-02-06 09:52:18 -08:00
Kristiyan Kostadinov 2de6dae16d fix(migrations): migrate RouterModule.forRoot with a config object to use features (#48935)
Previously if the standalone migration saw a `RouterModule.forRoot` with a config object, it wouldn't migrate it. These changes add some logic that convert the config object to a set of features from the new router API.

PR Close #48935
2023-02-03 11:40:45 -08:00
Kristiyan Kostadinov ba38178d19 fix(migrations): generate forwardRef for same file imports (#48898)
Adds some logic that will generate a `forwardRef` if necessary when adding imports.

PR Close #48898
2023-02-02 13:40:17 -08:00
Kristiyan Kostadinov 8389557848 fix(migrations): don't copy unmigrated declarations into imports array (#48882)
Currently the migration is set up to assume that any elements that exist in a `declarations` array will be converted to standalone and copied into the `imports` array, however that might be incorrect for some special cases like the root component.

These changes rework the declaration merging logic so that they take all the declarations being migrated into account.

PR Close #48882
2023-02-02 09:35:57 -08:00
Kristiyan Kostadinov a40cd47aa7 fix(migrations): avoid modifying testing modules without declarations (#48921)
Fixes that we were changing the testing modules that have no `declarations` unnecessarily, resulting in more formatting changes that users would have to clean up.

PR Close #48921
2023-02-02 09:31:09 -08:00
Kristiyan Kostadinov 03f47ac901 fix(migrations): use consistent quotes in generated imports (#48876)
Adds some logic so that the imports generated by the `ImportManager` use the same styles as the other imports.

PR Close #48876
2023-01-30 16:52:23 -08:00
Kristiyan Kostadinov f82bdc4b01 fix(migrations): don't delete classes that may provide dependencies transitively (#48866)
Fixes that we would incorrectly remove a module that imports another module which has providers. This is a follow-up from the following discussion: https://github.com/angular/angular/pull/48832#discussion_r1086623514

PR Close #48866
2023-01-27 16:55:20 +00:00
Kristiyan Kostadinov 345e737daa feat(core): add ng generate schematic to convert to standalone bootstrapping APIs (#48848)
Adds a new mode to the `@angular/core:standalone` schematic that allows users to switch from `bootstrapModule` to `bootstrapApplication`, as well as `provideRouter`, `provideAnimations` and `provideNoopAnimations`.

PR Close #48848
2023-01-26 17:02:50 +00:00
Alan Agius 2796230e95 fix(migrations): add enum in mode option in standalone schema (#48851)
Currently the `mode` is validated during schematic execution. While this cover a case of incorrect value this caused other parts were the correct values cannot be determined.

Options in schemas are used for a number of reasons during runtime.

- These are used to build auto complete
- Validation of inputs prior of the schematic is built with meaningful errors such as suggested inputs.
- Generation of help output.

Eventually these should also be used to generate DTS. This is already done in the CLI to avoid having to write Types manually.

PR Close #48851
2023-01-26 15:52:48 +00:00
Kristiyan Kostadinov e7318fc758 feat(core): add ng generate schematic to remove unnecessary modules (#48832)
Adds a new mode to the `@angular/core:standalone` schematic that automatically deletes modules that may not be necessary after the previous step of converting them to standalone.

PR Close #48832
2023-01-25 16:20:27 +00:00
Kristiyan Kostadinov a154db8a81 feat(core): add ng generate schematic to convert declarations to standalone (#48790)
Implements a new `ng generate @angular/core:standalone` schematic that allows the user to convert all the declarations in a set of NgModules to standalone.

PR Close #48790
2023-01-24 16:48:19 +00:00
Kristiyan Kostadinov b37a624985 build: set up ng generate schematics for core (#48790)
Adds the necessary boilerplate to allow for `ng generate` schematics to be included with `@angular/core`.

PR Close #48790
2023-01-24 16:48:19 +00:00
Kristiyan Kostadinov 1e30baaaa7 test: remove usages of deprecated runSchematicAsync function (#48745)
Removes our usages of `runSchematicAsync` since it is deprecated.

PR Close #48745
2023-01-17 09:13:39 -08: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
Paul Gschwendtner f44b322113 build: override schematics to be built and tested using CommonJS (#48521)
The Angular CLI does not yet support schematics running as ESM. For
this reason we switch the schematics BUILD targets to explicitly
use ESM (as an exception in the repo).

PR Close #48521
2022-12-19 19:50:42 +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
Alan Agius 249384b00c build: update Angular tooling packages to 15.0.0-next.3 (#47584)
- This update is needed to implement the changes in `ng add localize` https://github.com/angular/angular/pull/47569
- Add missing `root` options to all `angular.json`, this is required as otherwise the angular.json validation will fail.
- Remove `require.context` from test.ts integration test, as this is no longer needed.
- Update payloads golden files.

PR Close #47584
2022-09-30 10:53:04 -07:00
Paul Gschwendtner 616c8a89b8 test: update schematics workspace test to no longer verify JSON5 features (#46642)
The Angular CLI has removed the JSON5 parsing and now always uses
`jsonc-parser`. Our test checks if JSON5 features can be parsed, but
this now breaks and the test needs to be adjusted.

We still want to keep the test to ensure we do not parse the Angular
CLI workspace file in a different way, not e.g. supporting jsonc.

PR Close #46642
2022-07-01 10:20:51 -07: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
Dylan Hunn c26915c8cf refactor(core): Make the typed forms migration apply to all usages of the symbols. (#45311)
Previously, the migration only migrated constructor calls. Now, the migration will rewrite every usage, in all contexts. Both ways are technically correct, but migrating all symbols is likely to produce clearer and more readable results.

PR Close #45311
2022-03-21 14:40:59 -07:00
Dylan Hunn 6cec8aa728 refactor(core): Improve the efficiency of the Typed Forms migration. (#45288)
Consider a file that imports `FormControl` and then never uses it. In that case, we don't need to add the import for `UntypedFormControl`.

By examining constructor calls *first*, we can identify these cases and skip over them.

This will reduce the memory footprint of the migration when run in tsunami, hopefully making OOM errors less likely.

PR Close #45288
2022-03-08 12:06:16 -08:00
Dylan Hunn d336ba96d9 fix(forms): Update the typed forms migration. (#45281)
The typed forms migration was previously designed to add `<any>` type parameters to existing forms classes. However, due to some design changes, the new opt-out strategy requires untyped versions of the classes, as introduced in #45205 and #45268.

This PR updates the migration to import these new classes (in an idempotent manner), and replace constructor calls with the new classes. It respects qualified imports as well. Finally, the code has been refactored to move as much common code as possible into `util.ts`.

PR Close #45281
2022-03-07 12:24:59 -08:00
Dylan Hunn cae1e44608 fix(forms): Update the typed forms migration to use FormArray<T> instead of FormArray<T[]>. (#44933)
Previously, `FormArray` accepted an array generic. Now it accepts the element type, so the migration must be update accordingly.

PR Close #44933
2022-02-02 01:58:18 +00: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
Dylan Hunn 9921b2ca35 feat(core): Add a migration for typed forms. (#44449)
This migration will insert `<AnyForUntypedForms>` or `<AnyForUntypedForms[]>` at existing uses of `AbstractControl` classes, as well as calls to `FormBuilder` methods.

We need to submit this ahead of time in order to get started with the migration in google3.

PR Close #44449
2021-12-15 13:20:33 -05:00