Fix bundling logic on download page #10
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alright, until I get around to completing #2, this PR will serve as the documentation of the expected behavior of bundles.
The Before: Django website downloads (aka API v1)
A
POST /downloadrequest was treated as a trigger to download a bundle with the specified languages. This endpoint acceptedContent-Typeof typeapplication/x-www-form-urlencodedwhere the keys were languages to be packaged (e.g.bash=1&cpp=1&javascript=1).The Now: Next.js website downloads (aka API v2)
A
POST /api/downloadrequest triggers a bundle download. This endpoint accepts aContent-Typeofapplication/jsonwhere languages are listed in thelanguagesstring array.Were there any BC breaks with the new website?
No. The current
/downloadpage rewrites any requests matching API v1 expectations to be v2 compatible using the/api/downloadendpoint.Nothing should have broken with the release of the new website. There have been no complaints since that haven't been addressed, so either no one cares, or it works as expected.
Now, what's in the download bundle?
Here's where things get a bit tricky. The overall structure of the downloaded ZIP between API v1 and v2 is almost identical, or at least shouldn't have any breaking changes.
Here is a non-exhaustive overview of a downloaded bundle's structure,
DIGESTS.md: contains the SHA384 hashes of each of the generated files that are included in the bundlees/languages/: contains minified and non-minified versions of grammars in ESM formathighlight.js: the pure library in an ESM format; non-minified with NO grammars concatenatedhighlight.min.js: a minified version of thehighlight.jsin this same folderlanguages/: contains both minified and non-minified variants of the grammars in CJS formathighlight.js: the pure library WITH the selected grammars concatenated at the end in CJS format; this can be dropped on a web server and it'll work in the browserhighlight.min.js: a minified version of the CJS version ofhighlight.jsaboveAPI v1 vs v2 differences
API v1 appears to have a long-standing bug of bundling up a pure version of
highlight.jsand ONLY concatenating grammars in thehighlight.min.js. If a bundle is requested using V1 of the API, then thehighlight.jswill remain without the concatenated languages at the end for... legacy reasons.API v2 is new and was just introduced with this Next.js website. I consider it a bug that the unminified
highlight.jsfile does not have grammars concatenated at the end. Therefore, this has been changed in the V2 bundles.Fixes #5