Skip to content

Commit 369ec0f

Browse files
nartukyk-gr
authored andcommitted
Add PNPM package manager support
1 parent 3700256 commit 369ec0f

5 files changed

Lines changed: 128 additions & 1 deletion

File tree

buildtools/cli.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/mvn"
3232
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/npm"
3333
containerutils "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/ocicontainer"
34+
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/pnpm"
3435
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/terraform"
3536
"github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/yarn"
3637
commandsUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/utils"
@@ -68,6 +69,7 @@ import (
6869
"github.com/jfrog/jfrog-cli/docs/buildtools/pipenvconfig"
6970
"github.com/jfrog/jfrog-cli/docs/buildtools/pipenvinstall"
7071
"github.com/jfrog/jfrog-cli/docs/buildtools/pipinstall"
72+
"github.com/jfrog/jfrog-cli/docs/buildtools/pnpmcommand"
7173
"github.com/jfrog/jfrog-cli/docs/buildtools/pnpmconfig"
7274
"github.com/jfrog/jfrog-cli/docs/buildtools/poetry"
7375
"github.com/jfrog/jfrog-cli/docs/buildtools/poetryconfig"
@@ -426,6 +428,23 @@ func GetCommands() []cli.Command {
426428
return cliutils.CreateConfigCmd(c, project.Pnpm)
427429
},
428430
},
431+
{
432+
Name: "pnpm",
433+
Usage: pnpmcommand.GetDescription(),
434+
HelpName: corecommon.CreateUsage("pnpm", pnpmcommand.GetDescription(), pnpmcommand.Usage),
435+
UsageText: pnpmcommand.GetArguments(),
436+
SkipFlagParsing: true,
437+
BashComplete: corecommon.CreateBashCompletionFunc("install", "i", "add", "ci", "publish", "p"),
438+
Category: buildToolsCategory,
439+
Action: func(c *cli.Context) (errFromCmd error) {
440+
cmdName, _ := getCommandName(c.Args())
441+
return securityCLI.WrapCmdWithCurationPostFailureRun(c,
442+
func(c *cli.Context) error {
443+
return pnpmGenericCmd(c, cmdName, false)
444+
},
445+
techutils.Pnpm, cmdName)
446+
},
447+
},
429448
{
430449
Name: "docker",
431450
Flags: cliutils.GetCommandFlags(cliutils.Docker),
@@ -1422,6 +1441,74 @@ func GetNpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string,
14221441
return
14231442
}
14241443

1444+
func pnpmGenericCmd(c *cli.Context, cmdName string, collectBuildInfoIfRequested bool) error {
1445+
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
1446+
return err
1447+
}
1448+
switch cmdName {
1449+
// Aliases accepted by pnpm.
1450+
case "i", "add", "install":
1451+
cmdName = "install"
1452+
collectBuildInfoIfRequested = true
1453+
case "ci":
1454+
collectBuildInfoIfRequested = true
1455+
case "publish", "p":
1456+
return PnpmPublishCmd(c)
1457+
}
1458+
1459+
// Run generic pnpm command.
1460+
pnpmCmd := pnpm.NewPnpmCommand(cmdName, collectBuildInfoIfRequested)
1461+
1462+
configFilePath, args, err := GetPnpmConfigAndArgs(c)
1463+
if err != nil {
1464+
return err
1465+
}
1466+
pnpmCmd.SetConfigFilePath(configFilePath).SetArgs(args)
1467+
if err = pnpmCmd.Init(); err != nil {
1468+
return err
1469+
}
1470+
return commands.Exec(pnpmCmd)
1471+
}
1472+
1473+
func PnpmPublishCmd(c *cli.Context) (err error) {
1474+
if show, err := cliutils.ShowGenericCmdHelpIfNeeded(c, c.Args(), "pnpmpublishhelp"); show || err != nil {
1475+
return err
1476+
}
1477+
1478+
configFilePath, args, err := GetPnpmConfigAndArgs(c)
1479+
if err != nil {
1480+
return err
1481+
}
1482+
1483+
pnpmCmd := pnpm.NewPnpmPublishCommand()
1484+
pnpmCmd.SetConfigFilePath(configFilePath).SetArgs(args)
1485+
if err = pnpmCmd.Init(); err != nil {
1486+
return err
1487+
}
1488+
if pnpmCmd.GetXrayScan() {
1489+
commandsUtils.ConditionalUploadScanFunc = scan.ConditionalUploadDefaultScanFunc
1490+
}
1491+
// deployment view are not available for native pnpm commands
1492+
printDeploymentView, detailedSummary := log.IsStdErrTerminal() && !pnpmCmd.UseNative(), pnpmCmd.IsDetailedSummary()
1493+
if !detailedSummary {
1494+
pnpmCmd.SetDetailedSummary(printDeploymentView)
1495+
}
1496+
err = commands.Exec(pnpmCmd)
1497+
result := pnpmCmd.Result()
1498+
defer cliutils.CleanupResult(result, &err)
1499+
err = cliutils.PrintCommandSummary(pnpmCmd.Result(), detailedSummary, printDeploymentView, false, err)
1500+
return
1501+
}
1502+
1503+
func GetPnpmConfigAndArgs(c *cli.Context) (configFilePath string, args []string, err error) {
1504+
configFilePath, err = getProjectConfigPathOrThrow(project.Pnpm, "pnpm", "pnpm-config")
1505+
if err != nil {
1506+
return
1507+
}
1508+
_, args = getCommandName(c.Args())
1509+
return
1510+
}
1511+
14251512
func PipCmd(c *cli.Context) error {
14261513
return pythonCmd(c, project.Pip)
14271514
}

