Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Url in deno dir #2572

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mod tests {
tokio_util::init(|| {
let specifier = "./tests/002_hello.ts";
use deno::ModuleSpecifier;
let module_name = ModuleSpecifier::resolve_root(specifier)
let module_name = ModuleSpecifier::resolve_url_or_path(specifier)
.unwrap()
.to_string();

Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
fn test_bundle_async() {
let specifier = "./tests/002_hello.ts";
use deno::ModuleSpecifier;
let module_name = ModuleSpecifier::resolve_root(specifier)
let module_name = ModuleSpecifier::resolve_url_or_path(specifier)
.unwrap()
.to_string();

Expand Down
3 changes: 2 additions & 1 deletion cli/deno_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl DenoError {
use ModuleResolutionError::*;
match err {
InvalidUrl(err) | InvalidBaseUrl(err) => Self::url_error_kind(err),
ImportPathPrefixMissing => ErrorKind::ImportPathPrefixMissing,
InvalidPath => ErrorKind::InvalidPath,
ImportPrefixMissing => ErrorKind::ImportPrefixMissing,
}
}
Repr::Diagnostic(ref _err) => ErrorKind::Diagnostic,
Expand Down
4 changes: 3 additions & 1 deletion cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ pub enum DenoSubcommand {

fn get_default_bundle_filename(source_file: &str) -> String {
use deno::ModuleSpecifier;
let url = ModuleSpecifier::resolve_root(source_file).unwrap().to_url();
let url = ModuleSpecifier::resolve_url_or_path(source_file)
.unwrap()
.to_url();
let path_segments = url.path_segments().unwrap();
let last = path_segments.last().unwrap();
String::from(last.trim_end_matches(".ts").trim_end_matches(".js"))
Expand Down
4 changes: 1 addition & 3 deletions cli/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ impl ImportMap {
continue;
}

let normalized_address = ModuleSpecifier::resolve(&url_string, ".")
.expect("Address should be valid module specifier");
normalized_addresses.push(normalized_address);
normalized_addresses.push(url.into());
}

normalized_addresses
Expand Down
3 changes: 2 additions & 1 deletion cli/msg.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ enum ErrorKind: byte {
WouldBlock,
InvalidInput,
InvalidData,
InvalidPath,
TimedOut,
Interrupted,
WriteZero,
Expand Down Expand Up @@ -141,7 +142,7 @@ enum ErrorKind: byte {
NoAsyncSupport,
NoSyncSupport,
ImportMapError,
ImportPathPrefixMissing,
ImportPrefixMissing,

// other kinds
Diagnostic,
Expand Down
2 changes: 1 addition & 1 deletion cli/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ fn op_create_worker(
err_check(worker.execute("denoMain()"));
err_check(worker.execute("workerMain()"));

let module_specifier = ModuleSpecifier::resolve_root(specifier)?;
let module_specifier = ModuleSpecifier::resolve_url_or_path(specifier)?;

let op =
worker
Expand Down
5 changes: 3 additions & 2 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ impl Loader for ThreadSafeState {
}
}

ModuleSpecifier::resolve(specifier, referrer).map_err(DenoError::from)
ModuleSpecifier::resolve_import(specifier, referrer)
.map_err(DenoError::from)
}

/// Given an absolute url, load its source code.
Expand Down Expand Up @@ -252,7 +253,7 @@ impl ThreadSafeState {
None
} else {
let root_specifier = argv_rest[1].clone();
match ModuleSpecifier::resolve_root(&root_specifier) {
match ModuleSpecifier::resolve_url_or_path(&root_specifier) {
Ok(specifier) => Some(specifier),
Err(e) => {
// TODO: handle unresolvable specifier
Expand Down
10 changes: 5 additions & 5 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
#[test]
fn execute_mod_esm_imports_a() {
let module_specifier =
ModuleSpecifier::resolve_root("tests/esm_imports_a.js").unwrap();
ModuleSpecifier::resolve_url_or_path("tests/esm_imports_a.js").unwrap();
let argv = vec![String::from("./deno"), module_specifier.to_string()];
let state = ThreadSafeState::new(
flags::DenoFlags::default(),
Expand Down Expand Up @@ -169,7 +169,7 @@ mod tests {
#[test]
fn execute_mod_circular() {
let module_specifier =
ModuleSpecifier::resolve_root("tests/circular1.js").unwrap();
ModuleSpecifier::resolve_url_or_path("tests/circular1.js").unwrap();
let argv = vec![String::from("./deno"), module_specifier.to_string()];
let state = ThreadSafeState::new(
flags::DenoFlags::default(),
Expand Down Expand Up @@ -197,7 +197,7 @@ mod tests {
#[test]
fn execute_006_url_imports() {
let module_specifier =
ModuleSpecifier::resolve_root("tests/006_url_imports.ts").unwrap();
ModuleSpecifier::resolve_url_or_path("tests/006_url_imports.ts").unwrap();
let argv = vec![String::from("deno"), module_specifier.to_string()];
let mut flags = flags::DenoFlags::default();
flags.reload = true;
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
// "foo" is not a valid module specifier so this should return an error.
let mut worker = create_test_worker();
let module_specifier =
ModuleSpecifier::resolve_root("does-not-exist").unwrap();
ModuleSpecifier::resolve_url_or_path("does-not-exist").unwrap();
let result = worker.execute_mod_async(&module_specifier, false).wait();
assert!(result.is_err());
})
Expand All @@ -340,7 +340,7 @@ mod tests {
// tests).
let mut worker = create_test_worker();
let module_specifier =
ModuleSpecifier::resolve_root("./tests/002_hello.ts").unwrap();
ModuleSpecifier::resolve_url_or_path("./tests/002_hello.ts").unwrap();
let result = worker.execute_mod_async(&module_specifier, false).wait();
assert!(result.is_ok());
})
Expand Down
Loading