Sub topic 4
Configuring sfdx-project.json for packaging
This chapter assumes you have a Dev Hub with your namespace linked, a Salesforce DX project in source format, and the Salesforce CLI (sf) installed. You will configure sfdx-project.json, the file the CLI reads to learn what to package.
What the file does
sfdx-project.json sits at the root of your project. For packaging, it answers four questions:
- Which folder holds the package source?
- What is the package called, and which version is being built?
- Which earlier version can subscribers upgrade from?
- Which namespace do the components belong to?
The CLI reads these values each time you create a package or a package version. A mistake here usually shows up later, as a failed build.
A minimal managed package configuration
{
"packageDirectories": [
{
"path": "force-app",
"default": true,
"package": "AcmeApp",
"versionName": "Initial release",
"versionNumber": "1.0.0.NEXT",
"versionDescription": "First version of the Acme app",
"ancestorVersion": "NONE"
}
],
"namespace": "acme",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}Package directory fields
Each entry in packageDirectories describes one folder of source.
| Field | Purpose |
|---|---|
| `path` | Folder that holds the package source. |
| `default` | Marks the folder where new source is retrieved. Exactly one entry is the default. |
| `package` | The package name. It must match the name you pass to `sf package create`. |
| `versionName` | A human-readable label, such as "Spring update". |
| `versionNumber` | The `major.minor.patch.build` number. `NEXT` lets the CLI assign the build number. |
| `versionDescription` | Optional text describing the version. |
| `ancestorVersion` | The earlier version this one builds on. Use `NONE` for the first version. |
Project-level fields
These fields sit outside packageDirectories and apply to the whole project.
namespaceis the namespace prefix. It must be a namespace linked to your Dev Hub, or package creation fails.sfdcLoginUrlis the login URL the CLI uses. The default ishttps://login.salesforce.com.sourceApiVersionis the API version used when the CLI deploys and retrieves source.
Common errors
- Namespace not linked. The
namespacevalue is not registered with the Dev Hub you are targeting. Link it first, or fix the spelling. - Package name mismatch. The
packagevalue differs from the name used insf package create. Use the same name in both places. - Hard-coded build number. Writing
1.0.0.1instead of1.0.0.NEXTmakes you edit the file for every build. - Missing ancestor. Leaving out
ancestorVersionon a later version can block upgrades. Set it deliberately each time.
Exercise
You are building the first version of a managed package. Which versionNumber and ancestorVersion values should you use so the CLI picks the build number and no earlier version is referenced?
Show answer
Use "versionNumber": "1.0.0.NEXT" and "ancestorVersion": "NONE". NEXT lets the CLI assign the build number. NONE states that this version has no ancestor.