Make WordPress Core

Opened 9 months ago

Last modified 7 weeks ago

#61575 new defect (bug)

Node Modules in sub-directories not getting ignored while exporting the theme

Reported by: rajinsharwar's profile rajinsharwar Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch close
Focuses: Cc:

Description

There is an issue with node_modules not getting ignored while in the sub-directory and adding a new filter for permission capability for the Export button.

To replicate try to run these commands to add the node_modules under any sub-directory in the theme.:

  1. cd ../path/to/wp-content/themes/twentytwentythree/assets
  2. npm install some-package
  3. Export the theme.

You will see that the node_modules folder is present when the theme is exported.

Change History (6)

This ticket was mentioned in PR #6970 on WordPress/wordpress-develop by @rajinsharwar.


9 months ago
#1

  • Keywords has-patch added

Fixing issue with node_modules not getting ignored while in sub-directory and adding new filter for permission capability for Export button.

https://github.com/WordPress/wordpress-develop/assets/68213636/371cb20e-365c-4d2e-8e21-d71361dc0f00

Trac ticket: https://core.trac.wordpress.org/ticket/61575

#2 @peterwilsoncc
9 months ago

It's difficult to know the developer's intent with regard to exporting node_modules.

As NPM packages include both production and development dependencies, it's possible the intent is to include the folder as it contains code required for production websites.

If the theme directory includes NPM or yarn config files, it might be safe to assume that the node_modules folder can be excluded and require it be run upon deploy. If it doesn't then I think we certainly want to retain node_modules.

The complicating factor is when accounting for uploading of themes. If the folder doesn't include node_modules and the site owner has no way of running it then there is a risk of breaking sites.

#3 @rajinsharwar
9 months ago

  • Keywords 2nd-opinion added

As of my understanding, currently, even without the patch, we are not checking if the theme has NPM or yearn config files, and then only deleting the node_modules folder if it does.

Not entirely sure, but should we consider adding a filter or something using which the theme author can define if he exclusively wants the node_modules or any other folder in the theme to be included or not @peterwilsoncc?

#4 @Mista-Flo
6 months ago

@peterwilsoncc Do you have any example of a theme that embeds node_modules folder important for the theme to run?

From my knowledge, we usually have a dist folder that is built and necessary for the export, can't find a reason why a node_modules folder should be included.

#5 @peterwilsoncc
6 months ago

@Mista-Flo Unfortunately, it's not really that simple. Many of the sites built with WordPress are custom themes built by agencies. While it's known that no bundled themes include files within node_modules, it's not possible to make the assumption about custom builds or all the themes in the plugin repository.

#6 @desrosj
7 weeks ago

  • Keywords close added; 2nd-opinion removed

It would be nice if the export feature could be configured within theme.json. Then theme developers could maybe disable export entirely, or configure a list of patterns, assets, or even directories to include or exclude when performing exports.

I personally lean towards closing this out, though. Without a way for a theme developer to intentionally indicate what should be considered a requirement for the theme, it's impossible for Core to guess correctly 100% of the time.

In the case of node_modules, it's either required, or someone is _doing_it_wrong() when zipping up their theme release or uploading/deploying their custom theme. Skipping it during export would hide the fact that the directory is present on the server, which could be a way to inform them that they should remove it.

Note: See TracTickets for help on using tickets.