diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-02-14 00:43:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 00:43:53 +0100 |
commit | bd6ddd9b469b01b3663bbd275b7b11f7ac6e1ec2 (patch) | |
tree | 653285454e444f17b00f000c2e6c5bb72015c260 /core/extensions.rs | |
parent | f917d2e2c10e0a94e564a9016217e7ce27c8bbee (diff) |
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 <crowlkats@toaxl.com>
Diffstat (limited to 'core/extensions.rs')
-rw-r--r-- | core/extensions.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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<Vec<ExtensionFileSource>>, esm_files: Option<Vec<ExtensionFileSource>>, + esm_entry_point: Option<&'static str>, ops: Option<Vec<OpDecl>>, opstate_fn: Option<Box<OpStateFn>>, middleware_fn: Option<Box<OpMiddlewareFn>>, @@ -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<Vec<OpDecl>> { // TODO(@AaronO): maybe make op registration idempotent @@ -158,6 +163,7 @@ impl Extension { pub struct ExtensionBuilder { js: Vec<ExtensionFileSource>, esm: Vec<ExtensionFileSource>, + esm_entry_point: Option<&'static str>, ops: Vec<OpDecl>, state: Option<Box<OpStateFn>>, middleware: Option<Box<OpMiddlewareFn>>, @@ -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<OpDecl>) -> &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(), |