Add support for npm deprecate
What does this MR do and why?
Adds support for npm deprecate
This command will update the npm registry entry for a package, providing a deprecation warning to all who attempt to npm install it.
It works on version ranges as well as specific versions. CLI examples:
npm deprecate @scope/package_name "All package versions are deprecated"
npm deprecate @scope/package_name@1.0.1 "Only version 1.0.1 is deprecated"
npm deprecate @scope/package_name@"< 1.0.5" "All 1.0.5 prerelease versions are deprecated"
npm deprecate @scope/package_name@1.x "All 1.x versions are deprecated"
we can un-deprecate a package version by sending the deprecation warning as empty string:
npm deprecate @scope/package_name ""
npm deprecate @scope/package_name@1.0.1 ""
npm deprecate @scope/package_name@"< 1.0.5" ""
npm deprecate @scope/package_name@1.x ""
How does npm deprecate work?
- When we hit
npm deprecate, NPM would send agetrequest to the package registrymetadataendpoint i.e:get "/api/v4/projects/:id/packages/npm/:package_name" - After receiving the metadata endpoint response, npm would attach this response as a request body to a
putrequest to the same endpoint that handlesnpm publishi.eput "/api/v4/projects/:id/packages/npm/:package_name" - In
npm publishendpoint, we need to check for the'Npm-Command'header, and if its value isdeprecatewe can let the deprecation serviceHandlePackageDeprecationServicehandle the request. - each npm package has a
npm_metadatumrecord inpackages_npm_metadatatable. In order to deprecate a package, we need to add adeprecatedkey with the deprecation warning as value to thenpm_metadatum'spackage_jsonjsonbfield.
Since we use the same endpoint of npm publish, this command is only supported on the project level.
Screenshots or screen recordings
How to set up and validate locally
- Publish multiple versions of an npm package to your local GitLab package registry.
- Run
npm deprecatefrom the root of the package and try the variations of deprecate/un-deprecate examples mentioned above. - When deprecating a package version, you should see a deprecation warning when you try to run
npm install. - You should also see the deprecation warning when you run
npm viewto get the package metadata.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #396763 (closed)
Database Analysis
Edited by Moaz Khalifa

