WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 8 days ago

#50460 new enhancement

Don't minimize the `script-loader-packages.php` file

Reported by: desrosj Owned by:
Milestone: 5.8 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch close
Focuses: Cc:

Description

The wp-includes/assets/script-loader-packages.php file was added in #48154 through [47352] as a means to automate the process of updating the NPM packages from the Gutenberg repository (including dependencies and versions) in a way that the packages would still be available through the wp_(enqueue|register)_scripts().

This works great, but the file is a single line return statement that returns a multidimensional array, which makes it impossible to read through without reformatting it.

I am proposing that the file not be minimized to one line in order to make it human readable. This would have an added benefit of making the changesets readable, allowing someone to view a changeset and understand exactly what was changed or updated (see [47920], [47517], [47513]).

Change History (10)

#1 @desrosj
10 months ago

The generation of this file is handled in Webpack through the Dependency Extraction plugin in the Gutenberg repo. It doesn't seem that the output can be formatted in anything but single line looking over how that code works.

It may be easier to handle this in Core after the file is created.

#2 @johnbillion
4 months ago

There's a PHP plugin for Prettier, so the output could be post-processed with that.

https://github.com/prettier/plugin-php

This ticket was mentioned in Slack in #core by desrosj. View the logs.


3 weeks ago

#4 @desrosj
3 weeks ago

  • Milestone changed from Awaiting Review to 5.8

I'm going to try and tackle this for 5.8. This is a huge pain when comparing updates to this file.

#5 @johnjamesjacoby
3 weeks ago

  • Milestone changed from 5.8 to Awaiting Review

I am +1 to not minimizing this file.

It is helpful – at least to my human eyes – to visually verify the changes that get auto-generated into it.

#6 @peterwilsoncc
3 weeks ago

My preference is to stop committing it (see #49635) as it's ignored on the build server which uses the npm generated version. @azaozz had some minor concerns about doing so but suggested biting the bullet, my inclination is to do so for 5.8.

#7 @SergeyBiryukov
3 weeks ago

  • Milestone changed from Awaiting Review to 5.8

#8 @desrosj
3 weeks ago

  • Keywords close added

Ah, thanks for pointing #49635 out, @peterwilsoncc. I had missed that one. I think that eliminating the need to include this file is preferable.

I'll leave this open for now, but only need to tackle this if the fix suggested in #49635 is not committed.

#9 @gziolo
9 days ago

Maybe we can tweak it in the webpack plugin, it looks like the following lines are responsible of the output format:

https://github.com/WordPress/gutenberg/blob/48e470eca70966c8a9ff89f342c875b7aa9845b0/packages/dependency-extraction-webpack-plugin/lib/index.js#L95-L99

#10 @gziolo
8 days ago

The npm library we use to output PHP code from the JSON representation can be always inlined and modified to meet our requirements:
https://github.com/daniel-zahariev/json2php/blob/master/lib/json2php.js

Unless we find a way to run unit tests without wp-includes/assets/script-loader-packages.php file present as discussed in #49635.

Note: See TracTickets for help on using tickets.