Skip to content

Add Perl script to list JS dependencies and suggest a load order - #965

Closed
nylen wants to merge 1 commit into
masterfrom
add/js-dependencies-script
Closed

nylen wants to merge 1 commit into
masterfrom
add/js-dependencies-script

Conversation

@nylen

@nylen nylen commented May 31, 2017

Copy link
Copy Markdown
Member

I wrote this script while I was working on #929 to better understand the dependencies between our various Webpack bundles. I'm not sure that we want to add this to the repo or not, but it was useful to me to determine the needed order of these modules in our Webpack config. (This is mainly important for the test build, as in the actual plugin this is handled via WP's script dependency resolution mechanism).

It's a bit unfortunate that we have to do this twice (once on the client side and once on the server side). However, I'm also thinking that this script (or something like it) will come in handy to calculate actual dependencies when we start adding more Webpack-built files to WP core.

@nylen

nylen commented May 31, 2017

Copy link
Copy Markdown
Member Author

I meant to include example output here as well:

$ bin/list-js-dependencies.pl 
'blocks' depends on 'components'
'blocks' depends on 'element'
'blocks' depends on 'i18n'
'blocks' depends on 'utils'
'components' depends on 'element'
'components' depends on 'i18n'
'editor' depends on 'blocks'
'editor' depends on 'components'
'editor' depends on 'date'
'editor' depends on 'element'
'editor' depends on 'i18n'
'editor' depends on 'utils'

Suggested load order:

element
i18n
components
utils
blocks
date
editor

A more robust version of this task would actually parse the JS files instead of just looking for a regex like from '(blocks|component|date|....

@aduth

aduth commented May 31, 2017

Copy link
Copy Markdown
Member

Are we depending on a specific load order?

@nylen

nylen commented Jun 1, 2017

Copy link
Copy Markdown
Member Author

Yes. On the server this is handled by registering script dependencies via WordPress's standard mechanism; also, the test build will break if the entry points in the Webpack config are rearranged sufficiently.

I'm fine with closing this out and saving the script that way. I opened a PR because I found it useful, and it may be more useful in the future.

@aduth

aduth commented Jun 2, 2017

Copy link
Copy Markdown
Member

I'm indifferent. Fine with merging, or as Gist territory.

@nylen

nylen commented Jun 5, 2017

Copy link
Copy Markdown
Member Author

@nylen nylen closed this Jun 5, 2017
@nylen
nylen deleted the add/js-dependencies-script branch June 5, 2017 15:29
@nylen

nylen commented Aug 3, 2017 •

Copy link
Copy Markdown
Member Author

This script still comes in handy occasionally (#2205). I've also updated the gist above for the recent changes to our import syntax in #2172.

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.

2 participants