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(rspack): support xtask #7915

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lint = "clippy --workspace --all-targets -- --deny warnings"
# AKA `test-update`, handy cargo rst update without install `cargo-rst` binary
t = "test --no-fail-fast"
tu = "run -p cargo-rst -- update"
xtask = "run --package xtask --"

[target.'cfg(all())']
rustflags = [
Expand Down
123 changes: 122 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cargo-features = ["trim-paths"]

[workspace]
members = ["crates/*"]
resolver = "2" # See https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
members = ["crates/*", "xtask"]
resolver = "2" # See https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2

[workspace.package]
authors = ["Rspack Teams"]
Expand Down
18 changes: 18 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"
publish = false
authors.workspace = true
categories.workspace = true
documentation.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
anyhow = { workspace = true }
clap = { version = "4.4.6", features = ["derive"] }

[lints]
workspace = true
36 changes: 36 additions & 0 deletions xtask/src/commands/api_extractor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};

use crate::utils::command::run_command;

#[derive(Debug, Parser)]
pub struct ApiExtractorCmd {
#[clap(subcommand)]
sub_cmd: ApiExtractorSubCmd,
}

#[derive(Debug, Subcommand)]
pub enum ApiExtractorSubCmd {
Update,
Ci,
}

impl ApiExtractorCmd {
pub fn run(&self) -> Result<()> {
match &self.sub_cmd {
ApiExtractorSubCmd::Update => {
run_command("pnpm", &["-w", "build:js"])?;
run_command(
"pnpm",
&["--filter", "@rspack/*", "api-extractor", "--local"],
)?;
}
ApiExtractorSubCmd::Ci => {
run_command("pnpm", &["--filter", "@rspack/*", "api-extractor:ci"]).with_context(|| {
"Api-extractor testing failed. Did you forget to update the snapshots locally?\nRun the command below locally to fix this error (in the *ROOT* of rspack workspace).\n$ ./x api-extractor update"
})?;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the benefit of run pnpm script in xtask then in justfile directly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use cmd args more flexibly. This is just a start, and perhaps api-extractor isn't the best choice. I expect to implement commands like debug, publish, and version in xtask.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure put js related task into xtask is a good idea, maybe we should start with rust related task first, @h-a-n-a what's your idea?

Ok(())
}
}
1 change: 1 addition & 0 deletions xtask/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod api_extractor;
31 changes: 31 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use commands::*;

mod commands;
mod utils;

#[derive(Debug, Parser)]
#[clap(
name = "Rspack Development CLI",
version = "1.0",
about = "CLI for development of Rspack"
)]
struct CliArgs {
#[clap(subcommand)]
cmd: Cmd,
}

#[derive(Debug, Subcommand)]
enum Cmd {
#[clap(name = "api-extractor")]
ApiExtractor(api_extractor::ApiExtractorCmd),
}

fn main() -> Result<()> {
let args = CliArgs::parse();

match args.cmd {
Cmd::ApiExtractor(cmd) => cmd.run(),
}
}
30 changes: 30 additions & 0 deletions xtask/src/utils/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::process::Command;

use anyhow::{Context, Result};

#[cfg(windows)]
const PNPM: &str = "pnpm.cmd";
#[cfg(not(windows))]
const PNPM: &str = "pnpm";

pub fn run_command(command: &str, args: &[&str]) -> Result<()> {
let program = match command {
"pnpm" => PNPM,
other => other,
};

let status = Command::new(program)
.args(args)
.status()
.context("Failed to execute command")?;

if status.success() {
Ok(())
} else {
Err(anyhow::anyhow!(
"Command `{}` failed with status code: {}",
command,
status.code().unwrap_or(-1)
))
}
}
1 change: 1 addition & 0 deletions xtask/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod command;
Loading