ng update @my/lib@version - Which migration schematics will be executed? 馃し
Krzysztof Platis
Posted on February 4, 2024
The command ng update @my/lib@version
downloads the specified version of the library and launches all schematics listed in its migrations.json
that have an appropriate property of "version" within the semver range from >installedVersion
to <=targetVersion
.
Example
For instance, consider the following conditions:
- The locally installed version of
@my/lib
in my project is1.1.0
. - The latest published npm version of
@my/lib
is4.8.9
. - Now, when we run
ng update @my/lib
(or...@my/lib@4
or...@my/lib@4.8
or...@my/lib@4.8.9
, it doesn't matter), - and the file
migration.json
of@my/lib
contains migrations for the"version"
2.0.0
and4.5.0
:
{
"schematics": {
"migration-v2": {
"version": "2.0.0",
"factory": "./migration-v2#migrate",
"description": "Migration for v2.0.0"
},
"migration-v4.5": {
"version": "4.5.0",
"factory": "./migration-v4_5#migrate",
"description": "Migration for v4.5.0"
},
}
}
...then the following migrations will be executed, in ascending order of version:
- Migration for v2.0.0
- Migration for v4.5.0
This is because they fall between the currently installed version (>1.1.0
) and the target version (<=4.8.9
).
Note: If we were to run ng update @my/lib@
with the target version lower than 4.5.0
, for example, ng update @my/lib@3
, only the following migration would be executed:
- Migration for v2.0.0
However, the Migration for v4.5.0
would not run.
Angular CLI source code analysis
Here's a proof in the source code of the Angular CLI:
If the "version" field from
migrations.json
belongs to the appropriate semver range, then this migration is launched (see source).The appropriate semver range means something between
>fromVersion
and<=toVersion
(see sources: executeMigration() and invocation of executeMigration()).The
fromVersion
andtoVersion
respectively mean:installed.version
andtarget.version
(see source).
Therefore, all migrations between >installed.version
and <=target.version
are launched.
If you really feel like buying me a coffee
... then feel free to do it. Many thanks! 馃檶
Posted on February 4, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 24, 2024
February 4, 2024