mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(compile): follow redirects when resolving (#14161)
This commit is contained in:
parent
1d24b2cf63
commit
b0f974fbfd
4 changed files with 48 additions and 2 deletions
|
@ -135,7 +135,14 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
referrer: &str,
|
||||
_is_main: bool,
|
||||
) -> Result<ModuleSpecifier, AnyError> {
|
||||
let referrer = deno_core::resolve_url_or_path(referrer).unwrap();
|
||||
// Try to follow redirects when resolving.
|
||||
let referrer = match self.eszip.get_module(referrer) {
|
||||
Some(eszip::Module { ref specifier, .. }) => {
|
||||
deno_core::resolve_url_or_path(specifier)?
|
||||
}
|
||||
None => deno_core::resolve_url_or_path(referrer)?,
|
||||
};
|
||||
|
||||
self.maybe_import_map_resolver.as_ref().map_or_else(
|
||||
|| {
|
||||
deno_core::resolve_import(specifier, referrer.as_str())
|
||||
|
@ -154,7 +161,6 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
let module_specifier = module_specifier.clone();
|
||||
|
||||
let is_data_uri = get_source_from_data_url(&module_specifier).ok();
|
||||
|
||||
let module = self
|
||||
.eszip
|
||||
.get_module(module_specifier.as_str())
|
||||
|
|
|
@ -186,6 +186,39 @@ fn standalone_load_datauri() {
|
|||
assert_eq!(output.stdout, b"Hello Deno!\n");
|
||||
}
|
||||
|
||||
// https://github.com/denoland/deno/issues/13704
|
||||
#[test]
|
||||
fn standalone_follow_redirects() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let exe = if cfg!(windows) {
|
||||
dir.path().join("follow_redirects.exe")
|
||||
} else {
|
||||
dir.path().join("follow_redirects")
|
||||
};
|
||||
let output = util::deno_cmd()
|
||||
.current_dir(util::testdata_path())
|
||||
.arg("compile")
|
||||
.arg("--unstable")
|
||||
.arg("--output")
|
||||
.arg(&exe)
|
||||
.arg("./standalone_follow_redirects.ts")
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
let output = Command::new(exe)
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
assert_eq!(output.stdout, b"Hello\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standalone_compiler_ops() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
|
2
cli/tests/testdata/standalone_follow_redirects.ts
vendored
Normal file
2
cli/tests/testdata/standalone_follow_redirects.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
import "./standalone_follow_redirects_2.js";
|
||||
console.log("Hello");
|
5
cli/tests/testdata/standalone_follow_redirects_2.js
vendored
Normal file
5
cli/tests/testdata/standalone_follow_redirects_2.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
// unversioned import redirects with dependencies.
|
||||
import {
|
||||
assertNotEquals as _a,
|
||||
assertStrictEquals as _b,
|
||||
} from "https://deno.land/std/testing/asserts.ts";
|
Loading…
Reference in a new issue