Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
24 changes: 18 additions & 6 deletions src/rs_lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<PathBuf, anyhow::Error> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/link_jsr_entrypoint/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
Expand Down