Skip to content

Commit

Permalink
added pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 20, 2023
1 parent de2a504 commit e610b71
Show file tree
Hide file tree
Showing 30 changed files with 1,129 additions and 0 deletions.
82 changes: 82 additions & 0 deletions completers/pnpm_completer/cmd/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cmd

import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace-bin/pkg/actions/tools/npm"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pnpm"
"github.com/rsteube/carapace-bin/pkg/util"
"github.com/spf13/cobra"
)

var addCmd = &cobra.Command{
Use: "add",
Short: "Installs a package and any packages that it depends on",
GroupID: "manage",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(addCmd).Standalone()

addCmd.Flags().Bool("aggregate-output", false, "Aggregate output from child processes that are run in parallel")
addCmd.Flags().String("changed-files-ignore-pattern", "", "Defines files to ignore when filtering for changed projects since the specified commit/branch")
addCmd.Flags().Bool("color", false, "Controls colors in the output")
addCmd.Flags().StringP("dir", "C", "", "Change to directory <dir>")
addCmd.Flags().String("filter", "", "set filter")
addCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
addCmd.Flags().BoolP("global", "g", false, "Install as a global package")
addCmd.Flags().Bool("global-dir", false, "Specify a custom directory to store global packages")
addCmd.Flags().BoolP("help", "h", false, "Output usage information")
addCmd.Flags().Bool("ignore-scripts", false, "Don't run lifecycle scripts")
addCmd.Flags().String("loglevel", "", "What level of logs to report")
addCmd.Flags().Bool("no-color", false, "Controls colors in the output")
addCmd.Flags().Bool("no-save-exact", false, "Do not install exact version")
addCmd.Flags().Bool("no-save-workspace-protocol", false, "Do not save packages from the workspace with a \"workspace:\" protocol")
addCmd.Flags().Bool("offline", false, "Trigger an error if any required dependencies are not available")
addCmd.Flags().Bool("prefer-offline", false, "Skip staleness checks for cached data")
addCmd.Flags().BoolP("recursive", "r", false, "Run installation recursively in every package found in subdirectories")
addCmd.Flags().BoolP("save-dev", "D", false, "Save package to your `devDependencies`")
addCmd.Flags().BoolP("save-exact", "E", false, "Install exact version")
addCmd.Flags().BoolP("save-optional", "O", false, "Save package to your `optionalDependencies`")
addCmd.Flags().Bool("save-peer", false, "Save package to your `peerDependencies` and `devDependencies`")
addCmd.Flags().BoolP("save-prod", "P", false, "Save package to your `dependencies`")
addCmd.Flags().Bool("save-workspace-protocol", false, "Save packages from the workspace with a \"workspace:\" protocol")
addCmd.Flags().Bool("silent", false, "turn off all logging")
addCmd.Flags().String("store-dir", "", "The directory in which all the packages are saved on the disk")
addCmd.Flags().Bool("stream", false, "Stream output from child processes immediately")
addCmd.Flags().String("test-pattern", "", "Defines files related to tests")
addCmd.Flags().Bool("use-stderr", false, "Divert all output to stderr")
addCmd.Flags().String("virtual-store-dir", "", "The directory with links to the store")
addCmd.Flags().Bool("workspace", false, "Only adds the new dependency if it is found in the workspace")
addCmd.Flags().BoolP("workspace-root", "w", false, "Run the command on the root workspace project")
rootCmd.AddCommand(addCmd)

carapace.Gen(addCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"filter": pnpm.ActionFilter(),
"loglevel": pnpm.ActionLoglevel(),
"store-dir": carapace.ActionDirectories(),
"virtual-store-dir": carapace.ActionDirectories(),
})

carapace.Gen(addCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.Value) {
return carapace.ActionFiles()
}

if strings.HasPrefix(c.Value, "https://") {
return git.ActionRepositorySearch(git.SearchOpts{}.Default())
}

return carapace.Batch(
npm.ActionPackageSearch(""),
git.ActionRepositorySearch(git.SearchOpts{}.Default()),
carapace.ActionFiles(),
).ToA()
}),
)
}
30 changes: 30 additions & 0 deletions completers/pnpm_completer/cmd/audit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var auditCmd = &cobra.Command{
Use: "audit",
Short: "Checks for known security issues with the installed packages",
GroupID: "review",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(auditCmd).Standalone()

auditCmd.Flags().String("audit-level", "", "Only print advisories with severity greater than or equal to")
auditCmd.Flags().BoolP("dev", "D", false, "Only audit \"devDependencies\"")
auditCmd.Flags().Bool("fix", false, "Add overrides to the package.json file in order to force non-vulnerable versions of the dependencies")
auditCmd.Flags().Bool("ignore-registry-errors", false, "Use exit code 0 if the registry responds with an error")
auditCmd.Flags().Bool("json", false, "Output audit report in JSON format")
auditCmd.Flags().Bool("no-optional", false, "Don't audit \"optionalDependencies\"")
auditCmd.Flags().BoolP("prod", "P", false, "Only audit \"dependencies\" and \"optionalDependencies\"")
rootCmd.AddCommand(auditCmd)

carapace.Gen(auditCmd).FlagCompletion(carapace.ActionMap{
"audit-level": carapace.ActionValues("low", "moderate", "high", "critical"),
})
}
36 changes: 36 additions & 0 deletions completers/pnpm_completer/cmd/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
)

