-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
shulaoda
wants to merge
1
commit into
web-infra-dev:main
Choose a base branch
from
shulaoda:feat/xtask
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+242
−3
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
})?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod api_extractor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod command; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 likedebug
,publish
, andversion
inxtask
.There was a problem hiding this comment.
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?