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/libin my project is1.1.0. - The latest published npm version of
@my/libis4.8.9. - Now, when we run
ng update @my/lib(or...@my/lib@4or...@my/lib@4.8or...@my/lib@4.8.9, it doesn't matter), - and the file
migration.jsonof@my/libcontains migrations for the"version"2.0.0and4.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.jsonbelongs to the appropriate semver range, then this migration is launched (see source).The appropriate semver range means something between
>fromVersionand<=toVersion(see sources: executeMigration() and invocation of executeMigration()).The
fromVersionandtoVersionrespectively mean:installed.versionandtarget.version(see source).
Therefore, all migrations between >installed.version and <=target.version are launched.
Top comments (0)