var execCmd = &cobra.Command{
Use: "exec",
Short: "Executes a shell command in scope of a project",
GroupID: "run",
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagParsing: true,
}

func init() {
carapace.Gen(execCmd).Standalone()

rootCmd.AddCommand(execCmd)

carapace.Gen(execCmd).PositionalCompletion(
carapace.Batch(
carapace.ActionExecutables(),
carapace.ActionFiles(),
).ToA(),
)

carapace.Gen(execCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
command := c.Args[0]
c.Args = c.Args[1:]
return bridge.ActionCarapaceBin(command).Invoke(c).ToA()
}),
)
}
19 changes: 19 additions & 0 deletions completers/pnpm_completer/cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var importCmd = &cobra.Command{
Use: "import",
Short: "Generates pnpm-lock.yaml from an npm package-lock.json",
GroupID: "manage",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(importCmd).Standalone()

rootCmd.AddCommand(importCmd)
}
93 changes: 93 additions & 0 deletions completers/pnpm_completer/cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pnpm"
"github.com/spf13/cobra"
)

var installCmd = &cobra.Command{
Use: "install",
Aliases: []string{"i"},
Short: "Installs all dependencies of the project in the current working directory",
GroupID: "manage",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(installCmd).Standalone()

installCmd.Flags().Bool("aggregate-output", false, "Aggregate output from child processes that are run in parallel")
installCmd.Flags().String("changed-files-ignore-pattern", "", "Defines files to ignore when filtering for changed projects since the specified commit/branch")
installCmd.Flags().String("child-concurrency", "", "Controls the number of child processes run parallelly")
installCmd.Flags().Bool("color", false, "Controls colors in the output")
installCmd.Flags().BoolP("dev", "D", false, "Only `devDependencies` are installed regardless of the `NODE_ENV`")
installCmd.Flags().StringP("dir", "C", "", "Change to directory <dir>")
installCmd.Flags().String("filter", "", "set filter")
installCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
installCmd.Flags().Bool("fix-lockfile", false, "Fix broken lockfile entries automatically")
installCmd.Flags().Bool("force", false, "Force reinstall dependencies")
installCmd.Flags().Bool("frozen-lockfile", false, "Don't generate a lockfile and fail if an update is needed")
installCmd.Flags().Bool("global-dir", false, "Specify a custom directory to store global packages")
installCmd.Flags().BoolP("help", "h", false, "Output usage information")
installCmd.Flags().String("hoist-pattern", "", "Hoist all dependencies matching the pattern to")
installCmd.Flags().Bool("ignore-pnpmfile", false, "Disable pnpm hooks defined in .pnpmfile.cjs")
installCmd.Flags().Bool("ignore-scripts", false, "Don't run lifecycle scripts")
installCmd.Flags().String("lockfile-dir", "", "The directory in which the pnpm-lock.yaml will be created")
installCmd.Flags().Bool("lockfile-only", false, "Dependencies are not downloaded")
installCmd.Flags().String("loglevel", "", "What level of logs to report")
installCmd.Flags().String("modules-dir", "", "The directory in which dependencies will be installed")
installCmd.Flags().String("network-concurrency", "", "Maximum number of concurrent network requests")
installCmd.Flags().Bool("no-color", false, "Controls colors in the output")
installCmd.Flags().Bool("no-frozen-lockfile", false, "Don't generate a lockfile and fail if an update is needed")
installCmd.Flags().Bool("no-hoist", false, "Dependencies inside the modules directory will have access only to their listed dependencies")
installCmd.Flags().Bool("no-lockfile", false, "Don't read or generate a `pnpm-lock.yaml` file")
installCmd.Flags().Bool("no-optional", false, "`optionalDependencies` are not installed")
installCmd.Flags().Bool("no-verify-store-integrity", false, "If false, doesn't check whether packages in the store were mutated")
installCmd.Flags().Bool("offline", false, "Trigger an error if any required dependencies are not available in local store")
installCmd.Flags().String("package-import-method", "", "configure import method")
installCmd.Flags().Bool("prefer-frozen-lockfile", false, "If the available `pnpm-lock.yaml` satisfies the `package.json` then perform a headless installation")
installCmd.Flags().Bool("prefer-offline", false, "Skip staleness checks for cached data, but request missing data from the server")
installCmd.Flags().BoolP("prod", "P", false, "Packages in `devDependencies` won't be installed")
installCmd.Flags().String("public-hoist-pattern", "", "Hoist all dependencies matching the pattern to the root of the modules directory")
installCmd.Flags().BoolP("recursive", "r", false, "Run installation recursively in every package found in subdirectories")
installCmd.Flags().String("reporter", "", "configure output")
installCmd.Flags().Bool("shamefully-hoist", false, "All the subdeps will be hoisted into the root node_modules")
installCmd.Flags().Bool("side-effects-cache", false, "Use or cache the results of (pre/post)install hooks")
installCmd.Flags().Bool("side-effects-cache-readonly", false, "Only use the side effects cache if present, do not create it for new packages")
installCmd.Flags().BoolP("silent", "s", false, "No output is logged to the console, except fatal errors")
installCmd.Flags().String("store-dir", "", "The directory in which all the packages are saved on the disk")
installCmd.Flags().Bool("stream", false, "Stream output from child processes immediately")
installCmd.Flags().Bool("strict-peer-dependencies", false, "Fail on missing or invalid peer dependencies")
installCmd.Flags().String("test-pattern", "", "Defines files related to tests")
installCmd.Flags().Bool("use-running-store-server", false, "Only allows installation with a store server")
installCmd.Flags().Bool("use-stderr", false, "Divert all output to stderr")
installCmd.Flags().Bool("use-store-server", false, "Starts a store server in the background")
installCmd.Flags().Bool("verify-store-integrity", false, "If false, doesn't check whether packages in the store were mutated")
installCmd.Flags().String("virtual-store-dir", "", "The directory with links to the store")
installCmd.Flags().BoolP("workspace-root", "w", false, "Run the command on the root workspace project")
rootCmd.AddCommand(installCmd)

carapace.Gen(installCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"filter": pnpm.ActionFilter(),
"filter-prod": pnpm.ActionFilter(),
"lockfile-dir": carapace.ActionDirectories(),
"loglevel": pnpm.ActionLoglevel(),
"modules-dir": carapace.ActionDirectories(),
"package-import-method": carapace.ActionValuesDescribed(
"auto", "Clones/hardlinks or copies packages",
"clone", "Clone (aka copy-on-write) packages from the store",
"copy", "Copy packages from the store",
"hardlink", "Hardlink packages from the store",
),
"reporter": carapace.ActionValuesDescribed(
"append-only", "The output is always appended to the end",
"default", "The default reporter when the stdout is TTY",
"ndjson", "The most verbose reporter",
"silent", "No output is logged to the console, except fatal errors",
),
"store-dir": carapace.ActionDirectories(),
"virtual-store-dir": carapace.ActionDirectories(),
})
}
94 changes: 94 additions & 0 deletions completers/pnpm_completer/cmd/installTest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/pnpm"
"github.com/spf13/cobra"
)

