Skip to content

Commit aba6140

Browse files
authored
fix(base): should handle the entrypoint passed from js land correctly (#511)
1 parent 6612a9f commit aba6140

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

crates/base/src/runtime/mod.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -632,14 +632,10 @@ where
632632
base_url,
633633
} = rt_provider;
634634

635-
let entrypoint = metadata
636-
.entrypoint
637-
.as_ref()
638-
.with_context(|| "could not find entrypoint from metadata")?;
639-
635+
let entrypoint = metadata.entrypoint.as_ref();
640636
let main_module_url = match entrypoint {
641-
Entrypoint::Key(key) => base_url.join(key)?,
642-
Entrypoint::ModuleCode(_) => Url::parse(
637+
Some(Entrypoint::Key(key)) => base_url.join(key)?,
638+
Some(Entrypoint::ModuleCode(_)) | None => Url::parse(
643639
maybe_entrypoint
644640
.as_ref()
645641
.with_context(|| "could not find entrypoint key")?,
@@ -668,16 +664,25 @@ where
668664
let (fs, maybe_s3_fs) = build_file_system_fn(if is_user_worker {
669665
Arc::new(StaticFs::new(
670666
static_files,
671-
main_module_url
672-
.to_file_path()
673-
.map_err(|_| {
674-
anyhow!("failed to resolve base dir using main module url")
675-
})
676-
.and_then(|it| {
677-
it.parent()
678-
.map(Path::to_path_buf)
679-
.with_context(|| "failed to determine parent directory")
680-
})?,
667+
if matches!(entrypoint, Some(Entrypoint::ModuleCode(_)) | None)
668+
&& maybe_entrypoint.is_some()
669+
{
670+
// it is eszip from before v2
671+
base_url
672+
.to_file_path()
673+
.map_err(|_| anyhow!("failed to resolve base url"))?
674+
} else {
675+
main_module_url
676+
.to_file_path()
677+
.map_err(|_| {
678+
anyhow!("failed to resolve base dir using main module url")
679+
})
680+
.and_then(|it| {
681+
it.parent()
682+
.map(Path::to_path_buf)
683+
.with_context(|| "failed to determine parent directory")
684+
})?
685+
},
681686
vfs_path,
682687
vfs,
683688
npm_snapshot,
@@ -993,10 +998,10 @@ where
993998

994999
let main_module_id = {
9951000
match entrypoint {
996-
Entrypoint::Key(_) => {
1001+
Some(Entrypoint::Key(_)) | None => {
9971002
js_runtime.load_main_es_module(&main_module_url).await?
9981003
}
999-
Entrypoint::ModuleCode(module_code) => {
1004+
Some(Entrypoint::ModuleCode(module_code)) => {
10001005
js_runtime
10011006
.load_main_es_module_from_code(
10021007
&main_module_url,

0 commit comments

Comments
 (0)