Skip to content

Commit 64fd6de

Browse files
authored
chore: add old eszip migration test part 2 (#517)
* chore: add `get_eszip_testdata.sh` * stamp: polishing * chore(base): add a dev dependency * chore: update `Cargo.lock` * chore: add old eszip migration test * fix: introduce eszip migrate options * fix: allow specifying context regardless worker mode * chore: update `scripts/get_eszip_testdata.sh` * chore(ci): add a step that brings test eszip binaries * fix(cli): reintroduce `--import-map` flag of the bundle command * chore(ci): using checkout action instead of s3 to get test binaries * stamp: token * stamp: test * stamp: polishing * stamp: debug * stamp: decomp * stamp: test * stamp: polishing * chore: add old eszip migration test (#512) * chore(base): add a dependency * chore(base): add `.gitignore` * chore: add scripts * chore(ci): add a step that brings test eszip binaries * chore(base): update `.gitignore` * chore(base): add old eszip migration test * chore(base): add snapshots for old eszip migration tests * stamp(ci): change bucket name * stamp: update snapshots * stamp: polishing * stamp: update snapshots
1 parent 90c8de2 commit 64fd6de

File tree

806 files changed

+521
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

806 files changed

+521
-130
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
RUSTUP_MAX_RETRIES: 10
1616
ORT_DYLIB_PATH: /tmp/onnxruntime/lib/libonnxruntime.so
1717
RUST_LOG: ext_event_worker=trace
18+
ESZIP_TESTDATA_REPO: supabase/edge-runtime-test-eszip
1819

1920
jobs:
2021
cargo-fmt:
@@ -75,7 +76,31 @@ jobs:
7576
- name: Install ONNX Runtime Library
7677
run: ./scripts/install_onnx.sh ${{ env.ONNXRUNTIME_VERSION }} linux x64 /tmp/onnxruntime
7778

78-
- name: Install S3 credentials for testing
79+
- name: Prepare test eszip binaries
80+
if: |
81+
github.actor != 'dependabot[bot]' &&
82+
(
83+
github.event_name != 'pull_request'
84+
|| github.event.pull_request.head.repo.full_name == github.repository
85+
)
86+
uses: actions/checkout@v4
87+
with:
88+
repository: ${{ env.ESZIP_TESTDATA_REPO }}
89+
path: ./edge-runtime-test-eszip
90+
token: ${{ secrets.EDGE_RUNTIME_ORG_TOKEN }}
91+
- name: Decompress test eszip binaries
92+
if: |
93+
github.actor != 'dependabot[bot]' &&
94+
(
95+
github.event_name != 'pull_request'
96+
|| github.event.pull_request.head.repo.full_name == github.repository
97+
)
98+
run: |
99+
mkdir -p crates/base/tests/fixture/testdata
100+
./scripts/esbr.cjs decompress ./edge-runtime-test-eszip/testdata
101+
mv ./edge-runtime-test-eszip/testdata/*.out crates/base/tests/fixture/testdata
102+
103+
- name: Install Supabase Storage S3 credentials for testing
79104
if: |
80105
github.actor != 'dependabot[bot]' &&
81106
(

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ fn get_bundle_command() -> Command {
301301
.help("Glob pattern for static files to be included")
302302
.action(ArgAction::Append),
303303
)
304+
.arg(
305+
arg!(--"import-map" <Path>).help("(DEPRECATED) Path to import map file"),
306+
)
304307
.arg(
305308
arg!(--"checksum" <KIND>)
306309
.env("EDGE_RUNTIME_BUNDLE_CHECKSUM")

cli/src/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use base::worker::pool::WorkerPoolPolicy;
1818
use base::CacheSetting;
1919
use base::InspectorOption;
2020
use base::WorkerKind;
21+
use deno::ConfigMode;
2122
use deno::DenoOptionsBuilder;
2223
use deno_facade::extract_from_file;
2324
use deno_facade::generate_binary_eszip;
@@ -269,6 +270,8 @@ fn main() -> Result<ExitCode, anyhow::Error> {
269270
Some(("bundle", sub_matches)) => {
270271
let output_path =
271272
sub_matches.get_one::<String>("output").cloned().unwrap();
273+
let import_map_path =
274+
sub_matches.get_one::<String>("import-map").cloned();
272275
let static_patterns =
273276
if let Some(val_ref) = sub_matches.get_many::<String>("static") {
274277
val_ref.map(|s| s.as_str()).collect::<Vec<&str>>()
@@ -311,11 +314,18 @@ fn main() -> Result<ExitCode, anyhow::Error> {
311314
emitter_factory.set_permissions_options(Some(
312315
base::get_default_permissions(WorkerKind::MainWorker),
313316
));
314-
emitter_factory.set_deno_options(
315-
DenoOptionsBuilder::new()
316-
.entrypoint(entrypoint_script_path.clone())
317-
.build()?,
318-
);
317+
318+
let mut builder =
319+
DenoOptionsBuilder::new().entrypoint(entrypoint_script_path.clone());
320+
321+
if let Some(path) = import_map_path {
322+
let path = PathBuf::from(path);
323+
if !path.exists() || !path.is_file() {
324+
bail!("import map path is incorrect");
325+
}
326+
builder.set_config(Some(ConfigMode::Path(path)));
327+
}
328+
emitter_factory.set_deno_options(builder.build()?);
319329

320330
let mut metadata = Metadata::default();
321331
let eszip = generate_binary_eszip(

crates/base/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tests/fixture/testdata/*
2+
!tests/fixture/testdata/**/*.snapshot
3+
!tests/fixture/testdata/**/*.metadata

crates/base/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ tokio-rustls = "0.25.0"
8080
winapi = { workspace = true, features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }
8181

8282
[dev-dependencies]
83+
eszip_trait.workspace = true
8384
serial_test.workspace = true
8485
tokio-util = { workspace = true, features = ["rt", "compat"] }
8586
tracing-subscriber = { workspace = true, features = ["env-filter", "tracing-log"] }

crates/base/src/runtime/mod.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ use deno_core::ResolutionKind;
6868
use deno_core::RuntimeOptions;
6969
use deno_facade::generate_binary_eszip;
7070
use deno_facade::metadata::Entrypoint;
71+
use deno_facade::migrate::MigrateOptions;
7172
use deno_facade::module_loader::standalone::create_module_loader_for_standalone_from_eszip_kind;
7273
use deno_facade::module_loader::RuntimeProviders;
7374
use deno_facade::EmitterFactory;
@@ -491,9 +492,7 @@ where
491492
let is_some_entry_point = maybe_entrypoint.is_some();
492493

493494
let maybe_user_conf = conf.as_user_worker();
494-
let user_context = maybe_user_conf
495-
.and_then(|it| it.context.clone())
496-
.unwrap_or_default();
495+
let context = conf.context().cloned().unwrap_or_default();
497496

498497
let permissions_options = maybe_user_conf
499498
.and_then(|it| it.permissions.clone())
@@ -608,15 +607,22 @@ where
608607
};
609608

610609
let has_inspector = worker.inspector.is_some();
611-
let need_source_map = user_context
610+
let need_source_map = context
612611
.get("sourceMap")
613612
.and_then(serde_json::Value::as_bool)
614613
.unwrap_or_default();
614+
let maybe_import_map_path = context
615+
.get("importMapPath")
616+
.and_then(|it| it.as_str())
617+
.map(str::to_string);
615618

616619
let rt_provider = create_module_loader_for_standalone_from_eszip_kind(
617620
eszip,
618621
permissions_options,
619622
has_inspector || need_source_map,
623+
Some(MigrateOptions {
624+
maybe_import_map_path,
625+
}),
620626
)
621627
.await?;
622628

@@ -907,16 +913,16 @@ where
907913
};
908914

