Commit graph

153 commits

Author SHA1 Message Date
Paul Gschwendtner
185b7801ee build: migrate packages/core/schematics to ts_project (#61420)
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 #61420
2025-05-16 15:53:27 +00:00
Kristiyan Kostadinov
7be6e5dc50 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:08 -07:00
JoostK
9241615ad0 fix(core): reduce total memory usage of various migration schematics (#60776)
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 #60776
2025-04-08 16:12:57 -07:00
Kristiyan Kostadinov
a382066165 refactor(migrations): simplify integration of tsurge migrations into the CLI (#60386) (#60776)
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

PR Close #60776
2025-04-08 16:12:56 -07: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
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
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
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
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
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
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
Paul Gschwendtner
35d7ca55b2 test: support parallel tsurge unit combining in batch test infra (#58280)
This allows the batch test for the signal input migration to pass.

PR Close #58280
2024-10-25 18:47:41 +00:00
Paul Gschwendtner
8143016b91 refactor(migrations): support parallel tsurge metadata merging (#58280)
This is helpful and important for large scale migrations where a single
call for merging _all_ unit data's can be subject to memory / disk
resource constraints. Consider a compilation unit data for every target
in Google3, and those being merged in a single program.

PR Close #58280
2024-10-25 18:47:41 +00:00
Andrew Kushnir
888657a12e Revert "refactor(migrations): support parallel tsurge metadata merging (#58280)" (#58313)
This reverts commit 21b6613b90.

PR Close #58313
2024-10-22 12:27:53 -07:00
Andrew Kushnir
9aa686896d Revert "test: support parallel tsurge unit combining in batch test infra (#58280)" (#58313)
This reverts commit cb34e406ba.

PR Close #58313
2024-10-22 12:27:53 -07:00
Paul Gschwendtner
cb34e406ba test: support parallel tsurge unit combining in batch test infra (#58280)
This allows the batch test for the signal input migration to pass.

PR Close #58280
2024-10-22 11:29:16 -07:00
Paul Gschwendtner
21b6613b90 refactor(migrations): support parallel tsurge metadata merging (#58280)
This is helpful and important for large scale migrations where a single
call for merging _all_ unit data's can be subject to memory / disk
resource constraints. Consider a compilation unit data for every target
in Google3, and those being merged in a single program.

PR Close #58280
2024-10-22 11:29:15 -07:00
Paul Gschwendtner
c1aa411cf1 fix(migrations): properly resolve tsconfig paths on windows (#58137)
The Angular CLI devkit and Tsurge, as well as TypeScript only deal with
Posix paths. We also normalize paths into posix paths, and try to
implement a devkit compatible virtual file system for the compiler-cli.

This commit fixes an issue where we accidentally resolved `/` to the
system root on Windows. e.g. `C:/`. This broke the posix and devkit
paths throughout tsconfig parsing.

This commit fixes this.

Fixes #58132.

PR Close #58137
2024-10-09 15:23:33 +00:00
Paul Gschwendtner
754a857f8c refactor(migrations): support extra return info for TsurgeMigration#migrate (#58106)
This allows us to return extra properties along with `#migrate`
replacements. Useful for language service integration or other
integrations of Tsurge migrations in special runners.

PR Close #58106
2024-10-08 06:19:37 +00:00
Paul Gschwendtner
9ce839fc7d test(migrations): add test for statistic collection tsurge (#58019)
Adds a test for statistic testing of Tsurge

PR Close #58019
2024-10-01 11:29:00 +00:00
Paul Gschwendtner
273444ab9a refactor(migrations): support getting statistics in tsurge testing (#58019)
This allows us to test statistics in future commits.

PR Close #58019
2024-10-01 11:28:59 +00:00
Paul Gschwendtner
9f08ff2baf refactor(migrations): support statistic tracking in tsurge migrations (#58019)
We should support tracking statistics in Tsurge migrations. This allows
us to print them after migration, or run migrations periodically as
large scale changes to track to progress.

TODO is an internal implementation that eventually runs periodcally
in LSC modes.

PR Close #58019
2024-10-01 11:28:59 +00:00
Paul Gschwendtner
806db68556 refactor(migrations): skip query migration if problematic QueryList usages are discovered (#57992)
If we see a reference to e.g. `QueryList#changes`, we should skip
migration to be on the safe side. Similar for other fields of query
lists.

PR Close #57992
2024-09-30 13:33:45 -07:00
Paul Gschwendtner
2fe393ac60 refactor(migrations): improve tsurge diff helper to simplify output (#57961)
Instead of printing the full diff, which may be a super large file or
golden, we only print context around lines with diff. This makes the
diffs much more actionable and readable.

PR Close #57961
2024-09-26 14:29:03 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Paul Gschwendtner
04a48736b1 refactor(migrations): add TODO for special output of signal input migration (#57918)
Sometimes we may insert `undefined!` or `any`. We should add a TODO in
those cases.

PR Close #57918
2024-09-23 13:41:48 +02:00
Paul Gschwendtner
505c0f788e refactor(migrations): add better explanation on what color diff represents in testing (#57919)
This clarifies what colors mean in the Tsurge text diff Jasmine matcher.

PR Close #57919
2024-09-23 12:43:17 +02:00
cexbrayat
eb77b533b8 refactor(migrations): avoid TS error 18003 when no files found (#57899)
When running a migration, tsurge creates a TS program from the tsconfig files found.
This can result in a 18003 error when no files are found (based on the includes/files of the config).

For example, the signal input migration throws in a CLI project that has no spec files:

```
ng g @angular/core:signal-inputs --defaults
Tsconfig could not be parsed or is invalid:

No inputs were found in config file '/tsconfig.spec.json'. Specified 'include' paths were '["src/**/*.spec.ts","src/**/*.d.ts"]' and 'exclude' paths were '["/out-tsc/spec"]'.
```

A similar issue has already been raised in the CDK migration (see https://github.com/angular/components/issues/27055).

This was solved in the CDK (credits to @crisbeto) by ignoring the 18003 error (see 9c1112d408361a47c98dfd470b8e990cbd1753db).

This PR does the same in tsurge.

PR Close #57899
2024-09-23 12:42:33 +02:00
Paul Gschwendtner
5bb7050c59 refactor(migrations): add common helpers for inserting TODOs (#57898)
Adds a common helper for inserting TODOs to Tsurge.

PR Close #57898
2024-09-23 12:41:34 +02:00
Paul Gschwendtner
ef5412c9bc refactor(migrations): fix virtual devkit file system not detecting directories (#57897)
The compiler and its file system implementation expects `fs.exists` to
return `true` even for directories. This caused issues with the TSConfig
resolution as `/` was looked up.

We fix this by making use of `stat` which is equally expensive to
`tree.exists`. The devkit tree's don't expose directory existance checks
out of the box.

Fixes #57887.

PR Close #57897
2024-09-20 15:06:33 +02:00
Paul Gschwendtner
8ecafce2d9 refactor(migrations): do not run optional TCB operations in input migration (#57835)
Optional operations that don't run in the actual application compilation
would then cause fatal diagnostic errors breaking the compiler
initialization at runtime.

We should try to keep the migration as close as possible to the
application build.

PR Close #57835
2024-09-17 11:08:37 +02:00
Paul Gschwendtner
fd081e8ee4 refactor(migrations): add compiler filesystem for devkit virtual tree (#57794)
The file system will be used for dev-kit wiring up of Tsurge migrations
in e.g. `ng generate` and `ng update`

PR Close #57794
2024-09-13 14:13:58 +02:00
Paul Gschwendtner
2591b988ce refactor(migrations): add jasmine diff matcher to tsurge testing utilities (#57777)
Commonly when testing Tsurge migrations, we need to diff text content of
files. This commit adds a colored diff helper that makes writing tests
much easier.

PR Close #57777
2024-09-11 17:48:29 +00:00
Paul Gschwendtner
1c663ca820 refactor(migrations): add helper for dedenting to tsurge (#57777)
Dedenting the smallest leading whitespace is useful for conveniently
testing the output of a migration. This commit includes the helper in
Tsurge.

PR Close #57777
2024-09-11 17:48:29 +00:00
Paul Gschwendtner
acafa3b91d refactor(migrations): add own build file for tsurge AST helpers (#57766)
This separates tsurge from its optional AST helpers more cleanly.

PR Close #57766
2024-09-11 14:26:58 +00:00
Paul Gschwendtner
2e60eb08f4 refactor(migrations): ensure project paths respect root directories (#57677)
Migrations may resolve files in e.g. `blaze-out` and try to compute a
path for the file that is "recognizable" across workers. E.g. in one
worker, it may be the actual `.ts` file inside the source tree, while in
the other, the file may be inside `blaze-out`.

Tsurge currently expects project relative paths to be passed around.
Those project relative paths are currently only based on the single root
directory. Hence paths inside `blaze-out` would actually not be
recognizable.

The fix idea here is that we introduce a structure for Project files.
This structure will contain two fields:

- an ID of a file. This is similar to a module ID in the project. Those
  are resolved with respect to all root directories. This matches the
  conceptual virtual roots of `tsconfig#rootDirs`. The IDs can be used
  for matching files across workers, assuming those are executing using
  the same root directories, and handle the same overall project (e.g.
  google3).

- a path relative to the primary project root. Multiple roots may be
  configured, but the primary project root, is the directory that
  contains all others. See: `tsconfig.rootDir`. This path is NOT
  necessarily useful for matching files between stages etc, but it's
  useful for writing replacements for a given file to disk.

Note that those two things cannot be combind into one conceptual
"project relative path" because a path relative to the most appropriate
root directory cannot be used for safe replacements. E.g. consider a
replacement matches a file from a root directory like `/sub/`. The path
inside `/sub/` would then omit the `/sub/` and later on when writing
replacements, we wouldn't know which root directory it actually was part
of. Hence the concept of a "project root relative path" and the "ID".

ds

PR Close #57677
2024-09-06 19:44:07 +00:00
Paul Gschwendtner
227d13b86d refactor(migrations): preserve brace spacing when applying imports (#57672)
Currently the import manager always add a space after the import clause
brace. We should only do this if the existing import did the same.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
00852118cc refactor(migrations): preserve multi-line imports if possible when editing imports (#57672)
Currently whenever we apply the import manager changes in migations, we
leave the decision of multi-line or single-line to the TS printer.

This works, but in practice can cause signficiant file jumps/changes if
there are large imports that aren't wrapped for example, or the other
way around. We should try to be minimal here and preserve the existing
formatting, assuming that a multi-line import remains multi-line, while
a single-line import remains single-line if it already had many items in
a single line, intentionally.

PR Close #57672
2024-09-05 19:33:04 +00:00
Paul Gschwendtner
1251ee0ac6 refactor(migrations): share logic for looking up property access (#57645)
This commit shares the logic for looking up a property access, using
`ts.Type` information. This is helpful in case where no linked TS
symbols are available; e.g. templates in test files without TCB.

This helper will be useful for handling object expansion in the signal
input migration; resolving references like `const {x} = this`.

PR Close #57645
2024-09-03 14:29:54 -07:00
Paul Gschwendtner
a8e3ba9550 refactor(migrations): properly handle cases of --strict=false in signal input migration (#57629)
Sometimes `--strictPropertyInitialization` is not enabled, while strict
null checks is enabled. In those cases, `undefined` cannot be used as
initial value with `input()`, nor can we expand the type of the input.

We can migrate those instances to `undefined!` to preserve the original
semantics and behavior. In addition, in the future we may leave a TODO
or we may consider skipping migration of such inputs.

PR Close #57629
2024-09-03 07:55:09 -07:00
Paul Gschwendtner
2ad9609a8d refactor(migrations): pass project-relative paths for tsurge replacements (#57584)
This allows for the replacements to be conveniently passed between
migration stages. This is especially relevant in 1P where stages may
have different root directories.

Tsunami attempts to relativize paths in general, similar to how we do
here, but this doesn't work with e.g. Funnel-based migrations where
replacements are serialized in between stages; and where the migration
stage at the end doesn't know about the previous root directory anymore.

PR Close #57584
2024-08-29 14:28:02 -07:00
Paul Gschwendtner
82f4590216 refactor(migrations): avoid relative imports in schematic code (#57214)
This allows us to bundle e.g. the signal input migration into
language-service without duplicating code. Rollup with Bazel may end up
duplicating because it isn't able to associate the local sources with
the linked modules from `node_modules/@angular/compiler-cli`.

PR Close #57214
2024-08-29 07:50:41 -07:00
Paul Gschwendtner
1f067f4507 feat(language-service): add code reactoring action to migrate @Input to signal-input (#57214)
(experimental at this point)

Language service refactoring action that can convert `@Input()`
declarations to signal inputs.

The user can click on an `@Input` property declaration in e.g. the VSCode
extension and ask for the input to be migrated. All references, imports and
the declaration are updated automatically.

PR Close #57214
2024-08-29 07:50:41 -07:00
Paul Gschwendtner
29e526c147 refactor(migrations): allow tsurge migrations to run with just NgCompiler (#57562)
This is important so that migrations can easily be wired up in the
language service where only `NgCompiler` is available.

PR Close #57562
2024-08-28 08:47:45 -07:00
Paul Gschwendtner
c4681989ac refactor(migrations): properly handle multi query migration (#57556)
Properly handles queries with multiple results, by extracting the
type from the `QueryList`.

Also adds more tests and handles imports.

PR Close #57556
2024-08-28 08:43:38 -07:00
Paul Gschwendtner
86e6f7b5d6 refactor(migrations): initial migration logic for converting to signal queries (#57556)
Adds initial migration logic to convert decorator query declarations to
signal queries.

We will re-use more part of the signal input migration in follow-ups, to
properly migrate, and e.g. even handle control flow

PR Close #57556
2024-08-28 08:43:38 -07:00
Alex Rickabaugh
76b9e2b836 Revert "refactor(migrations): initial migration logic for converting to signal queries (#57525)" (#57555)
This reverts commit 6f5b435a69.

Reason: breaks g3

PR Close #57555
2024-08-27 14:03:06 -07:00
Alex Rickabaugh
0ba2a95bf6 Revert "refactor(migrations): properly handle multi query migration (#57525)" (#57555)
This reverts commit f454ad3bcf.

Reason: breaks g3

PR Close #57555
2024-08-27 14:03:06 -07:00