Sub topic 7
Pinning a Version or Floating with LATEST
This chapter assumes you can read sfdx-project.json, know the MAJOR.MINOR.PATCH.BUILD format, and have created a package version with the sf CLI. It covers how a dependency picks the version it resolves to, and how to choose between a fixed version and a floating one.
Two ways to name a dependency version
A dependency in sfdx-project.json can name its target in two ways.
- Floating: give a
versionNumberand end it withLATEST, for example1.1.0.LATEST. The build number is resolved when you create your package version. - Pinned: use an alias that maps to one exact subscriber package version ID (a
04tID), for example[email protected].
Floating with LATEST
The LATEST keyword replaces only the build number. Salesforce looks for the highest build of the MAJOR.MINOR.PATCH you wrote.
{
"path": "app",
"package": "Sales App",
"versionNumber": "2.0.0.NEXT",
"dependencies": [
{ "package": "Utils", "versionNumber": "1.1.0.LATEST" }
]
}Here the dependency resolves to the newest build of Utils 1.1.0. The NEXT in 2.0.0.NEXT is a different keyword. It sets the build number of the package version you are creating.
Resolution depends on where the dependency is built:
- If
Utilsis in the same project,LATESTuses the newest build ofUtilsthat exists when you create theSales Appversion. - When you create a released version of
Sales App, its dependencies must also be released versions. A beta build ofUtilsdoes not satisfyLATESTin that case. - If you omit
versionNumber, you need a pinned alias instead. Without either, the dependency does not point to a version.
Pinning an exact version
A pinned dependency names one version through an alias:
{
"path": "app",
"package": "Sales App",
"versionNumber": "2.0.0.NEXT",
"dependencies": [
{ "package": "[email protected]" }
]
}The alias is defined in packageAliases:
"packageAliases": {
"Utils": "0Ho000000000001AAA",
"[email protected]": "04t000000000001AAA"
}Pinning is the choice when you depend on a package from another project or team. It also fits any case where you need a build you have tested and want to keep fixed. The aliases are written for you when you run sf package version create, so you rarely type the 04t IDs by hand.
Choosing between them
| Situation | Better choice | Reason |
|---|---|---|
| Both packages live in the same repository and ship together | `LATEST` | Each new `Utils` build is picked up without editing the file |
| Depending on a package owned by another team | Pinned | Their new build cannot change your result unexpectedly |
| You need repeatable builds for a release | Pinned | The same input always resolves to the same version |
| Rapid development in a scratch org | `LATEST` | You always test against the newest dependency |
Floating trades repeatability for convenience. Two builds of the same Sales App source made a week apart can depend on different Utils builds. Pinning gives you the same result each time, but you must update the alias yourself when you want a newer build.
Common mistakes
- Writing
1.1.0.LATESTwhen the onlyUtilsbuilds are betas, while creating a released version. The dependency cannot be found. - Using an alias that is missing from
packageAliases. The CLI cannot map the name to an ID. - Assuming
LATESTmoves to the next minor version. It does not.1.1.0.LATESTnever resolves to 1.2.0.
Exercise
Your team's Sales App depends on Utils, which is owned by another team that publishes new builds daily. You need release builds that are reproducible. Should you use 1.1.0.LATEST or [email protected], and why?
Show answer
Use the pinned alias [email protected]. With LATEST, a new daily build from the other team could change which Utils build your next Sales App version depends on. The alias always maps to one 04t ID, so the result is the same each time.