Fix #1569.

* Change `guessPackageName` to translate arbitrary strings into valid
package names.
* Change type of `packageName` flag from String to PackageName and
reject names that do not pass PackageName's corresponding parse
function.