From bd6ddd9b469b01b3663bbd275b7b11f7ac6e1ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 14 Feb 2023 00:43:53 +0100 Subject: feat(core): allow to specify entry point for snapshotted ES modules (#17771) This commit adds "ExtensionBuilder::esm_entry_point()" function that allows to specify which of the extension files should be treated as an entry point. If the entry point is not provided all modules are loaded and evaluated, but if it is provided then only the entry point is explicitly loaded and evaluated. Co-authored-by: Leo Kettmeir --- core/extensions.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/extensions.rs') diff --git a/core/extensions.rs b/core/extensions.rs index 16cca924d..e497b8003 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -43,6 +43,7 @@ impl OpDecl { pub struct Extension { js_files: Option>, esm_files: Option>, + esm_entry_point: Option<&'static str>, ops: Option>, opstate_fn: Option>, middleware_fn: Option>, @@ -100,6 +101,10 @@ impl Extension { } } + pub fn get_esm_entry_point(&self) -> Option<&'static str> { + self.esm_entry_point + } + /// Called at JsRuntime startup to initialize ops in the isolate. pub fn init_ops(&mut self) -> Option> { // TODO(@AaronO): maybe make op registration idempotent @@ -158,6 +163,7 @@ impl Extension { pub struct ExtensionBuilder { js: Vec, esm: Vec, + esm_entry_point: Option<&'static str>, ops: Vec, state: Option>, middleware: Option>, @@ -197,6 +203,11 @@ impl ExtensionBuilder { self } + pub fn esm_entry_point(&mut self, entry_point: &'static str) -> &mut Self { + self.esm_entry_point = Some(entry_point); + self + } + pub fn ops(&mut self, ops: Vec) -> &mut Self { self.ops.extend(ops); self @@ -234,6 +245,7 @@ impl ExtensionBuilder { Extension { js_files, esm_files, + esm_entry_point: self.esm_entry_point.take(), ops, opstate_fn: self.state.take(), middleware_fn: self.middleware.take(), -- cgit v1.2.3