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..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 }; @@ -707,7 +711,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,13 +764,21 @@ 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 { - 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 { 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], });