Skip to content

Fix a bug with the metadata during the npm package upload

David Fernandez requested to merge 345759-fix-npm-uploads-with-readme into master

🍍 Context

In !73639 (merged), we added support for the metadata (basically a JSON structure) sent during the upload request done by $ npm publish. That metadata is then sent back when $ npm contacts the "metadata" endpoint.

At that time, we made the decision that the "metadata" endpoint would return the abbreviated form of the metadata.

This change has been deployed with a feature flag. Currently, it is enabled by default.

Since we're persisting a JSON structure to the database, we also implemented a limit: the structure has to fit in 20K chars. It is documented here.

In #345759 (closed), a typebug has been discovered: during the upload $ npm publish can insert more fields than the ones present in the package.json file. One of them is the README file content. That content can easily be quite large and since we persist the whole JSON struct = it's easy to hit the 20K chars limit = upload is rejected 💥

This MR fixes this typebug by ignoring the readme field when persisting the JSON structure.

🔍 What does this MR do and why?

  • Ignore the readme and readmeFilename fields when persisting the NPM package version metadata in the database
  • Update the related specs

How to set up and validate locally

  1. Create an NPM package and setup it as documented in https://docs.gitlab.com/ee/user/packages/npm_registry/
  2. Be sure to add a large README.md file.
  3. Try to $ npm publish the package
    • On master, it fails
    • On this MR's branch, it succeeds.

🛃 MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports

Loading