Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add pnpm support #4291

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions lib/cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct Add {
/// Add the JavaScript bindings using "yarn add".
#[clap(long, groups = &["bindings", "js"])]
yarn: bool,
/// Add the JavaScript bindings using "pnpm add".
#[clap(long, groups = &["bindings", "js"])]
pnpm: bool,
/// Add the package as a dev-dependency.
#[clap(long, requires = "js")]
dev: bool,
Expand Down Expand Up @@ -72,13 +75,14 @@ impl Add {
}

fn target(&self) -> Result<Target, Error> {
match (self.pip, self.npm, self.yarn) {
(false, false, false) => Err(anyhow::anyhow!(
"at least one of --npm, --pip or --yarn has to be specified"
match (self.pip, self.npm, self.yarn, self.pnpm) {
(false, false, false, false) => Err(anyhow::anyhow!(
"at least one of --npm, --pip, --yarn or --pnpm has to be specified"
)),
(true, false, false) => Ok(Target::Pip),
(false, true, false) => Ok(Target::Npm { dev: self.dev }),
(false, false, true) => Ok(Target::Yarn { dev: self.dev }),
(true, false, false, false) => Ok(Target::Pip),
(false, true, false, false) => Ok(Target::Npm { dev: self.dev }),
(false, false, true, false) => Ok(Target::Yarn { dev: self.dev }),
(false, false, false, true) => Ok(Target::Pnpm { dev: self.dev }),
_ => Err(anyhow::anyhow!(
"only one of --npm, --pip or --yarn has to be specified"
)),
Expand Down Expand Up @@ -116,13 +120,16 @@ enum Target {
Pip,
Yarn { dev: bool },
Npm { dev: bool },
Pnpm { dev: bool },
}

impl Target {
fn language(self) -> ProgrammingLanguage {
match self {
Target::Pip => ProgrammingLanguage::PYTHON,
Target::Yarn { .. } | Target::Npm { .. } => ProgrammingLanguage::JAVASCRIPT,
Target::Pnpm { .. } | Target::Yarn { .. } | Target::Npm { .. } => {
ProgrammingLanguage::JAVASCRIPT
}
}
}

Expand Down Expand Up @@ -163,14 +170,24 @@ impl Target {
}
Target::Npm { dev } => {
if Command::new("npm").arg("--version").output().is_err() {
return Err(anyhow::anyhow!("yarn not installed"));
return Err(anyhow::anyhow!("npm not installed"));
}
if dev {
"npm install --dev"
} else {
"npm install"
}
}
Target::Pnpm { dev } => {
if Command::new("pnpm").arg("--version").output().is_err() {
return Err(anyhow::anyhow!("pnpm not installed"));
}
if dev {
"pnpm add --dev"
} else {
"pnpm add"
}
}
};
let mut command_line = command_line.to_string();

Expand Down
Loading