Skip to content

Commit eeb389e

Browse files
branchseerclaude
andcommitted
refactor: use typed AbsolutePath::strip_prefix in resolve_glob_to_workspace_relative
RelativePathBuf guarantees valid UTF-8 with forward slashes, so the manual to_str() check and backslash normalization are no longer needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1b833d5 commit eeb389e

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

  • crates/vite_task_graph/src/config

crates/vite_task_graph/src/config/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,23 @@ fn resolve_glob_to_workspace_relative(
194194
package_dir: &AbsolutePath,
195195
workspace_root: &AbsolutePath,
196196
) -> Result<Str, ResolveTaskConfigError> {
197-
use cow_utils::CowUtils as _;
198-
199197
let glob = wax::Glob::new(pattern).map_err(|source| ResolveTaskConfigError::InvalidGlob {
200198
pattern: Str::from(pattern),
201199
source: Box::new(source),
202200
})?;
203201
let (invariant_prefix, variant) = glob.partition();
204202

205203
let joined = package_dir.join(&invariant_prefix).clean();
206-
let stripped = joined.as_path().strip_prefix(workspace_root.as_path()).map_err(|_| {
204+
let stripped = joined.strip_prefix(workspace_root).map_err(|_| {
207205
ResolveTaskConfigError::GlobOutsideWorkspace { pattern: Str::from(pattern) }
208206
})?;
209207

210208
// Re-escape the prefix path for use in a glob pattern
211-
let stripped_str = stripped.to_str().ok_or_else(|| {
212-
ResolveTaskConfigError::GlobOutsideWorkspace { pattern: Str::from(pattern) }
209+
let stripped = stripped.ok_or_else(|| ResolveTaskConfigError::GlobOutsideWorkspace {
210+
pattern: Str::from(pattern),
213211
})?;
214-
// Normalize backslashes to forward slashes for cross-platform compatibility
215-
let escaped = wax::escape(stripped_str);
216-
let escaped_prefix = escaped.cow_replace('\\', "/");
212+
213+
let escaped_prefix = wax::escape(stripped.as_str());
217214

218215
let result = match variant {
219216
Some(variant_glob) if escaped_prefix.is_empty() => {

0 commit comments

Comments
 (0)