summaryrefslogtreecommitdiff
path: root/core/module_specifier.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-03-14 16:47:09 -0400
committerGitHub <noreply@github.com>2023-03-14 16:47:09 -0400
commit96ea5b1d3d7b4ddec386d8708dc8a01c5fa946e9 (patch)
tree6c0209413506bce00494dafda93f7c9026e917b6 /core/module_specifier.rs
parenteb990efcce1e5390e4ed76b858c05c6f9b3b6c11 (diff)
refactor: deno_core not using std::env::current_dir (#18173)
This commit changes "deno_core" to not rely on implicitly calling "std::env::current_dir()" when resolving module specifiers using APIs from "deno_core::modules_specifier". Supersedes https://github.com/denoland/deno/pull/15454
Diffstat (limited to 'core/module_specifier.rs')
-rw-r--r--core/module_specifier.rs26
1 files changed, 2 insertions, 24 deletions
diff --git a/core/module_specifier.rs b/core/module_specifier.rs
index 94ccd298c..20358e79c 100644
--- a/core/module_specifier.rs
+++ b/core/module_specifier.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::normalize_path;
-use std::env::current_dir;
use std::error::Error;
use std::fmt;
use std::path::Path;
@@ -9,8 +8,6 @@ use std::path::PathBuf;
use url::ParseError;
use url::Url;
-pub const DUMMY_SPECIFIER: &str = "<unknown>";
-
/// Error indicating the reason resolving a module specifier failed.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ModuleResolutionError {
@@ -85,18 +82,7 @@ pub fn resolve_import(
// 3. Return the result of applying the URL parser to specifier with base
// URL as the base URL.
Err(ParseError::RelativeUrlWithoutBase) => {
- let base = if base == DUMMY_SPECIFIER {
- // Handle <unknown> case, happening under e.g. repl.
- // Use CWD for such case.
-
- // Forcefully join base to current dir.
- // Otherwise, later joining in Url would be interpreted in
- // the parent directory (appending trailing slash does not work)
- let path = current_dir().unwrap().join(base);
- Url::from_file_path(path).unwrap()
- } else {
- Url::parse(base).map_err(InvalidBaseUrl)?
- };
+ let base = Url::parse(base).map_err(InvalidBaseUrl)?;
base.join(specifier).map_err(InvalidUrl)?
}
@@ -181,20 +167,12 @@ mod tests {
use super::*;
use crate::serde_json::from_value;
use crate::serde_json::json;
+ use std::env::current_dir;
use std::path::Path;
#[test]
fn test_resolve_import() {
- fn get_path(specifier: &str) -> Url {
- let base_path = current_dir().unwrap().join("<unknown>");
- let base_url = Url::from_file_path(base_path).unwrap();
- base_url.join(specifier).unwrap()
- }
- let awesome = get_path("/awesome.ts");
- let awesome_srv = get_path("/service/awesome.ts");
let tests = vec![
- ("/awesome.ts", "<unknown>", awesome.as_str()),
- ("/service/awesome.ts", "<unknown>", awesome_srv.as_str()),
(
"./005_more_imports.ts",
"http://deno.land/core/tests/006_url_imports.ts",