Skip to content

Commit 2890784

Browse files
authored
fix: support specifying an absolute path in the patch field (#161)
1 parent 6a527ef commit 2890784

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ thiserror = "2"
3737
deno_error = { version = "0.5.3", features = ["url"] }
3838
boxed_error = "0.2.3"
3939
deno_semver = { version = "0.7.1", optional = true }
40-
deno_package_json = { version = "0.4.0", optional = true }
40+
deno_package_json = { version = "0.5.0", optional = true }
4141
deno_path_util = "0.3.0"
4242
sys_traits.workspace = true
4343

src/workspace/discovery.rs

+10
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,16 @@ fn resolve_patch_config_folders<TSys: FsRead + FsMetadata + FsReadDir>(
942942
let resolve_patch_dir_url =
943943
|raw_patch: &str| -> Result<Url, WorkspaceDiscoverError> {
944944
let patch = ensure_trailing_slash(raw_patch);
945+
// support someone specifying an absolute path
946+
if !cfg!(windows) && patch.starts_with('/')
947+
|| cfg!(windows) && patch.chars().any(|c| c == '\\')
948+
{
949+
if let Ok(value) =
950+
deno_path_util::url_from_file_path(&PathBuf::from(patch.as_ref()))
951+
{
952+
return Ok(value);
953+
}
954+
}
945955
let patch_dir_url =
946956
root_config_file_directory_url.join(&patch).map_err(|err| {
947957
WorkspaceDiscoverErrorKind::ResolvePatch {

src/workspace/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,7 @@ pub mod test {
22352235

22362236
use deno_path_util::normalize_path;
22372237
use deno_path_util::url_from_directory_path;
2238+
use deno_path_util::url_from_file_path;
22382239
use pretty_assertions::assert_eq;
22392240
use serde_json::json;
22402241
use sys_traits::impls::InMemorySys;
@@ -2809,6 +2810,28 @@ pub mod test {
28092810
);
28102811
}
28112812

2813+
#[test]
2814+
fn test_patch_absolute_path() {
2815+
let root_path = root_dir().join("../dir");
2816+
let workspace_dir = workspace_for_root_and_member_with_fs(
2817+
json!({
2818+
"patch": [root_path.to_string_lossy().to_string()],
2819+
}),
2820+
json!({}),
2821+
|fs| {
2822+
fs.fs_insert_json(root_dir().join("../dir/deno.json"), json!({}));
2823+
},
2824+
);
2825+
assert_eq!(workspace_dir.workspace.diagnostics(), vec![]);
2826+
let patch_folders =
2827+
workspace_dir.workspace.patch_folders().collect::<Vec<_>>();
2828+
assert_eq!(patch_folders.len(), 1);
2829+
assert_eq!(
2830+
patch_folders[0].deno_json.as_ref().unwrap().specifier,
2831+
url_from_file_path(&root_dir().join("../dir/deno.json")).unwrap()
2832+
)
2833+
}
2834+
28122835
#[test]
28132836
fn test_root_member_imports_and_scopes() {
28142837
let workspace_dir = workspace_for_root_and_member(

0 commit comments

Comments
 (0)