Nexus 3 regular cleanup on NPM repository

1,350 views
Skip to first unread message

Georgi Petrov

unread,
Aug 17, 2017, 10:26:03 AM8/17/17
to Nexus Users

Hi,

 

I want to apply cleanup on NPM repository. So far i was able to delete assets but i hade difficulties in root json changes.

 

Here is my groovy script:

 

 


import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.storage.Asset
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet

def request = new JsonSlurper().parseText(args)
assert request.repoName: 'repoName parameter is required'
assert request.startDate: 'startDate parameter is required, format: yyyy-mm-dd'
def repo = repository.repositoryManager.get(request.repoName)
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
tx.begin()

Iterable<Asset> assets = tx.findAssets(Query.builder().where("last_updated > '2017-08-01'").and("content_type != 'application/json'").build(), [repo])

assets.each {asset ->

tx.deleteAsset(asset)

}

tx.commit()

return "DONE"

 

This script successfully delete assets but in PACKAGE_ROOT asset(application/json) was not updated.

 

Any suggestions?


Thanks in advance,

Georgi

 

Carlo Reggiani

unread,
Aug 31, 2017, 11:40:18 AM8/31/17
to Nexus Users
I think you have to first declare "deprecated" the specific version of the component:

Here the info: https://support.sonatype.com/hc/en-us/articles/221433608-Deleting-a-specific-npm-package-version-in-Nexus-Repository-Manager-2-x

The official npm tool maintainers viewpoint is that deleting npm packages from a registry is not a recommended operation.
The npm deprecate command is preferred, however only Nexus Repository Manager 3.x supports the deprecate command.


Also in my npm repository I need to delete outdated "snapshot-like" version of components: not clear why there is not a task in Nexus3 to manage archiving "deprecated" components.

Please Georgi let me know if your script complete the task!

Carlo

Mariska Hoogenboom

unread,
Sep 14, 2017, 9:31:03 AM9/14/17
to Nexus Users (nexus-users@glists.sonatype.com)

Are you able to use “npm deprecate” with nexus 3.5?

 

I’m running the latest nexus 3.5.2-01 and get a server error (500) when I try to deprecate a package:

$ npm deprecate http://mynexus:8081/nexus/repository/npm-local my...@1.0.0 “This package is deprecated”

 

Error in the nexus.log:

2017-09-14 15:26:26,832+0200 WARN  [qtp1419408657-426] admin org.sonatype.nexus.repository.httpb

ridge.internal.ViewServlet - Failure servicing: PUT /nexus/repository/npm-local/mynpm

java.lang.ClassCastException: Cannot cast java.lang.Boolean to java.lang.String

        at java.lang.Class.cast(Class.java:3369)

        at org.sonatype.nexus.common.collect.AttributesMap.coerce(AttributesMap.java:75)

        at org.sonatype.nexus.common.collect.AttributesMap.get(AttributesMap.java:153)

        at org.sonatype.nexus.common.collect.AttributesMap.get(AttributesMap.java:162)

        at com.sonatype.nexus.repository.npm.internal.NpmHostedFacetImpl.updateDeprecationFlags(

NpmHostedFacetImpl.java:159)

 

Met vriendelijke groet/Kind regards,


Mariska Hoogenboom

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/dca54aed-7cad-47a8-887d-479971b82eab%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.



CCV disclaimer


Peter Lynch

unread,
Sep 14, 2017, 10:05:47 AM9/14/17
to Nexus Users (nexus-users@glists.sonatype.com)
On Thu, Sep 14, 2017 at 10:30 AM, Mariska Hoogenboom <M.Hoog...@nl.ccv.eu> wrote:

Are you able to use “npm deprecate” with nexus 3.5?

 

npm deprecate works with 3.5.2. The error suggests something is wrong with the versions section values of your package metadata. What does the versions section show for this package metadata?


 

To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.

To post to this group, send email to nexus...@glists.sonatype.com.

Mariska Hoogenboom

unread,
Sep 14, 2017, 10:29:41 AM9/14/17
to Peter Lynch, Nexus Users (nexus-users@glists.sonatype.com)

You are right, something was wrong with my versioning (or other field). I’ve published another test package and now I can deprecate this just fine. Not sure yet what was wrong, because I was able to install the published package. But will investigate this further.

 

Thanks for the hint!

 

Met vriendelijke groet/Kind regards,


Mariska Hoogenboom

 

 

From: nexus...@glists.sonatype.com [mailto:nexus...@glists.sonatype.com] On Behalf Of Peter Lynch
Sent: donderdag 14 september 2017 16:06
Cc: Nexus Users (nexus...@glists.sonatype.com)
Subject: Re: Nexus 3 regular cleanup on NPM repository

 

 

 

On Thu, Sep 14, 2017 at 10:30 AM, Mariska Hoogenboom <M.Hoog...@nl.ccv.eu> wrote:

To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.

 

--

You received this message because you are subscribed to the Google Groups "Nexus Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.


To post to this group, send email to nexus...@glists.sonatype.com.

Reply all
Reply to author
Forward
0 new messages