From 8a84839ac951096aa23aea26064b14baecb5c12e Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 17:57:03 -0400 Subject: [PATCH 1/2] feat: support providing a file: URL to configPath --- src/mod.ts | 2 +- src/rs_lib/lib.rs | 18 +++++++++++++----- tests/link_jsr_entrypoint/main.test.ts | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mod.ts b/src/mod.ts index 5a9e527..df30c24 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -49,7 +49,7 @@ export interface WorkspaceOptions { noConfig?: boolean; /** Do not respect the lockfile. */ noLock?: boolean; - /** Path to the config file if you do not want to do config file discovery. */ + /** Path or file: URL to the config file if you do not want to do config file discovery. */ configPath?: string; /** Node resolution conditions to use for resolving package.json exports. */ nodeConditions?: string[]; diff --git a/src/rs_lib/lib.rs b/src/rs_lib/lib.rs index 0326c3d..725184f 100644 --- a/src/rs_lib/lib.rs +++ b/src/rs_lib/lib.rs @@ -166,7 +166,7 @@ impl DenoWorkspace { let config_discovery = if options.no_config.unwrap_or_default() { ConfigDiscoveryOption::Disabled } else if let Some(config_path) = options.config_path { - ConfigDiscoveryOption::Path(resolve_absolute_path(config_path, &cwd)) + ConfigDiscoveryOption::Path(resolve_absolute_path(config_path, &cwd)?) } else { ConfigDiscoveryOption::DiscoverCwd }; @@ -707,7 +707,7 @@ impl DenoLoader { return Ok(deno_path_util::url_from_file_path(&resolve_absolute_path( specifier.into_owned(), cwd, - ))?); + )?)?); } let referrer = deno_path_util::url_from_directory_path(cwd)?; Ok(self.resolver.resolve( @@ -760,9 +760,17 @@ fn create_external_repsonse(url: &Url) -> JsValue { obj.into() } -fn resolve_absolute_path(path: String, cwd: &Path) -> PathBuf { - let path = sys_traits::impls::wasm_string_to_path(path); - cwd.join(path) +fn resolve_absolute_path( + path: String, + cwd: &Path, +) -> Result { + if path.starts_with("file:///") { + let url = Url::parse(&path)?; + Ok(deno_path_util::url_to_file_path(&url)?) + } else { + let path = sys_traits::impls::wasm_string_to_path(path); + Ok(cwd.join(path)) + } } fn create_js_error(err: anyhow::Error) -> JsValue { diff --git a/tests/link_jsr_entrypoint/main.test.ts b/tests/link_jsr_entrypoint/main.test.ts index d516ed8..7ff5108 100644 --- a/tests/link_jsr_entrypoint/main.test.ts +++ b/tests/link_jsr_entrypoint/main.test.ts @@ -8,7 +8,7 @@ import { Deno.test("loads linked entrypoint", async () => { const mainFile = import.meta.dirname + "/testdata/main/main.ts"; const { loader } = await createLoader({ - configPath: import.meta.dirname + "/testdata/main/deno.json", + configPath: import.meta.resolve("./testdata/main/deno.json"), }, { entrypoints: [mainFile], }); From 4e14f908c19641de69bb1779f709eb9be995a303 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 17:58:46 -0400 Subject: [PATCH 2/2] update --- src/rs_lib/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rs_lib/lib.rs b/src/rs_lib/lib.rs index 725184f..f6b6d13 100644 --- a/src/rs_lib/lib.rs +++ b/src/rs_lib/lib.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; +use anyhow::Context; use anyhow::bail; use deno_ast::ModuleKind; use deno_cache_dir::file_fetcher::CacheSetting; @@ -166,7 +167,10 @@ impl DenoWorkspace { let config_discovery = if options.no_config.unwrap_or_default() { ConfigDiscoveryOption::Disabled } else if let Some(config_path) = options.config_path { - ConfigDiscoveryOption::Path(resolve_absolute_path(config_path, &cwd)?) + ConfigDiscoveryOption::Path( + resolve_absolute_path(config_path, &cwd) + .context("Failed resolving config path.")?, + ) } else { ConfigDiscoveryOption::DiscoverCwd }; @@ -774,7 +778,7 @@ fn resolve_absolute_path( } fn create_js_error(err: anyhow::Error) -> JsValue { - wasm_bindgen::JsError::new(&err.to_string()).into() + wasm_bindgen::JsError::new(&format!("{:#}", err)).into() } fn parse_resolution_mode(resolution_mode: u8) -> node_resolver::ResolutionMode {