Skip to content

Commit 21d1a45

Browse files
authored
Remove any prerequisites for generic npm cmds (#338)
1 parent 325fe0d commit 21d1a45

File tree

3 files changed

+11
-74
lines changed

3 files changed

+11
-74
lines changed

artifactory/commands/npm/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ type CommonArgs struct {
3838
NpmCommand
3939
}
4040

41-
func (com *CommonArgs) preparePrerequisites(repo string) error {
41+
func (com *CommonArgs) preparePrerequisites(repo string, overrideNpmrc bool) error {
4242
log.Debug("Preparing prerequisites...")
4343
var err error
4444
com.npmVersion, com.executablePath, err = biutils.GetNpmVersionAndExecPath(log.Logger)
4545
if err != nil {
4646
return err
4747
}
48-
48+
if !overrideNpmrc {
49+
return nil
50+
}
4951
if com.npmVersion.Compare(minSupportedNpmVersion) > 0 {
5052
return errorutils.CheckErrorf(
5153
"JFrog CLI npm %s command requires npm client version "+minSupportedNpmVersion+" or higher. The Current version is: %s", com.cmdName, com.npmVersion.GetVersion())
@@ -60,7 +62,6 @@ func (com *CommonArgs) preparePrerequisites(repo string) error {
6062
return err
6163
}
6264
log.Debug("Working directory set to:", com.workingDirectory)
63-
6465
if err = com.setArtifactoryAuth(); err != nil {
6566
return err
6667
}

artifactory/commands/npm/generic.go

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ package npm
22

33
import (
44
"fmt"
5-
commandUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
6-
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
5+
"os"
6+
77
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
88
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
99
npmutils "github.com/jfrog/jfrog-cli-core/v2/utils/npm"
1010
"github.com/jfrog/jfrog-client-go/utils/errorutils"
1111
"github.com/jfrog/jfrog-client-go/utils/log"
12-
"os"
1312
)
1413

1514
type GenericCommandArgs struct {
@@ -18,7 +17,6 @@ type GenericCommandArgs struct {
1817

1918
// GenericCommand represents any npm command which is not "install", "ci" or "publish".
2019
type GenericCommand struct {
21-
configFilePath string
2220
*GenericCommandArgs
2321
}
2422

@@ -32,77 +30,15 @@ func (gc *GenericCommand) CommandName() string {
3230
return "rt_npm_generic"
3331
}
3432

35-
func (gc *GenericCommand) SetConfigFilePath(configFilePath string) *GenericCommand {
36-
gc.configFilePath = configFilePath
37-
return gc
38-
}
39-
40-
func (gc *GenericCommand) SetServerDetails(serverDetails *config.ServerDetails) *GenericCommand {
41-
gc.serverDetails = serverDetails
42-
return gc
43-
}
44-
45-
func (gc *GenericCommand) Init() error {
46-
// Filter out JFrog CLI's specific flags.
47-
_, _, _, filteredCmd, _, err := commandUtils.ExtractNpmOptionsFromArgs(gc.npmArgs)
48-
if err != nil {
49-
return err
50-
}
51-
52-
err = gc.setServerDetailsAndRepo()
53-
if err != nil {
54-
return err
55-
}
56-
gc.SetNpmArgs(filteredCmd).SetBuildConfiguration(&utils.BuildConfiguration{})
57-
return nil
33+
func (gca *GenericCommandArgs) ServerDetails() (*config.ServerDetails, error) {
34+
return gca.serverDetails, nil
5835
}
5936

6037
func (gc *GenericCommand) Run() (err error) {
61-
if err = gc.preparePrerequisites(gc.repo); err != nil {
38+
if err = gc.preparePrerequisites("", false); err != nil {
6239
return
6340
}
64-
defer func() {
65-
e := gc.restoreNpmrcFunc()
66-
if err == nil {
67-
err = e
68-
}
69-
}()
70-
if err = gc.createTempNpmrc(); err != nil {
71-
return
72-
}
73-
err = gc.runNpmGenericCommand()
74-
return
75-
}
76-
77-
func (gc *GenericCommand) setServerDetailsAndRepo() error {
78-
// Read config file.
79-
log.Debug("Preparing to read the config file", gc.configFilePath)
80-
vConfig, err := utils.ReadConfigFile(gc.configFilePath, utils.YAML)
81-
if err != nil {
82-
return err
83-
}
84-
85-
// Set server details if exists, with priority to deployer.
86-
for _, prefix := range []string{utils.ProjectConfigDeployerPrefix, utils.ProjectConfigResolverPrefix} {
87-
if vConfig.IsSet(prefix) {
88-
params, err := utils.GetRepoConfigByPrefix(gc.configFilePath, prefix, vConfig)
89-
if err != nil {
90-
return err
91-
}
92-
rtDetails, err := params.ServerDetails()
93-
if err != nil {
94-
return errorutils.CheckError(err)
95-
}
96-
gc.SetServerDetails(rtDetails)
97-
gc.repo = params.TargetRepo()
98-
return nil
99-
}
100-
}
101-
return nil
102-
}
103-
104-
func (gca *GenericCommandArgs) ServerDetails() (*config.ServerDetails, error) {
105-
return gca.serverDetails, nil
41+
return gc.runNpmGenericCommand()
10642
}
10743

10844
func (gca *GenericCommandArgs) runNpmGenericCommand() error {

artifactory/commands/npm/installorci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (nic *NpmInstallOrCiCommand) ServerDetails() (*config.ServerDetails, error)
8383
}
8484

8585
func (nic *NpmInstallOrCiCommand) Run() (err error) {
86-
if err = nic.preparePrerequisites(nic.repo); err != nil {
86+
if err = nic.preparePrerequisites(nic.repo, true); err != nil {
8787
return
8888
}
8989

0 commit comments

Comments
 (0)