Fix restoring plugins from package.json
Some of the code removed in GH-750 had side effects on the rest of the
plugin restoration procedure. Namely, despite wanting to migrate to
package.json, we actually relied on config.xml for retrieving the plugin
spec and variables. When we stopped syncing changes back to config.xml,
those plugins stopped getting restored.
I've refactored this significantly to reduce complexity and make it
easier to read and understand.
The existing tests did neither describe nor test the new behavior
sufficiently.