mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(compile): regression handling redirects (#26586)
Closes https://github.com/denoland/deno/issues/26583
This commit is contained in:
parent
6ef2875395
commit
de610f6201
4 changed files with 31 additions and 5 deletions
|
@ -173,6 +173,7 @@ pub struct RemoteModulesStoreBuilder {
|
||||||
|
|
||||||
impl RemoteModulesStoreBuilder {
|
impl RemoteModulesStoreBuilder {
|
||||||
pub fn add(&mut self, specifier: &Url, media_type: MediaType, data: Vec<u8>) {
|
pub fn add(&mut self, specifier: &Url, media_type: MediaType, data: Vec<u8>) {
|
||||||
|
log::debug!("Adding '{}' ({})", specifier, media_type);
|
||||||
let specifier = specifier.to_string();
|
let specifier = specifier.to_string();
|
||||||
self.specifiers.push((specifier, self.data_byte_len));
|
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
|
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<Url, Url>) {
|
pub fn add_redirects(&mut self, redirects: &BTreeMap<Url, Url>) {
|
||||||
self.redirects.reserve(redirects.len());
|
self.redirects.reserve(redirects.len());
|
||||||
for (from, to) in redirects {
|
for (from, to) in redirects {
|
||||||
|
log::debug!("Adding redirect '{}' -> '{}'", from, to);
|
||||||
let from = from.to_string();
|
let from = from.to_string();
|
||||||
let to = to.to_string();
|
let to = to.to_string();
|
||||||
self.redirects_len += (4 + from.len() + 4 + to.len()) as u64;
|
self.redirects_len += (4 + from.len() + 4 + to.len()) as u64;
|
||||||
|
@ -354,17 +356,17 @@ impl RemoteModulesStore {
|
||||||
|
|
||||||
pub fn read<'a>(
|
pub fn read<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
specifier: &'a Url,
|
original_specifier: &'a Url,
|
||||||
) -> Result<Option<DenoCompileModuleData<'a>>, AnyError> {
|
) -> Result<Option<DenoCompileModuleData<'a>>, AnyError> {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut current = specifier;
|
let mut specifier = original_specifier;
|
||||||
loop {
|
loop {
|
||||||
if count > 10 {
|
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)) => {
|
Some(RemoteModulesStoreSpecifierValue::Redirect(to)) => {
|
||||||
current = to;
|
specifier = to;
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
Some(RemoteModulesStoreSpecifierValue::Data(offset)) => {
|
Some(RemoteModulesStoreSpecifierValue::Data(offset)) => {
|
||||||
|
|
22
tests/specs/compile/redirects/__test__.jsonc
Normal file
22
tests/specs/compile/redirects/__test__.jsonc
Normal file
|
@ -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
tests/specs/compile/redirects/main.out
Normal file
1
tests/specs/compile/redirects/main.out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Hello
|
1
tests/specs/compile/redirects/main.ts
Normal file
1
tests/specs/compile/redirects/main.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
import "http://localhost:4546/run/003_relative_import.ts";
|
Loading…
Reference in a new issue