Skip to content

Commit 07879ca

Browse files
authored
fix: static files weren't extracted when running the unbundle (#609)
1 parent 159fc1d commit 07879ca

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

cli/src/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn get_unbundle_command() -> Command {
380380
.default_value("./"),
381381
)
382382
.arg(
383-
arg!(--"eszip" <DIR>)
383+
arg!(--"eszip" <Path>)
384384
.help("Path of eszip to extract")
385385
.required(true),
386386
)

crates/deno_facade/eszip/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,31 @@ pub async fn extract_eszip(payload: ExtractEszipPayload) -> bool {
11961196
if let Some(lowest_path) =
11971197
deno::util::path::find_lowest_path(&file_specifiers)
11981198
{
1199-
extract_modules(&eszip, &file_specifiers, &lowest_path, &output_folder)
1200-
.await;
1199+
let targets = eszip
1200+
.specifiers()
1201+
.iter()
1202+
.filter(|it| it.starts_with("static:"))
1203+
.cloned()
1204+
.collect::<Vec<_>>();
1205+
1206+
{
1207+
let mut modules = eszip.eszip.modules.0.lock().unwrap();
1208+
for asset in targets {
1209+
let url = Url::parse(&asset).unwrap();
1210+
modules.insert(
1211+
format!("file://{}", url.path()),
1212+
EszipV2Module::Redirect { target: asset },
1213+
);
1214+
}
1215+
}
1216+
1217+
extract_modules(
1218+
&eszip,
1219+
&extract_file_specifiers(&eszip),
1220+
&lowest_path,
1221+
&output_folder,
1222+
)
1223+
.await;
12011224
true
12021225
} else {
12031226
panic!("Path seems to be invalid");

crates/deno_facade/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::fs::File;
23
use std::io::Write;
34
use std::path::Path;
@@ -35,13 +36,22 @@ fn ensure_unix_relative_path(path: &Path) -> &Path {
3536
path
3637
}
3738

39+
fn strip_file_scheme(input: &str) -> Cow<'_, str> {
40+
if input.starts_with("file://") {
41+
Cow::Owned(input.strip_prefix("file://").unwrap().to_owned())
42+
} else {
43+
Cow::Borrowed(input)
44+
}
45+
}
46+
3847
async fn create_module_path(
3948
global_specifier: &str,
4049
entry_path: &Path,
4150
output_folder: &Path,
4251
) -> PathBuf {
52+
let cleaned_specifier = strip_file_scheme(global_specifier);
4353
let cleaned_specifier =
44-
global_specifier.replace(entry_path.to_str().unwrap(), "");
54+
cleaned_specifier.replace(entry_path.to_str().unwrap(), "");
4555
let module_path = PathBuf::from(cleaned_specifier);
4656

4757
if let Some(parent) = module_path.parent() {
@@ -70,7 +80,7 @@ async fn extract_modules(
7080
lowest_path: &str,
7181
output_folder: &Path,
7282
) {
73-
let main_path = PathBuf::from(lowest_path);
83+
let main_path = PathBuf::from(&*strip_file_scheme(lowest_path));
7484
let entry_path = main_path.parent().unwrap();
7585
for global_specifier in specifiers {
7686
let module_path =

0 commit comments

Comments
 (0)