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

Add @polka/compression package #148

Merged
merged 11 commits into from
Mar 7, 2024
Merged

Conversation

developit
Copy link

This implements gzip + brotli (native) compression as a new @polka/compression package. It should be ready to go, with tests and docs.

@lukeed
Copy link
Owner

lukeed commented Sep 15, 2020

Legend, thank you sir!

I'll pass through tomorrow for the failing Node 8.x suite and do some docs shuffling. Looks great though 🙌

@developit
Copy link
Author

developit commented Sep 15, 2020

Ah so the failing suite is because on Node < 12.7, this package automatically disables brotli (since its unsupported). I just updated the tests to skip the brotli suite for node versions without it, and relaxed to engines.node>=6 same as polka.

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2020

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3b4d866) to head (b4a6a69).
Report is 54 commits behind head on next.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              next      #148    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            4         5     +1     
  Lines          117       322   +205     
==========================================
+ Hits           117       322   +205     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@developit
Copy link
Author

Can probably get coverage back up by doing a test that uses createReadStream(file).pipe(res).

@developit
Copy link
Author

developit commented Sep 15, 2020

I broke CI somehow - tests should be passing on 8/10/12 though (see https://github.com/lukeed/polka/actions/runs/254918502).

@newtriks
Copy link

newtriks commented Jul 2, 2021

After reading through open PR's I can see you're most likely very busy, just wanted to see if there was a chance at some point to merge @developit's work @lukeed?

@developit
Copy link
Author

IIRC Luke found and fixed a bug in the version of this that we have inlined in WMR, I need to backport that here.

@patak-dev
Copy link

Sorry for bumping this @lukeed @developit, but FYI Vite is also going to inline this PR (once we merge vitejs/vite#6557). If there is a chance to get it merged at one point, we could reduce the maintenance burden for both WMR and Vite.

@nicksrandall
Copy link

Is this ready to be merged?

@Kikobeats
Copy link

what a good PR 👏 @lukeed could be nice if you can take a look and move this forward

@pke
Copy link

pke commented Oct 23, 2022

While I like the implementation I wonder if such should be part of an application server or better be left to reverse proxies like nginx. For me applications servers only handle the application and not logging, tracing, auditing, caching or compression.

@developit
Copy link
Author

@pke There are numerous cases where compression is necessary in an application server. Nobody should have to run a reverse proxy just for local development (as Patak alluded to above).

@pke
Copy link

pke commented Oct 25, 2022

I never needed compression during local development, what would be some of the use cases? I try to understand.

Beside that I am all for merging this, but the project seems to be pretty much dead and unmaintained. I might switch back to koa, although its not express middleware compatible.

@lukeed
Copy link
Owner

lukeed commented Oct 25, 2022

Stable and dead are different things. There are two flavors of Polka and both work well for different use cases.

This PR still needs me to backport some fixes I/we found in the wmr integration & tests to solidify those fixes long term.

@pke
Copy link

pke commented Oct 26, 2022

Nice to see you here @lukeed ;) I just thought a 2 year old PR, which is green is not merged seemed like a dead project. But I didn't understand the implications of this PRs merge.

There are also a bunch of issues open without any response (incl one of me ;) so if there is anything we could help with to get "next" out of beta I'd be glad to assist.

@Kikobeats
Copy link

The implementation code of this PR is really appreciated, there is no real alternatives these days for taking advantage of brotli, so I decided to just put it in standalone package and anyone can take advantage of it

https://github.com/Kikobeats/http-compression

Full credits to @developit for writing that simple and elegant code, I promise to maintain the code and keep it evolving

const listeners = pendingListeners;
pendingListeners = null;
listeners.forEach(p => on.apply(res, p));
if (pendingStatus) writeHead.call(res, pendingStatus);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that @lukeed updated this line in wmr: preactjs/wmr@23bee83

Copy link

@benmccann benmccann Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benmccann
Copy link

This version already contains the main fix that Vite copied from wmr (preactjs/wmr#155) when they did their initial commit. It is missing one other fix though that I pointed out above (#148 (comment)).

Once that change makes its way in, I think it'd be great to merge and release this! It looks like the version that Vite copied into their codebase almost exactly two years ago has been running there without any fixes necessary in the time since, so this is probably pretty stable. It also looks like this would fix the issue we were having in SvelteKit with the compression library, so I would love to be able to use this!

@Kikobeats
Copy link

Kikobeats commented Mar 7, 2024

@benmccann any particular reason you don't want to use Kikobeats/http-compression? Same source code, shipped as npm package, reasy to use.

@pke
Copy link

pke commented Mar 7, 2024

@Kikobeats thanks for putting this in a module, which seems good way to keep polka small and lean. Then this PR can be closed @developit?

Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @benmccann for the team ping to resurrect this (and multiple others for trying over the lifetime of this PR!)

Long ago, when this PR initially appeared, I had some quirks that I (and rest of wmr team) were trying to chase down. I've had a few iterations of this running in production over the years – but wasn't great at organizing my findings on all of them – and wanted to ensure confidence in this (v important) package before releasing. Great to see that the wmr version (which wasn't this PR) has been proven stable by Vite/WMR/others' usage all this time.

Of course, a massive thank-you to @developit who was brave enough to tackle this problem in the first place & (patiently) entrusted the work over to the Polka household. Thank you 🐐 🦊 🏆

@lukeed lukeed merged commit a2105e0 into lukeed:next Mar 7, 2024
7 checks passed
@benmccann
Copy link

Amazing!! Thank you so much @lukeed for getting this across the finish line and making it part of @polka and @developit for contributing it!

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.

9 participants