Sub topic 2
Reading and choosing version numbers
This chapter assumes you know Salesforce DX projects, the sf CLI, and Dev Hubs, and that you can read sfdx-project.json. It covers how a package version number is built, how to choose the next one, and what the NEXT and LATEST keywords do.
The four parts of a version number
Second-generation packages (unlocked and managed) use the format MAJOR.MINOR.PATCH.BUILD, for example 1.1.0.3.
| Part | Who sets it | Meaning |
|---|---|---|
| MAJOR | You | A large change, such as a new feature set or a breaking change |
| MINOR | You | A smaller, compatible addition |
| PATCH | You | A bug fix |
| BUILD | Salesforce, or you | A counter for each version you create |
Salesforce stores the first three parts as the version you intend to ship. The build number tells apart the many versions you create while working toward it. Two versions can share 1.1.0 and differ only in the build number, as in 1.1.0.1 and 1.1.0.2.
On the command line and in aliases, a version is often written in a short form, 1.1.0-1. This is MAJOR.MINOR.PATCH-BUILD. It names the same version as 1.1.0.1.
Choosing the next number
You set the number in the versionNumber field of the package directory in sfdx-project.json. You can raise any part.
- Raise MAJOR for a change that callers could notice or that breaks them.
- Raise MINOR when you add something that doesn't break existing users.
- Raise PATCH for a fix with no new features.
Managed packages have an extra rule. Once you release a version, you can't change what its MAJOR.MINOR number means in a way that breaks subscribers. Treat the number as a promise to the people who install it.
The NEXT keyword
Writing the build number by hand is tedious and error-prone. Use NEXT instead.
{
"path": "util",
"package": "Utils",
"versionName": "Utils 1.1",
"versionNumber": "1.1.0.NEXT"
}When you run sf package version create, Salesforce replaces NEXT with the next unused build number for that 1.1.0 version. The first run gives 1.1.0.1, the second gives 1.1.0.2, and so on. Build numbers start over at 1 when you change MAJOR, MINOR, or PATCH.
The LATEST keyword
LATEST appears in a dependency, not in the package's own version. It tells Salesforce to use the highest build of a given MAJOR.MINOR.PATCH.
"dependencies": [
{ "package": "Utils", "versionNumber": "1.1.0.LATEST" }
]Here the Sales App depends on the newest build of Utils 1.1.0 that exists. A later chapter covers how this choice is resolved and when to pin an exact version instead.
The two keywords are easy to mix up. This table keeps them apart.
| Keyword | Used in | Result |
|---|---|---|
| `NEXT` | A package's own `versionNumber` | A new build number is assigned |
| `LATEST` | A dependency's `versionNumber` | The highest existing build is selected |
How the build number is assigned
The diagram shows what happens when you create several versions of the same MAJOR.MINOR.PATCH.
Common mistakes
- Writing a fixed build number such as
1.1.0.5in your ownversionNumber. If that build already exists, the create fails. UseNEXT. - Using
LATESTin your ownversionNumber. It is only valid in dependencies. - Lowering a version number below one you already created. Each new version needs a higher number than the last one for that package.
- Forgetting that
1.1.0-1and1.1.0.1are the same version when you read aliases.
Exercise
Your Utils package has builds 1.1.0.1 to 1.1.0.4. You change versionNumber to "1.2.0.NEXT" and create a version. What number does the new version get, and why?
Show answer
It gets 1.2.0.1. Build numbers are counted separately for each MAJOR.MINOR.PATCH, so changing MINOR starts the count again at 1.
Exercise
A dependency says "versionNumber": "1.1.0.LATEST". Builds 1.1.0.1, 1.1.0.2 and 1.2.0.1 exist. Which one is used?
Show answer
1.1.0.2. LATEST picks the highest build within 1.1.0 only, so 1.2.0.1 is not considered.