909915
let extra_context = {
910-
let mut context =
916+
let mut extra_context =
911917
serde_json::json!(RuntimeContext::get_extra_context());
912918

913919
json::merge_object(
914-
&mut context,
915-
&serde_json::Value::Object(user_context),
920+
&mut extra_context,
921+
&serde_json::Value::Object(context),
916922
);
917-
json::merge_object(&mut context, &tokens);
923+
json::merge_object(&mut extra_context, &tokens);
918924

919-
context
925+
extra_context
920926
};
921927

922928
let context = js_runtime.main_context();
@@ -2077,6 +2083,7 @@ mod test {
20772083
worker_pool_tx,
20782084
shared_metric_src: None,
20792085
event_worker_metric_src: None,
2086+
context: None,
20802087
})
20812088
}
20822089
},
@@ -2189,6 +2196,7 @@ mod test {
21892196
worker_pool_tx,
21902197
shared_metric_src: None,
21912198
event_worker_metric_src: None,
2199+
context: None,
21922200
})
21932201
},
21942202
static_patterns: vec![],
@@ -2253,6 +2261,7 @@ mod test {
22532261
worker_pool_tx,
22542262
shared_metric_src: None,
22552263
event_worker_metric_src: None,
2264+
context: None,
22562265
})
22572266
},
22582267
static_patterns: vec![],
@@ -2332,6 +2341,7 @@ mod test {
23322341
worker_pool_tx,
23332342
shared_metric_src: None,
23342343
event_worker_metric_src: None,
2344+
context: None,
23352345
})
23362346
},
23372347
static_patterns: vec![],

