How to use “sfdx force:source:pull” with folders other than “main/default” where components are added in the scratch org?

I’ve setup the folder structure for a new project following the pattern identified in sfdx-isv/sfdx-falcon-template. Also see this question Two SFDX project folder structure questions for some background.

When I add e.g. a new SObject in the scratch org and use:

sfdx force:source:pull

the new components are put in a fixed folder “main/default” – there is no option to nominate the correct folder. So the folder structure is compromised.

The change I am making in the scratch org is adding a new SObject and multiple fields: no sfdx commands at present to make that easy from the command line.

(When components are already present locally in folders other than “main/default” the pull does place the changes correctly.)

Is there a work-around here apart from just sticking to using “main/default” for everything or creating everything locally so the component can be setup in the right folder?

PS

Tried the manual workaround of pulling then moving the files locally but so far no joy: the move is seen as a delete that is bad news when you next push.

Answer

This is by no means great, but you can force your way around this by editing the local file used to track changes.

  1. create a new field in the org
  2. sfdx force:source:pull -> field gets pulled into force-app/main/default
  3. move the field to a separate directory (at this point sfdx thinks i’ve deleted the field)
  4. open .sfdx/orgs/<your_scratch_org_username>/sourcePathInfos.json
  5. delete any entries related to the original path
  6. remind yourself that benioff is free from original sin, so all bugs are features, but you aren’t so try and write some decent code

Big picture, SFDX had grand dreams of letting you organize stuff into multiple folders. But there are major bugs with the implementation, and it’s been multiple years at this point and none of them are fixed. If you can just stick to one folder. If you do multiple folders, prepare to pay for it in pain.

Issues I’m aware of

  • refreshing a file outside of the default folder ends up with an extra copy of the file in the default package folder and no updates to the one you intended to refresh
  • if you move metadata from one package directory to another scratch org commands think you’re deleting stuff
  • when you pull metadata you’ve got no good way to control where it goes

Attribution
Source : Link , Question Author : Keith C , Answer Author : Ralph Callaway

Leave a Comment