Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts: Defer installation of dependencies until they are used for the first time #17987

Closed
gziolo opened this issue Oct 17, 2019 · 4 comments
Closed
Labels
Needs Dev Ready for, and needs developer efforts [Package] Scripts /packages/scripts [Type] Enhancement A suggestion for improvement.

Comments

@gziolo
Copy link
Member

gziolo commented Oct 17, 2019

A related issue which this would resolve #15667.

We would like to defer the installation of some bigger npm dependencies when installing @wordpress/scripts. The whole idea is explained in #17871 (comment) by @youknowriad:

  • if you runwp-scripts test:e2e for the first time, the testing dependencies "puppeteer"... get added automatically to your package.json and dependencies installed before running the script
  • if your run wp-scripts env for the first time, the environment dependencies get added and installed...

This won't solve the issue for Gutenberg because we use all the dependencies but it's important for Plugin/Theme authors if they only use wp-scripts for bundling for instance.

Another related comment from @epiqueras shared in #17871 (comment):

Parcel does that a lot, I think we should take some inspiration from them and see how they do it.

They have separate packages that are required dynamically by looking at the dependencies in package.json and testing each one with a RegExp, installing new packages if it needs them and they are not already installed.

So what we can do is break down each script into a separate package, then have the core of wp-scripts do this when ran:

  • Check if the script being called is already installed, install it if not.
  • Resolve its location in node_modules and require it.

In the ideal scenario, when you run npx wp-scripts e2e-tests for the first time, it installs puppeteer (with Chromium) behind the scenes and then bootstraps WordPress environment as well 😄

@gziolo
Copy link
Member Author

gziolo commented Jan 20, 2020

I opened this patch puppeteer/puppeteer#5325 against Puppeteer to explore some better ideas on how this could be solved on the @wordpress/scripts side.

@tomhoad
Copy link

tomhoad commented Feb 18, 2020

+1 for this.

Because of the way that VIP environments deploy built branches (see: https://github.com/Automattic/vip-go-build/blob/master/deploy.sh) the large Chromium dependency causes problems where deployments fail as Github doesn't like files bigger than 100MB.

The workarounds aren't great:

  • Don't use wp-scripts at all, use your own build scripts
  • Delete the large dependency after npm install but before the deploy.sh script above runs (still results in the deployments downloading Chromium, which is slow and - in our case - unnecessary as we don't use Puppeteer e2e parts of wp-scripts.

Our situation is fairly unique to our VIP Go setup, but having such a large dependency inside a utility tool where it's all-or-nothing is problematic.

@gziolo
Copy link
Member Author

gziolo commented Feb 18, 2020

At some point, I even considered making test-e2e an extension to wp-scripts to remove all those dependencies by default. Now, we are on a good path to run Chromium download optional so it feels like we can leave it as is. There is one upstream issue in puppeteer that blocks upgrade to the latest version which I expect to be resolved in the upcoming days. I hope that using npm aliases for puppeteer-core will work for us.

@gziolo
Copy link
Member Author

gziolo commented Apr 20, 2020

In the ideal scenario, when you run npx wp-scripts e2e-tests for the first time, it installs puppeteer (with Chromium) behind the scenes and then bootstraps WordPress environment as well 😄

It's now implemented in master 🎉

wp-scripts env is going to be deprecated later this year.

@gziolo gziolo closed this as completed Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Dev Ready for, and needs developer efforts [Package] Scripts /packages/scripts [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants