Dependency Management
sfp provides powerful commands to manage and understand package dependencies in your Salesforce projects. These tools help you maintain clean dependency declarations, troubleshoot dependency issues, and optimize your build processes.
Available Commands
Add all transitive dependencies to make them explicit
Remove redundant transitive dependencies for cleaner configuration
Analyze and understand package dependencies
Understanding Dependencies
In Salesforce DX projects, packages can depend on other packages. These dependencies come in two forms:
Direct Dependencies: Dependencies explicitly declared in a package's configuration
Transitive Dependencies: Dependencies of your dependencies (indirect dependencies)
For example, if Package A depends on Package B, and Package B depends on Package C, then:
Package A has a direct dependency on Package B
Package A has a transitive dependency on Package C
Dependency Management Workflow
A typical dependency management workflow involves:
Development Phase: Use
sfp dependency:expand
to make all dependencies explicit during development, helping identify potential issues earlyAnalysis: Use
sfp dependency:explain
to understand dependency relationships and identify unnecessary dependenciesCleanup: Use
sfp dependency:shrink
before committing to maintain minimal, clean dependency declarationsBuild Optimization: Expanded dependencies help build tools understand the complete dependency graph for optimized builds
External Dependencies
External dependencies are packages from outside your project, typically:
Managed packages from AppExchange
Packages from other Dev Hub organizations
Third-party components
These are configured in your sfdx-project.json
under plugins.sfp.externalDependencyMap
:
{
"plugins": {
"sfp": {
"externalDependencyMap": {
"external-package-name": [
{
"package": "04tXXXXXXXXXXXXXXX",
"versionNumber": "1.0.0.LATEST"
}
]
}
}
}
}
Best Practices
Keep dependencies minimal: Only declare direct dependencies in your source control
Use expand for analysis: Temporarily expand dependencies to understand the full graph
Validate regularly: Run dependency commands in CI/CD to catch issues early
Document external dependencies: Clearly document why each external dependency is needed
Version carefully: Use specific versions for production,
.LATEST
for development
Common Issues and Solutions
Circular Dependencies
If packages depend on each other in a circular manner, the dependency commands will report an error. Refactor your packages to break the circular dependency.
Missing Dependencies
If a package references components from another package without declaring the dependency, add the missing dependency to the package's configuration.
Version Conflicts
When different packages require different versions of the same dependency, sfp will use the highest compatible version. Consider standardizing versions across your project.
See Also
Package Dependencies - Conceptual overview of dependencies
Transitive Dependency Resolution - How sfp resolves dependencies
Last updated