@@ -10,29 +10,35 @@ import (
1010 "github.com/jfrog/jfrog-client-go/artifactory/services"
1111 specutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils"
1212 "github.com/jfrog/jfrog-client-go/utils/log"
13+ "strings"
1314)
1415
1516type npmPublish struct {
1617 * NpmPublishCommand
1718}
1819
19- func (npu * npmPublish ) upload () ( err error ) {
20+ func (npu * npmPublish ) upload () error {
2021 for _ , packedFilePath := range npu .packedFilePaths {
2122
22- if err = npu .readPackageInfoFromTarball (packedFilePath ); err != nil {
23+ if err : = npu .readPackageInfoFromTarball (packedFilePath ); err != nil {
2324 return err
2425 }
25- target := fmt .Sprintf ("%s/%s" , npu .repo , npu .packageInfo .GetDeployPath ())
26+
27+ targetRepo , err := npu .getTargetRepo ()
28+ if err != nil {
29+ return err
30+ }
31+ target := fmt .Sprintf ("%s/%s" , targetRepo , npu .packageInfo .GetDeployPath ())
2632
2733 // If requested, perform a Xray binary scan before deployment. If a FailBuildError is returned, skip the deployment.
2834 if npu .xrayScan {
2935 if err = performXrayScan (packedFilePath , npu .repo , npu .serverDetails , npu .scanOutputFormat ); err != nil {
30- return
36+ return err
3137 }
3238 }
3339 err = errors .Join (err , npu .publishPackage (npu .executablePath , packedFilePath , npu .serverDetails , target ))
3440 }
35- return err
41+ return nil
3642}
3743
3844func (npu * npmPublish ) getBuildArtifacts () ([]buildinfo.Artifact , error ) {
@@ -82,3 +88,33 @@ func (npu *npmPublish) publishPackage(executablePath, filePath string, serverDet
8288 }
8389 return nil
8490}
91+
92+ func (npu * NpmPublishCommand ) getTargetRepo () (string , error ) {
93+ var registryString string
94+ scope := npu .packageInfo .Scope
95+ if scope == "" {
96+ registryString = "registry"
97+ } else {
98+ registryString = scope + ":registry"
99+ }
100+ configCommand := gofrogcmd.Command {
101+ Executable : npu .executablePath ,
102+ CmdName : "config" ,
103+ CmdArgs : []string {"get" , registryString },
104+ }
105+ data , err := configCommand .RunWithOutput ()
106+ repoConfig := string (data )
107+ if err != nil {
108+ log .Error ("Error occurred while running npm config get: " , err )
109+ npu .result .SetFailCount (npu .result .FailCount () + 1 )
110+ return "" , err
111+ }
112+ return extractRepoName (repoConfig ), nil
113+ }
114+
115+ func extractRepoName (configUrl string ) string {
116+ url := strings .TrimSpace (configUrl )
117+ urlParts := strings .Split (url , "/" )
118+ repoName := urlParts [len (urlParts )- 1 ]
119+ return repoName
120+ }
0 commit comments