Skip to content
Merged
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
86 changes: 72 additions & 14 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ allocator-api2 = { version = "0.2.21", default-features = false, features = ["al
anyhow = "1.0.98"
assert2 = "0.3.16"
assertables = "9.8.1"
async-trait = "0.1.89"
base64 = "0.22.1"
bincode = "2.0.1"
bindgen = "0.72.1"
Expand Down Expand Up @@ -122,6 +123,7 @@ vite_path = { path = "crates/vite_path" }
vite_shell = { path = "crates/vite_shell" }
vite_str = { path = "crates/vite_str" }
vite_task_graph = { path = "crates/vite_task_graph" }
vite_task_plan = { path = "crates/vite_task_plan" }
vite_workspace = { path = "crates/vite_workspace" }
wax = "0.6.0"
which = "8.0.0"
Expand Down
3 changes: 3 additions & 0 deletions crates/vite_path/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ serde = { workspace = true, features = ["derive", "rc"] }
thiserror = { workspace = true }
vite_str = { workspace = true }

[features]
absolute-redaction = []

[lints]
workspace = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "absolute-redaction")]
pub mod redaction;

use std::{
ffi::OsStr,
fmt::Display,
Expand All @@ -8,6 +11,7 @@ use std::{
};

use ref_cast::{RefCastCustom, ref_cast_custom};
use serde::Serialize;

use crate::relative::{FromPathError, InvalidPathDataError, RelativePathBuf};

Expand All @@ -21,6 +25,35 @@ impl AsRef<Self> for AbsolutePath {
}
}

impl Serialize for AbsolutePath {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
#[cfg(feature = "absolute-redaction")]
{
use redaction::REDACTION_PREFIX;

if let Some(redaction_prefix) = REDACTION_PREFIX
.with(|redaction_prefix| redaction_prefix.borrow().as_ref().map(Arc::clone))
{
match self.strip_prefix(redaction_prefix) {
Ok(Some(stripped_path)) => return stripped_path.serialize(serializer),
Err(strip_error) => {
return Err(serde::ser::Error::custom(format!(
"Failed to redact absolute path '{}': {}",
self.as_path().display(),
strip_error
)));
}
Ok(None) => { /* continue to serialize full path */ }
}
}
}
self.as_path().serialize(serializer)
}
}

impl PartialEq<AbsolutePathBuf> for AbsolutePath {
fn eq(&self, other: &AbsolutePathBuf) -> bool {
self.0 == other.0
Expand All @@ -46,6 +79,14 @@ impl From<&AbsolutePath> for Arc<AbsolutePath> {
}
}

impl From<&AbsolutePath> for Box<AbsolutePath> {
fn from(path: &AbsolutePath) -> Self {
let path_box: Box<Path> = path.0.into();
let path_box_raw = Box::into_raw(path_box) as *mut AbsolutePath;
unsafe { Self::from_raw(path_box_raw) }
}
}

impl AbsolutePath {
/// Creates a [`AbsolutePath`] if the give path is absolute.
pub fn new<P: AsRef<Path> + ?Sized>(path: &P) -> Option<&Self> {
Expand Down
25 changes: 25 additions & 0 deletions crates/vite_path/src/absolute/redaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::sync::Arc;

use super::AbsolutePath;

thread_local! {
pub(crate) static REDACTION_PREFIX: std::cell::RefCell<Option<Arc<AbsolutePath>>> = std::cell::RefCell::new(None);
}

#[derive(Debug)]
pub struct RedactionGuard(());

impl Drop for RedactionGuard {
fn drop(&mut self) {
REDACTION_PREFIX.set(None);
}
}

pub fn redact_absolute_paths(prefix: &Arc<AbsolutePath>) -> RedactionGuard {
REDACTION_PREFIX.with(|redaction_prefix| {
let mut redaction_prefix = redaction_prefix.borrow_mut();
assert!(redaction_prefix.is_none(), "RedactionGuard already active");
*redaction_prefix = Some(Arc::clone(&prefix));
});
RedactionGuard(())
}
2 changes: 2 additions & 0 deletions crates/vite_path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub mod relative;

use std::io;

#[cfg(feature = "absolute-redaction")]
pub use absolute::redaction;
pub use absolute::{AbsolutePath, AbsolutePathBuf};
pub use relative::{RelativePath, RelativePathBuf};

Expand Down
9 changes: 9 additions & 0 deletions crates/vite_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true, features = ["derive"] }
bstr = { workspace = true }
clap = { workspace = true, features = ["derive"] }
compact_str = { workspace = true, features = ["serde"] }
dashmap = { workspace = true }
derive_more = { workspace = true }
diff-struct = { workspace = true }
fspy = { workspace = true }
futures-core = { workspace = true }
Expand All @@ -41,11 +44,17 @@ vite_glob = { workspace = true }
vite_path = { workspace = true }
vite_shell = { workspace = true }
vite_str = { workspace = true }
vite_task_graph = { workspace = true }
vite_task_plan = { workspace = true }
vite_workspace = { workspace = true }
wax = { workspace = true }

[target.'cfg(unix)'.dependencies]
nix = { workspace = true }

[dev-dependencies]
copy_dir = { workspace = true }
insta = { workspace = true, features = ["glob", "json", "redactions"] }
tempfile = { workspace = true }
toml = { workspace = true }
vite_path = { workspace = true, features = ["absolute-redaction"] }
13 changes: 13 additions & 0 deletions crates/vite_task/src/bin/vite.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use clap::Parser;
use vite_str::Str;
use vite_task::CLIArgs;

#[derive(Debug, Parser)]
enum CustomTaskSubCommand {
/// oxlint
Lint { args: Vec<Str> },
}

fn main() {
let _subcommand = CLIArgs::<CustomTaskSubCommand>::parse();
}
Loading