diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-04-30 14:37:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-30 14:37:06 +0200 |
| commit | 46bfcbbaa84b4b715f3b829c9b4ac3b5154adfb6 (patch) | |
| tree | f856f4ccb96ac4c3eca4105985684885bf62d824 /cli/state.rs | |
| parent | 5f8c4d9b686efc10abe2abb7ba453020ecfe4814 (diff) | |
refactor(core): add "prepare_load" hook to ModuleLoader trait (#4866)
This PR adds prepare_load hook method to ModuleLoader trait. It allows implementors to perform preparation work before starting actual module loading into isolate. It's meant to be used in CLI; where "transpilation" step will be explicitly performed during prepare_load instead of doing it adhoc for each module if needed.
Diffstat (limited to 'cli/state.rs')
| -rw-r--r-- | cli/state.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/cli/state.rs b/cli/state.rs index 32c027c03..8003ea732 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -11,11 +11,13 @@ use crate::permissions::DenoPermissions; use crate::web_worker::WebWorkerHandle; use deno_core::Buf; use deno_core::ErrBox; +use deno_core::ModuleLoadId; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; use deno_core::Op; use deno_core::ZeroCopyBuf; use futures::future::FutureExt; +use futures::Future; use rand::rngs::StdRng; use rand::SeedableRng; use serde_json::Value; @@ -28,7 +30,6 @@ use std::rc::Rc; use std::str; use std::thread::JoinHandle; use std::time::Instant; - #[derive(Copy, Clone, Eq, PartialEq)] pub enum DebugType { /// Can be debugged, will wait for debugger when --inspect-brk given. @@ -309,6 +310,27 @@ impl ModuleLoader for State { fut.boxed_local() } + + fn prepare_load( + &self, + _load_id: ModuleLoadId, + _module_specifier: &ModuleSpecifier, + _maybe_referrer: Option<String>, + _is_dyn_import: bool, + ) -> Pin<Box<dyn Future<Output = Result<(), ErrBox>>>> { + // TODO(bartlomieju): + // 1. recursively: + // a) resolve specifier + // b) check permission if dynamic import + // c) fetch/download source code + // d) parse the source code and extract all import/exports (dependencies) + // e) add discovered deps and loop algorithm until no new dependencies + // are discovered + // 2. run through appropriate compiler giving it access only to + // discovered files + + async { Ok(()) }.boxed_local() + } } impl State { |
