diff --git a/Cargo.lock b/Cargo.lock index 7369f5e..2d7040c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,7 @@ name = "deno_config" version = "0.44.0" dependencies = [ "boxed_error", + "capacity_builder", "deno_error", "deno_package_json", "deno_path_util", diff --git a/Cargo.toml b/Cargo.toml index b13720a..be309b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ sync = ["deno_package_json/sync"] workspace = ["deno_json", "deno_semver", "package_json"] [dependencies] +capacity_builder = { version = "0.5.0" } indexmap = { version = "2", features = ["serde"] } jsonc-parser = { version = "0.26.0", features = ["serde"], optional = true } log = "0.4.20" diff --git a/src/glob/mod.rs b/src/glob/mod.rs index 647a24e..dfb27de 100644 --- a/src/glob/mod.rs +++ b/src/glob/mod.rs @@ -631,17 +631,20 @@ impl GlobPattern { Some(p) => (true, p), None => (false, p), }; + let base_str = base.to_string_lossy().replace('\\', "/"); let p = p.strip_prefix("./").unwrap_or(p); - let mut pattern = String::new(); - if is_negated { - pattern.push('!'); - } - pattern.push_str(&base.to_string_lossy().replace('\\', "/")); - if !pattern.ends_with('/') { - pattern.push('/'); - } let p = p.strip_suffix('/').unwrap_or(p); - pattern.push_str(p); + let pattern = capacity_builder::StringBuilder::::build(|builder| { + if is_negated { + builder.append('!'); + } + builder.append(&base_str); + if !base_str.ends_with('/') { + builder.append('/'); + } + builder.append(p); + }) + .unwrap(); GlobPattern::new(&pattern) }