Skip to content

Conversation

@epeicher
Copy link
Contributor

@epeicher epeicher commented May 28, 2025

Related issues

Proposed Changes

  • Create a patch for the archiver third party package so it follows the symlinks when archiving directories

Testing Instructions

This can be tested using Studio or the CLI

  • Apply this branch and run npm install
  • Start Studio with npm start or if using the CLI run npm run cli:watch
  • Create a site and inside the wp-content folder, add some symlinks for either plugins or themes (although they can be on any other folder). For example, if you download the following repo to your ~/github folder, you could add a symbolic link to it in your plugins folder using ln -s ~/github/wp-data-layer-app-pages ~/Studio/my-symlinked-website/wp-content/plugins/wp-data-layer-app-pages (replacing my-symlinked-website by your Studio site).
  • Create a symlink to a file, for example, create a symlink that points to a dummy plugin file outside of the site folder, .e.g. save the following file and add a symlink to it in the plugins folder:
<?php
/**
 * Plugin Name: My Test Plugin
 * Plugin URI: https://example.com/
 * Description: A simple test plugin that doesn't do anything.
 * Version: 1.0
 * Author: Your Name
 * Author URI: https://example.com/
 * License: GPL2
 */

// Silence is golden.
  • On the Studio app, navigate to Previews and create a preview site or on a terminal, open the root folder of the studio repo and run node dist/cli/main.js preview create --path ~/Studio/my-symlinked-website
  • Once created, navigate to the preview site, and open /wp-admin/plugins.php or navigate to Plugins -> Intalled Plugins
  • Check you can see the symlinked plugins, if you followed the example, you should see WP Data Layer App Pages and you should also see My Test Plugin, for example:
    CleanShot 2025-05-28 at 18 00 38@2x

Test broken symlinks

  • Following the steps above, delete or move the target folders and file of the symlinks so the symlinks will point to a non-existing directory and file.
  • Create a preview site and make sure that there are no unexpected errors.
  • Open the preview site, and confirm that you cannot see the Plugins, but you don't see any errors.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected, and now Preview sites follow symlinks when generating the zip file.

Let's rename the patch file from patches/archiver+6.0.2.patch to patches/archiver+6.0.1.patch. I got a warning when installing the dependencies with npm install.

patch-package 8.0.0
Applying patches...
@automattic/[email protected] ✔
@wordpress/[email protected] ✔
@wordpress/[email protected][email protected] ✔

Warning: patch-package detected a patch file version mismatch

  Don't worry! This is probably fine. The patch was still applied
  successfully. Here's the deets:

  Patch file created for

    [email protected]

  applied to

    [email protected]
  
  At path
  
    node_modules/archiver

  This warning is just to give you a heads-up. There is a small chance of
  breakage even though the patch was applied successfully. Make sure the package
  still behaves like you expect (you wrote tests, right?) and then run

    patch-package archiver

  to update the version in the patch file name and make this warning go away.

---
patch-package finished with 1 warning(s).

stat: true,
- dot: true
+ dot: true,
+ follow: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider using the same code from your node-archiver PR: archiverjs/node-archiver#810

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I decided to use this simple approach because it will be discarded if there is a potential upgrade. But thinking about it, and related to this other PR #1448, it is more explicit to set the option from the calling code, i.e. archiver('zip', {followSymlinks: true}), and the changes in the calling code will reflect better why the symlinks are followed, so I will apply your suggested changes instead 👍

Copy link
Contributor Author

@epeicher epeicher May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as part of latest commits f10e4c8, be3b8a6 and 51437f9

@epeicher epeicher requested a review from sejas May 29, 2025 12:17
@epeicher epeicher merged commit ebb56a5 into trunk May 30, 2025
12 checks passed
@epeicher epeicher deleted the patch/archiver-to-follow-symlinks branch May 30, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants