Skip to content

Commit 461dc6c

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

6 files changed

Lines changed: 128 additions & 5 deletions

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+
}

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,6 @@ github.com/jellydator/ttlcache/v3 v3.4.0 h1:YS4P125qQS0tNhtL6aeYkheEaB/m8HCqdMMP
12061206
github.com/jellydator/ttlcache/v3 v3.4.0/go.mod h1:Hw9EgjymziQD3yGsQdf1FqFdpp7YjFMd4Srg5EJlgD4=
12071207
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
12081208
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
1209-
github.com/jfrog/build-info-go v1.13.1-0.20260130140656-2d0d5593fccf h1:BDaC0fek3yu20zbCOSozoM5+NzZe6u7wXAvufCmTkO0=
1210-
github.com/jfrog/build-info-go v1.13.1-0.20260130140656-2d0d5593fccf/go.mod h1:+OCtMb22/D+u7Wne5lzkjJjaWr0LRZcHlDwTH86Mpwo=
12111209
github.com/jfrog/froggit-go v1.20.6 h1:Xp7+LlEh0m1KGrQstb+u0aGfjRUtv1eh9xQBV3571jQ=
12121210
github.com/jfrog/froggit-go v1.20.6/go.mod h1:obSG1SlsWjktkuqmKtpq7MNTTL63e0ot+ucTnlOMV88=
12131211
github.com/jfrog/go-mockhttp v0.3.1 h1:/wac8v4GMZx62viZmv4wazB5GNKs+GxawuS1u3maJH8=
@@ -1218,8 +1216,6 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
12181216
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
12191217
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260127112223-c5078af84b5a h1:Yvl7XuMoI1cXk3jzB1oWcZvFy5K3aUAIin9o5GRaqzE=
12201218
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260127112223-c5078af84b5a/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw=
1221-
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260203090305-f5f8aed71eaf h1:3W7qIxrkJkC1K0vB/By3fVyCkU3qgY9SdHQs7o5RNRo=
1222-
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260203090305-f5f8aed71eaf/go.mod h1:DkLAN+AvZ4v6jcuUStufi9DuhAS1dvSRJhILJyRa9kg=
12231219
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260128134755-624b659a398e h1:jGtYjWMMfCINDl1JbRtvAijtVwD+j+yvR5BuYMZvRrA=
12241220
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260128134755-624b659a398e/go.mod h1:+Hnaikp/xCSPD/q7txxRy4Zc0wzjW/usrCSf+6uONSQ=
12251221
github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20260125120022-1c6f4f382dbb h1:4nGzxRxVcXxkFg95jr+zMjESisZGqSYecXfHsA37rpA=

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)