Here are the steps that I follow which worked for me .
- Retrieve source in DX Source format from the Managed Package directly using the SalesforceDX CLI .
This process generally involves first pulling all the metadata from the package using madapi command using package name and then running source convert command .
In order to make this seamless I have created a simple DX Plugin that should allow you to retrieve the source code in SalesforceDX Source format directly.
You can install the plugin using
sfdx plugins:install mo-dx-plugin
You will need to authenticate with the packaging org using CLI and then retrieve source using
$ sfdx retrieve:pkgsource -n "packagename" -u <username/alias>
At this point if you are lucky the convert command succeeds (note that SFDX has still bugs on convert command for specific metadata types and hence this might fail as well) then you have the source folder that you need to commit to repo .
In case the source conversion fails then one would need to follow process listed in this blog .
Create a new branch and commit the dx source format code. Note that git will not allow you to rename files and this blogpost will show you how you can get around this .
Try to push the dx source format code to the scratch org .This again you need to be really lucky to get past this . If not then you may have to figure the errors and create a folder to use mdapi for unsupported metadata in scratch orgs .
Load some test data in scratch org and run a full regression .
Build a Continuous Pipeline to allow deployment from scratch org source format into both scratch orgs and other orgs .
The merge to master again bump the limit of file renaming using below
git config merge.renameLimit 999999