Skip to content

Commit

Permalink
fix(compile): regression handling redirects (#26586)
Browse files Browse the repository at this point in the history
Closes #26583
  • Loading branch information
dsherret authored and bartlomieju committed Oct 29, 2024
1 parent 6ef2875 commit de610f6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cli/standalone/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub struct RemoteModulesStoreBuilder {

impl RemoteModulesStoreBuilder {
pub fn add(&mut self, specifier: &Url, media_type: MediaType, data: Vec<u8>) {
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
Expand All @@ -182,6 +183,7 @@ impl RemoteModulesStoreBuilder {
pub fn add_redirects(&mut self, redirects: &BTreeMap<Url, Url>) {
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;
Expand Down Expand Up @@ -354,17 +356,17 @@ impl RemoteModulesStore {

pub fn read<'a>(
&'a self,
specifier: &'a Url,
original_specifier: &'a Url,
) -> Result<Option<DenoCompileModuleData<'a>>, 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)) => {
Expand Down
22 changes: 22 additions & 0 deletions tests/specs/compile/redirects/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}]
}
1 change: 1 addition & 0 deletions tests/specs/compile/redirects/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
1 change: 1 addition & 0 deletions tests/specs/compile/redirects/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "http://localhost:4546/run/003_relative_import.ts";

0 comments on commit de610f6

Please sign in to comment.