summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/examples/fs_module_loader.rs6
-rw-r--r--core/examples/ts_module_loader.rs6
-rw-r--r--core/module_specifier.rs10
3 files changed, 16 insertions, 6 deletions
diff --git a/core/examples/fs_module_loader.rs b/core/examples/fs_module_loader.rs
index a8d33e104..737ff1d5c 100644
--- a/core/examples/fs_module_loader.rs
+++ b/core/examples/fs_module_loader.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use anyhow::Context;
use deno_core::anyhow::Error;
use deno_core::FsModuleLoader;
use deno_core::JsRuntime;
@@ -24,7 +25,10 @@ fn main() -> Result<(), Error> {
.enable_all()
.build()?;
- let main_module = deno_core::resolve_path(main_url)?;
+ let main_module = deno_core::resolve_path(
+ main_url,
+ &std::env::current_dir().context("Unable to get CWD")?,
+ )?;
let future = async move {
let mod_id = js_runtime.load_main_module(&main_module, None).await?;
diff --git a/core/examples/ts_module_loader.rs b/core/examples/ts_module_loader.rs
index b57b04493..289b43dc9 100644
--- a/core/examples/ts_module_loader.rs
+++ b/core/examples/ts_module_loader.rs
@@ -9,6 +9,7 @@ use std::rc::Rc;
use anyhow::anyhow;
use anyhow::bail;
+use anyhow::Context;
use anyhow::Error;
use deno_ast::MediaType;
use deno_ast::ParseParams;
@@ -106,7 +107,10 @@ fn main() -> Result<(), Error> {
..Default::default()
});
- let main_module = resolve_path(main_url)?;
+ let main_module = resolve_path(
+ main_url,
+ &std::env::current_dir().context("Unable to get CWD")?,
+ )?;
let future = async move {
let mod_id = js_runtime.load_main_module(&main_module, None).await?;
diff --git a/core/module_specifier.rs b/core/module_specifier.rs
index c65f34110..72d693723 100644
--- a/core/module_specifier.rs
+++ b/core/module_specifier.rs
@@ -4,6 +4,7 @@ use crate::normalize_path;
use std::env::current_dir;
use std::error::Error;
use std::fmt;
+use std::path::Path;
use std::path::PathBuf;
use url::ParseError;
use url::Url;
@@ -128,7 +129,9 @@ pub fn resolve_url_or_path(
if specifier_has_uri_scheme(specifier) {
resolve_url(specifier)
} else {
- resolve_path(specifier)
+ let cwd = current_dir()
+ .map_err(|_| ModuleResolutionError::InvalidPath(specifier.into()))?;
+ resolve_path(specifier, &cwd)
}
}
@@ -137,10 +140,9 @@ pub fn resolve_url_or_path(
/// working directory.
pub fn resolve_path(
path_str: &str,
+ current_dir: &Path,
) -> Result<ModuleSpecifier, ModuleResolutionError> {
- let path = current_dir()
- .map_err(|_| ModuleResolutionError::InvalidPath(path_str.into()))?
- .join(path_str);
+ let path = current_dir.join(path_str);
let path = normalize_path(path);
Url::from_file_path(&path)
.map_err(|()| ModuleResolutionError::InvalidPath(path))