Skip to content

Commit acb6894

Browse files
committed
fixes
1 parent 5742008 commit acb6894

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ jobs:
2626
- uses: actions/setup-node@v7
2727
with:
2828
node-version: "20"
29-
registry-url: "https://registry.npmjs.org"
3029

3130
- name: Format
3231
if: matrix.os == 'ubuntu-latest'

rs-lib/src/mappings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ impl Mappings {
125125
if !mappings.contains_key(key) {
126126
if let Some(path) = mappings.get(value).map(ToOwned::to_owned) {
127127
mappings.insert(key.clone(), path);
128-
} else {
128+
} else if !specifiers.has_mapped(value) {
129+
// specifiers mapped to a package have no file in the output
129130
panic!("dnt bug - Could not find the mapping for {}", value);
130131
}
131132
}

rs-lib/tests/integration/in_memory_loader.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type RemoteFileResult = Result<(RemoteFileText, RemoteFileHeaders), String>;
2424
pub struct InMemoryLoader {
2525
pub sys: InMemorySys,
2626
remote_files: HashMap<ModuleSpecifier, RemoteFileResult>,
27+
remote_redirects: HashMap<ModuleSpecifier, String>,
2728
}
2829

2930
impl InMemoryLoader {
@@ -38,6 +39,7 @@ impl InMemoryLoader {
3839
Self {
3940
sys,
4041
remote_files: HashMap::new(),
42+
remote_redirects: HashMap::new(),
4143
}
4244
}
4345

@@ -87,6 +89,18 @@ impl InMemoryLoader {
8789
self
8890
}
8991

92+
pub fn add_remote_redirect(
93+
&mut self,
94+
specifier: impl AsRef<str>,
95+
location: impl AsRef<str>,
96+
) -> &mut Self {
97+
self.remote_redirects.insert(
98+
ModuleSpecifier::parse(specifier.as_ref()).unwrap(),
99+
location.as_ref().to_string(),
100+
);
101+
self
102+
}
103+
90104
pub fn add_remote_file_with_error(
91105
&mut self,
92106
specifier: impl AsRef<str>,
@@ -118,6 +132,12 @@ impl deno_cache_dir::file_fetcher::HttpClient for InMemoryLoader {
118132
specifier: &ModuleSpecifier,
119133
_headers: HeaderMap,
120134
) -> Result<SendResponse, SendError> {
135+
if let Some(location) = self.remote_redirects.get(specifier) {
136+
return Ok(SendResponse::Redirect(to_headers(HashMap::from([(
137+
"location".to_string(),
138+
location.clone(),
139+
)]))));
140+
}
121141
let result = self
122142
.remote_files
123143
.get(&specifier)

rs-lib/tests/integration_test.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,45 @@ async fn transform_specifier_mappings() {
11681168
);
11691169
}
11701170

1171+
#[tokio::test]
1172+
async fn transform_specifier_mapping_of_redirected_specifier() {
1173+
let result = TestBuilder::new()
1174+
.with_loader(|loader| {
1175+
loader
1176+
.add_local_file(
1177+
"/mod.ts",
1178+
"import * as remote from 'http://localhost/mod.ts';",
1179+
)
1180+
.add_remote_redirect(
1181+
"http://localhost/mod.ts",
1182+
"http://localhost/redirected/mod.ts",
1183+
)
1184+
.add_remote_file("http://localhost/redirected/mod.ts", "");
1185+
})
1186+
.add_package_specifier_mapping(
1187+
"http://localhost/redirected/mod.ts",
1188+
"remote-module",
1189+
Some("1.0.0"),
1190+
None,
1191+
)
1192+
.transform()
1193+
.await
1194+
.unwrap();
1195+
1196+
assert_files!(
1197+
result.main.files,
1198+
&[("mod.ts", "import * as remote from 'remote-module';")]
1199+
);
1200+
assert_eq!(
1201+
result.main.dependencies,
1202+
&[Dependency {
1203+
name: "remote-module".to_string(),
1204+
version: "1.0.0".to_string(),
1205+
peer_dependency: false,
1206+
}]
1207+
);
1208+
}
1209+
11711210
#[tokio::test]
11721211
async fn transform_not_found_mappings() {
11731212
let error_message = TestBuilder::new()

0 commit comments

Comments
 (0)