Refactoring.

Introduce two helper functions to break a giant case statement.
Formatting.
Refactoring.

Split 'onBuildConfig' into two (local) functions.
Rename a function.
Detect when a sandbox was created for an already configured package.

In this case we need to reconfigure immediately, skipping reinstallation of
add-source deps.

Fixes #1349.