Mac package installer installs the folder "Contents" in /Applications instead of the bundle
Took me a few tries to get this working (the installer managed to do some really strange stuff on my first few attempts). But this seems to work reliably.

I created a temporary folder with just the application I wanted to package (leaving the app sitting elsewhere seemed to result in the aforementioned strange behaviour), then package it from there. So I created a temporary folder called "test" on my desktop and dropped the app in there on its own. The following command then reliably results in a working package on my Desktop.

productbuild --component ~/Desktop/test/myapp.app /Applications ~/Desktop/myapp.pkg --sign "my certificate identity name"


Something that is helpful when testing is to run sudo opensnoop | grep installd in a Terminal at the same time. It generates a lot of output but you should be able to see the application bundle being created in something like /var/folders/zz/GIBBERISH/C/PKInstallSandboxManager/GIBBERISH.activeSandbox/Root/ and then copied to its final destination.

Note: I'm not certain why you are using -s in the second example productbuild command you gave in your question. There are three options arguments to productbuild that start with "s" (synthesis, scripts and sign) and the man page doesn't mention using the shorter "-s" for any of them. Perhaps this is the problem. Of course it could just be a typo. :)