Ghost: "Download theme" action should skip zipping of `node_modules`

Created on 19 Jul 2019  路  5Comments  路  Source: TryGhost/Ghost

Issue Summary

When performing local development of a theme it can be useful to click the "download" button for the theme in the admin area to get a zip in order to upload it. However, if you have any node modules installed in the theme then they can get bundled up, creating a _huge_ zip file and potentially breaking the theme import.

This issue was originally reported on the forum here https://forum.ghost.org/t/failed-to-read-zip-file/8325

To Reproduce

  1. cd into the content/themes directory and run cp -R casper casper-custom
  2. cd casper-custom then run yarn
  3. start Ghost
  4. navigation to the Design screen in the admin area
  5. click the "download" link for the custom casper theme to get a zip
  6. click "Upload a theme" and attempt to upload the zip file
  7. note the error messages in your server logs

The upload is failing because the node_modules directory is included in the zip and Casper uses the gscan module which has an intentionally bad symlink in it's test files to ensure that theme uploads fail on bad symlinks.

Although it's not always the _correct_ way of creating a zip file for a local theme (it won't run any build steps for example) the above flow is still useful in many circumstances. We should ensure that the node_modules directory is skipped when creating a zip to fix the flow and to reduce server load from attempting to zip potentially thousands of module files.

Potential Solution

For reference, zip files creation is triggered in ThemeStorage class and uses the zip-folder utility which in turn uses the external archiver module.

A potential solution could be performing some file globbing (Ghost already has the glob dependency) to generate a file list excluding the node_modules directory which can then be passed to the archiver instance.

bug good first issue help wanted server / core

Most helpful comment

Hey - I haven't worked on open source tickets before, can i give this a go?

All 5 comments

Hey - I haven't worked on open source tickets before, can i give this a go?

@annas-abuhassan sure, PRs are welcome 馃檪 If you run into any issues our forum is a great place to get help!

Hey - I haven't worked on open source tickets before, can i give this a go?

How are you getting on with this issue?

@annas-abuhassan @mrbenosborne Are you guys working on this one? If not, I can send a pull request. @kevinansfield Tried using the glob approach locally. Seems to work fine.

Hi all - sorry, please go for it @lunaticmonk

Was this page helpful?
0 / 5 - 0 ratings