-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement output.clean.keep: Option<string> (#8479)
- Loading branch information
Showing
23 changed files
with
470 additions
and
45 deletions.
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
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,31 @@ | ||
use napi_derive::napi; | ||
use rspack_core::CleanOptions; | ||
use rspack_napi::napi; | ||
|
||
/// File clean options | ||
/// | ||
/// This matches with: | ||
/// - keep: | ||
/// - If a string, keep the files under this path | ||
#[napi(object, object_to_js = false)] | ||
#[derive(Debug)] | ||
pub struct JsCleanOptions { | ||
pub keep: Option<String>, | ||
// todo: | ||
// - support RegExp type | ||
// if path match the RegExp, keep the file | ||
// - support function type | ||
// if the fn returns true on path str, keep the file | ||
} | ||
|
||
impl JsCleanOptions { | ||
pub fn to_clean_options(&self) -> CleanOptions { | ||
let keep = self.keep.as_ref(); | ||
if let Some(path) = keep { | ||
let p = path.as_str(); | ||
CleanOptions::from(p) | ||
} else { | ||
CleanOptions::CleanAll(false) | ||
} | ||
} | ||
} |
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
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,51 @@ | ||
use std::{path::PathBuf, str::FromStr}; | ||
|
||
use rspack_paths::Utf8PathBuf; | ||
|
||
/// rust representation of the clean options | ||
// TODO: support RegExp and function type | ||
#[derive(Debug)] | ||
pub enum CleanOptions { | ||
// if true, clean all files | ||
CleanAll(bool), | ||
// keep the files under this path | ||
KeepPath(Utf8PathBuf), | ||
} | ||
|
||
impl CleanOptions { | ||
pub fn keep(&self, path: &str) -> bool { | ||
match self { | ||
Self::CleanAll(value) => !*value, | ||
Self::KeepPath(value) => { | ||
let path = PathBuf::from(path); | ||
path.starts_with(value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<bool> for CleanOptions { | ||
fn from(value: bool) -> Self { | ||
Self::CleanAll(value) | ||
} | ||
} | ||
|
||
impl From<&'_ str> for CleanOptions { | ||
fn from(value: &str) -> Self { | ||
let pb = Utf8PathBuf::from_str(value).expect("should be a valid path"); | ||
Self::KeepPath(pb) | ||
} | ||
} | ||
impl From<&String> for CleanOptions { | ||
fn from(value: &String) -> Self { | ||
let pb = Utf8PathBuf::from_str(value).expect("should be a valid path"); | ||
Self::KeepPath(pb) | ||
} | ||
} | ||
|
||
impl From<String> for CleanOptions { | ||
fn from(value: String) -> Self { | ||
let pb = Utf8PathBuf::from_str(&value).expect("should be a valid path"); | ||
Self::KeepPath(pb) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -31,3 +31,5 @@ mod node; | |
pub use node::*; | ||
mod filename; | ||
pub use filename::*; | ||
mod clean_options; | ||
pub use clean_options::*; |
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
Oops, something went wrong.
044e8e3
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.
📝 Benchmark detail: Open
044e8e3
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.
📝 Ran ecosystem CI: Open