Commit Graph

277 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
Matthieu Riegler f755853b75 refactor(compiler): Remove unused TransformVisitor & NullVisitor (#48646)
NullVisitor & TransformVisitor are unused and unexported outside the compiler package, we can remove them.

PR Close #48646
2023-05-09 14:38:09 -07:00
Kristiyan Kostadinov 41b7ec4eb9 refactor(migrations): log a link to the standalone migration (#49752)
Resolves an old TODO about adding a link to the standalone migration guide.

PR Close #49752
2023-04-10 09:04:02 -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
Alan Agius 0f2937ef83 refactor: update code to be ES2022 compliant (#49559)
This commit updates parts of the FW to be ES2022 complaint.

These changes are needed to fix the following problems problems with using properties before they are initialized.

Example
```ts
class Foo {
   bar = this.buz;
   constructor(private buz: unknown){}
}
```

PR Close #49559
2023-03-23 08:18:45 -07:00
Andrew Scott 4d455e06c7 Revert "refactor: update code to be ES2022 compliant (#49332)" (#49554)
This reverts commit 349ff01c4b.

PR Close #49554
2023-03-22 14:34:25 -07:00
Alan Agius 349ff01c4b refactor: update code to be ES2022 compliant (#49332)
This commit updates parts of the FW to be ES2022 complaint.

These changes are needed to fix the following problems problems with using properties before they are initialized.

Example
```ts
class Foo {
   bar = this.buz;
   constructor(private buz: unknown){}
}
```

PR Close #49332
2023-03-22 14:00:19 -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
Andrew Scott e1355e7d16 refactor(migrations): Move ChangeTracker to common utils (#49308)
The `ChangeTracker` is generally useful and could be used by a lot of
migrations instead of having to rewrite similar boilerplate.

PR Close #49308
2023-03-03 22:03:37 +00:00
Kristiyan Kostadinov 10c8eae6d4 refactor(migrations): expose current file in import remapper (#49288)
Passes the path of the current file to the import remapper. Useful if we want to generate absolute paths.

PR Close #49288
2023-03-02 21:48:34 +00: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 87affadb87 fix(migrations): avoid migrating the same class multiple times in standalone migration (#49245)
If a class is declared in multiple modules, the standalone migration may end up generating invalid code. While declaring a class in multiple modules is an error, it can happen with modules in tests. These changes avoid the issue by using a `Set` to track the classes being migrated.

PR Close #49245
2023-02-28 10:04:54 -08:00
Kristiyan Kostadinov 99d874fe3b feat(core): add support for TypeScript 5.0 (#49126)
Updates the project to support TypeScript 5.0 and to resolve any errors that came up as a result of the update.

PR Close #49126
2023-02-28 08:24:47 -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
Kristiyan Kostadinov 79cdfeb392 feat(compiler): drop support for TypeScript 4.8 (#49155)
Drops support for TypeScript 4.8 from the compiler and removes all of the compatibility code we had for it.

BREAKING CHANGE:
* TypeScript 4.8 is no longer supported.

PR Close #49155
2023-02-23 10:39:43 -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 ebae506d89 fix(migrations): use import remapper in root component (#49046)
Fixes that in #49022 the component import remapping function was being passed into the standalone migration.

PR Close #49046
2023-02-13 16:08:18 +01: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 521ccfbe6c fix(migrations): avoid interrupting the migration if language service lookup fails (#49010)
In some internal migrations the language service was throwing for some file reads which was crashing the migration. These changes add a `try/catch` to avoid interrupting it.

PR Close #49010
2023-02-09 15:37:18 +01:00
Kristiyan Kostadinov 26cb7ab2e6 perf(migrations): speed up language service lookups (#49010)
For the module pruning and bootstrap API migration steps we depend heavily upon the TypeScript `LanguageService` which ends up being slow on a large project. E.g. in some large internal projects single-file lookups were taking around 30s.

These changes introduce a wrapper around the `LanguageService` that we can use to trick it into not traversing the entire project every time.

PR Close #49010
2023-02-09 15:37:18 +01:00
Kristiyan Kostadinov bdbf21d04b fix(migrations): avoid generating imports with forward slashes (#48993)
We're using Node's `path` utilities to remap existing imports and create new ones which can yield paths with forward slash separators.

These changes add some logic to ensure that we only generate forward slashes.

PR Close #48993
2023-02-08 15:19:59 +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 ffad1b49d9 fix(migrations): reduce number of files that need to be checked (#48987)
Attempts to speed up the standalone migration by:
1. Not analyzing typechecker files.
2. Telling TS not to check libraries.

PR Close #48987
2023-02-08 15:18:05 +01:00
Kristiyan Kostadinov e9e4449a43 fix(migrations): preserve tsconfig in standalone migration (#48987)
For the standalone migration we need to pass a couple of compiler flags which accidentally also overwrote the project's compiler options. These changes extend the options instead.

PR Close #48987
2023-02-08 15:18:05 +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
Walid Bouguima 73394126b6 docs(core): standalone-migration schematics typos fix and properties addition (#48961)
Fixed a typo and updated the hyphenation in a couple of words to keep consistency across schematics docs style. Assuming beginners reading docs, I also added the property called 

public showGreeting = true;

This is because it is available in the examples `.HTML` `*ngIf` directive snippets without being present in the `.ts` class properties declarations.  also this removes potential inference that this absence is a result of the standalone migration schematics work.
PR Close #48961
2023-02-06 12:32:57 -08:00
Kristiyan Kostadinov a47721c2f1 refactor(migrations): add API to remap generated import names (#48974)
Internally we'll need to remap some imports to generate better import statements. These changes add an API that we can use to do the remapping.

PR Close #48974
2023-02-06 12:28:38 -08:00
Kristiyan Kostadinov 4f6127aa34 refactor(migrations): account for internal module names in module reference check (#48974)
Fixes that the code which checks if something is a reference to a specific class didn't work internally.

PR Close #48974
2023-02-06 12:28:38 -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 49a7c9f94a fix(migrations): standalone migration incorrectly throwing path error for multi app projects (#48958)
Fixes that the standalone migration was throwing the "Could not find any paths to migrate..." error on a per-tsconfig-basis, preventing the migration from running on any configs that might occur further down in the project.

These changes move the error to after all the configs have been checked.

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 584976e6c8 fix(migrations): support --defaults in standalone migration (#48921)
Fixes that running the standalone migration with `--defaults` was throwing an error, because all the properties were specified as required. We don't need to set them as required, because they have default values.

Fixes #48845.

PR Close #48921
2023-02-02 09:31:09 -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 c865b8b59c docs(migrations): follow-up readme fixes (#48866)
Addresses a couple of notes from #48848 that came in after the PR was merged.

PR Close #48866
2023-01-27 16:55:20 +00:00
Kristiyan Kostadinov ed8f70125e docs(core): add readme for standalone migration (#48848)
Updates the readme for the standalone migration to describe the process and the different transformations that are happening.

PR Close #48848
2023-01-26 17:02:50 +00:00