crates/base/src/server.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -724,17 +724,13 @@ pub struct Builder {
724724
tls: Option<Tls>,
725725
main_service_path: String,
726726
event_worker_path: Option<String>,
727-
// decorator: Option<DecoratorType>,
728727
user_worker_policy: Option<WorkerPoolPolicy>,
729-
// import_map_path: Option<String>,
730728
flags: ServerFlags,
731729
callback_tx: Option<Sender<ServerHealth>>,
732730
entrypoints: WorkerEntrypoints,
733731
termination_token: Option<TerminationToken>,
734732
static_patterns: Vec<String>,
735733
inspector: Option<Inspector>,
736-
// jsx_specifier: Option<String>,
737-
// jsx_module: Option<String>,
738734
}
739735

740736
impl Builder {
@@ -768,21 +764,11 @@ impl Builder {
768764
self
769765
}
770766

771-
// pub fn decorator(&mut self, val: DecoratorType) -> &mut Self {
772-
// self.decorator = Some(val);
773-
// self
774-
// }
775-
776767
pub fn user_worker_policy(&mut self, val: WorkerPoolPolicy) -> &mut Self {
777768
self.user_worker_policy = Some(val);
778769
self
779770
}
780771

781-
// pub fn import_map_path(&mut self, val: &str) -> &mut Self {
782-
// self.import_map_path = Some(val.to_owned());
783-
// self
784-
// }
785-
786772
pub fn event_callback(
787773
&mut self,
788774
val: mpsc::Sender<ServerHealth>,
@@ -818,16 +804,6 @@ impl Builder {
818804
self
819805
}
820806

821-
// pub fn jsx_specifier(&mut self, val: &str) -> &mut Self {
822-
// self.jsx_specifier = Some(val.to_owned());
823-
// self
824-
// }
825-
826-
// pub fn jsx_module(&mut self, val: &str) -> &mut Self {
827-
// self.jsx_module = Some(val.to_owned());
828-
// self
829-
// }
830-
831807
pub fn flags_mut(&mut self) -> &mut ServerFlags {
832808
&mut self.flags
833809
}

crates/base/src/utils/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ impl TestBedBuilder {
251251
worker_pool_tx,
252252
shared_metric_src: None,
253253
event_worker_metric_src: None,
254+
context: None,
254255
}),
255256
static_patterns: vec![],
256257

crates/base/src/worker/worker_surface_creation.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,7 @@ impl MainWorkerSurfaceBuilder {
581581
mut inner,
582582
main_worker_path,
583583
no_module_cache,
584-
// import_map_path,
585584
entrypoint,
586-
// decorator,
587-
// jsx,
588585
worker_pool_tx,
589586
shared_metric_src,
590587
event_worker_metric_src,
@@ -611,13 +608,13 @@ impl MainWorkerSurfaceBuilder {
611608
timing: None,
612609
maybe_eszip,
613610
maybe_entrypoint: entrypoint,
614-
// maybe_decorator: decorator,
615611
maybe_module_code: None,
616612
conf: WorkerRuntimeOpts::MainWorker(MainWorkerRuntimeOpts {
617613
worker_pool_tx: worker_pool_tx
618614
.context("worker_pool_sender must be specified")?,
619615
shared_metric_src,
620616
event_worker_metric_src,
617+
context: None,
621618
}),
622619
env_vars: std::env::vars().collect(),
623620
static_patterns: vec![],
@@ -696,9 +693,7 @@ impl EventWorkerSurfaceBuilder {
696693

697694
event_worker_path: event_worker_path.as_ref().to_path_buf(),
698695
no_module_cache: None,
699-
// import_map_path: None,
700696
entrypoint: None,
701-
// decorator: None,
702697
}
703698
}
704699

@@ -707,49 +702,27 @@ impl EventWorkerSurfaceBuilder {
707702
self
708703
}
709704

710-
// pub fn import_map_path(mut self, value: &str) -> Self {
711-
// self.import_map_path = Some(value.to_string());
712-
// self
713-
// }
714-
715705
pub fn entrypoint(mut self, value: &str) -> Self {
716706
self.entrypoint = Some(value.to_string());
717707
self
718708
}
719709

720-
// pub fn decorator(mut self, value: DecoratorType) -> Self {
721-
// self.decorator = Some(value);
722-
// self
723-
// }
724-
725710
pub fn set_no_module_cache(&mut self, value: Option<bool>) -> &mut Self {
726711
self.no_module_cache = value;
727712
self
728713
}
729714

730-
// pub fn set_import_map_path(&mut self, value: Option<&str>) -> &mut Self {
731-
// self.import_map_path = value.map(str::to_string);
732-
// self
733-
// }
734-
735715
pub fn set_entrypoint(&mut self, value: Option<&str>) -> &mut Self {
736716
self.entrypoint = value.map(str::to_string);
737717
self
738718
}
739719

740-
// pub fn set_decorator(&mut self, value: Option<DecoratorType>) -> &mut Self {
741-
// self.decorator = value;
742-
// self
743-
// }
744-
745720
pub async fn build(self) -> Result<EventWorkerSurface, anyhow::Error> {
746721
let Self {
747722
mut inner,
748723
event_worker_path,
749724
no_module_cache,
750-
// import_map_path,
751725
entrypoint,
752-
// decorator,
753726
} = self;
754727

755728
let (event_msg_tx, event_msg_rx) =
@@ -773,16 +746,15 @@ impl EventWorkerSurfaceBuilder {
773746
service_path,
774747
no_module_cache: no_module_cache.unwrap_or(flags.no_module_cache),
775748

776-
// import_map_path,
777749
env_vars: std::env::vars().collect(),
778750
timing: None,
779751
maybe_eszip,
780752
maybe_entrypoint: entrypoint,
781-
// maybe_decorator: decorator,
782753
maybe_module_code: None,
783754
conf: WorkerRuntimeOpts::EventsWorker(EventWorkerRuntimeOpts {
784755
events_msg_rx: Some(event_msg_rx),
785756
event_worker_exit_deadline_sec: Some(event_worker_exit_deadline_sec),
757+
context: None,
786758
}),
787759
static_patterns: vec![],
788760

0 commit comments

Comments
 (0)