studio icon indicating copy to clipboard operation
studio copied to clipboard

Plugins and themes can't be symlinked

Open jasonbahl opened this issue 1 year ago • 12 comments

What

I would love to be able to symlink plugins and themes.

Why

As a plugin developer, I often spin up new sites to reproduce specific scenarios, discover edge cases, etc and I would like to be able to symlink plugin(s) into my studio managed sites so that I can use a canonical version of the plugin(s) on my machine across different studio sites.

How

I would like to be able to :

  • navigate to the plugins directory of my studio site: cd ~/Studio/site-name/wp-content/plugins

  • symlink a plugin I have on my machine into the site: ln -s ~/path/to/my/plugin

  • Activate the symlinked plugin in my studio site


Currently, I can symlink a plugin into the plugins directory and it shows properly symlinked on my machine, but the WP admin does not show the symlinked plugin as an available plugin to activate.

jasonbahl avatar Apr 24 '24 15:04 jasonbahl

If there is support for symlinks was also one of my first thoughts when I installed Studio. Unfortunately, symlinks do not (yet) work. This would be a big plus for Studio.

miczh avatar May 22 '24 07:05 miczh

Upvote!

divydovy avatar Jun 27 '24 14:06 divydovy

Really need this working. With out it myself and team can't use the app which is a great shame. Any idea on how to get this working or when it will be fixed. Thanks

AndrewBrightbulb avatar Aug 06 '24 21:08 AndrewBrightbulb

@AndrewBrightbulb We are in planning phases for this now, in fact! We'll ping on this issue when we have a build for you to test out.

danielbachhuber avatar Aug 06 '24 22:08 danielbachhuber

Heads up that this was solved on macOS in https://github.com/Automattic/studio/pull/510. Stay tuned as it will be released in version 1.1.3 🎊 .

cc @jeroenpf

fluiddot avatar Sep 25 '24 15:09 fluiddot

Heads up that this was solved on macOS in #510. Stay tuned as it will be released in version 1.1.3 🎊 .

cc @jeroenpf

That is amazing :) We will be using it once it is released.

AndrewBrightbulb avatar Sep 25 '24 15:09 AndrewBrightbulb

Hi, I have downloaded the latest version 1.1.3 and unfortunately the symlink still isn't working for me

AndrewBrightbulb avatar Oct 02 '24 08:10 AndrewBrightbulb

Hi, I have downloaded the latest version 1.1.3 and unfortunately the symlink still isn't working for me

Hey @AndrewBrightbulb, I've tested version 1.1.3 and I confirmed that symlinks are working on my side. I wonder if you could share your case so we can take a look and try to debug it. Thanks 🙇 !

As an example, I symlinked the Gutenberg plugin for development:

  1. Select a site.
  2. Click on Terminal.
  3. Run the command ln -s <PATH_TO_GUTENGERG_REPO> ./wp-content/plugins/gutenberg (replace the path to Gutenberg with an actual path).
  4. Navigate to WP-Admin -> Plugins.
  5. Observe that the plugin is listed.

fluiddot avatar Oct 02 '24 09:10 fluiddot

I can confirm this is working for me in version 1.1.3 on macOS. Thank you!

mindctrl avatar Oct 07 '24 15:10 mindctrl

Hmm, it seems if a symlinked theme is activated and the site is stopped in Studio, when the site is restarted it goes back to the default theme. This does not happen if using a theme that is not symlinked.

mindctrl avatar Oct 07 '24 15:10 mindctrl

I was able to symlink plugins and themes. But it's true that the symlinked themes is replaced by the default one when restarting the site server.

I've also experienced the same issue when just changing the window focus to Studio. It seems that the logic that captures the home screenshot resets the theme to the default one.

https://github.com/user-attachments/assets/3f6e6aa8-ba30-4aa6-8546-3922e407bf75

sejas avatar Oct 09 '24 16:10 sejas

I've identified where the error comes from, but I don't have a solution.

It seems that when we run a PHP code or WP-CLI command by spawning a new child process in src/lib/site-server-process-child.ts, it starts a new server and that seems to reset the theme to default, probably because it's removing the symlink temporarly.

Commenting these two focus hooks, I can see the selected theme persists. Although stopping and starting seems to reset it some times.

https://github.com/Automattic/studio/blob/587292a9a0e64bbee0b4c223cb228e10a47dab6a/src/hooks/use-chat-context.tsx#L133-L142

https://github.com/Automattic/studio/blob/587292a9a0e64bbee0b4c223cb228e10a47dab6a/src/hooks/use-theme-details.tsx#L75-L81

sejas avatar Oct 10 '24 12:10 sejas

First of all, thanks for getting the initial Symlinking working :) I did do some testing with WooCommerce and noticed that when I symlink WooCommerce a lot of the REST requests fail, not all of them though, around 90%. But when I install WooCommerce as a plugin all the REST requests work fine.

louwie17 avatar Nov 27 '24 12:11 louwie17

Just noting that on Studio version 1.3.0, symlinked plugins on macOS randomly stop working, after having worked for hours. This results in deactivated plugins when it happens. Sometimes the plugins will show up after a couple refreshes in admin, and sometimes I have to restart the site. In any case, the plugin must be reactivated afterwards. It's unclear to me why this would happen, since it's all on the same file system.

mindctrl avatar Jan 08 '25 15:01 mindctrl

The root cause of this issue is that WP-cli executions don't mount symlinked folders, so during a WP-cli run, WordPress can't find the symlinked themes and plugins.

Mount symlinks when executing WP-cli commands #809 addresses this by mounting the project path before executing WP-cli commands.

bgrgicak avatar Jan 17 '25 09:01 bgrgicak