
Package : a Salesforce package is a container that you fill with metadata, in order to move it from one org to another
Unlocked Packages : is a type of Salesforce packages that is especially suited to for internal business apps not ISV apps (AppExhange)
Wokflow for Unlocked Packages
Second generation packages are source driven (Version Control System is the source of truth) and their life cycle differs from the first generation package.

Generate
In this step you create the package(container) and you specify some characteristic info about it: name, description, namespace.
The package is linked to the default devhub or the one specified during the creation and sfdx-project.json gets updated with the package infos and the package id (starting by 0Ho) is generated
Example command
sfdx force:package:create -n YourPackageName -t Unlocked -r force-app
Release
In this step one or multiple immutable package versions are created (Id starting by 04t) and can be deployed to scratch orgs/sandbox. Package version is a snapshot of the metadatas contained in the folder specified during the package creation
Once the version is fully tested it can be promoted to the released state, so it can be installed into production orgs
Example command (creating a version)
sfdx force:package:version:create -d YourPackageName
Example command (promoting a version)
sfdx force:package:version:promote -p YourPackageName
Install
In this step you install the package version in to a sandbox/production using the user interface or a command line tool
Example command
sfdx force:package:install -p YourPackageName
Package upgrade

One of the advantages of the Unlocked Packages over Unmanaged Packages is that they are upgradable
A new version of the Unlocked Package can be installed using the command line or the UI and the upgrade type can be specified during the installation
- Delete specifies to delete all removed components.
- DeprecateOnly specifies that all removed components must be marked deprecated.
- Mixed (the default) specifies that some removed components are deleted, and other are marked deprecated. see Metadata Coverage.
Package dependency

Second generation packages can have dependent packages and these dependencies are specified in the sfdx-projet.json file
{
"path": "force-app",
"package": "YourPackageName",
"versionName": "v 1.0",
"versionDescription": "Summer 2019 Release",
"versionNumber": "1.0.0.NEXT",
"dependencies": [
{
"package" : "BasePackage@1.0.0"
}
]
}Package dependencies are enforced during the package installation, use this sample script provided by Salesforce to auto-install the package dependencies
