mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
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.
This commit is contained in:
parent
5f8c4d9b68
commit
46bfcbbaa8
3 changed files with 150 additions and 13 deletions
24
cli/state.rs
24
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue