I’m developing a plugin for the nexus repository manager. I can get the artifact version for maven as below. But I’m having an issue getting the version for NPM artifacts. What is the best way to get the version programmatically? I’m using 3.26.1-02 nexus-plugin version.
Seem like you already have Coordinates of your component, so you can just call coordinates.getVersion() to get version of that component. Please take a look at MavenPath.Coordinates implementation to find more.
Do you have a Component or Asset object for that NPM artifact? If you do, Asset::getComponent gives you the Component, which has Component::version.
However, your code snippet suggests you may have only the request context. In that case you need to remember that some of your request will be for metadata file that does not have any version associated with. If your context is from request for a tarball, then your code should be working fine, but if your request is coming for a metadata you need to obtain the tarball to get version (this is how npm client works).
@dsawa This is my context object. I need to get the version of the i18n artifact to check that particular version has vulnerabilities. But I see only the package name here. I think package version supposed to come under tokens with the package name. Is it a bug in nexus?
@mpiggott@dsawa This is not a tarball request. I’m using below package.json file in the nodejs sample project to download the dependencies. I need to validate the artifact before download it via my plugin. I can get the artifact version for Maven & Nuget. But I can’t find a way to get it for NPM.