diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 12927845bc..7b63c584e7 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -173,6 +173,7 @@ pub struct RemoteModulesStoreBuilder { impl RemoteModulesStoreBuilder { pub fn add(&mut self, specifier: &Url, media_type: MediaType, data: Vec) { + log::debug!("Adding '{}' ({})", specifier, media_type); let specifier = specifier.to_string(); self.specifiers.push((specifier, self.data_byte_len)); self.data_byte_len += 1 + 8 + data.len() as u64; // media type (1 byte), data length (8 bytes), data @@ -182,6 +183,7 @@ impl RemoteModulesStoreBuilder { pub fn add_redirects(&mut self, redirects: &BTreeMap) { self.redirects.reserve(redirects.len()); for (from, to) in redirects { + log::debug!("Adding redirect '{}' -> '{}'", from, to); let from = from.to_string(); let to = to.to_string(); self.redirects_len += (4 + from.len() + 4 + to.len()) as u64; @@ -354,17 +356,17 @@ impl RemoteModulesStore { pub fn read<'a>( &'a self, - specifier: &'a Url, + original_specifier: &'a Url, ) -> Result>, AnyError> { let mut count = 0; - let mut current = specifier; + let mut specifier = original_specifier; loop { if count > 10 { - bail!("Too many redirects resolving '{}'", specifier); + bail!("Too many redirects resolving '{}'", original_specifier); } - match self.specifiers.get(current) { + match self.specifiers.get(specifier) { Some(RemoteModulesStoreSpecifierValue::Redirect(to)) => { - current = to; + specifier = to; count += 1; } Some(RemoteModulesStoreSpecifierValue::Data(offset)) => { diff --git a/tests/specs/compile/redirects/__test__.jsonc b/tests/specs/compile/redirects/__test__.jsonc new file mode 100644 index 0000000000..07ce693999 --- /dev/null +++ b/tests/specs/compile/redirects/__test__.jsonc @@ -0,0 +1,22 @@ +{ + "tempDir": true, + "steps": [{ + "if": "unix", + "args": "compile -A --output main main.ts", + "output": "[WILDCARD]" + }, { + "if": "unix", + "commandName": "./main", + "args": [], + "output": "main.out" + }, { + "if": "windows", + "args": "compile -A --output main.exe main.ts", + "output": "[WILDCARD]" + }, { + "if": "windows", + "commandName": "./main.exe", + "args": [], + "output": "main.out" + }] +} diff --git a/tests/specs/compile/redirects/main.out b/tests/specs/compile/redirects/main.out new file mode 100644 index 0000000000..e965047ad7 --- /dev/null +++ b/tests/specs/compile/redirects/main.out @@ -0,0 +1 @@ +Hello diff --git a/tests/specs/compile/redirects/main.ts b/tests/specs/compile/redirects/main.ts new file mode 100644 index 0000000000..4396319014 --- /dev/null +++ b/tests/specs/compile/redirects/main.ts @@ -0,0 +1 @@ +import "http://localhost:4546/run/003_relative_import.ts";