var installTestCmd = &cobra.Command{
Use: "install-test",
Aliases: []string{"it"},

Short: "Runs a `pnpm install` followed immediately by a `pnpm test`",
GroupID: "manage",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(installTestCmd).Standalone()

installTestCmd.Flags().Bool("aggregate-output", false, "Aggregate output from child processes that are run in parallel")
installTestCmd.Flags().String("changed-files-ignore-pattern", "", "Defines files to ignore when filtering for changed projects since the specified commit/branch")
installTestCmd.Flags().String("child-concurrency", "", "Controls the number of child processes run parallelly")
installTestCmd.Flags().Bool("color", false, "Controls colors in the output")
installTestCmd.Flags().BoolP("dev", "D", false, "Only `devDependencies` are installed regardless of the `NODE_ENV`")
installTestCmd.Flags().StringP("dir", "C", "", "Change to directory <dir>")
installTestCmd.Flags().String("filter", "", "set filter")
installTestCmd.Flags().String("filter-prod", "", "Restricts the scope to package names matching the given pattern")
installTestCmd.Flags().Bool("fix-lockfile", false, "Fix broken lockfile entries automatically")
installTestCmd.Flags().Bool("force", false, "Force reinstall dependencies")
installTestCmd.Flags().Bool("frozen-lockfile", false, "Don't generate a lockfile and fail if an update is needed")
installTestCmd.Flags().Bool("global-dir", false, "Specify a custom directory to store global packages")
installTestCmd.Flags().BoolP("help", "h", false, "Output usage information")
installTestCmd.Flags().String("hoist-pattern", "", "Hoist all dependencies matching the pattern to")
installTestCmd.Flags().Bool("ignore-pnpmfile", false, "Disable pnpm hooks defined in .pnpmfile.cjs")
installTestCmd.Flags().Bool("ignore-scripts", false, "Don't run lifecycle scripts")
installTestCmd.Flags().String("lockfile-dir", "", "The directory in which the pnpm-lock.yaml will be created")
installTestCmd.Flags().Bool("lockfile-only", false, "Dependencies are not downloaded")
installTestCmd.Flags().String("loglevel", "", "What level of logs to report")
installTestCmd.Flags().String("modules-dir", "", "The directory in which dependencies will be installed")
installTestCmd.Flags().String("network-concurrency", "", "Maximum number of concurrent network requests")
installTestCmd.Flags().Bool("no-color", false, "Controls colors in the output")
installTestCmd.Flags().Bool("no-frozen-lockfile", false, "Don't generate a lockfile and fail if an update is needed")
installTestCmd.Flags().Bool("no-hoist", false, "Dependencies inside the modules directory will have access only to their listed dependencies")
installTestCmd.Flags().Bool("no-lockfile", false, "Don't read or generate a `pnpm-lock.yaml` file")
installTestCmd.Flags().Bool("no-optional", false, "`optionalDependencies` are not installed")
installTestCmd.Flags().Bool("no-verify-store-integrity", false, "If false, doesn't check whether packages in the store were mutated")
installTestCmd.Flags().Bool("offline", false, "Trigger an error if any required dependencies are not available in local store")
installTestCmd.Flags().String("package-import-method", "", "configure import method")
installTestCmd.Flags().Bool("prefer-frozen-lockfile", false, "If the available `pnpm-lock.yaml` satisfies the `package.json` then perform a headless installation")
installTestCmd.Flags().Bool("prefer-offline", false, "Skip staleness checks for cached data, but request missing data from the server")
installTestCmd.Flags().BoolP("prod", "P", false, "Packages in `devDependencies` won't be installed")
installTestCmd.Flags().String("public-hoist-pattern", "", "Hoist all dependencies matching the pattern to the root of the modules directory")
installTestCmd.Flags().BoolP("recursive", "r", false, "Run installation recursively in every package found in subdirectories")
installTestCmd.Flags().String("reporter", "", "configure output")
installTestCmd.Flags().Bool("shamefully-hoist", false, "All the subdeps will be hoisted into the root node_modules")
installTestCmd.Flags().Bool("side-effects-cache", false, "Use or cache the results of (pre/post)install hooks")
installTestCmd.Flags().Bool("side-effects-cache-readonly", false, "Only use the side effects cache if present, do not create it for new packages")
installTestCmd.Flags().BoolP("silent", "s", false, "No output is logged to the console, except fatal errors")
installTestCmd.Flags().String("store-dir", "", "The directory in which all the packages are saved on the disk")
installTestCmd.Flags().Bool("stream", false, "Stream output from child processes immediately")
installTestCmd.Flags().Bool("strict-peer-dependencies", false, "Fail on missing or invalid peer dependencies")
installTestCmd.Flags().String("test-pattern", "", "Defines files related to tests")
installTestCmd.Flags().Bool("use-running-store-server", false, "Only allows installation with a store server")
installTestCmd.Flags().Bool("use-stderr", false, "Divert all output to stderr")
installTestCmd.Flags().Bool("use-store-server", false, "Starts a store server in the background")
installTestCmd.Flags().Bool("verify-store-integrity", false, "If false, doesn't check whether packages in the store were mutated")
installTestCmd.Flags().String("virtual-store-dir", "", "The directory with links to the store")
installTestCmd.Flags().BoolP("workspace-root", "w", false, "Run the command on the root workspace project")
rootCmd.AddCommand(installTestCmd)

carapace.Gen(installTestCmd).FlagCompletion(carapace.ActionMap{
"dir": carapace.ActionDirectories(),
"filter": pnpm.ActionFilter(),
"filter-prod": pnpm.ActionFilter(),
"lockfile-dir": carapace.ActionDirectories(),
"loglevel": pnpm.ActionLoglevel(),
"modules-dir": carapace.ActionDirectories(),
"package-import-method": carapace.ActionValuesDescribed(
"auto", "Clones/hardlinks or copies packages",
"clone", "Clone (aka copy-on-write) packages from the store",
"copy", "Copy packages from the store",
"hardlink", "Hardlink packages from the store",
),
"reporter": carapace.ActionValuesDescribed(
"append-only", "The output is always appended to the end",
"default", "The default reporter when the stdout is TTY",
"ndjson", "The most verbose reporter",
"silent", "No output is logged to the console, except fatal errors",
),
"store-dir": carapace.ActionDirectories(),
"virtual-store-dir": carapace.ActionDirectories(),
})
}
Loading

0 comments on commit e610b71

Please sign in to comment.