wp-local-docker-v2 icon indicating copy to clipboard operation
wp-local-docker-v2 copied to clipboard

Add sudo to postinstall so that mkcert doesn't get hung up

Open ggutenberg opened this issue 2 years ago • 2 comments

Description of the Change

This fixes an issue where, on MacOS Ventura (possibly others), if ~/Library/Application Support/mkcert/rootCA.pem doesn't already exist, a hidden sudo prompt occurs, and the installation hangs forever.

I attempted to use the sudo.exec() method, but it causes an error to be thrown - SecTrustSettingsSetTrustSettings: The authorization was denied since no user interaction was possible - which seems related to this https://developer.apple.com/forums/thread/671582 .

How to test the Change

  1. Be on a Mac, running Ventura.
  2. Delete ~/Library/Application Support/mkcert/ from your computer.
  3. Run sudo -k to make sure sudo isn't cached.
  4. Run npm uninstall -g wp-local-docker to fully remove it.
  5. Run npm i -g wp-local-docker to install it from the NPM Registry. Note that after a few mins it just stops. Behind the scenes it's waiting for a sudo password.

To test this branch:

  1. Repeat steps 1-4 above.
  2. Switch to this branch and cd to the root of this repo.
  3. Edit src/commands/postinstall.js and comment out the return statement on line 16. If you don't do this, the local installation will exit before making it to the problem command.
  4. Run npm i. You will be prompted for your sudo password when npm run postinstall is executed, and this will carry through to the mkcert command.
  5. Once complete, verify that you have ~/Library/Application Support/mkcert/rootCA.pem.

Changelog Entry

Fixed - Installation from NPM Registry would sometimes hang on mkcert

Credits

Props @ggutenberg

Checklist:

  • [x] I agree to follow this project's Code of Conduct.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my change.
  • [ ] All new and existing tests pass.

ggutenberg avatar Nov 22 '22 17:11 ggutenberg