buildtools/help.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/jfrog/jfrog-cli/docs/buildtools/dockerpush"
1010
"github.com/jfrog/jfrog-cli/docs/buildtools/npmci"
1111
"github.com/jfrog/jfrog-cli/docs/buildtools/npminstall"
12+
"github.com/jfrog/jfrog-cli/docs/buildtools/pnpmpublish"
1213
"github.com/jfrog/jfrog-cli/docs/common"
1314
"github.com/jfrog/jfrog-cli/utils/cliutils"
1415
"github.com/urfave/cli"
@@ -80,5 +81,13 @@ func GetBuildToolsHelpCommands() []cli.Command {
8081
ArgsUsage: common.CreateEnvVars(),
8182
Hidden: true,
8283
},
84+
{
85+
Name: "pnpmpublishhelp",
86+
Flags: cliutils.GetCommandFlags(cliutils.PnpmPublish),
87+
Usage: pnpmpublish.GetDescription(),
88+
HelpName: corecommon.CreateUsage("pnpm publish", pnpmpublish.GetDescription(), pnpmpublish.Usage),
89+
ArgsUsage: common.CreateEnvVars(),
90+
Hidden: true,
91+
},
8392
})
8493
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package pnpmcommand
2+
3+
var Usage = []string{"pnpm <pnpm arguments> [command options]"}
4+
5+
func GetDescription() string {
6+
return "Run pnpm command."
7+
}
8+
9+
func GetArguments() string {
10+
return ` ci Run pnpm ci.
11+
publish, p Packs and deploys the pnpm package to the designated npm repository.
12+
install, i, add Run pnpm install.
13+
help, h`
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package pnpmpublish
2+
3+
var Usage = []string{"pnpm publish [command options]"}
4+
5+
func GetDescription() string {
6+
return "Packs and deploys the pnpm package to the designated npm repository."
7+
}

utils/cliutils/commandsflags.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const (
5757
NpmInstallCi = "npm-install-ci"
5858
NpmPublish = "npm-publish"
5959
PnpmConfig = "pnpm-config"
60+
Pnpm = "pnpm"
61+
PnpmInstallCi = "pnpm-install-ci"
62+
PnpmPublish = "pnpm-publish"
6063
YarnConfig = "yarn-config"
6164
Yarn = "yarn"
6265
NugetConfig = "nuget-config"
@@ -1908,7 +1911,14 @@ var commandFlags = map[string][]string{
19081911
BuildName, BuildNumber, module, Project, npmDetailedSummary, xrayScan, xrOutput, runNative, npmWorkspaces,
19091912
},
19101913
PnpmConfig: {
1911-
global, serverIdResolve, repoResolve,
1914+
global, serverIdResolve, serverIdDeploy, repoResolve, repoDeploy,
1915+
},
1916+
Pnpm: {},
1917+
PnpmInstallCi: {
1918+
BuildName, BuildNumber, module, Project, runNative,
1919+
},
1920+
PnpmPublish: {
1921+
BuildName, BuildNumber, module, Project, npmDetailedSummary, xrayScan, xrOutput, runNative,
19121922
},
19131923
YarnConfig: {
19141924
global, serverIdResolve, repoResolve,

0 commit comments

Comments
 (0)